Merge remote-tracking branch 'origin/GP-0_Dan_testFixes20211201-3' into Ghidra_10.1

This commit is contained in:
Ryan Kurtz
2021-12-01 13:01:09 -05:00

View File

@@ -26,6 +26,8 @@ import org.junit.Test;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import docking.ActionContext;
import docking.action.DockingActionIf;
import generic.Unique; import generic.Unique;
import ghidra.app.plugin.core.debug.gui.AbstractGhidraHeadedDebuggerGUITest; import ghidra.app.plugin.core.debug.gui.AbstractGhidraHeadedDebuggerGUITest;
import ghidra.app.plugin.core.debug.gui.action.AutoReadMemorySpec; import ghidra.app.plugin.core.debug.gui.action.AutoReadMemorySpec;
@@ -67,29 +69,39 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
listingProvider = waitForComponentProvider(DebuggerListingProvider.class); listingProvider = waitForComponentProvider(DebuggerListingProvider.class);
} }
protected void selectAndFocus(Address min, Address max) { protected void select(Address min, Address max) {
selectAndFocus(new ProgramSelection(min, max)); select(new ProgramSelection(min, max));
} }
protected void selectAndFocus(AddressSetView set) { protected void select(AddressSetView set) {
selectAndFocus(new ProgramSelection(set)); select(new ProgramSelection(set));
} }
protected void selectAndFocus(ProgramSelection sel) { protected void select(ProgramSelection sel) {
runSwing(() -> { runSwing(() -> {
listingProvider.requestFocus();
listingProvider.setSelection(sel); listingProvider.setSelection(sel);
}); });
} }
protected void assertDisabled(DockingActionIf action) {
ActionContext context = listingProvider.getActionContext(null);
assertFalse(action.isEnabledForContext(context));
}
protected void performEnabledAction(DockingActionIf action) {
ActionContext context = listingProvider.getActionContext(null);
waitForCondition(() -> action.isEnabledForContext(context));
performAction(action, context, false);
}
@Test @Test
public void testActionCopyIntoCurrentProgramWithoutRelocationCreateBlocks() throws Exception { public void testActionCopyIntoCurrentProgramWithoutRelocationCreateBlocks() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
createProgram(); createProgram();
AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace(); AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace();
programManager.openProgram(program); programManager.openProgram(program);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
createAndOpenTrace(); createAndOpenTrace();
try (UndoableTransaction tid = tb.startTransaction()) { try (UndoableTransaction tid = tb.startTransaction()) {
@@ -98,12 +110,11 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE); TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
} }
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
selectAndFocus(tb.addr(0x00400000), tb.addr(0x0040ffff)); select(tb.addr(0x00400000), tb.addr(0x0040ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoCurrentProgram);
performAction(copyActionsPlugin.actionCopyIntoCurrentProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
dialog.setRelocate(false); dialog.setRelocate(false);
@@ -126,11 +137,11 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoCurrentProgramWithoutRelocationCrossLanguage() throws Exception { public void testActionCopyIntoCurrentProgramWithoutRelocationCrossLanguage() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
createProgram(getSLEIGH_X86_LANGUAGE()); createProgram(getSLEIGH_X86_LANGUAGE());
createAndOpenTrace(ToyProgramBuilder._X64); createAndOpenTrace(ToyProgramBuilder._X64);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace(); AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace();
@@ -161,15 +172,14 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
programManager.openProgram(program); programManager.openProgram(program);
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
selectAndFocus(tb.set( select(tb.set(
tb.range(0x00400000, 0x0040ffff), tb.range(0x00400000, 0x0040ffff),
tb.range(0x7fff00400000L, 0x7fff0040ffffL), tb.range(0x7fff00400000L, 0x7fff0040ffffL),
tb.range(0xfffff000L, 0x100000fffL))); tb.range(0xfffff000L, 0x100000fffL)));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoCurrentProgram);
performAction(copyActionsPlugin.actionCopyIntoCurrentProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
dialog.setRelocate(false); dialog.setRelocate(false);
@@ -211,7 +221,7 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoCurrentProgramWithRelocationExistingBlocks() throws Exception { public void testActionCopyIntoCurrentProgramWithRelocationExistingBlocks() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
createAndOpenTrace(); createAndOpenTrace();
createProgramFromTrace(); createProgramFromTrace();
@@ -224,10 +234,10 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE); TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
} }
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
programManager.openProgram(program); programManager.openProgram(program);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace(); AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace();
MemoryBlock block; MemoryBlock block;
@@ -248,10 +258,9 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
.getOpenMappedViews(tb.trace, tb.set(tb.range(0x55550000, 0x5555ffff)), 0) .getOpenMappedViews(tb.trace, tb.set(tb.range(0x55550000, 0x5555ffff)), 0)
.get(program)); .get(program));
selectAndFocus(tb.addr(0x55550000), tb.addr(0x5555ffff)); select(tb.addr(0x55550000), tb.addr(0x5555ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoCurrentProgram);
performAction(copyActionsPlugin.actionCopyIntoCurrentProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
dialog.setRelocate(true); dialog.setRelocate(true);
@@ -274,7 +283,7 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoCurrentProgramWithRelocationOverlayBlocks() throws Exception { public void testActionCopyIntoCurrentProgramWithRelocationOverlayBlocks() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
createAndOpenTrace(); createAndOpenTrace();
createProgramFromTrace(); createProgramFromTrace();
@@ -287,10 +296,10 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE); TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
} }
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
programManager.openProgram(program); programManager.openProgram(program);
assertFalse(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoCurrentProgram);
AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace(); AddressSpace stSpace = program.getAddressFactory().getDefaultAddressSpace();
MemoryBlock block; MemoryBlock block;
@@ -311,10 +320,9 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
.getOpenMappedViews(tb.trace, tb.set(tb.range(0x55550000, 0x5555ffff)), 0) .getOpenMappedViews(tb.trace, tb.set(tb.range(0x55550000, 0x5555ffff)), 0)
.get(program)); .get(program));
selectAndFocus(tb.addr(0x55550000), tb.addr(0x5555ffff)); select(tb.addr(0x55550000), tb.addr(0x5555ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoCurrentProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoCurrentProgram);
performAction(copyActionsPlugin.actionCopyIntoCurrentProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
dialog.setRelocate(true); dialog.setRelocate(true);
@@ -340,7 +348,7 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoNewProgram() throws Exception { public void testActionCopyIntoNewProgram() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
createAndOpenTrace(); createAndOpenTrace();
@@ -350,12 +358,11 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE); TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
} }
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
selectAndFocus(tb.addr(0x55550000), tb.addr(0x5555ffff)); select(tb.addr(0x55550000), tb.addr(0x5555ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoNewProgram);
performAction(copyActionsPlugin.actionCopyIntoNewProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
dialog.setDestination(DebuggerCopyIntoProgramDialog.TEMP_PROGRAM); dialog.setDestination(DebuggerCopyIntoProgramDialog.TEMP_PROGRAM);
@@ -383,7 +390,7 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoNewProgramAdjacentRegions() throws Exception { public void testActionCopyIntoNewProgramAdjacentRegions() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
createAndOpenTrace(); createAndOpenTrace();
@@ -396,12 +403,11 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
TraceMemoryFlag.READ, TraceMemoryFlag.WRITE); TraceMemoryFlag.READ, TraceMemoryFlag.WRITE);
} }
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
selectAndFocus(tb.addr(0x55550000), tb.addr(0x5556ffff)); select(tb.addr(0x55550000), tb.addr(0x5556ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoNewProgram);
performAction(copyActionsPlugin.actionCopyIntoNewProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
assertFalse(dialog.cbCapture.isEnabled()); assertFalse(dialog.cbCapture.isEnabled());
@@ -436,7 +442,7 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
@Test @Test
public void testActionCopyIntoNewProgramCaptureLive() throws Exception { public void testActionCopyIntoNewProgramCaptureLive() throws Exception {
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
createTestModel(); createTestModel();
@@ -465,12 +471,11 @@ public class DebuggerCopyActionsPluginTest extends AbstractGhidraHeadedDebuggerG
traceManager.openTrace(tb.trace); traceManager.openTrace(tb.trace);
traceManager.activateTrace(tb.trace); traceManager.activateTrace(tb.trace);
assertFalse(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled()); assertDisabled(copyActionsPlugin.actionCopyIntoNewProgram);
selectAndFocus(tb.addr(0x55550000), tb.addr(0x5555ffff)); select(tb.addr(0x55550000), tb.addr(0x5555ffff));
waitForPass(() -> assertTrue(copyActionsPlugin.actionCopyIntoNewProgram.isEnabled())); performEnabledAction(copyActionsPlugin.actionCopyIntoNewProgram);
performAction(copyActionsPlugin.actionCopyIntoNewProgram, false);
DebuggerCopyIntoProgramDialog dialog = DebuggerCopyIntoProgramDialog dialog =
waitForDialogComponent(DebuggerCopyIntoProgramDialog.class); waitForDialogComponent(DebuggerCopyIntoProgramDialog.class);
assertTrue(dialog.cbCapture.isEnabled()); assertTrue(dialog.cbCapture.isEnabled());