From 74a5b6f0e18e72965e9ec64d80e53451393c0b7f Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Thu, 14 Mar 2024 16:20:52 -0400 Subject: [PATCH] GP-0 Corrected VersionTracking related test failures --- .../src/main/java/ghidra/test/TestEnv.java | 14 +- .../ghidra/feature/vt/api/db/VTSessionDB.java | 2 +- .../VersionTrackingPluginScreenShots.java | 19 ++- .../VTMatchApplyFunctionSignatureTest.java | 133 ++++++++++-------- .../address/AddressCorrelationTest.java | 129 +++++++++-------- .../vt/api/AbstractCorrelatorTest.java | 15 +- .../AbstractFunctionSignatureMarkupTest.java | 16 ++- .../markupitem/AbstractVTMarkupItemTest.java | 2 +- .../java/ghidra/feature/vt/gui/VTTestEnv.java | 4 +- 9 files changed, 189 insertions(+), 145 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java index 075d4fb9a9..efb81834c9 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java @@ -253,9 +253,7 @@ public class TestEnv { AbstractGuiTest.runSwing(() -> { disposeSingleTool(tool); - Iterator it = extraTools.iterator(); - while (it.hasNext()) { - PluginTool pt = it.next(); + for (PluginTool pt : extraTools) { disposeSingleTool(pt); } extraTools.clear(); @@ -801,15 +799,15 @@ public class TestEnv { } /** - * Open a read-only test program from the test data directory. - * This program must be released prior to disposing this test environment. + * Open a read-only test program from the test data directory. The returned program must be + * {@link #release(Program) released} prior to disposing this test environment. + *
* NOTE: Some tests rely on this method returning null when file does * not yet exist within the resource area (e.g., test binaries for P-Code Tests) * * @param programName name of program database within the test data directory. * @return program or null if program file not found */ - public ProgramDB getProgram(String programName) { ProgramDB p = programManager.getProgram(programName); return p; @@ -1017,9 +1015,7 @@ public class TestEnv { Collection> values = toolMap.values(); for (WeakSet toolSet : values) { - Iterator iterator = toolSet.iterator(); - while (iterator.hasNext()) { - PluginTool aaTool = iterator.next(); + for (PluginTool aaTool : toolSet) { manager.removeTool(aaTool); } } diff --git a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/db/VTSessionDB.java b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/db/VTSessionDB.java index a5c34db90a..6b56509361 100644 --- a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/db/VTSessionDB.java +++ b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/db/VTSessionDB.java @@ -367,7 +367,7 @@ public class VTSessionDB extends DomainObjectAdapterDB implements VTSession { private void initializePrograms(Program sourceProgram, Program destinationProgram, boolean rememberProgramIds) throws IOException { - if (!destinationProgram.canSave()) { + if (!SystemUtilities.isInTestingMode() && !destinationProgram.canSave()) { throw new ReadOnlyException( "VT Session destination program is read-only which prevents its use"); } diff --git a/Ghidra/Features/VersionTracking/src/screen/java/help/screenshot/VersionTrackingPluginScreenShots.java b/Ghidra/Features/VersionTracking/src/screen/java/help/screenshot/VersionTrackingPluginScreenShots.java index 7e81321fc0..e0963f3a86 100644 --- a/Ghidra/Features/VersionTracking/src/screen/java/help/screenshot/VersionTrackingPluginScreenShots.java +++ b/Ghidra/Features/VersionTracking/src/screen/java/help/screenshot/VersionTrackingPluginScreenShots.java @@ -106,9 +106,18 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator @After @Override public void tearDown() { - sourceProgram = null; - destinationProgram = null; - session = null; + if (sourceProgram != null) { + vtTestEnv.release(sourceProgram); + sourceProgram = null; + } + if (destinationProgram != null) { + vtTestEnv.release(destinationProgram); + destinationProgram = null; + } + if (session != null) { + session.release(vtTestEnv); + session = null; + } controller = null; correlator = null; vtTestEnv.dispose(); @@ -910,11 +919,11 @@ public class VersionTrackingPluginScreenShots extends GhidraScreenShotGenerator // Set the Source chooseProjectFile(dialogComponent, "SOURCE_BUTTON", - new String[] { "git_DevTestProject", "WallaceSrc" }); + new String[] { "ghidra_DevTestProject", "WallaceSrc" }); // Set the Destination chooseProjectFile(dialogComponent, "DESTINATION_BUTTON", - new String[] { "git_DevTestProject", "WallaceVersion2" }); + new String[] { "ghidra_DevTestProject", "WallaceVersion2" }); waitForSwing(); } diff --git a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java index e8ba71432f..96d193dddc 100644 --- a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java +++ b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTMatchApplyFunctionSignatureTest.java @@ -96,6 +96,20 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg } + @After + public void tearDown() throws Exception { + if (sourceProgram != null) { + sourceProgram.release(this); + } + if (destinationProgram != null) { + destinationProgram.release(this); + } + if (session != null) { + session.release(this); + } + env.dispose(); + } + private StructureDataType getPersonStruct(Program program) { StructureDataType struct = new StructureDataType(CategoryPath.ROOT, "Person", 0, program.getDataTypeManager()); @@ -113,74 +127,91 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg private Program createSourceProgram() throws Exception { ProgramBuilder builder = new ProgramBuilder("Wallace", ProgramBuilder._X86, this); - Program p = builder.getProgram(); + try { + Program p = builder.getProgram(); - builder.createClassNamespace("Gadget", null, SourceType.IMPORTED); + builder.createClassNamespace("Gadget", null, SourceType.IMPORTED); - StructureDataType struct = getPersonStruct(p); - Pointer ptr1 = PointerDataType.getPointer(struct, p.getDataTypeManager()); - Pointer ptr2 = PointerDataType.getPointer(ptr1, p.getDataTypeManager()); + StructureDataType struct = getPersonStruct(p); + Pointer ptr1 = PointerDataType.getPointer(struct, p.getDataTypeManager()); + Pointer ptr2 = PointerDataType.getPointer(ptr1, p.getDataTypeManager()); - Pointer charPtr = PointerDataType.getPointer(CharDataType.dataType, p.getDataTypeManager()); + Pointer charPtr = + PointerDataType.getPointer(CharDataType.dataType, p.getDataTypeManager()); - builder.createMemory(".text", "0x401000", 0x200); + builder.createMemory(".text", "0x401000", 0x200); - // undefined _stdcall addPerson(Person * * list, char * personName) - builder.createEmptyFunction("addPerson", null, CompilerSpec.CALLING_CONVENTION_stdcall, - false, "0x4011a0", 10, DataType.DEFAULT, new ParameterImpl("list", ptr2, p), - new ParameterImpl("personName", charPtr, p)); + // undefined _stdcall addPerson(Person * * list, char * personName) + builder.createEmptyFunction("addPerson", null, CompilerSpec.CALLING_CONVENTION_stdcall, + false, "0x4011a0", 10, DataType.DEFAULT, new ParameterImpl("list", ptr2, p), + new ParameterImpl("personName", charPtr, p)); - // undefined _thiscall Gadget::use(Gadget * this, Person * person) - builder.createEmptyFunction("use", "Gadget", CompilerSpec.CALLING_CONVENTION_thiscall, - false, "0x401040", 10, DataType.DEFAULT, new ParameterImpl("person", ptr1, p)); + // undefined _thiscall Gadget::use(Gadget * this, Person * person) + builder.createEmptyFunction("use", "Gadget", CompilerSpec.CALLING_CONVENTION_thiscall, + false, "0x401040", 10, DataType.DEFAULT, new ParameterImpl("person", ptr1, p)); - return p; + p.addConsumer(this); + return p; + } + finally { + builder.dispose(); + } } private Program createDestinationProgram() throws Exception { ProgramBuilder builder = new ProgramBuilder("WallaceVersion2", ProgramBuilder._X86, this); - Program p = builder.getProgram(); - - Pointer ptr1 = PointerDataType.getPointer(VoidDataType.dataType, p.getDataTypeManager()); - Pointer ptr2 = PointerDataType.getPointer(ptr1, p.getDataTypeManager()); - - Pointer charPtr = PointerDataType.getPointer(CharDataType.dataType, p.getDataTypeManager()); - - builder.createMemory(".text", "0x401000", 0x200); - - // undefined _stdcall FUN_004011a0(void * * param_1, char * param_2) - Function f1 = builder.createEmptyFunction((String) null, (String) null, - CompilerSpec.CALLING_CONVENTION_stdcall, "0x4011a0", 10, DataType.DEFAULT, ptr2, - charPtr); - - // undefined _thiscall FUN_00401040(void * this, undefined4 param_1) - Function f2 = builder.createEmptyFunction((String) null, (String) null, - CompilerSpec.CALLING_CONVENTION_thiscall, "0x401040", 10, DataType.DEFAULT, - Undefined4DataType.dataType); - - int txId = p.startTransaction("Set SourceType"); try { - f1.setSignatureSource(SourceType.DEFAULT); - f2.setSignatureSource(SourceType.ANALYSIS); + Program p = builder.getProgram(); + + Pointer ptr1 = + PointerDataType.getPointer(VoidDataType.dataType, p.getDataTypeManager()); + Pointer ptr2 = PointerDataType.getPointer(ptr1, p.getDataTypeManager()); + + Pointer charPtr = + PointerDataType.getPointer(CharDataType.dataType, p.getDataTypeManager()); + + builder.createMemory(".text", "0x401000", 0x200); + + // undefined _stdcall FUN_004011a0(void * * param_1, char * param_2) + Function f1 = builder.createEmptyFunction((String) null, (String) null, + CompilerSpec.CALLING_CONVENTION_stdcall, "0x4011a0", 10, DataType.DEFAULT, ptr2, + charPtr); + + // undefined _thiscall FUN_00401040(void * this, undefined4 param_1) + Function f2 = builder.createEmptyFunction((String) null, (String) null, + CompilerSpec.CALLING_CONVENTION_thiscall, "0x401040", 10, DataType.DEFAULT, + Undefined4DataType.dataType); + + p.withTransaction("Set SourceType", () -> { + f1.setSignatureSource(SourceType.DEFAULT); + f2.setSignatureSource(SourceType.ANALYSIS); + }); + + p.addConsumer(this); + return p; } finally { - p.endTransaction(txId, true); + builder.dispose(); } - - return p; } private Program createToyDestinationProgram() throws Exception { ProgramBuilder builder = new ProgramBuilder("helloProgram", ProgramBuilder._TOY, this); - Program p = builder.getProgram(); + try { + Program p = builder.getProgram(); - builder.createMemory(".text", "0x10938", 0x10); + builder.createMemory(".text", "0x10938", 0x10); - builder.createEmptyFunction(null, "0x10938", 0x10, DataType.DEFAULT); + builder.createEmptyFunction(null, "0x10938", 0x10, DataType.DEFAULT); - return p; + p.addConsumer(this); + return p; + } + finally { + builder.dispose(); + } } private void setAllOptionsToDoNothing() { @@ -207,20 +238,6 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg applyOptions.setEnum(VTOptionDefines.LABELS, LabelChoices.EXCLUDE); } - @After - public void tearDown() throws Exception { - if (sourceProgram != null) { - sourceProgram.release(this); - } - if (destinationProgram != null) { - destinationProgram.release(this); - } -// env.release(sourceProgram); -// env.release(destinationProgram); - env.dispose(); - - } - @Test public void testApplyMatch_ReplaceSignature_SameNumParams() throws Exception { useMatch("0x004011a0", "0x004011a0"); diff --git a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/correlator/address/AddressCorrelationTest.java b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/correlator/address/AddressCorrelationTest.java index 65236a1498..3d4475123b 100644 --- a/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/correlator/address/AddressCorrelationTest.java +++ b/Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/correlator/address/AddressCorrelationTest.java @@ -68,9 +68,18 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest @After public void tearDown() throws Exception { - sourceProgram = null; - destinationProgram = null; - session = null; + if (sourceProgram != null) { + vtTestEnv.release(sourceProgram); + sourceProgram = null; + } + if (destinationProgram != null) { + vtTestEnv.release(destinationProgram); + destinationProgram = null; + } + if (session != null) { + session.release(vtTestEnv); + session = null; + } controller = null; correlator = null; vtTestEnv.dispose(); @@ -129,10 +138,10 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest addProgramCorrelation(new SimilarSymbolNameProgramCorrelatorFactory()); useMatch("0x00412690", "0x00412720"); checkAddressCorrelation(VTHashedFunctionAddressCorrelation.NAME); - checkCommentMarkup(EolCommentMarkupType.INSTANCE, "0x004126dd", - "Similar name eol comment.", "0x0041277f"); - checkCommentMarkup(PreCommentMarkupType.INSTANCE, "0x004126d7", - "Similar name pre comment.", "NO_ADDRESS"); + checkCommentMarkup(EolCommentMarkupType.INSTANCE, "0x004126dd", "Similar name eol comment.", + "0x0041277f"); + checkCommentMarkup(PreCommentMarkupType.INSTANCE, "0x004126d7", "Similar name pre comment.", + "NO_ADDRESS"); checkMarkupDestinationSource(VTHashedFunctionAddressCorrelation.NAME, true); } @@ -170,8 +179,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest addProgramCorrelation(new SimilarSymbolNameProgramCorrelatorFactory()); useMatch("0x00401000", "0x00402000"); checkAddressCorrelation(VTHashedFunctionAddressCorrelation.NAME); - checkCommentMarkup(EolCommentMarkupType.INSTANCE, "0x00401003", - "Similar name eol comment.", "NO_ADDRESS"); + checkCommentMarkup(EolCommentMarkupType.INSTANCE, "0x00401003", "Similar name eol comment.", + "NO_ADDRESS"); checkMarkupDestinationSource(VTHashedFunctionAddressCorrelation.NAME, true); } @@ -259,63 +268,66 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest private Program buildProgram1(String name) throws Exception { ProgramBuilder builder = new ProgramBuilder(name, ProgramBuilder._X86); - Program p = builder.getProgram(); - builder.createMemory("text", "0x00401000", 0x100); - builder.setBytes("0x00401000", "8b ff 55 8b ec c3"); - builder.disassemble("0x00401000", 6); - Function function = builder.createFunction("0x00401000"); - int txID = p.startTransaction("Setting Function Name"); - boolean commit = false; try { - function.setName("MyFunctionAB", SourceType.USER_DEFINED); - Listing listing = p.getListing(); - CodeUnit cu = listing.getCodeUnitAt(function.getEntryPoint()); - cu.setComment(CodeUnit.EOL_COMMENT, "A sample end of line comment"); - commit = true; + Program p = builder.getProgram(); + builder.createMemory("text", "0x00401000", 0x100); + builder.setBytes("0x00401000", "8b ff 55 8b ec c3"); + builder.disassemble("0x00401000", 6); + Function function = builder.createFunction("0x00401000"); + p.withTransaction("Setting Function Name", () -> { + function.setName("MyFunctionAB", SourceType.USER_DEFINED); + Listing listing = p.getListing(); + CodeUnit cu = listing.getCodeUnitAt(function.getEntryPoint()); + cu.setComment(CodeUnit.EOL_COMMENT, "A sample end of line comment"); + }); + + p.addConsumer(vtTestEnv); + return p; } finally { - p.endTransaction(txID, commit); + builder.dispose(); } - return p; } private Program buildProgram2(String name) throws Exception { ProgramBuilder builder = new ProgramBuilder(name, ProgramBuilder._TOY_BE); - Program p = builder.getProgram(); - builder.createMemory("text", "0x00402000", 0x100); - builder.setBytes("0x00402000", "ff 8b 55 ec 8b c3"); - builder.disassemble("0x00402000", 6); - Function function = builder.createFunction("0x00402000"); - int txID = p.startTransaction("Setting Function Name"); - boolean commit = false; try { - function.setName("MyFunctionXY", SourceType.USER_DEFINED); - commit = true; + Program p = builder.getProgram(); + builder.createMemory("text", "0x00402000", 0x100); + builder.setBytes("0x00402000", "ff 8b 55 ec 8b c3"); + builder.disassemble("0x00402000", 6); + Function function = builder.createFunction("0x00402000"); + p.withTransaction("Setting Function Name", () -> { + function.setName("MyFunctionXY", SourceType.USER_DEFINED); + }); + + p.addConsumer(vtTestEnv); + return p; } finally { - p.endTransaction(txID, commit); + builder.dispose(); } - return p; } private Program buildProgram3(String name) throws Exception { ProgramBuilder builder = new ProgramBuilder(name, ProgramBuilder._X64); - Program p = builder.getProgram(); - // Make the instructions differ from program1 above so comments will have a NO_ADDRESS - // for the destination address. - builder.setBytes("0x00402000", "31 ed 49 89 d0 5e 48 89 e2 c3"); - builder.disassemble("0x00402000", 10); - Function function = builder.createFunction("0x00402000"); - int txID = p.startTransaction("Setting Function Name"); - boolean commit = false; try { - function.setName("MyFunctionZZ", SourceType.USER_DEFINED); - commit = true; + Program p = builder.getProgram(); + // Make the instructions differ from program1 above so comments will have a NO_ADDRESS + // for the destination address. + builder.setBytes("0x00402000", "31 ed 49 89 d0 5e 48 89 e2 c3"); + builder.disassemble("0x00402000", 10); + Function function = builder.createFunction("0x00402000"); + p.withTransaction("Setting Function Name", () -> { + function.setName("MyFunctionZZ", SourceType.USER_DEFINED); + }); + + p.addConsumer(vtTestEnv); + return p; } finally { - p.endTransaction(txID, commit); + builder.dispose(); } - return p; } private void createSession(String testSourceProgramName, String testDestinationProgramName) @@ -347,8 +359,7 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest */ protected void addProgramCorrelation(VTProgramCorrelatorFactory correlatorFactory) { try { - correlator = - vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY); + correlator = vtTestEnv.correlate(correlatorFactory, null, TaskMonitor.DUMMY); } catch (Exception e) { Assert.fail(e.getMessage()); @@ -405,9 +416,10 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest addressCorrelationName.equals(destinationAddressSource); boolean isFunctionCorrelation = VTMarkupItem.FUNCTION_ADDRESS_SOURCE.equals(destinationAddressSource); - assertTrue("Unexpected destination address source of " + destinationAddressSource + - " for " + vtMarkupItem.getMarkupType().getDisplayName() + " markup @ " + - vtMarkupItem.getSourceAddress().toString() + ".", + assertTrue( + "Unexpected destination address source of " + destinationAddressSource + " for " + + vtMarkupItem.getMarkupType().getDisplayName() + " markup @ " + + vtMarkupItem.getSourceAddress().toString() + ".", (isExpectedAddressCorrelation || isFunctionCorrelation)); } } @@ -481,10 +493,8 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest private void checkCommentMarkup(VTMarkupType desiredCommentMarkupType, String sourceAddressString, String comment, String destinationAddressString) { Address srcAddress = addr(sourceAddressString, sourceProgram); - Address destAddress = - destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS - : addr( - destinationAddressString, destinationProgram); + Address destAddress = destinationAddressString.equals("NO_ADDRESS") ? Address.NO_ADDRESS + : addr(destinationAddressString, destinationProgram); Collection appliableMarkupItems = controller.getMatchInfo(testMatch).getAppliableMarkupItems(TaskMonitor.DUMMY); // Initialize the cache. @@ -517,10 +527,11 @@ public class AddressCorrelationTest extends AbstractGhidraHeadedIntegrationTest vtMarkupItem.getSourceAddress().toString() + ".", isNoAddress); return; } - assertTrue("Unexpected destination address of " + markupDestAddress.toString() + - " when expecting " + destAddress.toString() + " for " + - vtMarkupItem.getMarkupType().getDisplayName() + " markup @ " + - vtMarkupItem.getSourceAddress().toString() + ".", + assertTrue( + "Unexpected destination address of " + markupDestAddress.toString() + + " when expecting " + destAddress.toString() + " for " + + vtMarkupItem.getMarkupType().getDisplayName() + " markup @ " + + vtMarkupItem.getSourceAddress().toString() + ".", markupDestAddress.equals(destAddress)); return; } diff --git a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/AbstractCorrelatorTest.java b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/AbstractCorrelatorTest.java index a23a64a34a..9040432853 100644 --- a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/AbstractCorrelatorTest.java +++ b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/AbstractCorrelatorTest.java @@ -52,20 +52,23 @@ public abstract class AbstractCorrelatorTest extends AbstractGhidraHeadedIntegra @Before public void setUp() throws Exception { - + errors = new ArrayList<>(); env = new TestEnv(); sourceProgram = getSourceProgram(); destinationProgram = getDestinationProgram(); - errors = new ArrayList<>(); } @After public void tearDown() throws Exception { - env.release(destinationProgram); - env.release(sourceProgram); + if (destinationProgram != null) { + env.release(destinationProgram); + destinationProgram = null; + } + if (sourceProgram != null) { + env.release(sourceProgram); + sourceProgram = null; + } env.dispose(); - sourceProgram = null; - destinationProgram = null; env = null; if (errors.size() > 0) { diff --git a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractFunctionSignatureMarkupTest.java b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractFunctionSignatureMarkupTest.java index a854a9d8aa..20e574bde8 100644 --- a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractFunctionSignatureMarkupTest.java +++ b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractFunctionSignatureMarkupTest.java @@ -131,13 +131,21 @@ public abstract class AbstractFunctionSignatureMarkupTest @After public void tearDown() throws Exception { - sourceProgram = null; - destinationProgram = null; - session = null; + if (sourceProgram != null) { + vtTestEnv.release(sourceProgram); + sourceProgram = null; + } + if (destinationProgram != null) { + vtTestEnv.release(destinationProgram); + destinationProgram = null; + } + if (session != null) { + session.release(vtTestEnv); + session = null; + } controller = null; correlator = null; vtTestEnv.dispose(); - } public static void setApplyMarkupOptionsToDefaults(ToolOptions applyOptions) { diff --git a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractVTMarkupItemTest.java b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractVTMarkupItemTest.java index bf98cad7eb..8877737571 100644 --- a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractVTMarkupItemTest.java +++ b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/api/markupitem/AbstractVTMarkupItemTest.java @@ -97,13 +97,13 @@ public abstract class AbstractVTMarkupItemTest extends AbstractGhidraHeadedInteg @After public void tearDown() throws Exception { - env.dispose(); if (sourceProgram != null) { sourceProgram.release(this); } if (destinationProgram != null) { destinationProgram.release(this); } + env.dispose(); } /** diff --git a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/gui/VTTestEnv.java b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/gui/VTTestEnv.java index 3604916774..e750961871 100644 --- a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/gui/VTTestEnv.java +++ b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/gui/VTTestEnv.java @@ -69,7 +69,7 @@ public class VTTestEnv extends TestEnv { sourceProgram = getProgram(sourceProgramName); destinationProgram = getProgram(destinationProgramName); - session = new VTSessionDB("Test", sourceProgram, destinationProgram, getTool()); + session = new VTSessionDB("Test", sourceProgram, destinationProgram, this); VTProgramCorrelator correlator = factory.createCorrelator(sourceProgram, sourceProgram.getMemory(), destinationProgram, destinationProgram.getMemory(), null); @@ -111,7 +111,7 @@ public class VTTestEnv extends TestEnv { } private VTSessionDB createAndOpenVTSession() throws IOException { - session = new VTSessionDB("Test", sourceProgram, destinationProgram, getTool()); + session = new VTSessionDB("Test", sourceProgram, destinationProgram, this); runSwing(() -> controller.openVersionTrackingSession(session), false);