Skip to content

Ghidra is a software reverse engineering (SRE) framework

Tests - added code for timing issue with incremental table models

dragonmacher7c45b684b5d4
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/disassembler/AutoTableDisassemblerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/disassembler/AutoTableDisassemblerTest.java
index ea62d98814..f8106aba1f 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/disassembler/AutoTableDisassemblerTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/disassembler/AutoTableDisassemblerTest.java
@@ -64,6 +64,17 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
private TestTaskListener taskListener = new TestTaskListener();
+ private AddressTableDialog dialog;
+ private JButton makeTable;
+ private JButton search;
+ private JButton disassemble;
+ private GTable table;
+ private JTextField viewOffset;
+ private JTextField offset;
+ private JTextField alignment;
+ private JCheckBox autoLabel;
+ private JCheckBox searchSelection;
+
@Before
public void setUp() throws Exception {
env = new TestEnv();
@@ -72,6 +83,20 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
plugin = env.getPlugin(AutoTableDisassemblerPlugin.class);
TaskUtilities.addTrackedTaskListener(taskListener);
+
+ performAction(searchAction);
+ dialog = waitForDialogComponent(AddressTableDialog.class);
+ makeTable = findButtonByText(dialog, "Make Table");
+ search = findButtonByText(dialog, "Search");
+ disassemble = findButtonByText(dialog, "Disassemble");
+ table = findComponent(dialog, GTable.class);
+
+ viewOffset = (JTextField) findComponentByName(dialog.getComponent(), "viewOffset");
+ offset = (JTextField) findComponentByName(dialog.getComponent(), "offset");
+ alignment = (JTextField) findComponentByName(dialog.getComponent(), "Alignment");
+ autoLabel = (JCheckBox) findAbstractButtonByText(dialog.getComponent(), "Auto Label");
+ searchSelection =
+ (JCheckBox) findAbstractButtonByText(dialog.getComponent(), "Search Selection");
}
@After
@@ -82,13 +107,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testBasicState() throws Exception {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton makeTable = findButtonByText(dialog, "Make Table");
- JButton search = findButtonByText(dialog, "Search");
- JButton disassemble = findButtonByText(dialog, "Disassemble");
- GTable table = findComponent(dialog, GTable.class);
-
// do the search
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
@@ -98,13 +116,13 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
"004038b0");
// select a result and make a table
- selectRow(table, 0, 0);
+ selectRow(0, 0);
assertTrue(makeTable.isEnabled());
assertTrue(disassemble.isEnabled());
waitFor(() -> pressButton(makeTable));
- select(table, "00401030");
- selectRow(table, 0, 0);
+ select("00401030");
+ selectRow(0, 0);
Symbol s = getUniqueSymbol(program, "AddrTable00401030");
assertNotNull(s);
@@ -129,7 +147,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
// make table at 00403870 - this one tests that the index does not go past the elements when the
// elements are valid index values (ie. the bytes pointed to by the table are values from 0 - len-1)
- select(table, "00403870");
+ select("00403870");
assertEnabled(makeTable, true);
assertEnabled(disassemble, true);
waitFor(() -> pressButton(makeTable));
@@ -160,7 +178,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
// make table selection for 004038b0
// this will test that index does not go past a table element when the table element occurs right after
// the table and the data is valid index values (0 - len-1)
- select(table, "004038b0");
+ select("004038b0");
assertEnabled(makeTable, true);
assertEnabled(disassemble, true);
waitFor(() -> pressButton(makeTable));
@@ -193,13 +211,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testMultiRowSelection() throws Exception {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton makeTable = findButtonByText(dialog, "Make Table");
- JButton search = findButtonByText(dialog, "Search");
- JButton disassemble = findButtonByText(dialog, "Disassemble");
- JTable table = findComponent(dialog, JTable.class);
-
// do the search
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
@@ -218,11 +229,11 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
// select a multiple results and make a table
assertEnabled(makeTable, false);
- selectRow(table, 0, 2);
+ selectRow(0, 2);
assertEnabled(makeTable, true);
assertEnabled(disassemble, true);
waitFor(() -> pressButton(makeTable));
- selectRow(table, 0, 2);
+ selectRow(0, 2);
assertEnabled(makeTable, true);
assertEnabled(disassemble, true);
@@ -273,16 +284,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testOffset() throws Exception {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton makeTable = findButtonByText(dialog, "Make Table");
- JButton search = findButtonByText(dialog, "Search");
- JButton disassemble = findButtonByText(dialog, "Disassemble");
- JTextField viewOffset =
- (JTextField) findComponentByName(dialog.getComponent(), "viewOffset");
- JTextField offset = (JTextField) findComponentByName(dialog.getComponent(), "offset");
- JTable table = findComponent(dialog, JTable.class);
-
// do the search
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
@@ -292,7 +293,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
"004038b0");
assertEnabled(makeTable, false);
- select(table, "004038b0");
+ select("004038b0");
assertEnabled(makeTable, true);
assertEnabled(disassemble, true);
@@ -301,7 +302,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
Listing l = program.getListing();
undo(program);
- select(table, "00402518");
+ select("00402518");
setText(offset, "4");
assertEnabled(makeTable, false);
assertEnabled(disassemble, false);
@@ -315,7 +316,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
waitFor(() -> pressButton(makeTable));
- select(table, "00402518");
+ select("00402518");
l = program.getListing();
Data d = l.getDataAt(addr("0x40251c"));
@@ -338,11 +339,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testAlignment() {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton search = findButtonByText(dialog, "Search");
- JTextField alignment = (JTextField) findComponentByName(dialog.getComponent(), "Alignment");
-
setText(alignment, "2");
assertEquals("2", alignment.getText());
@@ -365,15 +361,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testAutoLabelOff() throws Exception {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton makeTable = findButtonByText(dialog, "Make Table");
- JButton search = findButtonByText(dialog, "Search");
- JCheckBox autoLabel =
- (JCheckBox) findAbstractButtonByText(dialog.getComponent(), "Auto Label");
-
- JTable table = findComponent(dialog, JTable.class);
-
// do the search
pressButton(search);
waitForSwing();
@@ -385,7 +372,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
runSwing(() -> autoLabel.setSelected(false));
// select a result and make a table
- selectRow(table, 0, 0);
+ selectRow(0, 0);
waitFor(() -> pressButton(makeTable));
SymbolTable st = program.getSymbolTable();
@@ -410,12 +397,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testCodeSelection() {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton search = findButtonByText(dialog, "Search");
- final JCheckBox searchSelection =
- (JCheckBox) findAbstractButtonByText(dialog.getComponent(), "Search Selection");
-
// do the search
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
@@ -482,16 +463,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testOffsetFieldsEnabled() {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
-
- // make sure that the options are disabled by default
- JButton disassemble = findButtonByText(dialog, "Disassemble");
- JButton makeTable = findButtonByText(dialog, "Make Table");
- JCheckBox autoLabel =
- (JCheckBox) findAbstractButtonByText(dialog.getComponent(), "Auto Label");
- JTextField offset = (JTextField) findComponentByName(dialog.getComponent(), "offset");
-
Component[] offsetButtons = new Component[] { disassemble, makeTable };
Component[] infoFields = new Component[] { autoLabel, offset };
Component[] offsetPanelFields =
@@ -500,13 +471,11 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
checkOffsetFieldsEnabledState(offsetPanelFields, false);
// now search for data
- JButton search = findButtonByText(dialog, "Search");
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
waitForCondition(() -> !model.isBusy(), "Table model never finished");
// select a row
- JTable table = findComponent(dialog, JTable.class);
table.getSelectionModel().setSelectionInterval(0, 0);
// make sure the buttons are enabled
@@ -577,18 +546,12 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testSelectionNavigation() throws Exception {
- performAction(searchAction);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton search = findButtonByText(dialog, "Search");
-
// do the search
pressButton(search);
AutoTableDisassemblerModel model = plugin.getModel();
waitForModel(model);
assertEquals(8, model.getRowCount());
-
- GTable table = findComponent(dialog, GTable.class);
runSwing(() -> table.clearSelection());
int row = 0;
@@ -618,12 +581,6 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Test
public void testMakeSelection() throws Exception {
- performAction(searchAction, true);
- AddressTableDialog dialog = waitForDialogComponent(AddressTableDialog.class);
- JButton search = findButtonByText(dialog, "Search");
-
- // do the search
-
pressButton(search);
waitForSwing();
@@ -632,11 +589,10 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
assertEquals(8, model.getRowCount());
- JTable table = findComponent(dialog, JTable.class);
- select(table, "00401030", "004024ac", "00403870");
+ select("00401030", "004024ac", "00403870");
// make the selection
- JButton button = getActionButton("Make Selection", dialog);
+ JButton button = getActionButton("Make Selection");
assertNotNull(button);
pressButton(button);
@@ -668,12 +624,11 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
// Note: due to focus issues, we will call navigate directly
- GhidraTable table = (GhidraTable) gTable;
- runSwing(() -> table.navigate(row, 0));
+ runSwing(() -> ((GhidraTable) table).navigate(row, 0));
waitForSwing();
}
- private JButton getActionButton(String actionName, AddressTableDialog dialog) {
+ private JButton getActionButton(String actionName) {
Map<?, ?> actionMap = (Map<?, ?>) getInstanceField("actionMap", dialog);
Set<?> entrySet = actionMap.entrySet();
for (Object entry : entrySet) {
@@ -795,10 +750,10 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
}
}
- private void select(JTable table, String... addrs) {
+ private void select(String... addrs) {
List<Integer> rows = new ArrayList<>();
for (String addr : addrs) {
- rows.add(getRow(table, addr));
+ rows.add(getRow(addr));
}
ListSelectionModel model = table.getSelectionModel();
@@ -808,12 +763,12 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
}
}
- private void select(JTable table, String addr) {
- int row = getRow(table, addr);
- selectRow(table, row, row);
+ private void select(String addr) {
+ int row = getRow(addr);
+ selectRow(row, row);
}
- private int getRow(JTable table, String addr) {
+ private int getRow(String addr) {
int count = table.getRowCount();
for (int i = 0; i < count; i++) {
Object value = table.getValueAt(i, 0);
@@ -826,7 +781,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
return -1;// can't get here
}
- private void selectRow(final JTable table, final int rowStart, final int rowEnd) {
+ private void selectRow(final int rowStart, final int rowEnd) {
waitForSwing();
runSwing(() -> table.setRowSelectionInterval(rowStart, rowEnd));
}
@@ -842,7 +797,7 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
@Override
public void taskRemoved(Task task) {
- //
+ // don't care
}
void reset() {
@@ -852,6 +807,5 @@ public class AutoTableDisassemblerTest extends AbstractGhidraHeadedIntegrationTe
boolean started() {
return started.get() > 0;
}
-
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java
index 66ade1485d..fa9ab2bcbe 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/test/AbstractDockingTest.java
@@ -15,7 +15,8 @@
*/
package docking.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import java.awt.*;
import java.awt.datatransfer.*;
@@ -54,7 +55,8 @@ import generic.util.image.ImageUtils;
import ghidra.GhidraTestApplicationLayout;
import ghidra.framework.ApplicationConfiguration;
import ghidra.util.*;
-import ghidra.util.exception.*;
+import ghidra.util.exception.AssertException;
+import ghidra.util.exception.CancelledException;
import ghidra.util.task.SwingUpdateManager;
import ghidra.util.task.TaskMonitor;
import ghidra.util.worker.Worker;
@@ -220,7 +222,11 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
}
/**
- *
+ * Deprecated
+ * @param parentWindow
+ * @param text
+ * @param timeoutMS
+ * @return window
* @deprecated Instead call one of the methods that does not take a timeout
* (we are standardizing timeouts). The timeouts passed to this method will
* be ignored in favor of the standard value.
@@ -304,10 +310,9 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
}
/**
- * Waits for a window with the given name.
+ * Waits for a window with the given name
*
* @param title The title of the window for which to search
- * @param timeoutMS The timeout after which this method will wait no more
* @return The window, if found, null otherwise.
*/
public static Window waitForWindow(String title) {
@@ -477,8 +482,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
/**
* A convenience method to close all of the windows and frames that the current Java
- * windowing environment knows about.
- * @return true if any windows were closed
+ * windowing environment knows about
* @deprecated instead call the new {@link #closeAllWindows()}
*/
@Deprecated
@@ -488,8 +492,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
/**
* A convenience method to close all of the windows and frames that the current Java
- * windowing environment knows about.
- * @return true if any windows were closed
+ * windowing environment knows about
*/
public static void closeAllWindows() {
closeAllWindows(false);
@@ -987,7 +990,6 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
*
* @param provider the DialogComponentProvider containing the button.
* @param buttonText the text on the desired JButton.
- * @throws UsrException if the button isn't found.
*/
public static void pressButtonByText(DialogComponentProvider provider, String buttonText) {
pressButtonByText(provider.getComponent(), buttonText, true);
@@ -1001,7 +1003,6 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param buttonText the text on the desired JButton.
* @param waitForCompletion if true wait for action to complete before returning,
* otherwise schedule action to be performed and return immediately.
- * @throws UsrException if the button isn't found.
*/
public static void pressButtonByText(DialogComponentProvider provider, String buttonText,
boolean waitForCompletion) {
@@ -1057,6 +1058,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* <li>{@link JRadioButton}</li>
* <li>{@link EmptyBorderToggleButton}</li>
* </ul>
+ * @param button the button to select
* @param selected true to toggle the button to selected; false for de-selected
*/
public static void setToggleButtonSelected(AbstractButton button, boolean selected) {
@@ -1232,7 +1234,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param action action to be performed
* @param provider the component provider from which to get action context; if null,
* then an empty context will used
- * @param waitForCompletion if true wait for action to complete before returning,
+ * @param wait if true wait for action to complete before returning,
* otherwise schedule action to be performed and return immediately.
*/
public static void performAction(DockingActionIf action, ComponentProvider provider,
@@ -1387,7 +1389,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* This method should used for the special keyboard keys
* (ARROW, F1, END, etc) and alpha keys when associated with actions.
*
- * @param destination the component that should be the receiver of the key event; the event source
+ * @param c the component that should be the receiver of the key event; the event source
* @param modifiers the modifier keys down during event (shift, ctrl, alt, meta)
* Either extended _DOWN_MASK or old _MASK modifiers
* should be used, but both models should not be mixed
@@ -1413,8 +1415,9 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
}
/**
- * Simulates a user initiated keystroke using the keybinding of the given action.
- *
+ * Simulates a user initiated keystroke using the keybinding of the given action
+ *
+ * @param destination the action's destination component
* @param action The action to simulate pressing.
*/
public static void triggerActionKey(Component destination, DockingActionIf action) {
@@ -1449,7 +1452,10 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
triggerText(c, "\010");
}
- /** Simulates the user pressing the 'Enter' key on the given text field */
+ /**
+ * Simulates the user pressing the 'Enter' key on the given text field
+ * @param tf the text field
+ */
public static void triggerEnter(JTextField tf) {
// text components will not perform built-in actions if they are not focused
triggerFocusGained(tf);
@@ -1948,6 +1954,11 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
private static <T> void doWaitForTableModel(ThreadedTableModel<T, ?> model) {
+ // Always wait for Swing at least once. There seems to be a race condition for
+ // incremental threaded models where the table is not busy at the time this method
+ // is called, but there is an update pending via an invokeLater().
+ waitForSwing();
+
boolean didWait = false;
int waitTime = 0;
while (model.isBusy()) {
@@ -2150,7 +2161,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
*
* @param c the component
* @return the new image
- * @throws Exception if there is a problem creating the image
+ * @throws AWTException if there is a problem creating the image
*/
public static Image createScreenImage(Component c) throws AWTException {
@@ -2199,7 +2210,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
*
* @param image the image
* @param imageFile the file
- * @throws Exception if there is any issue writing the image
+ * @throws IOException if there is any issue writing the image
*/
public static void writeImage(Image image, File imageFile) throws IOException {
ImageUtils.writeFile(image, imageFile);