Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-3-16-22' into patch

This commit is contained in:
Ryan Kurtz 2022-03-16 13:00:53 -04:00
commit 19b1bcce0c

View file

@ -57,7 +57,6 @@ import ghidra.test.TestEnv;
import ghidra.util.SystemUtilities; import ghidra.util.SystemUtilities;
import ghidra.util.table.GhidraProgramTableModel; import ghidra.util.table.GhidraProgramTableModel;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest { public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
@ -100,8 +99,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
env.dispose(); env.dispose();
} }
/*******************************************************/
@Test @Test
public void testStructures() throws Exception { public void testStructures() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -187,15 +184,7 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
for (int element : TYPES) { for (int element : TYPES) {
int txId = program.startTransaction("TEST"); tx(program, () -> program.getListing().setComment(addr, element, "Test" + element));
try {
program.getListing().setComment(addr, element, "Test" + element);
}
finally {
program.endTransaction(txId, true);
}
program.flushEvents();
sendProgramLocation(addr, element); sendProgramLocation(addr, element);
@ -368,8 +357,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue(browser.goToField(addr, EolCommentFieldFactory.FIELD_NAME, 0, 0)); assertTrue(browser.goToField(addr, EolCommentFieldFactory.FIELD_NAME, 0, 0));
} }
/*******************************************************/
@Test @Test
public void testSetAll() throws Exception { public void testSetAll() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -405,8 +392,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(REPEAT, cu.getComment(CodeUnit.REPEATABLE_COMMENT)); assertEquals(REPEAT, cu.getComment(CodeUnit.REPEATABLE_COMMENT));
} }
/*******************************************************/
@Test @Test
public void testApplyButton() throws Exception { public void testApplyButton() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -421,8 +406,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertTrue(!commentsDialog.isVisible()); assertTrue(!commentsDialog.isVisible());
} }
/*******************************************************/
@Test @Test
public void testModify() throws Exception { public void testModify() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -436,8 +419,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(PRE_U, cu.getComment(CodeUnit.PRE_COMMENT)); assertEquals(PRE_U, cu.getComment(CodeUnit.PRE_COMMENT));
} }
/*******************************************************/
@Test @Test
public void testPromptForSaveChangesYes() throws Exception { public void testPromptForSaveChangesYes() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -544,8 +525,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
} }
} }
/*******************************************************/
@Test @Test
public void testReallyBigComment() throws Exception { public void testReallyBigComment() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -563,8 +542,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(comment, cu.getComment(CodeUnit.PRE_COMMENT)); assertEquals(comment, cu.getComment(CodeUnit.PRE_COMMENT));
} }
/*******************************************************/
@Test @Test
public void testNavigationFromSymbol() throws Exception { public void testNavigationFromSymbol() throws Exception {
openX86ProgramInTool(); openX86ProgramInTool();
@ -685,7 +662,7 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
Address destAddr = addr(0x01008394); Address destAddr = addr(0x01008394);
assertEquals(destAddr, browser.getCurrentLocation().getAddress()); assertEquals(destAddr, browser.getCurrentLocation().getAddress());
getProviders()[0].closeComponent(); runSwing(() -> getProviders()[0].closeComponent());
assertEquals(destAddr, browser.getCurrentLocation().getAddress()); assertEquals(destAddr, browser.getCurrentLocation().getAddress());
} }
@ -697,7 +674,6 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
open8051Program(); open8051Program();
AddressFactory af = program.getAddressFactory(); AddressFactory af = program.getAddressFactory();
AddressSpace codeSpace = af.getAddressSpace("CODE");
AddressSpace extmemSpace = af.getAddressSpace("EXTMEM"); AddressSpace extmemSpace = af.getAddressSpace("EXTMEM");
Address addr = extmemSpace.getAddress(0); Address addr = extmemSpace.getAddress(0);
@ -722,9 +698,7 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(spaceComment, cu.getComment(CodeUnit.PLATE_COMMENT)); assertEquals(spaceComment, cu.getComment(CodeUnit.PLATE_COMMENT));
} }
/*******************************************************/ /*
/**
* Test that when using the GoTo service the edit comments action * Test that when using the GoTo service the edit comments action
* is enabled. * is enabled.
* *
@ -837,13 +811,13 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
int transactionID = program.startTransaction("Test"); int transactionID = program.startTransaction("Test");
try { try {
memory.createInitializedBlock("test1", addr(0x1006000), 0x1000, (byte) 0, memory.createInitializedBlock("test1", addr(0x1006000), 0x1000, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
memory.createInitializedBlock("test2", addr(0x1008000), 0x1000, (byte) 0, memory.createInitializedBlock("test2", addr(0x1008000), 0x1000, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
memory.createInitializedBlock("test3", addr(0x100b000), 0x1000, (byte) 0, memory.createInitializedBlock("test3", addr(0x100b000), 0x1000, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
memory.createInitializedBlock("test4", addr(0xf0000000), 0x2000, (byte) 0, memory.createInitializedBlock("test4", addr(0xf0000000), 0x2000, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
SymbolTable st = program.getSymbolTable(); SymbolTable st = program.getSymbolTable();
Namespace ns = st.createNameSpace(null, "Deadpool", SourceType.USER_DEFINED); Namespace ns = st.createNameSpace(null, "Deadpool", SourceType.USER_DEFINED);
@ -854,8 +828,11 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
program.endTransaction(transactionID, true); program.endTransaction(transactionID, true);
} }
// write the file to the project to test external navigation for comment annotation // write the file to the project to test external navigation for comment annotation
env.getProject().getProjectData().getRootFolder().createFile("Test", program, env.getProject()
TaskMonitor.DUMMY); .getProjectData()
.getRootFolder()
.createFile("Test", program,
TaskMonitor.DUMMY);
env.showTool(program); env.showTool(program);
} }
@ -871,9 +848,9 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
int transactionID = program.startTransaction("Test"); int transactionID = program.startTransaction("Test");
try { try {
memory.createInitializedBlock("EEPROM", extmemSpace.getAddress(0), 0x100, (byte) 0, memory.createInitializedBlock("EEPROM", extmemSpace.getAddress(0), 0x100, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
memory.createInitializedBlock("CODE", codeSpace.getAddress(0), 0x100, (byte) 0, memory.createInitializedBlock("CODE", codeSpace.getAddress(0), 0x100, (byte) 0,
TaskMonitorAdapter.DUMMY_MONITOR, false); TaskMonitor.DUMMY, false);
} }
finally { finally {
program.endTransaction(transactionID, true); program.endTransaction(transactionID, true);
@ -884,23 +861,23 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
} }
private Reference addReference(long fromOffset, long toOffset, RefType refType) { private Reference addReference(long fromOffset, long toOffset, RefType refType) {
int transactionID = program.startTransaction("Add Reference");
try { return modifyProgram(program, p -> {
return program.getReferenceManager().addMemoryReference(addr(fromOffset), return p.getReferenceManager()
addr(toOffset), refType, SourceType.USER_DEFINED, 0); .addMemoryReference(addr(fromOffset),
} addr(toOffset), refType, SourceType.USER_DEFINED, 0);
finally { });
program.endTransaction(transactionID, true);
}
} }
private Function addFunction(String name, long functionEntry, int size) throws Exception { private Function addFunction(String name, long functionEntry, int size) throws Exception {
int transactionID = program.startTransaction("Add Function");
try { return modifyProgram(program, p -> {
Function function = Function function =
program.getFunctionManager().createFunction(name, addr(functionEntry), p.getFunctionManager()
new AddressSet(addr(functionEntry), addr(functionEntry + size - 1)), .createFunction(name, addr(functionEntry),
SourceType.USER_DEFINED); new AddressSet(addr(functionEntry), addr(functionEntry + size - 1)),
SourceType.USER_DEFINED);
ReturnParameterImpl returnParam = ReturnParameterImpl returnParam =
new ReturnParameterImpl(IntegerDataType.dataType, program); new ReturnParameterImpl(IntegerDataType.dataType, program);
ParameterImpl param1 = new ParameterImpl("p1", ByteDataType.dataType, program); ParameterImpl param1 = new ParameterImpl("p1", ByteDataType.dataType, program);
@ -912,10 +889,7 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED, FunctionUpdateType.DYNAMIC_STORAGE_FORMAL_PARAMS, true, SourceType.USER_DEFINED,
param1, param2); param1, param2);
return function; return function;
} });
finally {
program.endTransaction(transactionID, true);
}
} }
private void configureTool(PluginTool pluginTool) throws Exception { private void configureTool(PluginTool pluginTool) throws Exception {
@ -961,8 +935,7 @@ public class CommentsPluginTest extends AbstractGhidraHeadedIntegrationTest {
private void resetFormatOptions(CodeBrowserPlugin codeBrowserPlugin) { private void resetFormatOptions(CodeBrowserPlugin codeBrowserPlugin) {
Options fieldOptions = codeBrowserPlugin.getFormatManager().getFieldOptions(); Options fieldOptions = codeBrowserPlugin.getFormatManager().getFieldOptions();
List<String> names = fieldOptions.getOptionNames(); List<String> names = fieldOptions.getOptionNames();
for (int i = 0; i < names.size(); i++) { for (String name : names) {
String name = names.get(i);
if (!name.startsWith("Format Code")) { if (!name.startsWith("Format Code")) {
continue; continue;
} }