Ghidra is a software reverse engineering (SRE) framework
Test fixes for timing issue
dragonmacher3d0abddbff14
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.javaindex 8e7a4a308a..b2e058b09e 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java@@ -21,7 +21,6 @@ import java.awt.*;import java.awt.event.FocusListener;import java.awt.event.KeyEvent;import java.util.*;-import java.util.concurrent.atomic.AtomicBoolean;import javax.swing.*;import javax.swing.table.*;@@ -39,7 +38,6 @@ import docking.widgets.fieldpanel.support.FieldSelection;import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;import ghidra.app.plugin.core.datamgr.util.DataTypeChooserDialog;import ghidra.app.plugin.core.stackeditor.StackEditorModel;-import ghidra.app.plugin.core.stackeditor.StackFrameDataType;import ghidra.app.services.DataTypeManagerService;import ghidra.app.util.datatype.DataTypeSelectionEditor;import ghidra.framework.model.*;@@ -48,7 +46,6 @@ import ghidra.framework.plugintool.util.PluginException;import ghidra.program.database.ProgramBuilder;import ghidra.program.model.data.*;import ghidra.program.model.data.Composite;-import ghidra.program.model.data.Enum;import ghidra.program.model.listing.Program;import ghidra.test.AbstractGhidraHeadedIntegrationTest;import ghidra.test.TestEnv;@@ -155,9 +152,6 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationcloseAllWindows();- // this is an attempt to prevent stack traces when take down the environment out from- // under Swing-if (model != null) {model = null;}@@ -193,25 +187,6 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationreturn compositeDataType.getDisplayName() + " (" + dtmName + ")";}- @SuppressWarnings("unused")- private String getName(Composite composite) {- if (composite instanceof Structure) {- return "Structure Editor";- }- else if (composite instanceof Union) {- return "Union Editor";- }- else if (composite instanceof Enum) {- return "Enum Editor";- }- else if (composite instanceof StackFrameDataType) {- return "Stack Editor";- }- else {- return "Composite Data Type Editor";- }- }-protected CycleGroupAction getCycleGroup(DataType dt) {for (CycleGroupAction action : cycles) {CycleGroup group = action.getCycleGroup();@@ -272,7 +247,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration}private String arrayToString(int[] values) {- StringBuffer buf = new StringBuffer();+ StringBuilder buf = new StringBuilder();for (int value : values) {buf.append(Integer.toString(value) + ", ");}@@ -301,7 +276,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationif (componentProvider instanceof DataTypeChooserDialog) {// we must make a selectionObject treePanel = getInstanceField("treePanel", componentProvider);- final JTree tree = (JTree) getInstanceField("tree", treePanel);+ JTree tree = (JTree) getInstanceField("tree", treePanel);DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();DefaultMutableTreeNode matchingNode = findFirstLeafNode(root);TreePath treePath = (TreePath) invokeInstanceMethod("getTreePath", matchingNode);@@ -455,7 +430,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration/*** Types the indicated string- *+ ** <br>Note: Handles upper and lowercase alphabetic characters,* numeric characters, and other standard keyboard characters that are* printable characters. It also handles '\n', '\t', and '\b'.@@ -593,7 +568,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration@SuppressWarnings("unchecked")private void removeTableCellEditorsFocusLostListener() {- //+ //// Note: black magic code to disable focusLost from cancelling the current editor session//@@ -813,12 +788,11 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration}protected void checkEnablement(CompositeEditorTableAction action, boolean expectedEnablement) {- AtomicBoolean result = new AtomicBoolean();- runSwing(() -> result.set(action.isEnabledForContext(provider.getActionContext(null))));- boolean actionEnablement = result.get();- assertEquals(action.getName() + " is unexpectedly " +- (actionEnablement ? "enabled" : "disabled") + ".", expectedEnablement,- actionEnablement);+ boolean isEnabled =+ runSwing(() -> action.isEnabledForContext(provider.getActionContext(null)));+ assertEquals(+ action.getName() + " is unexpectedly " + (isEnabled ? "enabled" : "disabled") + ".",+ expectedEnablement, isEnabled);}protected void assertIsPackingEnabled(boolean aligned) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.javaindex 8d0abe4b6a..9c9b2b2963 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/AbstractStackEditorTest.java@@ -17,10 +17,12 @@ package ghidra.app.plugin.core.stackeditor;import static org.junit.Assert.*;-import javax.swing.*;+import javax.swing.JTable;+import javax.swing.JTextField;import javax.swing.event.ChangeEvent;-import org.junit.*;+import org.junit.After;+import org.junit.Before;import docking.action.DockingAction;import docking.action.DockingActionIf;@@ -36,6 +38,7 @@ import ghidra.program.model.data.*;import ghidra.program.model.listing.*;import ghidra.program.model.symbol.SourceType;import ghidra.program.util.ProgramLocation;+import ghidra.util.Swing;public abstract class AbstractStackEditorTest extends AbstractEditorTest {@@ -145,7 +148,7 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {Object editorPanel = getInstanceField("editorPanel", provider);final JTable table = (JTable) getInstanceField("table", editorPanel);runSwing(() -> table.editingCanceled(new ChangeEvent(table)));- waitForPostedSwingRunnables();// some editing notifications are in an invokeLater+ waitForSwing();// some editing notifications are in an invokeLater}@Override@@ -222,16 +225,16 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {finally {endTransaction(changed);}- if (provider != null) {- Assert.fail("Provider initialized more than once -- stop it!");- }++ assertNull("Provider initialized more than once", provider);+runSwing(() -> {installProvider(new StackEditorProvider(stackEditorMgr, stackFrame.getFunction()));assertNotNull(provider);model = ((StackEditorProvider) provider).getModel();});- waitForPostedSwingRunnables();-// assertTrue(!model.isLocked());++ waitForProgram(program);getActions();stackModel = (StackEditorModel) model;}@@ -247,9 +250,9 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {clearActions();Object editorPanel = getInstanceField("editorPanel", provider);- final JTable table = (JTable) getInstanceField("table", editorPanel);+ JTable table = (JTable) getInstanceField("table", editorPanel);runSwing(() -> table.editingCanceled(new ChangeEvent(table)));- waitForPostedSwingRunnables();// some editing notifications are in an invokeLater+ waitForSwing();// some editing notifications are in an invokeLaterrunSwing(() -> provider.dispose(), true);}@@ -365,7 +368,7 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {}void closeEditor() {- SwingUtilities.invokeLater(() -> provider.closeComponent());- waitForPostedSwingRunnables();+ Swing.runLater(() -> provider.closeComponent());+ waitForSwing();}}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorEnablementTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorEnablementTest.javaindex ea93174bab..8295ef297e 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorEnablementTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorEnablementTest.java@@ -48,8 +48,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {// Check enablement.for (CompositeEditorTableAction action : actions) {- if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction)) {+ if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction)) {checkEnablement(action, true);}else {@@ -79,8 +78,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {// Check enablement.for (CompositeEditorTableAction action : actions) {- if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction)) {+ if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction)) {checkEnablement(action, true);}else {@@ -125,8 +123,6 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {assertTrue(model.isValidName());// name should be validassertEquals(0, model.getNumSelectedComponentRows());assertEquals(0, model.getNumSelectedRows());-// assertTrue(!model.isLocked());-// assertTrue(!model.isLockable());assertEquals(function.getName(), stackModel.getCompositeName());assertEquals(stackModel.getTypeName(), "Stack");@@ -141,8 +137,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));checkEnablement(action, enabled);}- else if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) ||+ else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||(action instanceof ShowComponentPathAction) ||(action instanceof EditFieldAction) || (action instanceof ClearAction) ||(action instanceof DeleteAction) || (action instanceof ArrayAction) ||@@ -159,12 +154,9 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {numBytes = getModel().getMaxReplaceLength(5);for (CompositeEditorTableAction action : actions) {if (action instanceof FavoritesAction) {- FavoritesAction fav = (FavoritesAction) action;- DataType favDt = fav.getDataType();checkEnablement(action, true);}- else if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) ||+ else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||(action instanceof ShowComponentPathAction) ||(action instanceof EditFieldAction) || (action instanceof ClearAction) ||(action instanceof ArrayAction) || (action instanceof PointerAction)) {@@ -191,8 +183,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));checkEnablement(action, enabled);}- else if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) ||+ else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||(action instanceof ShowComponentPathAction) ||(action instanceof EditFieldAction) || (action instanceof ClearAction) ||(action instanceof DeleteAction) || (action instanceof ArrayAction) ||@@ -221,8 +212,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));checkEnablement(action, enabled);}- else if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) ||+ else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||(action instanceof ShowComponentPathAction) ||(action instanceof EditFieldAction) || (action instanceof ClearAction) ||(action instanceof ArrayAction) || (action instanceof PointerAction)) {@@ -249,8 +239,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));checkEnablement(action, enabled);}- else if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) ||+ else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||(action instanceof ShowComponentPathAction) ||(action instanceof EditFieldAction) || (action instanceof ClearAction) ||(action instanceof DeleteAction) || (action instanceof ArrayAction) ||@@ -270,9 +259,8 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {// Check enablement on a contiguous multi-component selection.runSwing(() -> model.setSelection(new int[] { 2, 3, 4 }));for (CompositeEditorTableAction action : actions) {- if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) || (action instanceof PointerAction) ||- (action instanceof ClearAction)) {+ if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||+ (action instanceof PointerAction) || (action instanceof ClearAction)) {checkEnablement(action, true);}else {@@ -288,8 +276,8 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {// Check enablement on a non-contiguous multi-component selection.runSwing(() -> model.setSelection(new int[] { 2, 3, 6, 7 }));for (CompositeEditorTableAction action : actions) {- if ((action instanceof CycleGroupAction) ||- (action instanceof HexNumbersAction) || (action instanceof ClearAction)) {+ if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||+ (action instanceof ClearAction)) {checkEnablement(action, true);}else {