From 730acdcd245d323849c18a1e6102bb2ff04fc846 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Thu, 18 Jul 2019 18:45:58 -0400 Subject: [PATCH] GT-3003 - Testing - updated framework test code to work in user installation with Eclipse --- ...AbstractGhidraHeadlessIntegrationTest.java | 4 +- .../framework/TestApplicationUtils.java | 113 +++++++++++++++--- 2 files changed, 98 insertions(+), 19 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java index 3a73e21c7a..aee8eb938b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java @@ -15,7 +15,7 @@ */ package ghidra.test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.IOException; @@ -55,7 +55,7 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock public static final String PROJECT_NAME = createProjectName(); private static String createProjectName() { - File repoDirectory = TestApplicationUtils.getRepoContainerDirectory(); + File repoDirectory = TestApplicationUtils.getInstallationDirectory(); return repoDirectory.getName() + PROJECT_NAME_SUFFIX; } diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java index 13410872f6..755f5b5b07 100644 --- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java +++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java @@ -16,18 +16,23 @@ package ghidra.framework; 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; public class TestApplicationUtils { - public static File getTestApplicationRootDirectory() { - // returns the application root used for testing; called before Application.initialize() - File repo = getCurrentRepoDirectory(); - return new File(repo, "Ghidra"); - } - - public static File getCurrentRepoDirectory() { + /** + * Returns the directory that contains the source code repository + * @return the directory that contains the source code repository + */ + private static File getCurrentRepoDirectory() { // Assumption: the user is running tests from within a repo sub-project // // 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 - * directory name is unique to the active clone collection, which makes it - * useful for creating unique temporary directories to allow multiple - * simultaneous test runs. + * Returns a directory that contains all repos for a given git clone. This directory name + * is unique to the active clone collection, which makes it useful for creating unique + * temporary directories to allow multiple simultaneous test runs. * * @return the parent dir of the current repo */ - public static File getRepoContainerDirectory() { + private static File getRepoContainerDirectory() { File repo = getCurrentRepoDirectory(); + if (repo == null) { + return null; + } File repoContainer = repo.getParentFile(); return repoContainer; } /** - * Creates a folder that is unique for the current repo. This allows clients - * to have multiple clones on their machine, running tests from each repo - * simultaneously. + * Returns the directory containing the installation of this application. The value returned + * here will either be an actual installation directory or the parent directory of a cloned + * repository. This method will work in the various modes of operation, including: + *
+ * /.../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' + *+ *
+ * /.../git_repos/ghidra_clone/ghidra/Ghidra/Features/Base/src/... + * + * which means this method will return 'ghidra_clone' + *+ *
+ * /.../Software/ghidra_10.0/Ghidra/Features/Base/lib/Base.jar + * + * which means this method will return 'ghidra_10.0' + *+ *