Ghidra is a software reverse engineering (SRE) framework
Tests - fixed timing issue; fixed Swing thread access issue
dragonmacher61af96034ed8
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.javaindex 1bba776d67..345b83e15a 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java@@ -477,12 +477,8 @@ public class BookmarkPluginTest extends AbstractGhidraHeadedIntegrationTest {waitForTable();selectAllTableRows();-runSwing(() -> provider.delete());-- waitForTable();-- assertEquals(0, table.getRowCount());+ waitForCondition(() -> table.getRowCount() == 0, "Bookmarks not deleted");}@Testdiff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/functioncompare/CompareFunctionsTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/functioncompare/CompareFunctionsTest.javaindex e52fc02f12..4e77e8ad6f 100644--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/functioncompare/CompareFunctionsTest.java+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/functioncompare/CompareFunctionsTest.java@@ -15,8 +15,7 @@*/package ghidra.app.plugin.core.functioncompare;-import static org.junit.Assert.assertNull;-import static org.junit.Assert.assertTrue;+import static org.junit.Assert.*;import java.util.Date;import java.util.Set;@@ -57,7 +56,7 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {private Function five;private FunctionComparisonPlugin plugin;private FunctionComparisonProvider provider;- private FunctionComparisonProvider provider0;+ private FunctionComparisonProvider provider2;private FunctionComparisonModel model;@Before@@ -70,23 +69,17 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {model = createTestModel();}- /**- *- * Tests for {@link FunctionComparisonService#compareFunctions(Set)}- *- */-@Testpublic void testSetNoFunctions() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet();- FunctionComparisonProvider provider = plugin.compareFunctions(functions);+ provider = compare(functions);assertNull(provider);}@Testpublic void testSetOneFunction() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo);}@@ -94,23 +87,23 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testSetDuplicateFunctionDifferentProviders() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo);- provider0 = plugin.compareFunctions(functions);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, foo);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, foo, foo);+ provider2 = compare(functions);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, foo);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, foo, foo);}@Testpublic void testSetDuplicateFunctionSameProvider() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo);- plugin.compareFunctions(functions, provider);+ compare(functions, provider);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo);}@@ -118,7 +111,7 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testSetMultipleFunctions() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, junk, stuff);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, junk, stuff);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, junk, stuff);CompareFunctionsTestUtility.checkTargetFunctions(provider, junk, foo, junk, stuff);@@ -130,16 +123,16 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {Set<Function> functions1 = CompareFunctionsTestUtility.getFunctionsAsSet(one, two);Set<Function> functions2 = CompareFunctionsTestUtility.getFunctionsAsSet(three, four, five);- provider = plugin.compareFunctions(functions1);- provider0 = plugin.compareFunctions(functions2);+ provider = compare(functions1);+ provider2 = compare(functions2);CompareFunctionsTestUtility.checkSourceFunctions(provider, one, two);CompareFunctionsTestUtility.checkTargetFunctions(provider, one, one, two);CompareFunctionsTestUtility.checkTargetFunctions(provider, two, one, two);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, three, four, five);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, three, three, four, five);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, four, three, four, five);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, five, three, four, five);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, three, four, five);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, three, three, four, five);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, four, three, four, five);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, five, three, four, five);}@Test@@ -147,8 +140,8 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {Set<Function> functions1 = CompareFunctionsTestUtility.getFunctionsAsSet(foo, two);Set<Function> functions2 = CompareFunctionsTestUtility.getFunctionsAsSet(bar, three, four);- provider = plugin.compareFunctions(functions1);- plugin.compareFunctions(functions2, provider);+ provider = compare(functions1);+ compare(functions2, provider);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, two, bar, three, four);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, two, bar, three, four);@@ -160,47 +153,35 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {four);}- /**- *- * Tests for {@link FunctionComparisonService#compareFunctions(Set, FunctionComparisonProvider)}- *- */-@Testpublic void testSetAddToSpecificProvider() throws Exception {Set<Function> functions1 = CompareFunctionsTestUtility.getFunctionsAsSet(foo, two);Set<Function> functions2 = CompareFunctionsTestUtility.getFunctionsAsSet(bar, three);Set<Function> functions3 = CompareFunctionsTestUtility.getFunctionsAsSet(four);- provider = plugin.compareFunctions(functions1);- provider0 = plugin.compareFunctions(functions2);+ provider = compare(functions1);+ provider2 = compare(functions2);- plugin.compareFunctions(functions3, provider0);+ compare(functions3, provider2);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, two);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, bar, three, four);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, bar, three, four);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, two);CompareFunctionsTestUtility.checkTargetFunctions(provider, two, foo, two);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, bar, bar, three, four);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, three, bar, three, four);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, four, bar, three, four);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, bar, bar, three, four);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, three, bar, three, four);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, four, bar, three, four);}- /**- *- * Tests for {@link FunctionComparisonService#removeFunction(Function)}- *- */-@Testpublic void testRemoveFunction() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, foo, bar);- plugin.removeFunction(foo);+ remove(foo);CompareFunctionsTestUtility.checkSourceFunctions(provider, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, bar);@@ -209,15 +190,17 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testRemoveFunctionTargetOnly() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);- provider = plugin.compareFunctions(functions);- plugin.compareFunctions(foo, two, provider); // add a target to foo, which is not also a source+ provider = compare(functions);++ // add a target to foo, which is not also a source+ runSwing(() -> plugin.compareFunctions(foo, two, provider));// Verify the structure with the new targetCompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, bar, two);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, foo, bar);- plugin.removeFunction(two);+ remove(two);// Verify the new target is goneCompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);@@ -228,85 +211,67 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testRemoveFunctionMultipleProviders() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);- provider = plugin.compareFunctions(functions);- provider0 = plugin.compareFunctions(functions);+ provider = compare(functions);+ provider2 = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, foo, bar);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, foo, bar);- plugin.removeFunction(foo);+ remove(foo);CompareFunctionsTestUtility.checkSourceFunctions(provider, bar);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, bar);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, bar);}@Testpublic void testRemoveNonexistentFunction() throws Exception {Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);- provider = plugin.compareFunctions(functions);+ provider = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, foo, bar);- plugin.removeFunction(two); // nothing should happen+ remove(two); // nothing should happenCompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, foo, bar);}- /**- *- * Tests for {@link FunctionComparisonService#removeFunction(Function, FunctionComparisonProvider)}- *- */-@Testpublic void testRemoveFunctionFromSpecificProvider() throws Exception {- Set<Function> functions1 = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);- provider = plugin.compareFunctions(functions1);- provider0 = plugin.compareFunctions(functions1);+ Set<Function> functions = CompareFunctionsTestUtility.getFunctionsAsSet(foo, bar);+ provider = compare(functions);+ provider2 = compare(functions);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, foo, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, foo, bar);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, foo, bar);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, foo, foo, bar);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, bar, foo, bar);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, foo, bar);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, foo, foo, bar);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, bar, foo, bar);- plugin.removeFunction(foo, provider);+ remove(foo, provider);CompareFunctionsTestUtility.checkSourceFunctions(provider, bar);CompareFunctionsTestUtility.checkTargetFunctions(provider, bar, bar);- CompareFunctionsTestUtility.checkSourceFunctions(provider0, foo, bar);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, foo, foo, bar);- CompareFunctionsTestUtility.checkTargetFunctions(provider0, bar, foo, bar);+ CompareFunctionsTestUtility.checkSourceFunctions(provider2, foo, bar);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, foo, foo, bar);+ CompareFunctionsTestUtility.checkTargetFunctions(provider2, bar, foo, bar);}- /**- *- * Tests for {@link FunctionComparisonService#compareFunctions(Function, Function)}- *- */-@Testpublic void testDualCompare() {- provider = plugin.compareFunctions(foo, bar);+ provider = compare(foo, bar);CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, bar);}- /**- *- * Tests for {@link FunctionComparisonService#compareFunctions(Function, Function, FunctionComparisonProvider)}- *- */-@Testpublic void testDualCompareAddToExisting() {- provider = plugin.compareFunctions(foo, bar);- plugin.compareFunctions(foo, two, provider);+ provider = compare(foo, bar);+ runSwing(() -> plugin.compareFunctions(foo, two, provider));CompareFunctionsTestUtility.checkSourceFunctions(provider, foo);CompareFunctionsTestUtility.checkTargetFunctions(provider, foo, bar, two);@@ -321,7 +286,7 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testGetTargets() {Set<Function> targets = model.getTargetFunctions();- assertTrue(targets.size() == 6);+ assertEquals(6, targets.size());assertTrue(targets.contains(bar));assertTrue(targets.contains(two));assertTrue(targets.contains(three));@@ -333,7 +298,7 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testGetTargetsForSource() {Set<Function> targets = model.getTargetFunctions(bar);- assertTrue(targets.size() == 3);+ assertEquals(3, targets.size());assertTrue(targets.contains(three));assertTrue(targets.contains(four));assertTrue(targets.contains(five));@@ -342,7 +307,7 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void getSources() {Set<Function> sources = model.getSourceFunctions();- assertTrue(sources.size() == 3);+ assertEquals(3, sources.size());assertTrue(sources.contains(foo));assertTrue(sources.contains(bar));assertTrue(sources.contains(junk));@@ -353,19 +318,39 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {model.removeFunction(bar);Set<Function> sources = model.getSourceFunctions();- assertTrue(sources.size() == 2);+ assertEquals(2, sources.size());assertTrue(sources.contains(foo));assertTrue(sources.contains(junk));Set<Function> targets = model.getTargetFunctions(foo);- assertTrue(targets.size() == 1);+ assertEquals(1, targets.size());assertTrue(targets.contains(two));targets = model.getTargetFunctions(junk);- assertTrue(targets.size() == 1);+ assertEquals(1, targets.size());assertTrue(targets.contains(stuff));}+ private void remove(Function f) {+ runSwing(() -> plugin.removeFunction(f));+ }++ private void remove(Function f, FunctionComparisonProvider fp) {+ runSwing(() -> plugin.removeFunction(f, fp));+ }++ private void compare(Set<Function> functions, FunctionComparisonProvider fp) {+ runSwing(() -> plugin.compareFunctions(functions, fp));+ }++ private FunctionComparisonProvider compare(Set<Function> functions) {+ return runSwing(() -> plugin.compareFunctions(functions));+ }++ private FunctionComparisonProvider compare(Function f1, Function f2) {+ return runSwing(() -> plugin.compareFunctions(f1, f2));+ }+private ProgramBuilder buildTestProgram1() throws Exception {ProgramBuilder builder = new ProgramBuilder("TestPgm1", ProgramBuilder._TOY_BE);builder.createMemory(".text", "0x1001000", 0x6600);@@ -404,26 +389,26 @@ public class CompareFunctionsTest extends AbstractGhidraHeadedIntegrationTest {}private FunctionComparisonModel createTestModel() {- FunctionComparisonModel model = new FunctionComparisonModel();+ FunctionComparisonModel newModel = new FunctionComparisonModel();FunctionComparison c1 = new FunctionComparison();c1.setSource(foo);c1.addTarget(bar);c1.addTarget(two);- model.addComparison(c1);+ newModel.addComparison(c1);FunctionComparison c2 = new FunctionComparison();c2.setSource(bar);c2.addTarget(three);c2.addTarget(four);c2.addTarget(five);- model.addComparison(c2);+ newModel.addComparison(c2);FunctionComparison c3 = new FunctionComparison();c3.setSource(junk);c3.addTarget(stuff);- model.addComparison(c3);+ newModel.addComparison(c3);- return model;+ return newModel;}}diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.javaindex 5e2ebfba7a..2f5ee8d530 100644--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java@@ -228,6 +228,18 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {"The Listing is not at the expected address");}+ @Override+ public void assertCurrentAddress(Address expected) {+ codeBrowser.updateNow();+ waitForSwing();++ waitForCondition(() -> {+ ProgramLocation loc = codeBrowser.getCurrentLocation();+ Address actual = loc.getAddress();+ return expected.equals(actual);+ }, "Listing is not at the expected address");+ }+private void assertExternalNavigationPerformed() {// going to the 'external linkage' means we went to the thunk function and not the// external programdiff --git a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.javaindex a1158054c7..4ce3cfa3eb 100644--- a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java+++ b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/filechooser/GhidraFileChooserTest.java@@ -1752,9 +1752,11 @@ public class GhidraFileChooserTest extends AbstractDockingTest {pressUp();selectFile(getListView(), 1);+ assertSelectedIndex(getListView(), 1);pressUp();selectFile(getListView(), 2);+ assertSelectedIndex(getListView(), 2);pressBack();assertSelectedIndex(getListView(), 1);@@ -1914,7 +1916,12 @@ public class GhidraFileChooserTest extends AbstractDockingTest {private void assertSelectedIndex(DirectoryList list, int expected) {int actual = runSwing(() -> list.getSelectedIndex());- assertEquals("Wrong list index selected", expected, actual);++ // debug code+ if (expected != actual) {+ waitForCondition(() -> expected == actual,+ "Wrong list index selected ");+ }}private void assertSelectedIndex(GTable table, int expected) {