Ghidra is a software reverse engineering (SRE) framework
GP-4886 Test fixes
ghidra1c3052c0c83dc
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/ClassicSampleX86ProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/test/ClassicSampleX86ProgramBuilder.javaindex f6a39d9aac..4ff6903bea 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/ClassicSampleX86ProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/ClassicSampleX86ProgramBuilder.java@@ -476,11 +476,11 @@ public class ClassicSampleX86ProgramBuilder extends ProgramBuilder {startTransaction();StringDataType string = new StringDataType();- DataType pointer = new Pointer32DataType(string);- Parameter p0 = new ParameterImpl("destStr", pointer, getProgram());- Parameter p3 = new ParameterImpl("parm_3", DataType.DEFAULT, getProgram());- Parameter p4 = new ParameterImpl("parm_4", DataType.DEFAULT, getProgram());- createEmptyFunction("sscanf", "0x0100415a", 78, new Undefined1DataType(), p0, p3, p4);+ DataType stringPtr = new Pointer32DataType(string);+ Parameter p0 = new ParameterImpl("destStr", stringPtr, getProgram());+ Parameter p3 = new ParameterImpl("parm_3", Pointer32DataType.dataType, getProgram());+ Parameter p4 = new ParameterImpl("parm_4", Pointer32DataType.dataType, getProgram());+ createEmptyFunction("sscanf", "0x0100415a", 78, IntegerDataType.dataType, p0, p3, p4);ReferenceManager referenceManager = getProgram().getReferenceManager();referenceManager.addStackReference(addr("0x0100416c"), 0, 0x4, RefType.READ,diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.javaindex 24262fb15e..d1e780aa57 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java@@ -834,7 +834,7 @@ public class TestEnv {AbstractGuiTest.runSwing(() -> {tool = launchDefaultTool();ProgramManager pm = tool.getService(ProgramManager.class);- pm.openProgram(program.getDomainFile());+ pm.openProgram(program);});if (tool == null) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/clipboard/CopyPasteFunctionInfoTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/clipboard/CopyPasteFunctionInfoTest.javaindex 71afa91362..71624f029a 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/clipboard/CopyPasteFunctionInfoTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/clipboard/CopyPasteFunctionInfoTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -45,6 +45,7 @@ import ghidra.framework.plugintool.PluginTool;import ghidra.program.database.ProgramBuilder;import ghidra.program.model.address.Address;import ghidra.program.model.data.DataType;+import ghidra.program.model.data.Undefined4DataType;import ghidra.program.model.listing.*;import ghidra.program.model.symbol.SourceType;import ghidra.program.model.symbol.Symbol;@@ -73,7 +74,7 @@ public class CopyPasteFunctionInfoTest extends AbstractGhidraHeadedIntegrationTeToyProgramBuilder builder = new ToyProgramBuilder(name, true, ProgramBuilder._TOY);builder.createMemory("test1", "0x01001000", 0x8000);builder.createEntryPoint("0x1006420", "entry");- DataType dt = DataType.DEFAULT;+ DataType dt = Undefined4DataType.dataType;Parameter p = new ParameterImpl(null, dt, builder.getProgram());builder.createEmptyFunction("ghidra", "0x1004600", 1, dt, p, p, p, p, p, p, p, p, p, p, p,p, p);@@ -87,7 +88,7 @@ public class CopyPasteFunctionInfoTest extends AbstractGhidraHeadedIntegrationTebuilder.createEntryPoint("0x1006420", "entry");builder.createFunction("0x1004700");builder.createComment("0x1006420", "FUNCTION", CodeUnit.PLATE_COMMENT);- DataType dt = DataType.DEFAULT;+ DataType dt = Undefined4DataType.dataType;Parameter p = new ParameterImpl(null, dt, builder.getProgram());builder.createEmptyFunction("BOB", "0x1004260", 1, dt, p, p, p, p, p, p, p, p, p, p, p, p,p);@@ -481,8 +482,7 @@ public class CopyPasteFunctionInfoTest extends AbstractGhidraHeadedIntegrationTeprivate void resetOptions() {List<String> names = fieldOptions2.getOptionNames();- for (int i = 0; i < names.size(); i++) {- String name = names.get(i);+ for (String name : names) {if (!name.startsWith("Format Code")) {continue;}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 4296fa4dcd..f9ca443082 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@@ -358,7 +358,9 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration}protected DataTypeComponent getComponent(int index) {- return runSwing(() -> model.getComponent(index));+ return runSwing(() ->+ model.getComponent(index));+}protected int getOffset(int index) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.javaindex 17f0d2d14f..a620c67926 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/Function1Test.java@@ -39,6 +39,7 @@ import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;import ghidra.app.plugin.core.data.DataPlugin;import ghidra.app.plugin.core.disassembler.DisassemblerPlugin;import ghidra.app.plugin.core.highlight.SetHighlightPlugin;+import ghidra.app.plugin.core.instructionsearch.model.InstructionSearchData.UpdateType;import ghidra.app.plugin.core.navigation.*;import ghidra.app.services.ProgramManager;import ghidra.app.util.AddEditDialog;@@ -52,6 +53,7 @@ import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressFactory;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;+import ghidra.program.model.listing.Function.FunctionUpdateType;import ghidra.program.model.symbol.*;import ghidra.program.util.ProgramSelection;import ghidra.test.*;@@ -1271,6 +1273,11 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {env.showTool();loadProgram("notepad");Function f = createFunctionAtEntry();+ // Test requires a size-constrained register variable edit+ program.withTransaction("Update Signature",+ () -> f.updateFunction(null, null, FunctionUpdateType.CUSTOM_STORAGE, true,+ SourceType.ANALYSIS, new ParameterImpl("test", Undefined4DataType.dataType,+ program.getRegister("EBX"), program)));setCustomParameterStorage(f, true);waitForSwing();@@ -1284,7 +1291,6 @@ public class Function1Test extends AbstractGhidraHeadedIntegrationTest {DataTypeSelectionDialog dialog = waitForDialogComponent(DataTypeSelectionDialog.class);setEditorText(dialog, "int[0x8888888]");-// FIXME: Dialog does not appear to register type entry until it is dismissed// For the test to pass, the status field should show an error message containing// the following text (this is only a part of the status message, but is enoughdiff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcherTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcherTest.javaindex 876e3e58af..a08d26cf54 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcherTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcherTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -142,7 +142,7 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationT// example// dword ptr param, EAX- String searchText = "param";+ String searchText = "local_";SearchOptions options = new SearchOptions(searchText, false, true, false);searcher =new ListingDisplaySearcher(tool, program, startLoc, null, options, TaskMonitor.DUMMY);@@ -163,7 +163,7 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationT// example// dword ptr param, EAX- String searchText = "param";+ String searchText = "local_";SearchOptions options = new SearchOptions(searchText, false, false, false);searcher =@@ -187,17 +187,21 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationT// example// dword ptr param, EAX- SearchOptions options = new SearchOptions("param", false, false, false, false, true, true,+ SearchOptions options = new SearchOptions("local_", false, false, false, false, true, true,false, false, false, true, false, false);searcher =new ListingDisplaySearcher(tool, program, startLoc, null, options, TaskMonitor.DUMMY);//set up list of answersArrayList<Address> startList = new ArrayList<>();- startList.add(addr(0x0100416c));- startList.add(addr(0x01004186));- startList.add(addr(0x01004189));- startList.add(addr(0x0100419c));+ startList.add(addr(0x01004162));+ startList.add(addr(0x01004169));+ startList.add(addr(0x0100416f));+ startList.add(addr(0x01004178));+ startList.add(addr(0x0100417c));+ startList.add(addr(0x01004180));+ startList.add(addr(0x01004196));+ startList.add(addr(0x010041a1));//check that the text is found there in the correct fieldcheckTextFound(startList, OperandFieldLocation.class);@@ -268,11 +272,9 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationTint transactionID = program.startTransaction("test");try {DataType dt = program.getDataTypeManager()- .addDataType(struct,- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(struct, DataTypeConflictHandler.DEFAULT_HANDLER);floatDt = program.getDataTypeManager()- .addDataType(new FloatDataType(),- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(new FloatDataType(), DataTypeConflictHandler.DEFAULT_HANDLER);listing.createData(addr(0x0100689b), dt);listing.createData(addr(0x0100688c), floatDt);listing.createData(addr(0x01006890), floatDt);@@ -347,11 +349,9 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationTint transactionID = program.startTransaction("test");try {DataType dt = program.getDataTypeManager()- .addDataType(struct,- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(struct, DataTypeConflictHandler.DEFAULT_HANDLER);floatDt = program.getDataTypeManager()- .addDataType(new FloatDataType(),- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(new FloatDataType(), DataTypeConflictHandler.DEFAULT_HANDLER);listing.createData(addr(0x0100689b), dt);listing.createData(addr(0x0100688c), floatDt);listing.createData(addr(0x01006890), floatDt);@@ -437,11 +437,9 @@ public class ListingDisplaySearcherTest extends AbstractGhidraHeadedIntegrationTint transactionID = program.startTransaction("test");try {DataType dt = program.getDataTypeManager()- .addDataType(struct,- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(struct, DataTypeConflictHandler.DEFAULT_HANDLER);floatDt = program.getDataTypeManager()- .addDataType(new FloatDataType(),- DataTypeConflictHandler.DEFAULT_HANDLER);+ .addDataType(new FloatDataType(), DataTypeConflictHandler.DEFAULT_HANDLER);listing.createData(addr(0x0100689b), dt);listing.createData(addr(0x0100688c), floatDt);listing.createData(addr(0x01006890), floatDt);diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/function/editor/FunctionEditorModelTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/function/editor/FunctionEditorModelTest.javaindex 18541d0844..bd295ad46e 100644--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/function/editor/FunctionEditorModelTest.java+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/function/editor/FunctionEditorModelTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -492,9 +492,10 @@ public class FunctionEditorModelTest extends AbstractGuiTest {public void testAutoStorageFix() {model.addParameter();ParamInfo paramInfo = model.getParameters().get(0);// param_0@Stack[0x4]:4+ model.setParameterFormalDataType(paramInfo, IntegerDataType.dataType);model.setUseCustomizeStorage(true);Varnode v = paramInfo.getStorage().getFirstVarnode();- assertEquals(1, v.getSize());+ assertEquals(4, v.getSize());assertEquals(4, v.getOffset());model.setParameterFormalDataType(paramInfo, new Undefined8DataType());assertTrue(model.isValid());@@ -507,9 +508,9 @@ public class FunctionEditorModelTest extends AbstractGuiTest {public void testAutoStorageFixReg() throws Exception {model.addParameter();ParamInfo paramInfo = model.getParameters().get(0);+ model.setParameterFormalDataType(paramInfo, new Undefined2DataType());model.setUseCustomizeStorage(true);- model.setParameterFormalDataType(paramInfo, new Undefined2DataType());assertTrue(model.getStatusText(), model.isValid());Varnode v = paramInfo.getStorage().getFirstVarnode();assertEquals(2, v.getSize());@@ -1046,7 +1047,7 @@ public class FunctionEditorModelTest extends AbstractGuiTest {param = model.getParameters().get(3);assertEquals("param_2", param.getName());assertTrue(DefaultDataType.dataType.isEquivalent(param.getDataType()));- assertEquals("Stack[0xc]:1", param.getStorage().toString());+ assertEquals("<UNASSIGNED>", param.getStorage().toString());model.setParameterFormalDataType(param, struct);@@ -1156,7 +1157,7 @@ public class FunctionEditorModelTest extends AbstractGuiTest {param = model.getParameters().get(3);assertEquals("param_2", param.getName());assertTrue(DefaultDataType.dataType.isEquivalent(param.getDataType()));- assertEquals("R9B:1", param.getStorage().toString());+ assertEquals("<UNASSIGNED>", param.getStorage().toString());model.setParameterFormalDataType(param, struct);diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/compare/CompareFunctionsDecompilerViewTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/compare/CompareFunctionsDecompilerViewTest.javaindex ad7ea9c94d..a921a17038 100644--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/compare/CompareFunctionsDecompilerViewTest.java+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/compare/CompareFunctionsDecompilerViewTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -55,7 +55,6 @@ public class CompareFunctionsDecompilerViewTest extends AbstractGhidraHeadedInteFunctionManager functionManager = program1.getFunctionManager();fun1 = functionManager.getFunctionAt(addr(0x01002cf5));fun2 = functionManager.getFunctionAt(addr(0x0100415a));-}private Address addr(long offset) {@@ -69,6 +68,8 @@ public class CompareFunctionsDecompilerViewTest extends AbstractGhidraHeadedInte@Testpublic void testDecompDifView() throws Exception {+ assertFalse(program1.isClosed());+Set<Function> functions = Set.of(fun1, fun2);compareFunctions(functions);@@ -76,13 +77,12 @@ public class CompareFunctionsDecompilerViewTest extends AbstractGhidraHeadedIntewaitForComponentProvider(FunctionComparisonProvider.class);checkFunctions(provider, LEFT, fun1, fun1, fun2);- DecompilerCodeComparisonPanel panel =- (DecompilerCodeComparisonPanel) provider- .getCodeComparisonPanelByName(DecompilerCodeComparisonPanel.NAME);+ DecompilerCodeComparisonPanel panel = (DecompilerCodeComparisonPanel) provider+ .getCodeComparisonPanelByName(DecompilerCodeComparisonPanel.NAME);waitForDecompiler(panel);assertHasLines(panel.getLeftPanel(), 28);- assertHasLines(panel.getRightPanel(), 23);+ assertHasLines(panel.getRightPanel(), 22);}private void checkFunctions(FunctionComparisonProvider provider, Side side,@@ -113,8 +113,7 @@ public class CompareFunctionsDecompilerViewTest extends AbstractGhidraHeadedInte}private Program buildTestProgram() throws Exception {- ClassicSampleX86ProgramBuilder builder =- new ClassicSampleX86ProgramBuilder("Test", false);+ ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder("Test", false);return builder.getProgram();}