mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-3003 - Testing - updated framework test code to work in user
installation with Eclipse
This commit is contained in:
parent
66f49b210a
commit
730acdcd24
2 changed files with 98 additions and 19 deletions
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.test;
|
package ghidra.test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -55,7 +55,7 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
|
||||||
public static final String PROJECT_NAME = createProjectName();
|
public static final String PROJECT_NAME = createProjectName();
|
||||||
|
|
||||||
private static String createProjectName() {
|
private static String createProjectName() {
|
||||||
File repoDirectory = TestApplicationUtils.getRepoContainerDirectory();
|
File repoDirectory = TestApplicationUtils.getInstallationDirectory();
|
||||||
return repoDirectory.getName() + PROJECT_NAME_SUFFIX;
|
return repoDirectory.getName() + PROJECT_NAME_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,23 @@
|
||||||
package ghidra.framework;
|
package ghidra.framework;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import ghidra.util.Msg;
|
||||||
|
import ghidra.util.SystemUtilities;
|
||||||
|
import ghidra.util.exception.AssertException;
|
||||||
|
import utilities.util.FileUtilities;
|
||||||
import utility.module.ModuleUtilities;
|
import utility.module.ModuleUtilities;
|
||||||
|
|
||||||
public class TestApplicationUtils {
|
public class TestApplicationUtils {
|
||||||
|
|
||||||
public static File getTestApplicationRootDirectory() {
|
/**
|
||||||
// returns the application root used for testing; called before Application.initialize()
|
* Returns the directory that contains the source code repository
|
||||||
File repo = getCurrentRepoDirectory();
|
* @return the directory that contains the source code repository
|
||||||
return new File(repo, "Ghidra");
|
*/
|
||||||
}
|
private static File getCurrentRepoDirectory() {
|
||||||
|
|
||||||
public static File getCurrentRepoDirectory() {
|
|
||||||
// Assumption: the user is running tests from within a repo sub-project
|
// Assumption: the user is running tests from within a repo sub-project
|
||||||
//
|
//
|
||||||
// At the time writing "user.dir" is the "Ghidra" directory.
|
// At the time writing "user.dir" is the "Ghidra" directory.
|
||||||
|
@ -39,31 +44,105 @@ public class TestApplicationUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a directory that contains all repos for a given git clone. This
|
* Returns a directory that contains all repos for a given git clone. This directory name
|
||||||
* directory name is unique to the active clone collection, which makes it
|
* is unique to the active clone collection, which makes it useful for creating unique
|
||||||
* useful for creating unique temporary directories to allow multiple
|
* temporary directories to allow multiple simultaneous test runs.
|
||||||
* simultaneous test runs.
|
|
||||||
*
|
*
|
||||||
* @return the parent dir of the current repo
|
* @return the parent dir of the current repo
|
||||||
*/
|
*/
|
||||||
public static File getRepoContainerDirectory() {
|
private static File getRepoContainerDirectory() {
|
||||||
File repo = getCurrentRepoDirectory();
|
File repo = getCurrentRepoDirectory();
|
||||||
|
if (repo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
File repoContainer = repo.getParentFile();
|
File repoContainer = repo.getParentFile();
|
||||||
return repoContainer;
|
return repoContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a folder that is unique for the current repo. This allows clients
|
* Returns the directory containing the installation of this application. The value returned
|
||||||
* to have multiple clones on their machine, running tests from each repo
|
* here will either be an actual installation directory or the parent directory of a cloned
|
||||||
* simultaneously.
|
* repository. This method will work in the various modes of operation, including:
|
||||||
|
* <ul>
|
||||||
|
* <li><u>Development Mode</u> - running from a repo clone, from inside of an IDE or the
|
||||||
|
* command-line. In this mode a sample directory structure is:
|
||||||
|
* <pre>
|
||||||
|
* /.../git_repos/ghidra_clone/ghidra/Ghidra/Features/Base/src/...
|
||||||
*
|
*
|
||||||
* @return a folder that is unique for the current repo.
|
* which means this method will return 'ghidra_clone'
|
||||||
|
* </pre>
|
||||||
|
* </li>
|
||||||
|
* <li><u>Batch Testing Mode</u> - running from a test server, but not from inside a
|
||||||
|
* complete build. This mode uses jar files for the compiled source code, but is running
|
||||||
|
* from within the structure of a cloned repo. In this mode a sample directory structure is:
|
||||||
|
* <pre>
|
||||||
|
* /.../git_repos/ghidra_clone/ghidra/Ghidra/Features/Base/src/...
|
||||||
|
*
|
||||||
|
* which means this method will return 'ghidra_clone'
|
||||||
|
* </pre>
|
||||||
|
* </li>
|
||||||
|
* <li><u>Eclipse Release Development Mode</u> - running from a full application release.
|
||||||
|
* This mode uses jar files from the installation for dependencies. The user test files
|
||||||
|
* are run from within an Eclipse that has been linked with the application installation.
|
||||||
|
* In this mode a sample directory structure is:
|
||||||
|
* <pre>
|
||||||
|
* /.../Software/ghidra_10.0/Ghidra/Features/Base/lib/Base.jar
|
||||||
|
*
|
||||||
|
* which means this method will return 'ghidra_10.0'
|
||||||
|
* </pre>
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return the installation directory
|
||||||
|
*/
|
||||||
|
public static File getInstallationDirectory() {
|
||||||
|
|
||||||
|
File repo = getCurrentRepoDirectory();
|
||||||
|
if (repo != null) {
|
||||||
|
// development mode: either user-level or test machine
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assumption - in an installation the current user dir is /.../<Ghidra Install Dir>/Ghidra
|
||||||
|
|
||||||
|
String currentDir = System.getProperty("user.dir");
|
||||||
|
Msg.debug(null, "user.dir: " + currentDir);
|
||||||
|
|
||||||
|
// Assume that core library files are bundled in a jar file. Find the installation
|
||||||
|
// directory by using the distributed jar file.
|
||||||
|
File jarFile = SystemUtilities.getSourceLocationForClass(SystemUtilities.class);
|
||||||
|
if (jarFile == null || !jarFile.getName().endsWith(".jar")) {
|
||||||
|
throw new AssertException("Unable to determine the installation directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assumption - jar file location follows this form:
|
||||||
|
// <Installation Dir>/App Name/Module Group/Module Name/lib/file.jar
|
||||||
|
List<String> parts = FileUtilities.pathToParts(jarFile.getAbsolutePath());
|
||||||
|
int last = parts.size() - 1;
|
||||||
|
int installDir = last - 5; // 5 folders above the filename (see above)
|
||||||
|
|
||||||
|
String path = StringUtils.join(parts.subList(0, installDir + 1), File.separator);
|
||||||
|
return new File(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a folder that is unique for the current installation. This allows clients to
|
||||||
|
* have multiple clones (for development mode) or multiple installations (for release mode)
|
||||||
|
* on their machine, running tests from each repo simultaneously.
|
||||||
|
*
|
||||||
|
* @return a folder that is unique for the current installation
|
||||||
*/
|
*/
|
||||||
public static File getUniqueTempFolder() {
|
public static File getUniqueTempFolder() {
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a unique name based upon the repo from which we are running.
|
// Create a unique name based upon the repo from which we are running.
|
||||||
//
|
//
|
||||||
File reposContainer = TestApplicationUtils.getRepoContainerDirectory();
|
File reposContainer = getRepoContainerDirectory();
|
||||||
|
if (reposContainer == null) {
|
||||||
|
File installDir = getInstallationDirectory();
|
||||||
|
reposContainer = installDir;
|
||||||
|
}
|
||||||
|
|
||||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
String tempName = tmpDir.getName();
|
String tempName = tmpDir.getName();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue