Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fix for screenshot user name

dragonmacher7679fed7a253
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 3b579615d8..dff6866dee 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
-import org.junit.BeforeClass;
+import org.junit.AfterClass;
import docking.test.AbstractDockingTest;
import ghidra.GhidraTestApplicationLayout;
@@ -93,7 +93,7 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
System.setProperty(GhidraScriptConstants.USER_SCRIPTS_DIR_PROPERTY, getTestDirectoryPath());
}
- @BeforeClass
+ @AfterClass
public static void cleanDbTestDir() {
// keep files around in batch mode to allow tests to run faster; assume batch mode performs
// its own cleanup; only run once per class to allow subsequent tests to be faster
diff --git a/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java b/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java
index d60733089c..82801196a6 100644
--- a/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java
+++ b/Ghidra/Features/Base/src/main/java/help/screenshot/AbstractScreenShotGenerator.java
@@ -87,6 +87,8 @@ import resources.ResourceManager;
public abstract class AbstractScreenShotGenerator extends AbstractGhidraHeadedIntegrationTest {
+ private static final String SCREENSHOT_USER_NAME = "User-1";
+
static {
System.setProperty("user.name", "User-1");
}
@@ -122,6 +124,13 @@ public abstract class AbstractScreenShotGenerator extends AbstractGhidraHeadedIn
@Before
public void setUp() throws Exception {
+
+ // sanity check to ensure out user name override above is still working
+ String path = getTestDirectoryPath();
+ assertTrue("Seeing this failure means that some call has initialized the temporary test " +
+ "directory before out static call to change user.name above",
+ path.contains(SCREENSHOT_USER_NAME));
+
env = newTestEnv();
prepareTool();
diff --git a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGTest.java b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGTest.java
index c50652034e..a8ca9b9b8c 100644
--- a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGTest.java
+++ b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGTest.java
@@ -72,7 +72,8 @@ public abstract class AbstractGTest {
// 10x longer than normal
// private static final int PRIVATE_MAX_WAIT_TIMEOUT = DEFAULT_WAIT_TIMEOUT * 10;
- private static String testDirectoryPath = createTestDirectoryPath();
+ // let this get created lazily so that subclasses can change system state first
+ private static String testDirectoryPath; // = createTestDirectoryPath();
@Rule
public TestName testName = new TestName();
@@ -95,14 +96,11 @@ public abstract class AbstractGTest {
public TestRule ignoreUnfinishedRule = new IgnoreUnfinishedRule();
/**
- * Get the directory path within which all temporary test data files should be created.
- *
- * @return test directory path ending with a File.separator character
+ * Get the directory path within which all temporary test data files should be created. This
+ * method will only initialize the test directory path one time.
*/
- private static String createTestDirectoryPath() {
-
+ private static void initializeTestDirectoryPath() {
if (testDirectoryPath == null) {
-
//
// Build unique test data directory. Note that we can't make any calls which
// depend upon Application initialization, so we have to create directories using
@@ -123,8 +121,6 @@ public abstract class AbstractGTest {
}
System.out.println("Created test directory: " + testDir);
}
-
- return testDirectoryPath;
}
private static String buildBatchDirectoryPath() {
@@ -150,6 +146,7 @@ public abstract class AbstractGTest {
}
public static String getTestDirectoryPath() {
+ initializeTestDirectoryPath();
return testDirectoryPath;
}
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 b66df2a1cc..33d30ee520 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/TestApplicationUtils.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,6 @@ 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;
@@ -107,10 +106,6 @@ public class TestApplicationUtils {
}
// 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);