Ghidra is a software reverse engineering (SRE) framework
Added P-Code Test framework to facilitate semantic verification through emulation
ghidra1dd15435371ed
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifestindex 6a5d6e4538..ed2497532a 100644--- a/Ghidra/Features/Base/certification.manifest+++ b/Ghidra/Features/Base/certification.manifest@@ -33,6 +33,7 @@ data/parserprofiles/linux_32.prf||GHIDRA||||END|data/parserprofiles/linux_64.prf||GHIDRA||||END|data/parserprofiles/objc_mac_carbon.prf||GHIDRA||reviewed||END|data/parserprofiles/vs12Local.prf||GHIDRA||||END|+data/pcodetest/EmuTesting.gdt||GHIDRA||||END|data/stringngrams/StringModel.sng||GHIDRA||reviewed||END|data/symbols/win32/kernel32.hints||GHIDRA||||END|data/symbols/win32/mfc100.exports||GHIDRA||||END|@@ -1179,6 +1180,10 @@ src/main/resources/images/xor.png||GHIDRA||||END|src/main/resources/images/zoom.png||FAMFAMFAM Icons - CC 2.5|||silk|END|src/main/resources/images/zoom_in.png||FAMFAMFAM Icons - CC 2.5|||silk|END|src/main/resources/images/zoom_out.png||FAMFAMFAM Icons - CC 2.5|||silk|END|+src/main/resources/pcodetest/chunk1.hinc||GHIDRA||||END|+src/main/resources/pcodetest/chunk2.hinc||GHIDRA||||END|+src/main/resources/pcodetest/chunk3.hinc||GHIDRA||||END|+src/main/resources/pcodetest/chunk4.hinc||GHIDRA||||END|src/test.slow/resources/dirlist.txt||GHIDRA||reviewed||END|src/test.slow/resources/filterTestDirList.txt||GHIDRA||||END|src/test.slow/resources/ghidra/app/plugin/core/datamgr/TestDataType.txt||GHIDRA||||END|diff --git a/Ghidra/Features/Base/data/pcodetest/EmuTesting.gdt b/Ghidra/Features/Base/data/pcodetest/EmuTesting.gdtnew file mode 100644index 0000000000..84a232e99cBinary files /dev/null and b/Ghidra/Features/Base/data/pcodetest/EmuTesting.gdt differdiff --git a/Ghidra/Features/Base/ghidra_scripts/SearchBaseExtended.java b/Ghidra/Features/Base/ghidra_scripts/SearchBaseExtended.javaindex c370f370e6..f6e80fe5ef 100644--- a/Ghidra/Features/Base/ghidra_scripts/SearchBaseExtended.java+++ b/Ghidra/Features/Base/ghidra_scripts/SearchBaseExtended.java@@ -34,7 +34,7 @@ import ghidra.program.model.mem.Memory;public class SearchBaseExtended extends GhidraScript {//holds the mask and value for all the mnemonics, or commands like cmp, jmp, jnz etc- ArrayList<Case> mnemonics = new ArrayList<Case>();+ ArrayList<Case> mnemonics = new ArrayList<>();/** Holds the masks and values for all the operands. The arraylist portion will correspond to the operand number. An example is@@ -44,13 +44,13 @@ public class SearchBaseExtended extends GhidraScript {* operand. I set it up this was to conserve memory and allow for a dynamically growing collection.*/ArrayList<LinkedHashMap<Case, OperandCase>> ops =- new ArrayList<LinkedHashMap<Case, OperandCase>>();//holds masks and values for all operands.+ new ArrayList<>();//holds masks and values for all operands.- ArrayList<Case> db = new ArrayList<Case>();//holds the search results.+ ArrayList<Case> db = new ArrayList<>();//holds the search results.//These control the detail at which a scan is performed.//They determine how specific the instructions must match the currently selected ones- ArrayList<SLMaskControl> controlList = new ArrayList<SLMaskControl>();+ ArrayList<SLMaskControl> controlList = new ArrayList<>();@Overridepublic void run() throws Exception {@@ -59,7 +59,7 @@ public class SearchBaseExtended extends GhidraScript {}public void run(boolean mneonics, boolean op1, boolean op2, boolean constants) {- controlList = new ArrayList<SLMaskControl>();+ controlList = new ArrayList<>();controlList.add(new SLMaskControl(mneonics, op1, op2, constants));loadSelectedInstructions();executeSearch();@@ -72,11 +72,11 @@ public class SearchBaseExtended extends GhidraScript {}public void clearResults() {- db = new ArrayList<Case>();+ db = new ArrayList<>();}public void setState(SLMaskControl newState) {- controlList = new ArrayList<SLMaskControl>();+ controlList = new ArrayList<>();controlList.add(newState);}@@ -137,7 +137,7 @@ public class SearchBaseExtended extends GhidraScript {mnemonics.add(tCase); //adds the mnemonic mask and value to the arraylist//Gets a code unit which can be used to determine if the operands are constants.- CodeUnit cUnit = list.getCodeUnitAt(tempAddr);+ CodeUnit cu = list.getCodeUnitAt(tempAddr);//Iterates through all the operands for the currently selected instruction and stores them accordinglyfor (int x = 1; x <= logger.getNumOperands(); x++) {@@ -156,7 +156,7 @@ public class SearchBaseExtended extends GhidraScript {otCase.textRep = tempIns.getDefaultOperandRepresentation(x - 1);//Determines if the given operand is a constant value. If it is a constant then proper flag is set.- if (cUnit.getScalar(x - 1) != null) {+ if (cu.getScalar(x - 1) != null) {otCase.constant = true;}@@ -321,8 +321,8 @@ public class SearchBaseExtended extends GhidraScript {ArrayList<LinkedHashMap<Case, OperandCase>> localOperands,ArrayList<SLMaskControl> control) {- ArrayList<byte[]> masks = new ArrayList<byte[]>();- ArrayList<byte[]> values = new ArrayList<byte[]>();+ ArrayList<byte[]> masks = new ArrayList<>();+ ArrayList<byte[]> values = new ArrayList<>();//used for storing the byte stream currently being work on prior to being added to final data structureint totalLength = 0;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.javaindex 63b7fbe3b7..a2aff78339 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java@@ -770,7 +770,7 @@ public class TestEnv {* Open a read-only test program from the test data directory.* This program must be released prior to disposing this test environment.* NOTE: Some tests rely on this method returning null when file does- * not yet exist within the resource area (e.g., CUnit binaries for Processor Tests)+ * not yet exist within the resource area (e.g., test binaries for P-Code Tests)** @param programName name of program database within the test data directory.* @return program or null if program file not founddiff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/TestProgramManager.java b/Ghidra/Features/Base/src/main/java/ghidra/test/TestProgramManager.javaindex ca8051dba2..b2ba384715 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/TestProgramManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/TestProgramManager.java@@ -57,7 +57,7 @@ public class TestProgramManager {* Open a read-only test program from the test data directory.* This program must be released prior to disposing this test environment.* NOTE: Some tests rely on this method returning null when file does- * not yet exist within the resource area (e.g., CUnit binaries for Processor Tests)+ * not yet exist within the resource area (e.g., test binaries for P-Code Tests)** @param progName name of program database within the test data directory.* @return program or null if program file not founddiff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.javanew file mode 100644index 0000000000..ff266b05e8--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java@@ -0,0 +1,704 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.math.BigInteger;+import java.util.*;++import generic.timer.GhidraSwinglessTimer;+import generic.timer.TimerCallback;+import ghidra.app.emulator.*;+import ghidra.pcode.emulate.BreakCallBack;+import ghidra.pcode.emulate.EmulateExecutionState;+import ghidra.pcode.error.LowlevelError;+import ghidra.pcode.memstate.MemoryFaultHandler;+import ghidra.pcode.pcoderaw.PcodeOpRaw;+import ghidra.program.model.address.Address;+import ghidra.program.model.address.AddressSpace;+import ghidra.program.model.lang.Register;+import ghidra.program.model.lang.RegisterValue;+import ghidra.program.model.listing.Instruction;+import ghidra.program.model.listing.Program;+import ghidra.program.model.pcode.Varnode;+import ghidra.test.processors.support.PCodeTestAbstractControlBlock.FunctionInfo;+import ghidra.util.Msg;+import ghidra.util.StringUtilities;+import ghidra.util.exception.AssertException;+import ghidra.util.exception.CancelledException;+import ghidra.util.task.TaskMonitor;++public class EmulatorTestRunner {++ private Program program;+ private PCodeTestGroup testGroup;++ private EmulatorHelper emuHelper;+ private Emulator emu;+ private ExecutionListener executionListener;++ private volatile boolean haltedOnTimer = false;+ private String lastError;+ private int callOtherErrors; // only incremented on pass with callOtherCount != 0+ private int callOtherCount;++ private TreeSet<String> unimplementedSet = new TreeSet<>();++ private HashMap<Address, List<DumpPoint>> dumpPointMap = new HashMap<>();++ public EmulatorTestRunner(Program program, PCodeTestGroup testGroup,+ ExecutionListener executionListener) {+ this.program = program;+ this.testGroup = testGroup;+ this.executionListener = executionListener;+ emuHelper = new EmulatorHelper(program);+ emu = emuHelper.getEmulator();+ emuHelper.setMemoryFaultHandler(new MyMemoryFaultHandler(executionListener));++ emuHelper.registerDefaultCallOtherCallback(new BreakCallBack() {+ @Override+ public boolean pcodeCallback(PcodeOpRaw op) throws LowlevelError {+ int userOp = (int) op.getInput(0).getOffset();+ String pcodeOpName = emulate.getLanguage().getUserDefinedOpName(userOp);+ unimplementedSet.add(pcodeOpName);+ String outStr = "";+ Varnode output = op.getOutput();+ if (output != null) {+ outStr = ", unable to set output " + output.toString(program.getLanguage());+ }+ EmulatorTestRunner.this.executionListener.log(testGroup, "Unimplemented pcodeop '" ++ pcodeOpName + "' at: " + emu.getExecuteAddress() + outStr);+ ++callOtherCount;+ return true;+ }+ });+ }++ public void dispose() {+ emuHelper.dispose();+ emu = null;+ program = null;+ executionListener = null;+ testGroup = null;+ }++ Set<String> getUnimplementedPcodeops() {+ return unimplementedSet;+ }++ public PCodeTestGroup getTestGroup() {+ return testGroup;+ }++ public Program getProgram() {+ return program;+ }++ public EmulatorHelper getEmulatorHelper() {+ return emuHelper;+ }++ public void setContextRegister(RegisterValue ctxRegValue) {+ emuHelper.setContextRegister(ctxRegValue);+ }++ public Address getCurrentAddress() {+ return emuHelper.getExecutionAddress();+ }++ public Instruction getCurrentInstruction() {+ // TODO: Pull instruction from emulator instead of program after+ // merge with SleighRefactor branch+ return program.getListing().getInstructionAt(emu.getExecuteAddress());+ }++ private void flipBytes(byte[] bytes) {+ for (int i = 0; i < bytes.length / 2; i++) {+ byte b = bytes[i];+ int otherIndex = bytes.length - i - 1;+ bytes[i] = bytes[otherIndex];+ bytes[otherIndex] = b;+ }+ }++ public RegisterValue getRegisterValue(Register reg) {+ Register baseReg = reg.getBaseRegister();+ byte[] bytes = emuHelper.readMemory(baseReg.getAddress(), baseReg.getMinimumByteSize());+ if (!reg.isBigEndian()) {+ flipBytes(bytes);+ }+ byte[] maskValue = new byte[2 * bytes.length];+ Arrays.fill(maskValue, (byte) 0xff);+ System.arraycopy(bytes, 0, maskValue, bytes.length, bytes.length);+ RegisterValue baseValue = new RegisterValue(baseReg, maskValue);+ return baseValue.getRegisterValue(reg);+ }++ public String getRegisterValueString(Register reg) {+ String valStr = getRegisterValue(reg).getUnsignedValue().toString(16);+ return StringUtilities.pad(valStr, '0', reg.getMinimumByteSize() * 2);+ }++ public void setRegister(String regName, long value) {+ Register reg = program.getRegister(regName);+ if (reg == null) {+ throw new IllegalArgumentException("Undefined register: " + regName);+ }+ emuHelper.writeRegister(reg, value);+ }++ public void setRegister(String regName, BigInteger value) {+ Register reg = program.getRegister(regName);+ if (reg == null) {+ throw new IllegalArgumentException("Undefined register: " + regName);+ }+ emuHelper.writeRegister(reg, value);+ }++ /**+ * Add memory dump point+ * @param breakAddr instruction address at which execution should pause (before it is executed)+ * so that the specified memory may be dumped to the log during trace execution mode.+ * @param dumpAddr memory address which should be dumped+ * @param dumpSize number elements which should be dumped+ * @param elementSize size of each element in bytes (be reasonable!)+ * @param elementFormat HEX, DECIMAL or FLOAT+ * @param comment dump comment+ */+ public void addDumpPoint(Address breakAddr, Address dumpAddr, int dumpSize, int elementSize,+ DumpFormat elementFormat, String comment) {+ List<DumpPoint> list = dumpPointMap.get(breakAddr);+ if (list == null) {+ list = new ArrayList<>();+ dumpPointMap.put(breakAddr, list);+ }+ list.add(new AddressDumpPoint(breakAddr, dumpAddr, dumpSize, elementSize, elementFormat,+ comment));+ }++ /**+ * Add memory dump point+ * @param breakAddr instruction address at which execution should pause (before it is executed)+ * so that the specified memory may be dumped to the log during trace execution mode.+ * @param dumpAddrReg register containing the memory address offset which should be dumped+ * @param relativeOffset dump register relative offset+ * @param dumpAddrSpace address space to which memory offset should be applied+ * @param dumpSize number elements which should be dumped+ * @param elementSize size of each element in bytes (be reasonable!)+ * @param elementFormat HEX, DECIMAL or FLOAT+ * @param comment dump comment+ */+ public void addDumpPoint(Address breakAddr, Register dumpAddrReg, int relativeOffset,+ AddressSpace dumpAddrSpace, int dumpSize, int elementSize, DumpFormat elementFormat,+ String comment) {+ List<DumpPoint> list = dumpPointMap.get(breakAddr);+ if (list == null) {+ list = new ArrayList<>();+ dumpPointMap.put(breakAddr, list);+ }+ list.add(new RegisterRelativeDumpPoint(breakAddr, dumpAddrReg, relativeOffset,+ dumpAddrSpace, dumpSize, elementSize, elementFormat, comment));+ }++ private void dump(List<DumpPoint> dumpList) {+ for (DumpPoint dumpPoint : dumpList) {+ Address dumpAddr = dumpPoint.getDumpAddress();+ executionListener.logState(this, dumpAddr, dumpPoint.dumpSize, dumpPoint.elementSize,+ dumpPoint.elementFormat, dumpPoint.comment);+ }+ }++ private String getLastFunctionName(PCodeTestGroup testGroup, boolean logError) {+ return testGroup.mainTestControlBlock.getLastFunctionName(this,+ logError ? executionListener : null, testGroup);+ }++ public String getEmuError() {+ return lastError;+ }++ /**+ * Get number of CALLOTHER errors detected when a test pass was registered.+ * This number should be subtracted from the pass count and possibly added+ * to the failure count. Number does not reflect total number of CALLOTHER+ * pcodeops encountered but only the number of passed tests affected.+ * See log for all CALLOTHER executions detected.+ * @return number of CALLOTHER errors+ */+ public int getCallOtherErrors() {+ return callOtherErrors;+ }++ /**+ * Execute test group without instruction stepping/tracing+ * @param timeLimitMS+ * @param monitor+ * @return+ * @throws CancelledException+ */+ public boolean execute(int timeLimitMS, TaskMonitor monitor) throws CancelledException {++ testGroup.clearFailures();+ lastError = null;+ callOtherErrors = 0;++ // Disable sprintf use+ testGroup.mainTestControlBlock.setSprintfEnabled(this, false);++ int alignment = program.getLanguage().getInstructionAlignment();++ Address breakOnDoneAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnDoneAddress(), alignment);+ Address breakOnPassAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnPassAddress(), alignment);+ Address breakOnErrorAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnErrorAddress(), alignment);++ emuHelper.setBreakpoint(breakOnDoneAddr);+ emuHelper.setBreakpoint(breakOnPassAddr);+ emuHelper.setBreakpoint(breakOnErrorAddr);++ GhidraSwinglessTimer safetyTimer = null;+ haltedOnTimer = false;+ boolean atBreakpoint = false;+ try {+ if (timeLimitMS > 0) {+ safetyTimer = new GhidraSwinglessTimer(timeLimitMS, new TimerCallback() {+ @Override+ public synchronized void timerFired() {+ haltedOnTimer = true;+ emuHelper.getEmulator().setHalt(true);+ }+ });+ safetyTimer.setRepeats(false);+ safetyTimer.start();+ }+ while (true) {+ callOtherCount = 0;++ boolean success;+ if (atBreakpoint) {+ success = emuHelper.run(monitor);+ }+ else {+ success = emuHelper.run(alignAddress(testGroup.functionEntryPtr, alignment),+ null, monitor);+ }++ String lastFuncName = getLastFunctionName(testGroup, false);+ String errFileName = testGroup.mainTestControlBlock.getLastErrorFile(this);+ int errLineNum = testGroup.mainTestControlBlock.getLastErrorLine(this);++ Address executeAddr = emuHelper.getExecutionAddress();+ if (!success) {+ lastError = emuHelper.getLastError();+ testGroup.severeTestFailure(lastFuncName, errFileName, errLineNum, program,+ executionListener);+ return false;+ }++ if (haltedOnTimer) {+ lastError = "Emulation halted due to execution timeout";+ testGroup.severeTestFailure(lastFuncName, errFileName, errLineNum, program,+ executionListener);+ return false;+ }++ if (executeAddr.equals(breakOnDoneAddr)) {+ return true; // done+ }++ if (executeAddr.equals(breakOnPassAddr)) {+ if (callOtherCount != 0) {+ // force error even if test passed - need to adjust pass count+ testGroup.testFailed(lastFuncName, errFileName, errLineNum, true, program,+ executionListener);+ ++callOtherErrors;+ }+ else {+ testGroup.testPassed(lastFuncName, errFileName, errLineNum, program,+ executionListener);+ }+ atBreakpoint = true;+ continue;+ }+ else if (executeAddr.equals(breakOnErrorAddr)) {+ testGroup.testFailed(lastFuncName, errFileName, errLineNum, false, program,+ executionListener);+ atBreakpoint = true;+ continue; // resume from breakpoint+ }++ throw new AssertException("Unexpected condition (executeAddr=" + executeAddr + ")");+ }+ }+ finally {+ if (safetyTimer != null) {+ synchronized (safetyTimer) {+ safetyTimer.stop();+ }+ }+ }++ }++ public boolean executeSingleStep(int stepLimit) {++ testGroup.clearFailures();+ lastError = null;+ callOtherErrors = 0;+ callOtherCount = 0;++ // force function address alignment to compensate for address encoding (e.g., Thumb mode)+ int alignment = program.getLanguage().getInstructionAlignment();++ HashMap<Address, FunctionInfo> subFunctionMap = new HashMap<>();+ int subFunctionCnt = testGroup.controlBlock.getNumberFunctions();+ for (int i = 1; i < subFunctionCnt; i++) {+ FunctionInfo functionInfo = testGroup.controlBlock.getFunctionInfo(i);+ subFunctionMap.put(alignAddress(functionInfo.functionAddr, alignment), functionInfo);+ }++ Address executeAddr = alignAddress(testGroup.functionEntryPtr, alignment);++ emuHelper.writeRegister(program.getLanguage().getProgramCounter(),+ executeAddr.getAddressableWordOffset());++ // Enable sprintf use+ testGroup.mainTestControlBlock.setSprintfEnabled(this, true);++ Address breakOnDoneAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnDoneAddress(), alignment);+ Address breakOnPassAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnPassAddress(), alignment);+ Address breakOnErrorAddr =+ alignAddress(testGroup.mainTestControlBlock.getBreakOnErrorAddress(), alignment);+ Address printfAddr =+ alignAddress(testGroup.mainTestControlBlock.getSprintf5Address(), alignment);++ executionListener.log(testGroup, "TestInfo pointers of interest:");+ executionListener.log(testGroup, " onDone -> " + breakOnDoneAddr);+ executionListener.log(testGroup, " onPass -> " + breakOnPassAddr);+ executionListener.log(testGroup, " onError -> " + breakOnErrorAddr);+ executionListener.log(testGroup, " printf5 -> " + printfAddr);++ if (!dumpPointMap.isEmpty()) {+ executionListener.log(testGroup, "Dump points:");+ List<Address> addressList = new ArrayList<>(dumpPointMap.keySet());+ Collections.sort(addressList);+ for (Address addr : addressList) {+ List<DumpPoint> dumpList = dumpPointMap.get(addr);+ for (DumpPoint dumpPoint : dumpList) {+ executionListener.log(testGroup, " " + dumpPoint);+ }+ }+ }++ executionListener.logState(this);++ int stepCount = 0;+ Address lastAddress = null;+ Address printfCallAddr = null;+ boolean assertTriggered = false;+ FunctionInfo currentFunction = null;++ MyMemoryAccessFilter memoryFilter = new MyMemoryAccessFilter();+ emu.addMemoryAccessFilter(memoryFilter);+ try {++ while (true) {+ if (!emuHelper.step(TaskMonitor.DUMMY)) {+ lastError = emuHelper.getLastError();++ String lastFuncName = getLastFunctionName(testGroup, true);+ String errFileName = testGroup.mainTestControlBlock.getLastErrorFile(this);+ int errLineNum = testGroup.mainTestControlBlock.getLastErrorLine(this);++ testGroup.severeTestFailure(lastFuncName, errFileName, errLineNum, program,+ executionListener);++ return false;+ }++ executeAddr = emuHelper.getExecutionAddress();++ List<DumpPoint> dumpList = dumpPointMap.get(executeAddr);+ if (dumpList != null) {+ dump(dumpList);+ }++ if (executeAddr.equals(breakOnDoneAddr)) {+ return true; // done+ }++ boolean onPass = executeAddr.equals(breakOnPassAddr);+ if (onPass || executeAddr.equals(breakOnErrorAddr)) {+ assertTriggered = true;+ String lastFuncName = getLastFunctionName(testGroup, true);+ String errFileName = testGroup.mainTestControlBlock.getLastErrorFile(this);+ int errLineNum = testGroup.mainTestControlBlock.getLastErrorLine(this);+ if (onPass) {+ if (callOtherCount != 0) {+ // force error even if test passed - need to adjust pass count+ testGroup.testFailed(lastFuncName, errFileName, errLineNum, true,+ program, executionListener);+ ++callOtherErrors;+ callOtherCount = 0;+ }+ else {+ testGroup.testPassed(lastFuncName, errFileName, errLineNum, program,+ executionListener);+ }+ }+ else {+ testGroup.testFailed(lastFuncName, errFileName, errLineNum, false, program,+ executionListener);+ }+ }+ else if (executeAddr.equals(printfAddr)) {+ // enter printf function+ printfCallAddr = lastAddress;+ memoryFilter.enabled = false;+ executionListener.log(testGroup, "printf invocation (log supressed) ...");+ }+ else if (printfCallAddr != null && isPrintfReturn(executeAddr, printfCallAddr)) {+ // return from printf function+ printfCallAddr = null;+ memoryFilter.enabled = true;++ String str = testGroup.controlBlock.emuReadString(emuHelper,+ testGroup.mainTestControlBlock.getPrintfBufferAddress());+ executionListener.log(testGroup, " " + str);+ }+ else {+ // detect start of new group test and remove from map+ FunctionInfo functionInfo = subFunctionMap.remove(executeAddr);+ if (functionInfo != null) {+ if (currentFunction != null && !assertTriggered) {+ executionListener.log(testGroup,+ "ERROR! Group test never executed pass/fail: " + currentFunction);+ }+ currentFunction = functionInfo;+ assertTriggered = (functionInfo.numberOfAsserts == 0);+ executionListener.log(testGroup,+ "-------- " + functionInfo.functionName + " (" ++ functionInfo.numberOfAsserts + functionInfo.numberOfAsserts ++ "-Asserts) --------");+ }+ }++ if (++stepCount > stepLimit) {+ executionListener.log(testGroup,+ "Emulation halted due to excessive execution steps");++ String lastFuncName = getLastFunctionName(testGroup, true);+ String errFileName = testGroup.mainTestControlBlock.getLastErrorFile(this);+ int errLineNum = testGroup.mainTestControlBlock.getLastErrorLine(this);++ testGroup.severeTestFailure(lastFuncName, errFileName, errLineNum, program,+ executionListener);+ return false;+ }++ if (memoryFilter.enabled) {+ executionListener.logState(this);+ }++ lastAddress = executeAddr;+ }+ }+ catch (Throwable t) {+ Msg.error(this, "Unexpected Exception", t);+ return false;+ }+ finally {+ memoryFilter.dispose();++ List<FunctionInfo> list = new ArrayList<>(subFunctionMap.values());+ if (!list.isEmpty()) {+ // Show list of sub-functions which were never executed+ Collections.sort(list);+ executionListener.log(testGroup,+ "The following sub-functions were never executed:");+ for (FunctionInfo functionInfo : list) {+ executionListener.log(testGroup, " " + functionInfo);+ }+ }+ else {+ executionListener.log(testGroup,+ "All " + (testGroup.controlBlock.getNumberFunctions() - 1) ++ " sub-functions were executed");+ }+ }++ }++ static long alignAddressOffset(long offset, int alignment) {+ return (offset / alignment) * alignment;+ }++ static Address alignAddress(Address addr, int alignment) {+ Address alignedAddr = addr;+ long offset = addr.getOffset();+ long alignedOffset = alignAddressOffset(offset, alignment);+ if (offset != alignedOffset) {+ alignedAddr = addr.getNewAddress(alignedOffset);+ }+ return alignedAddr;+ }++ private boolean isPrintfReturn(Address executeAddr, Address printfCallAddr) {+ // look for approximate return relative to address of printf call+ long offset = executeAddr.getOffset();+ long maxEnd = printfCallAddr.getOffset() + 32;+ return (offset > printfCallAddr.getOffset() && offset <= maxEnd);+ }++ private class MyMemoryAccessFilter extends MemoryAccessFilter {++ boolean enabled = true;++ @Override+ protected void processWrite(AddressSpace spc, long off, int size, byte[] values) {+ if (enabled) {+ executionListener.logWrite(EmulatorTestRunner.this, spc.getAddress(off), size,+ values);+ }+ }++ @Override+ protected void processRead(AddressSpace spc, long off, int size, byte[] values) {+ if (enabled &&+ emu.getEmulateExecutionState() != EmulateExecutionState.INSTRUCTION_DECODE) {+ executionListener.logRead(EmulatorTestRunner.this, spc.getAddress(off), size,+ values);+ }+ }+ }++ private class MyMemoryFaultHandler implements MemoryFaultHandler {++ private ExecutionListener executionListener;++ public MyMemoryFaultHandler(ExecutionListener executionListener) {+ this.executionListener = executionListener;+ }++ @Override+ public boolean unknownAddress(Address address, boolean write) {+ Address pc = emuHelper.getExecutionAddress();+ String access = write ? "written" : "read";+ executionListener.log(testGroup,+ "Unknown address " + access + " at " + pc + ": " + address);+ return false;+ }++ @Override+ public boolean uninitializedRead(Address address, int size, byte[] buf, int bufOffset) {+ if (emu.getEmulateExecutionState() == EmulateExecutionState.INSTRUCTION_DECODE) {+ return false;+ }+ Address pc = emuHelper.getExecutionAddress();+ if (!address.isUniqueAddress()) {+ Register reg = program.getRegister(address, size);+ if (reg != null) {+ executionListener.log(testGroup,+ "Uninitialized register read at " + pc + ": " + reg);+ return true;+ }+ }+ executionListener.log(testGroup,+ "Uninitialized read at " + pc + ": " + address.toString(true) + ":" + size);+ return true;+ }+ }++ public static enum DumpFormat {+ HEX, DECIMAL, FLOAT;+ }++ private abstract class DumpPoint {+ final Address breakAddr;+ final int dumpSize;+ final int elementSize;+ final DumpFormat elementFormat;+ final String comment;++ DumpPoint(Address breakAddr, int dumpSize, int elementSize, DumpFormat elementFormat,+ String comment) {+ this.breakAddr = breakAddr;+ this.dumpSize = dumpSize;+ this.elementSize = elementSize;+ this.elementFormat = elementFormat;+ this.comment = comment;+ }++ abstract Address getDumpAddress();++ public String toString(String addrStr) {+ return getClass().getSimpleName() + ": " + dumpSize + " " + elementSize ++ "-byte elements at " + addrStr;+ }+ }++ private class AddressDumpPoint extends DumpPoint {+ final Address dumpAddr;++ AddressDumpPoint(Address breakAddr, Address dumpAddr, int dumpSize, int elementSize,+ DumpFormat elementFormat, String comment) {+ super(breakAddr, dumpSize, elementSize, elementFormat, comment);+ this.dumpAddr = dumpAddr;+ }++ @Override+ Address getDumpAddress() {+ return dumpAddr;+ }++ @Override+ public String toString() {+ return toString(dumpAddr.toString(true));+ }+ }++ private class RegisterRelativeDumpPoint extends DumpPoint {+ final Register dumpAddrReg;+ final int relativeOffset;+ final AddressSpace dumpAddrSpace;++ RegisterRelativeDumpPoint(Address breakAddr, Register dumpAddrReg, int relativeOffset,+ AddressSpace dumpAddrSpace, int dumpSize, int elementSize, DumpFormat elementFormat,+ String comment) {+ super(breakAddr, dumpSize, elementSize, elementFormat, comment);+ this.dumpAddrReg = dumpAddrReg;+ this.relativeOffset = relativeOffset;+ this.dumpAddrSpace = dumpAddrSpace;+ }++ @Override+ Address getDumpAddress() {+ RegisterValue regVal = getRegisterValue(dumpAddrReg);+ return dumpAddrSpace.getAddress(regVal.getUnsignedValue().longValue()).add(+ relativeOffset);+ }++ @Override+ public String toString() {+ return toString("0x" + Integer.toHexString(relativeOffset) + "[" + dumpAddrReg + "]");+ }++ }++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ExecutionListener.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ExecutionListener.javanew file mode 100644index 0000000000..c1c1c84ddb--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ExecutionListener.java@@ -0,0 +1,29 @@+/* ###+ * IP: GHIDRA+ * REVIEWED: YES+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import ghidra.program.model.address.Address;++public interface ExecutionListener extends TestLogger {++ public void stepCompleted(EmulatorTestRunner testRunner);++ public void logWrite(EmulatorTestRunner testRunner, Address address, int size, byte[] values);++ public void logRead(EmulatorTestRunner testRunner, Address address, int size, byte[] values);++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestAbstractControlBlock.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestAbstractControlBlock.javanew file mode 100644index 0000000000..07cd0fd97a--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestAbstractControlBlock.java@@ -0,0 +1,477 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.util.*;++import ghidra.app.emulator.EmulatorHelper;+import ghidra.docking.settings.SettingsImpl;+import ghidra.pcode.memstate.MemoryState;+import ghidra.pcode.utils.Utils;+import ghidra.program.model.address.*;+import ghidra.program.model.data.*;+import ghidra.program.model.data.DataUtilities.ClearDataMode;+import ghidra.program.model.listing.Data;+import ghidra.program.model.listing.Program;+import ghidra.program.model.mem.*;+import ghidra.program.model.symbol.*;+import ghidra.program.model.util.CodeUnitInsertionException;+import ghidra.util.Msg;+import ghidra.util.exception.AssertException;+import ghidra.util.task.TaskMonitor;++/**+ * <code>PCodeTestAbstractControlBlock</code> data is models the general capabilities+ * of the TestInfo data structure which is used for different puposes as handled+ * by extensions of this class.+ */+public abstract class PCodeTestAbstractControlBlock {++ static final int SIZEOF_U4 = 4;++ protected final Program program;+ protected final AddressSpace codeSpace;+ protected final AddressSpace dataSpace;++ protected final int pointerSize;++ protected final Address infoStructAddr;+ protected final Structure infoProgramStruct;++ private List<FunctionInfo> functions = new ArrayList<>();+ private HashMap<String, FunctionInfo> functionMap = new HashMap<>();++ /**+ * Construct test control block instance for the specified program.+ * @param program program containing control block structure+ * @param infoStructAddr program address where structure resides+ * @param infoStruct appropriate Info structure definition which will have array+ * of FunctionInfo immediately following.+ */+ PCodeTestAbstractControlBlock(Program program, Address infoStructAddr, Structure infoStruct) {+ this.program = program;+ this.pointerSize = program.getDataTypeManager().getDataOrganization().getPointerSize();+ this.infoStructAddr = infoStructAddr;+ this.infoProgramStruct = (Structure) infoStruct.clone(program.getDataTypeManager());++ codeSpace = program.getAddressFactory().getDefaultAddressSpace();+ dataSpace = program.getLanguage().getDefaultDataSpace();+ }++ public Address getInfoStructureAddress() {+ return infoStructAddr;+ }++ public FunctionInfo getFunctionInfo(String functionName) {+ return functionMap.get(functionName);+ }++ public FunctionInfo getFunctionInfo(int functionIndex) {+ return functions.get(functionIndex);+ }++ public int getNumberFunctions() {+ return functions.size();+ }++ /**+ * Force an existing reference to refer to the code space. Pointers+ * created in the data space refer to the data space by default, this method+ * is used to change these pointers in the data space to refer to+ * code.+ * @param addr location with data space which contains code reference+ */+ void forceCodePointer(Address addr) {+ if (codeSpace == dataSpace) {+ return;+ }+ ReferenceManager refMgr = program.getReferenceManager();+ Reference ref = refMgr.getPrimaryReferenceFrom(addr, 0);+ if (ref == null) {+ return;+ }+ Address toAddr = ref.getToAddress();+ if (!toAddr.getAddressSpace().equals(codeSpace)) {+ toAddr = codeSpace.getAddress(toAddr.getAddressableWordOffset(), true);+ Reference newRef =+ refMgr.addMemoryReference(addr, toAddr, RefType.DATA, SourceType.ANALYSIS, 0);+ refMgr.setPrimary(newRef, true);+ refMgr.delete(ref);+ }+ }++ static byte[] getCharArrayBytes(Program program, String string) {+ DataOrganization dataOrganization = program.getDataTypeManager().getDataOrganization();+ int charSize = dataOrganization.getCharSize();+ byte[] strBytes = string.getBytes();+ if (charSize == 1) {+ return strBytes;+ }++ // generate aligned byte array+ int len = charSize * strBytes.length;+ byte[] bytes = new byte[len];+ boolean bigEndian = program.getMemory().isBigEndian();+ int index = 0;+ int pad = charSize - 1;+ for (byte strByte : strBytes) {+ if (bigEndian) {+ index += pad;+ }+ bytes[index++] = strByte;+ if (!bigEndian) {+ index += pad;+ }+ }+ return bytes;+ }++ private Address readPointer(MemBuffer buffer, int bufferOffset, AddressSpace addrSpace,+ boolean updateReference) {+ byte[] bytes = new byte[pointerSize];+ buffer.getBytes(bytes, bufferOffset);+ long offset = Utils.bytesToLong(bytes, pointerSize, buffer.isBigEndian()) *+ addrSpace.getAddressableUnitSize();+ Address addr = addrSpace.getAddress(offset);+ if (updateReference) {+ ReferenceManager refMgr = program.getReferenceManager();+ Address fromAddr = buffer.getAddress().add(bufferOffset);+ Reference ref = refMgr.getPrimaryReferenceFrom(fromAddr, 0);+ if (ref != null && !ref.getToAddress().equals(addr)) {+ refMgr.delete(ref);+ ref = null;+ }+ if (ref == null) {+ refMgr.addMemoryReference(fromAddr, addr, RefType.DATA, SourceType.USER_DEFINED, 0);+ }+ }+ return addr;+ }++ /**+ * Check for a Data pointer at the specified address and return the referenced+ * address.+ * @param addr address of stored pointer+ * @return pointer referenced address or null if no pointer found+ */+ protected Address readDefinedDataPointer(Address addr) {+ Data data = program.getListing().getDefinedDataAt(addr);+ if (data == null || !(data.getDataType() instanceof Pointer)) {+ return null;+ }+ return (Address) data.getValue();+ }++ protected Address readCodePointer(MemBuffer buffer, int bufferOffset, boolean updateReference) {+ Address codePtr = readPointer(buffer, bufferOffset, codeSpace, updateReference);++ // shift the pointer if code pointers are stored in memory shifted.+ int ptrShift = program.getDataTypeManager().getDataOrganization().getPointerShift();+ if (ptrShift != 0) {+ codePtr = codePtr.getNewAddress(codePtr.getOffset() << ptrShift);+ }++ // Check for potential procedure descriptor indirection (e.g., PPC64 .opd)+ // in which case a function pointer may refer to a procedure descriptor+ // record (we assume here that the first entry has been marked-up by the importer+ // and corresponds to the true function address++ Address ptr = readDefinedDataPointer(codePtr);+ if (ptr != null) {+ codePtr = ptr;+ }++ return codePtr;+ }++ protected Address readDataPointer(MemBuffer buffer, int bufferOffset, boolean updateReference) {+ return readPointer(buffer, bufferOffset, dataSpace, updateReference);+ }++ protected Address readPointer(int controlBlockOffset) throws MemoryAccessException {+ Address addr = infoStructAddr.add(controlBlockOffset);+ byte[] bytes = new byte[pointerSize];+ Memory memory = program.getMemory();+ if (memory.getBytes(addr, bytes) != pointerSize) {+ throw new MemoryAccessException(+ "Failed to read program memory: " + pointerSize + " bytes at " + addr);+ }+ long offset = Utils.bytesToLong(bytes, pointerSize, memory.isBigEndian());+ return infoStructAddr.getNewAddress(offset);+ }++// protected void applyPointerData(Program program, Address addr) {+// Pointer dt = new PointerDataType(program.getDataTypeManager());+// if (dt.getLength() != pointerSize) {+// switch (pointerSize) {+// case 2:+// dt = new Pointer16DataType();+// break;+// case 3:+// dt = new Pointer24DataType();+// break;+// case 4:+// dt = new Pointer32DataType();+// break;+// case 5:+// dt = new Pointer40DataType();+// break;+// case 6:+// dt = new Pointer48DataType();+// break;+// case 7:+// dt = new Pointer56DataType();+// break;+// case 8:+// dt = new Pointer64DataType();+// break;+// default:+// return;+// }+// }+// try {+// program.getListing().createData(addr, dt);+// }+// catch (CodeUnitInsertionException e) {+// // ignore+// }+// catch (DataTypeConflictException e) {+// // ignore+// }+// }++ protected void applyU4Data(Address addr) {+ try {+ program.getListing().createData(addr, DWordDataType.dataType);+ }+ catch (CodeUnitInsertionException e) {+ // ignore+ }+ catch (DataTypeConflictException e) {+ // ignore+ }+ }++ protected int getStructureComponent(Structure testInfoStruct, String fieldName) {+ for (DataTypeComponent component : testInfoStruct.getComponents()) {+ if (fieldName.equals(component.getFieldName())) {+ return component.getOffset();+ }+ }+ throw new RuntimeException(fieldName + " field not found within " ++ testInfoStruct.getName() + " structure definition at " + infoStructAddr.toString(true));+ }++ protected void readControlBlock(boolean applyStruct)+ throws InvalidControlBlockException, CodeUnitInsertionException {++ if (applyStruct) {+ DataUtilities.createData(program, infoStructAddr, infoProgramStruct, -1, false,+ ClearDataMode.CLEAR_ALL_CONFLICT_DATA);+ }++ TerminatedStringDataType stringType =+ new TerminatedStringDataType(program.getDataTypeManager());++ Structure functionInfoStruct =+ (Structure) infoProgramStruct.getDataTypeManager().getDataType(CategoryPath.ROOT,+ "FunctionInfo");+ if (functionInfoStruct == null) {+ throw new AssertException("FunctionInfo structure not yet resolved");+ }++ int nameOffset = getStructureComponent(functionInfoStruct, "name");+ int funcOffset = getStructureComponent(functionInfoStruct, "func");+ int numTestOffset = getStructureComponent(functionInfoStruct, "numTest");++ try {++ DumbMemBufferImpl memBuffer =+ new DumbMemBufferImpl(program.getMemory(), infoStructAddr);+ int functionArrayPtrOffset =+ getStructureComponent(infoProgramStruct, "funcInfoArrayPtr");+ Address functionInfoAddress =+ readDataPointer(memBuffer, functionArrayPtrOffset, applyStruct);++ Msg.info(this, "Loading FunctionInfo array at " + functionInfoAddress);++ while (true) {+ // Read function table+ memBuffer.setPosition(functionInfoAddress);++ if (applyStruct) {+ DataUtilities.createData(program, functionInfoAddress, functionInfoStruct, -1,+ false, ClearDataMode.CLEAR_ALL_CONFLICT_DATA);+ forceCodePointer(functionInfoAddress.add(funcOffset));+ }++ Address funcNamePtr = readDataPointer(memBuffer, nameOffset, applyStruct);+ Address funcPtr = readCodePointer(memBuffer, funcOffset, applyStruct);+ int numTest = memBuffer.getInt(numTestOffset);++ if (funcNamePtr.getOffset() == 0) {+ break;+ }++ memBuffer.setPosition(funcNamePtr);+ String functionName =+ (String) stringType.getValue(memBuffer, SettingsImpl.NO_SETTINGS, 0);++ if (funcPtr.getOffset() != 0) {+ MemoryBlock block = program.getMemory().getBlock(funcPtr);+ if (block == null || !block.isInitialized()) {+ throw new InvalidControlBlockException(+ infoProgramStruct.getName() + " @ " + infoStructAddr.toString(true) ++ " has invalid pointer offset for function: " + functionName ++ " -> " + funcPtr);+ }+ }++ if (funcPtr.getOffset() != 0) {+ FunctionInfo info = new FunctionInfo(functionName, funcPtr, numTest);+ functions.add(info);+ functionMap.put(functionName, info);+ }++ functionInfoAddress = functionInfoAddress.add(functionInfoStruct.getLength());++ }++ }+ catch (MemoryAccessException e) {+ throw new InvalidControlBlockException(+ infoProgramStruct.getName() + " program read error", e);+ }++ }++ protected String emuReadString(EmulatorHelper emu, Address strPtrAddr) {++ DataOrganization dataOrganization =+ emu.getProgram().getDataTypeManager().getDataOrganization();+ int charSize = dataOrganization.getCharSize();+ boolean isBigEndian = emu.getProgram().getMemory().isBigEndian();++ MemoryState memState = emu.getEmulator().getMemState();+ long offset = strPtrAddr.getOffset();+ if (isBigEndian) {+ offset += (charSize - 1);+ }+ char[] buffer = new char[128];+ int index = 0;+ while (index < buffer.length) {+ buffer[index] =+ (char) (memState.getValue(strPtrAddr.getAddressSpace(), offset, 1) & 0xff);+ if (buffer[index] == 0) {+ break;+ }+ offset += charSize;+ ++index;+ }+ return new String(buffer, 0, index);+ }++ protected long emuRead(EmulatorHelper emu, Address addr, int size) {+ if (size < 1 || size > 8) {+ throw new IllegalArgumentException("Unsupported EMU read size: " + size);+ }+ MemoryState memState = emu.getEmulator().getMemState();+ return memState.getValue(addr.getAddressSpace(), addr.getOffset(), size);+ }++ protected void emuWrite(EmulatorHelper emu, Address addr, int size, long value) {+ if (size < 1 || size > 8) {+ throw new IllegalArgumentException("Unsupported EMU read size: " + size);+ }+ MemoryState memState = emu.getEmulator().getMemState();+ memState.setValue(addr.getAddressSpace(), addr.getOffset(), size, value);+ }++ protected Address getMirroredDataAddress(EmulatorTestRunner emuTestRunner, Address addr) {+ AddressSpace defaultDataSpace =+ emuTestRunner.getProgram().getLanguage().getDefaultDataSpace();+ if (defaultDataSpace != null && !addr.getAddressSpace().equals(defaultDataSpace)) {+ addr = defaultDataSpace.getAddress(addr.getOffset());+ }+ return addr;+ }++ static Address findBytes(Memory memory, AddressSetView set, byte[] bytes) {+ for (AddressRange range : set.getAddressRanges()) {+ Address addr = memory.findBytes(range.getMinAddress(), range.getMaxAddress(), bytes,+ null, true, TaskMonitor.DUMMY);+ if (addr != null) {+ // ignore overlay blocks which may have been created by the importer+ if (addr.getAddressSpace().isOverlaySpace()) {+ continue;+ }+ return addr;+ }+ }+ return null;+ }++ static class InvalidControlBlockException extends Exception {++ private static final long serialVersionUID = 9137869694955008327L;++ public InvalidControlBlockException(String msg) {+ super(msg);+ }++ public InvalidControlBlockException(String msg, Throwable cause) {+ super(msg, cause);+ }+ }++ public static class FunctionInfo implements Comparable<FunctionInfo> {++ public final String functionName;+ public final Address functionAddr;+ public final int numberOfAsserts;++ FunctionInfo(String functionName, Address functionAddr, int numberOfAsserts) {+ this.functionName = functionName;+ this.functionAddr = functionAddr;+ this.numberOfAsserts = numberOfAsserts;+ }++ @Override+ public int compareTo(FunctionInfo other) {+ return functionName.compareTo(other.functionName);+ }++ @Override+ public boolean equals(Object obj) {+ if (!(obj instanceof FunctionInfo)) {+ return false;+ }+ FunctionInfo other = (FunctionInfo) obj;+ return functionName.equals(other.functionName) &+ functionAddr.equals(other.functionAddr);+ }++ @Override+ public int hashCode() {+ return functionAddr.hashCode();+ }++ @Override+ public String toString() {+ return functionName + "@" + functionAddr.toString(true);+ }+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestCombinedTestResults.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestCombinedTestResults.javanew file mode 100644index 0000000000..964456b478--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestCombinedTestResults.java@@ -0,0 +1,528 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.io.*;+import java.util.*;++import org.jdom.Document;+import org.jdom.Element;+import org.jdom.input.SAXBuilder;+import org.jdom.output.XMLOutputter;++import ghidra.test.processors.support.PCodeTestResults.TestResults;+import ghidra.util.HTMLUtilities;+import ghidra.util.Msg;+import ghidra.util.xml.GenericXMLOutputter;+import ghidra.util.xml.XmlUtilities;+import resources.ResourceManager;++public class PCodeTestCombinedTestResults {++ public static final String FILENAME = "pcode_test_results";++ private static String XML_VERSION = "1";++ // char width used when computing result column width+ private static int CHAR_WIDTH = 6;++ private File xmlFile;+ private File htmlFile;++ private Map<String, PCodeTestResults> combinedResults = new HashMap<>();++ PCodeTestCombinedTestResults(File reportsDir, boolean readExisting) throws IOException {+ this.xmlFile = new File(reportsDir, FILENAME + ".xml");+ this.htmlFile = new File(reportsDir, FILENAME + ".html");+ if (readExisting && xmlFile.exists()) {+ restoreFromXml();+ }+ }++ public PCodeTestResults getTestResults(String jUnitName, boolean create) {+ PCodeTestResults testResults = combinedResults.get(jUnitName);+ if (testResults == null && create) {+ testResults = new PCodeTestResults(jUnitName);+ combinedResults.put(jUnitName, testResults);+ }+ return testResults;+ }++ private void restoreFromXml() throws IOException {++ FileInputStream istream = new FileInputStream(xmlFile);+ BufferedInputStream bis = new BufferedInputStream(istream);+ try {+ SAXBuilder sax = XmlUtilities.createSecureSAXBuilder(false, false);+ Document doc = sax.build(bis);+ Element root = doc.getRootElement();++ if (!"PCODE_TESTS".equals(root.getName()) ||+ !XML_VERSION.equals(root.getAttributeValue("VERSION"))) {+ return;+ }++ @SuppressWarnings("unchecked")+ List<Element> elementList = root.getChildren(PCodeTestResults.TAG_NAME);+ for (Element element : elementList) {+ PCodeTestResults testResults = new PCodeTestResults(element);+ combinedResults.put(testResults.getJUnitName(), testResults);+ }+ }+ catch (org.jdom.JDOMException je) {+ throw new IOException("Invalid P-Code test results xml file: " + xmlFile, je);+ }+ finally {+ istream.close();+ }++ }++ void saveToXml() throws IOException {++ File dir = xmlFile.getParentFile();+ if (!dir.exists() && !dir.mkdir()) {+ throw new IOException("Failed to created directory: " + dir);+ }++ Element root = new Element("PCODE_TESTS");+ root.setAttribute("VERSION", XML_VERSION);++ for (String name : combinedResults.keySet()) {+ PCodeTestResults testResults = combinedResults.get(name);+ root.addContent(testResults.saveToXml());+ }++ // Store checkout data in temporary file+ File tmpFile = new File(xmlFile.getParentFile(), xmlFile.getName() + ".new");+ tmpFile.delete();+ FileOutputStream ostream = new FileOutputStream(tmpFile);+ BufferedOutputStream bos = new BufferedOutputStream(ostream);++ try {+ Document doc = new Document(root);+ XMLOutputter xmlout = new GenericXMLOutputter();+ xmlout.output(doc, bos);+ }+ finally {+ bos.close();+ }++ // Rename files+ File oldFile = null;+ if (xmlFile.exists()) {+ oldFile = new File(xmlFile.getParentFile(), xmlFile.getName() + ".bak");+ oldFile.delete();+ if (!xmlFile.renameTo(oldFile)) {+ throw new IOException("Failed to update: " + xmlFile.getAbsolutePath());+ }+ }+ if (!tmpFile.renameTo(xmlFile)) {+ if (oldFile != null) {+ oldFile.renameTo(xmlFile);+ }+ throw new IOException("Failed to update: " + xmlFile.getAbsolutePath());+ }++ Msg.info(this, "XML results file updated: " + xmlFile.getAbsolutePath());++ if (oldFile != null) {+ oldFile.delete();+ }+ }++ void copyResourceFile(String resourceName, PrintWriter w) throws IOException {+ InputStream in = ResourceManager.getResourceAsStream(resourceName);+ if (in == null) {+ throw new FileNotFoundException("Resource not found: " + resourceName);+ }+ in = new BufferedInputStream(in);+ BufferedReader br = new BufferedReader(new InputStreamReader(in));+ String line;+ while ((line = br.readLine()) != null) {+ w.println(line);+ }+ in.close();+ }++ private static class NamedTestColumn implements Comparable<NamedTestColumn> {+ private final String groupTestName;+ //String groupName;+ private final String testName;+ int charCount = 5; // char-count (minimum: -/-/-)++ /**+ *+ * @param groupTestName <group-name>.<test-name>+ */+ NamedTestColumn(String groupTestName) {+ this.groupTestName = groupTestName;++ int index = groupTestName.indexOf('.');+ //String groupName = "";+ String testName = groupTestName;+ if (index >= 0) {+ //groupName = groupTestName.substring(0, index);+ testName = groupTestName.substring(index + 1);+ }++ this.testName = testName;+ }++ /**+ * @return <group-name>.<test-name>+ */+ public String getGroupTestName() {+ return groupTestName;+ }++ /**+ * @return <test-name>+ */+ public String getTestName() {+ return testName;+ }++ @Override+ public int compareTo(NamedTestColumn o) {+ return testName.compareTo(o.testName);+ }++ @Override+ public int hashCode() {+ return testName.hashCode();+ }++ @Override+ public boolean equals(Object obj) {+ if (!(obj instanceof NamedTestColumn)) {+ return false;+ }+ NamedTestColumn other = (NamedTestColumn) obj;+ return testName.equals(other.testName);+ }++ public int getColumnWidth() {+ return (charCount + 2) * CHAR_WIDTH;+ }++ public void adjustWidth(TestResults testResults) {+ if (testResults == null) {+ return;+ }+ int count =+ computeCharCount(testResults.passCount) + computeCharCount(testResults.failCount) ++ computeCharCount(testResults.callOtherCount) + 2;+ charCount = Math.max(count, charCount);+ }++ private static int computeCharCount(int value) {+ int count = 1;+ while (value > 9) {+ ++count;+ value /= 10;+ }+ return count;+ }+ }++ void saveToHTML() throws IOException {+ File dir = htmlFile.getParentFile();+ if (!dir.exists() && !dir.mkdir()) {+ throw new IOException("Failed to created directory: " + dir);+ }++ List<String> sortedJUnitTestNames = new ArrayList<>();+ Map<String, Set<NamedTestColumn>> allTestNamesMap = new HashMap<>(); // mapped by <group-name>+ Map<String, NamedTestColumn> namedTestColumnMap = new HashMap<>(); // mapped by <group-name>.<test-name> key+ for (PCodeTestResults unitTestResults : combinedResults.values()) {+ sortedJUnitTestNames.add(unitTestResults.getJUnitName());+ for (String groupTestName : unitTestResults.getGroupTestNames()) {++ int index = groupTestName.indexOf('.');+ String groupName = "";+ if (index >= 0) {+ groupName = groupTestName.substring(0, index);+ }++ Set<NamedTestColumn> set = allTestNamesMap.get(groupName);+ if (set == null) {+ set = new HashSet<>();+ allTestNamesMap.put(groupName, set);+ }++ NamedTestColumn namedTestColumn = namedTestColumnMap.get(groupTestName);+ if (namedTestColumn == null) {+ namedTestColumn = new NamedTestColumn(groupTestName);+ namedTestColumnMap.put(groupTestName, namedTestColumn);+ set.add(namedTestColumn);+ }++ namedTestColumn.adjustWidth(unitTestResults.getTestResults(groupTestName, false));+ }+ }++ String[] groupNames = allTestNamesMap.keySet().toArray(new String[allTestNamesMap.size()]);+ Arrays.sort(groupNames);++ Map<String, NamedTestColumn[]> allTestNamesByGroup = new HashMap<>();+ for (String groupName : groupNames) {+ Set<NamedTestColumn> set = allTestNamesMap.get(groupName);+ NamedTestColumn[] namedTestColumns = set.toArray(new NamedTestColumn[set.size()]);+ Arrays.sort(namedTestColumns);+ allTestNamesByGroup.put(groupName, namedTestColumns);+ }++ Collections.sort(sortedJUnitTestNames);++ // Store checkout data in temporary file+ File tmpFile = new File(xmlFile.getParentFile(), xmlFile.getName() + ".new");+ tmpFile.delete();++ PrintWriter w = new PrintWriter(tmpFile);+ try {+ copyResourceFile("pcodetest/chunk1.hinc", w);++ writeTableHeader(w, groupNames, allTestNamesByGroup);++ copyResourceFile("pcodetest/chunk2.hinc", w);++ int rownum = 1;+ for (String name : sortedJUnitTestNames) {+ PCodeTestResults testResults = combinedResults.get(name);+ writeTestSummaryRow(w, testResults, (rownum++ % 2) == 1);+ }++ copyResourceFile("pcodetest/chunk3.hinc", w);++ boolean firstRow = true;+ for (String name : sortedJUnitTestNames) {+ PCodeTestResults testResults = combinedResults.get(name);+ writeTestResultsRow(w, groupNames, allTestNamesByGroup, testResults,+ (rownum++ % 2) == 1, firstRow);+ firstRow = false;+ }++ copyResourceFile("pcodetest/chunk4.hinc", w);+ }+ finally {+ w.flush();+ w.close();+ }++ // Rename files+ File oldFile = null;+ if (htmlFile.exists()) {+ oldFile = new File(htmlFile.getParentFile(), htmlFile.getName() + ".bak");+ oldFile.delete();+ if (!htmlFile.renameTo(oldFile)) {+ throw new IOException("Failed to update: " + htmlFile.getAbsolutePath());+ }+ }+ if (!tmpFile.renameTo(htmlFile)) {+ if (oldFile != null) {+ oldFile.renameTo(htmlFile);+ }+ throw new IOException("Failed to update: " + htmlFile.getAbsolutePath());+ }++ Msg.info(this, "HTML results file updated: " + htmlFile.getAbsolutePath());++ if (oldFile != null) {+ oldFile.delete();+ }+ }++ private void writeTableHeader(PrintWriter w, String[] groupNames,+ Map<String, NamedTestColumn[]> allTestNamesByGroup) {++ int[] groupWidth = new int[groupNames.length];++ w.println("<tr>");+ for (int groupIndex = 0; groupIndex < groupNames.length; groupIndex++) {+ String groupName = groupNames[groupIndex];+ NamedTestColumn[] namedTestColumns = allTestNamesByGroup.get(groupName);+ for (NamedTestColumn namedTestColumn : namedTestColumns) {+ int columnWidth = namedTestColumn.getColumnWidth();+ w.print("<td class=\"ResultHead\" align=\"center\" valign=\"bottom\">");+ w.print("<img src=\"X\" border=0 height=1 width=" + columnWidth + "><br>");+ w.print("<div class=\"r90\">");+ w.print(HTMLUtilities.friendlyEncodeHTML(namedTestColumn.getTestName()));+ w.println("</div></td>");+ groupWidth[groupIndex] += columnWidth;+ }+ }++ w.println("</tr><tr>");++ for (int groupIndex = 0; groupIndex < groupNames.length; groupIndex++) {+ String groupName = groupNames[groupIndex];+ NamedTestColumn[] namedTestColumns = allTestNamesByGroup.get(groupName);+ w.print(+ "<td class=\"GroupHead\" valign=\"middle\" colspan=\"" + namedTestColumns.length ++ "\" style=\"max-width:" + groupWidth[groupIndex] + ";\"> ");+ if (groupName.length() != 0) {+ w.print(HTMLUtilities.friendlyEncodeHTML(groupName));+ }+ w.println("</td>");+ }++ w.println("</tr>");+ }++ private void writeResultCount(PrintWriter w, int count, String color) {+ if (count == 0) {+ w.print("<font color=\"gray\">-</font>");+ }+ else {+ w.print("<font color=\"" + color + "\">" + Integer.toString(count) + "</font>");+ }+ }++ private void writeTestSummaryRow(PrintWriter w, PCodeTestResults testResults, boolean shaded) {+ String shadeStyle = "";+ if (shaded) {+ shadeStyle = " class=\"shade\"";+ }+ w.println("<tr" + shadeStyle + ">");++ w.print(" <td class=\"TestName\"><a href=\"../logs/" + testResults.getJUnitName() ++ ".log\" target=\"_log\">");+ w.print(testResults.getJUnitName());+ w.println("</a></td><td class=\"DateTime\">");++ String time = testResults.getTime();+ if (time == null) {+ time = " ";+ }+ w.print(time);+ w.println("</td>");++ // Summary result+ if (testResults.summaryHasIngestErrors || testResults.summaryHasRelocationErrors ||+ testResults.summaryHasDisassemblyErrors) {+ // analyzed program has relocation or disassembly errors+ w.print("<td align=\"center\" class=\"ResultSummary bad\">");+ if (testResults.summaryHasIngestErrors) {+ w.print("<font color=\"red\">Ingest-Err</font><br>");+ }+ if (testResults.summaryHasRelocationErrors) {+ w.print("<font color=\"red\">Reloc-Err</font><br>");+ }+ if (testResults.summaryHasDisassemblyErrors) {+ w.print("<font color=\"red\">Dis-Err</font>");+ }+ }+ else {+ w.print("<td align=\"center\" class=\"ResultSummary " ++ getSummaryHighlightColorClass(testResults) + "\">");+ writeResultCount(w, testResults.summaryPassCount, "green");+ w.print("/");+ writeResultCount(w, testResults.summaryFailCount, "red");+ w.print("/");+ writeResultCount(w, testResults.summaryCallOtherCount, "orange");+ if (testResults.summarySevereFailures != 0) {+ w.print("<br><font color=\"red\">ERR: " + testResults.summarySevereFailures ++ "</font>");+ }+ }++ w.println("</td>");++ w.println("</tr>");+ }++ private String getSummaryHighlightColorClass(PCodeTestResults testResults) {+ int failCount = testResults.summaryFailCount;+ String summaryHighlight = "";+ int totalAsserts =+ testResults.summaryPassCount + failCount + testResults.summaryCallOtherCount;+ if (testResults.summarySevereFailures != 0 ||+ totalAsserts != testResults.summaryTotalAsserts) {+ summaryHighlight = "bad";+ // bump-up failure count to reflect expected number of assertions+ int diff =+ totalAsserts - (testResults.summaryPassCount + testResults.summaryCallOtherCount);+ if (diff > 0) {+ failCount = diff;+ }+ }+ else if ((testResults.summaryPassCount != 0) && (failCount == 0) &&+ (testResults.summaryCallOtherCount == 0)) {+ summaryHighlight = "good";+ }+ return summaryHighlight;+ }++ private void writeTestResultsRow(PrintWriter w, String[] groupNames,+ Map<String, NamedTestColumn[]> allTestNamesByGroup, PCodeTestResults testResults,+ boolean shaded, boolean firstRow) {++ String shadeStyle = "";+ if (shaded) {+ shadeStyle = " class=\"shade\"";+ }+ w.println("<tr" + shadeStyle + ">");++ for (String groupName : groupNames) {+ NamedTestColumn[] namedTestColumns = allTestNamesByGroup.get(groupName);+ for (NamedTestColumn namedTestColumn : namedTestColumns) {+ String testName = namedTestColumn.getTestName();+ int pass = testResults.getPassResult(groupName, testName);+ int fail = testResults.getFailResult(groupName, testName);+ int callother = testResults.getCallOtherResult(groupName, testName);+ int total = pass + fail + callother;+ int totalAsserts = testResults.getTotalAsserts(groupName, testName);++ boolean severeFailure = testResults.hadSevereFailure(groupName, testName);++ boolean highlightBad = !severeFailure && (total != 0) && (total != totalAsserts);++ w.print(+ " <td align=\"center\" class=\"Result" + (highlightBad ? " bad" : "") + "\">");+ if (firstRow) {+ w.print("<img src=\"X\" border=0 height=1 width=" ++ namedTestColumn.getColumnWidth() + "><br>");+ }+ if (severeFailure) {+ w.print("<font color=\"red\">ERR</font>");+ }+ else {+ if (total == 0) {+ if (totalAsserts == 0) {+ w.print("<font color=\"gray\">-</font>");+ }+ else {+ w.print("<font color=\"red\">x</font>");+ }+ }+ else {+ writeResultCount(w, pass, "green");+ w.print("/");+ writeResultCount(w, fail, "red");+ w.print("/");+ writeResultCount(w, callother, "orange");+ if (total != totalAsserts) {+ w.print("<br><font color=\"red\">(!=" + totalAsserts + ")</font>");+ }+ }+ }+ w.println("</td>");+ }+ }+ w.println("</tr>");+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestControlBlock.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestControlBlock.javanew file mode 100644index 0000000000..9fe81b151b--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestControlBlock.java@@ -0,0 +1,418 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.util.ArrayList;+import java.util.List;++import ghidra.program.model.address.*;+import ghidra.program.model.data.DataOrganization;+import ghidra.program.model.data.Structure;+import ghidra.program.model.listing.Program;+import ghidra.program.model.mem.*;+import ghidra.program.model.util.CodeUnitInsertionException;+import ghidra.util.Msg;++/**+ * <code>PCodeTestControlBlock</code> data is read from each binary test file and+ * identified by the MAIN_CONTROL_BLOCK_MAGIC 64-bit character field value at the start of the+ * data structure. Only one instance of this should exist within the binary.+ */+public class PCodeTestControlBlock extends PCodeTestAbstractControlBlock {++ static final String INITIAL_FUNCTION_NAME = "<NONE>";+ static final String UNKNOWN_FUNCTION_NAME = "<UNKNOWN>";++ private static final String MAIN_CONTROL_BLOCK_MAGIC = "AbCdEFgH";++ private static Structure testInfoStruct; // TestInfo structure+ private static Structure groupInfoStruct; // GroupInfo structure++ private final AddressSetView restrictedSet;++ public final PCodeTestFile testFile;+ public final String cachedProgramPath;++ private List<PCodeTestGroup> testGroups; // test group data++ // TestInfo data read from program memory+ private Address onPassFunctionAddress;+ private Address onErrorFunctionAddress;+ private Address onDoneFunctionAddress;+ private Address sprintfFunctionAddress;+ private Address sprintfBufferAddress;++ // TestInfo structure offsets for runtime use+ private int numPassOffset;+ private int numFailOffset;+ private int lastTestPosOffset;+ private int lastErrorLineOffset;+ private int lastErrorFileOffset;+ private int lastFuncOffset;++ private int sprintfEnableOffset;++ private final PCodeTestResults testResults;++ /**+ * Construct test control block instance for the specified+ * program. Create TestInfo structure data within program if requested.+ * @param program program containing control block structure+ * @param restrictedSet the restricted memory area which should be searched+ * for control structures+ * @param testInfoStructAddr address of Main TestInfo structure+ * @param testFile original binary test file+ * @param cachedProgramPath program path within program file cache+ * @param applyStruct create structure Data within program if true+ * @throws InvalidControlBlockException+ * @throws CodeUnitInsertionException if applyStruct failed+ */+ private PCodeTestControlBlock(Program program, AddressSetView restrictedSet,+ Address testInfoStructAddr, PCodeTestFile testFile, String cachedProgramPath,+ boolean applyStruct, PCodeTestResults testResults)+ throws InvalidControlBlockException, CodeUnitInsertionException {+ super(program, testInfoStructAddr, testInfoStruct);++ this.restrictedSet = restrictedSet;+ this.testFile = testFile;+ this.cachedProgramPath = cachedProgramPath;+ this.testResults = testResults;++ readControlBlock(applyStruct);++ numPassOffset = getStructureComponent(infoProgramStruct, "numpass");+ numFailOffset = getStructureComponent(infoProgramStruct, "numfail");+ lastTestPosOffset = getStructureComponent(infoProgramStruct, "lastTestPos");+ lastErrorLineOffset = getStructureComponent(infoProgramStruct, "lastErrorLine");+ lastErrorFileOffset = getStructureComponent(infoProgramStruct, "lastErrorFile");+ lastFuncOffset = getStructureComponent(infoProgramStruct, "lastFunc");++ sprintfEnableOffset = getStructureComponent(infoProgramStruct, "sprintf5Enabled");+ }++ /**+ * Find Main TestInfo structure within memory and return instance of PCodeTestControlBlock+ * @param program+ * @param testFile original binary test file+ * @param restrictedSet a restricted set to be searched for control structures+ * @param cachedProgramPath program path within program file cache+ * @param testInfoStruct TestInfo structure definition+ * @param groupInfoStruct GroupInfo structure definition+ * @param applyStruct create structure Data within program if true+ * @param testResults test results storage object+ * @return instance of PCodeTestControlBlock+ * @throws InvalidControlBlockException+ * @throws CodeUnitInsertionException+ */+ static PCodeTestControlBlock getMainControlBlock(Program program, PCodeTestFile testFile,+ AddressSetView restrictedSet, String cachedProgramPath, Structure testInfoStruct,+ Structure groupInfoStruct, boolean applyStruct, PCodeTestResults testResults)+ throws InvalidControlBlockException, CodeUnitInsertionException {++ PCodeTestControlBlock.testInfoStruct = testInfoStruct;+ PCodeTestControlBlock.groupInfoStruct = groupInfoStruct;++ Memory memory = program.getMemory();+ byte[] magicBytes = getCharArrayBytes(program, MAIN_CONTROL_BLOCK_MAGIC);++ Address startOfControlBlock = findBytes(memory, restrictedSet, magicBytes);+ if (startOfControlBlock == null) {+ throw new InvalidControlBlockException("TestInfo structure not found");+ }++ return new PCodeTestControlBlock(program, restrictedSet, startOfControlBlock, testFile,+ cachedProgramPath, applyStruct, testResults);+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + ":" + testFile;+ }++ public List<PCodeTestGroup> getTestGroups() {+ return testGroups;+ }++ public Address getBreakOnDoneAddress() {+ return onDoneFunctionAddress;+ }++ public Address getBreakOnPassAddress() {+ return onPassFunctionAddress;+ }++ public Address getBreakOnErrorAddress() {+ return onErrorFunctionAddress;+ }++ public Address getSprintf5Address() {+ return sprintfFunctionAddress;+ }++ public Address getPrintfBufferAddress() {+ return sprintfBufferAddress;+ }++ public PCodeTestResults getTestResults() {+ return testResults;+ }++ @Override+ protected void readControlBlock(boolean applyStruct)+ throws InvalidControlBlockException, CodeUnitInsertionException {++ super.readControlBlock(applyStruct);++ int ptrSzOffset = getStructureComponent(infoProgramStruct, "ptrSz");+ int byteOrderOffset = getStructureComponent(infoProgramStruct, "byteOrder");+ int onPassPtrOffset = getStructureComponent(infoProgramStruct, "onPass");+ int onErrorPtrOffset = getStructureComponent(infoProgramStruct, "onError");+ int onDonePtrOffset = getStructureComponent(infoProgramStruct, "onDone");++ int sprintfPtrOffset = getStructureComponent(infoProgramStruct, "sprintf5");+ int sprintfBufferPtrOffset = getStructureComponent(infoProgramStruct, "sprintf5buffer");++ if (applyStruct) {+ forceCodePointer(infoStructAddr.add(onPassPtrOffset));+ forceCodePointer(infoStructAddr.add(onErrorPtrOffset));+ forceCodePointer(infoStructAddr.add(onDonePtrOffset));+ forceCodePointer(infoStructAddr.add(sprintfBufferPtrOffset));+ }++ DumbMemBufferImpl memBuffer = new DumbMemBufferImpl(program.getMemory(), infoStructAddr);+ try {++ // Check byte-order+ int byteOrder = memBuffer.getInt(byteOrderOffset);+ if (byteOrder != 0x1020304) {+ throw new InvalidControlBlockException(+ "TestInfo @ " + infoStructAddr.toString(true) ++ " has invalid byteOrder - language endianess may be incorrect (" ++ Integer.toHexString(byteOrder) + ")");+ }++ // Check pointer size+ // Must adjust size recorded by compiler+ int ptrSize = memBuffer.getInt(ptrSzOffset);+ DataOrganization dataOrganization = program.getDataTypeManager().getDataOrganization();+ ptrSize *= dataOrganization.getCharSize();+ if (ptrSize < 2 || ptrSize > 8) {+ throw new InvalidControlBlockException("TestInfo @ " ++ infoStructAddr.toString(true) + " has unsupported pointer size: " + ptrSize);+ }+ if (ptrSize != pointerSize) {+ String id =+ program.getLanguageID() + ":" + program.getCompilerSpec().getCompilerSpecID();+ Msg.warn(this, "TestInfo @ " + infoStructAddr.toString(true) + " ptrSz=" + ptrSize ++ " differs from data-organization size of " + pointerSize + " (" + id + ")");+ }++ // get onPass function pointer+ onPassFunctionAddress = readCodePointer(memBuffer, onPassPtrOffset, applyStruct);++ // get onError function pointer+ onErrorFunctionAddress = readCodePointer(memBuffer, onErrorPtrOffset, applyStruct);++ // get onDone function pointer+ onDoneFunctionAddress = readCodePointer(memBuffer, onDonePtrOffset, applyStruct);++ // get sprintf function pointer+ sprintfFunctionAddress = readCodePointer(memBuffer, sprintfPtrOffset, applyStruct);++ // get sprintf buffer pointer+ sprintfBufferAddress = readCodePointer(memBuffer, sprintfBufferPtrOffset, applyStruct);++ }+ catch (MemoryAccessException e) {+ throw new InvalidControlBlockException("TestInfo program read error", e);+ }++ // Find all test groups by locating corresponding TestInfo structure+ findTestGroups(applyStruct);++ }++ private void findTestGroups(boolean applyStruct)+ throws InvalidControlBlockException, CodeUnitInsertionException {++ Memory memory = program.getMemory();++ byte[] groupStructMagicBytes =+ getCharArrayBytes(program, PCodeTestGroupControlBlock.GROUP_CONTROL_BLOCK_MAGIC);++ testGroups = new ArrayList<>();++ AddressSet set = new AddressSet(restrictedSet);+ while (true) {++ Address startOfControlBlock = findBytes(memory, set, groupStructMagicBytes);+ if (startOfControlBlock == null) {+ break;+ }++ PCodeTestGroupControlBlock controlBlock = new PCodeTestGroupControlBlock(program,+ startOfControlBlock, groupInfoStruct, applyStruct, this);+ PCodeTestGroup testGroup = new PCodeTestGroup(controlBlock);+ testGroups.add(testGroup);++ // Remove previously searched addresses from search address set+ Address endAddr = startOfControlBlock.add(groupInfoStruct.getLength()).previous();+ AddressRange nextRange = set.getFirstRange();+ while (nextRange != null && !nextRange.contains(endAddr)) {+ set.delete(nextRange);+ nextRange = set.getFirstRange();+ }+ if (set.contains(endAddr)) {+ set = set.subtract(new AddressSet(set.getMinAddress(),+ startOfControlBlock.add(groupInfoStruct.getLength()).previous()));+ }+ }++ if (testGroups.size() == 0) {+ throw new InvalidControlBlockException(+ "P-Code test binary does not define any test groups");+ }++ }++ /**+ * Enable/Diable sprintf use within P-Code test emulation.+ * @param emuTestRunner emulator test runner+ * @param enable sprintf enablement+ */+ void setSprintfEnabled(EmulatorTestRunner emuTestRunner, boolean enable) {+ Address addr =+ getMirroredDataAddress(emuTestRunner, infoStructAddr.add(sprintfEnableOffset));+ emuWrite(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4, enable ? 1 : 0);+ }++ /**+ * Get 'numpass' field value from emulation memory state+ * @param emuTestRunner emulator test runner+ * @return 'numpass' field value+ */+ int getNumberPassed(EmulatorTestRunner emuTestRunner) {+ Address addr = getMirroredDataAddress(emuTestRunner, infoStructAddr.add(numPassOffset));+ return (int) emuRead(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4);+ }++ /**+ * Set 'numpass' field value within emulation memory state+ * @param emuTestRunner emulator test runner+ * @param value field value+ */+ void setNumberPassed(EmulatorTestRunner emuTestRunner, int value) {+ Address addr = getMirroredDataAddress(emuTestRunner, infoStructAddr.add(numPassOffset));+ emuWrite(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4, value);+ }++ /**+ * Get 'numfail' field value from emulation memory state+ * @param emuTestRunner emulator test runner+ * @return 'numfail' field value+ */+ int getNumberFailed(EmulatorTestRunner emuTestRunner) {+ Address addr = getMirroredDataAddress(emuTestRunner, infoStructAddr.add(numFailOffset));+ return (int) emuRead(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4);+ }++ /**+ * Set 'numfail' field value within emulation memory state+ * @param emuTestRunner emulator test runner+ * @param value field value+ */+ void setNumberFailed(EmulatorTestRunner emuTestRunner, int value) {+ Address addr = getMirroredDataAddress(emuTestRunner, infoStructAddr.add(numFailOffset));+ emuWrite(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4, value);+ }++ /**+ * Get 'lastTestPos' field value from emulation memory state+ * @param emuTestRunner emulator test runner+ * @return 'lastTestPos' field value+ */+ int getLastTestIndex(EmulatorTestRunner emuTestRunner) {+ Address addr = getMirroredDataAddress(emuTestRunner, infoStructAddr.add(lastTestPosOffset));+ return (int) emuRead(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4);+ }++ /**+ * Get 'lastErrorLine' field value from emulation memory state+ * @param emuTestRunner emulator test runner+ * @return 'lastErrorLine' field value+ */+ int getLastErrorLine(EmulatorTestRunner emuTestRunner) {+ Address addr =+ getMirroredDataAddress(emuTestRunner, infoStructAddr.add(lastErrorLineOffset));+ return (int) emuRead(emuTestRunner.getEmulatorHelper(), addr, SIZEOF_U4);+ }++ /**+ * Get 'lastErrorFile' string value from emulation memory state. Must follow string+ * pointer contained within lastErrorFile field.+ * @param emuTestRunner emulator test runner+ * @return 'lastErrorLine' field value+ */+ String getLastErrorFile(EmulatorTestRunner emuTestRunner) {+ Address addr =+ getMirroredDataAddress(emuTestRunner, infoStructAddr.add(lastErrorFileOffset));+ long fileNameOffset = emuRead(emuTestRunner.getEmulatorHelper(), addr, pointerSize);+ addr = addr.getNewAddress(fileNameOffset, true);+ addr = getMirroredDataAddress(emuTestRunner, addr);+ return emuReadString(emuTestRunner.getEmulatorHelper(), addr);+ }++ /**+ * Get the name of the last test function to be run+ * @param emuTestRunner+ * @return last test function name+ */+ String getLastFunctionName(EmulatorTestRunner emuTestRunner, TestLogger logger,+ PCodeTestGroup activeGroup) {+ Address ptrStorageAddr = infoStructAddr.add(lastFuncOffset);+ Address ptrAddr = getMirroredDataAddress(emuTestRunner, ptrStorageAddr);+ long funcNameOffset = emuRead(emuTestRunner.getEmulatorHelper(), ptrAddr, pointerSize);+ Address strAddr = ptrAddr.getNewAddress(funcNameOffset, true);+ strAddr = getMirroredDataAddress(emuTestRunner, strAddr);+ String fnName = emuReadString(emuTestRunner.getEmulatorHelper(), strAddr);+ if ("none".equals(fnName)) {+ if (logger != null) {+ logger.log(activeGroup, "ERROR last executed function name pointer stored at " ++ ptrStorageAddr + " has not been set (reported as <NONE>)");+ }+ return INITIAL_FUNCTION_NAME;+ }+ String altName = null;+ if (!fnName.endsWith(PCodeTestGroupControlBlock.TEST_GROUP_FUNCTION_SUFFIX)) {+ altName = fnName + PCodeTestGroupControlBlock.TEST_GROUP_FUNCTION_SUFFIX;+ }+ if (activeGroup != null) {+ if (activeGroup.controlBlock.getFunctionInfo(fnName) != null) {+ return fnName;+ }+ if (altName != null && activeGroup.controlBlock.getFunctionInfo(altName) != null) {+ return fnName;+ }+ }+ if (logger != null) {+ logger.log(activeGroup,+ "ERROR last executed function name pointer stored at " + ptrStorageAddr ++ " was improperly set (reported as <UNKNOWN>, pointer=" + strAddr + ")");+ }+ return UNKNOWN_FUNCTION_NAME;+ }++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestFile.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestFile.javanew file mode 100644index 0000000000..41edb97a50--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestFile.java@@ -0,0 +1,67 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.io.File;++public class PCodeTestFile {++ public final File file;+ public final String fileReferencePath;++ public PCodeTestFile(File f, String fileReferencePath) {+ this.file = f;+ this.fileReferencePath = fileReferencePath;+ }++ @Override+ public String toString() {+ return fileReferencePath;+ }++ @Override+ public int hashCode() {+ final int prime = 31;+ int result = 1;+ result = prime * result + ((file == null) ? 0 : file.hashCode());+ result = prime * result + ((fileReferencePath == null) ? 0 : fileReferencePath.hashCode());+ return result;+ }++ @Override+ public boolean equals(Object obj) {+ if (this == obj)+ return true;+ if (obj == null)+ return false;+ if (getClass() != obj.getClass())+ return false;+ PCodeTestFile other = (PCodeTestFile) obj;+ if (file == null) {+ if (other.file != null)+ return false;+ }+ else if (!file.equals(other.file))+ return false;+ if (fileReferencePath == null) {+ if (other.fileReferencePath != null)+ return false;+ }+ else if (!fileReferencePath.equals(other.fileReferencePath))+ return false;+ return true;+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroup.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroup.javanew file mode 100644index 0000000000..34fc81b7c8--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroup.java@@ -0,0 +1,122 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.util.ArrayList;+import java.util.List;++import ghidra.program.model.address.Address;+import ghidra.program.model.listing.Program;+import ghidra.program.model.symbol.Symbol;+import ghidra.program.model.symbol.SymbolUtilities;+import ghidra.util.Msg;++/**+ * <code>PCodeTestGroup</code> identifies a test group function and its corresponding+ * PCodeTestGroupControlBlock.+ */+public class PCodeTestGroup implements Comparable<PCodeTestGroup> {++ /**+ * All test-group function names defined within the test binary must start with "main_"+ */+ public static final String FUNCTION_NAME_PREFIX = "main_";++ public final String testGroupName;+ public final Address functionEntryPtr;+// public final int testCount; // TODO: not yet fully implemented - do not use!++ public final PCodeTestControlBlock mainTestControlBlock;+ public final PCodeTestGroupControlBlock controlBlock;++ private ArrayList<String> testFailures = new ArrayList<>();++ PCodeTestGroup(PCodeTestGroupControlBlock controlBlock) {+ this.testGroupName = controlBlock.getTestGroupName();+ this.functionEntryPtr = controlBlock.getTestGroupMainAddress();+// this.testCount = testCount;+ this.controlBlock = controlBlock;+ this.mainTestControlBlock = controlBlock.mainTestControlBlock;+ }++ @Override+ public String toString() {+ return testGroupName + "@" + functionEntryPtr;+ }++ void testPassed(String testName, String errFileName, int errLineNum, Program program,+ TestLogger logger) {+ mainTestControlBlock.getTestResults().addPassResult(testGroupName, testName);+ }++ void testFailed(String testName, String errFileName, int errLineNum, boolean callOtherFailure,+ Program program, TestLogger logger) {+ if (callOtherFailure) {+ mainTestControlBlock.getTestResults().addCallOtherResult(testGroupName, testName);+ }+ else {+ mainTestControlBlock.getTestResults().addFailResult(testGroupName, testName);+ }+ String failure = testName;+ if (testName != null) {+ Symbol symbol = SymbolUtilities.getLabelOrFunctionSymbol(program, testName,+ err -> Msg.error(this, err));+ if (symbol != null) {+ failure += " @ " + symbol.getAddress().toString(true);+ }+ failure += " (" + errFileName + ":" + errLineNum + ")";+ }+ testFailures.add(failure);+ logger.log(this,+ "Test Failed: " + failure + (callOtherFailure ? " (callother error)" : ""));+ }++ void severeTestFailure(String testName, String errFileName, int errLineNum, Program program,+ TestLogger logger) {+ mainTestControlBlock.getTestResults().addSevereFailResult(testGroupName, testName);+ testFailed(testName, errFileName, errLineNum, false, program, logger);+ }++ void clearFailures() {+ testFailures.clear();+ }++ /**+ * @return list of recorded emulation test failures+ */+ public List<String> getTestFailures() {+ return new ArrayList<>(testFailures);+ }++ @Override+ public int hashCode() {+ return testGroupName.hashCode();+ }++ @Override+ public boolean equals(Object obj) {+ if (!(obj instanceof PCodeTestGroup)) {+ return false;+ }+ PCodeTestGroup other = (PCodeTestGroup) obj;+ return (controlBlock == other.controlBlock) && testGroupName.equals(other.testGroupName);+ }++ @Override+ public int compareTo(PCodeTestGroup o) {+ return testGroupName.compareTo(o.testGroupName);+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroupControlBlock.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroupControlBlock.javanew file mode 100644index 0000000000..9ca083d891--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestGroupControlBlock.java@@ -0,0 +1,84 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import ghidra.program.model.address.Address;+import ghidra.program.model.data.Structure;+import ghidra.program.model.listing.Program;+import ghidra.program.model.util.CodeUnitInsertionException;++/**+ * <code>PCodeTestGroupControlBlock</code> corresponds to each test group contained within+ * a binary test file and identified by the GROUP_CONTROL_BLOCK_MAGIC 64-bit character+ * field value at the start of the data structure.+ */+public class PCodeTestGroupControlBlock extends PCodeTestAbstractControlBlock {++ static String TEST_GROUP_NAME_SUFFIX = "_main";+ static String TEST_GROUP_FUNCTION_SUFFIX = "_Main";++ static final String GROUP_CONTROL_BLOCK_MAGIC = "aBcDefGh";++ public final PCodeTestControlBlock mainTestControlBlock;++ private String testGroupName;+ private Address testGroupMainAddr;++ /**+ * Construct test group control block instance for the specified+ * program. Create GroupInfo structure data within program if requested.+ * @param program+ * @param groupInfoStructAddr program address where structure resides+ * @param groupInfoStruct GroupInfo structure definition+ * @param applyStruct create GroupInfo structure data within program if true+ * @throws InvalidControlBlockException+ * @throws CodeUnitInsertionException if applyStruct failed+ */+ PCodeTestGroupControlBlock(Program program, Address groupInfoStructAddr,+ Structure groupInfoStruct, boolean applyStruct,+ PCodeTestControlBlock mainTestControlBlock)+ throws InvalidControlBlockException, CodeUnitInsertionException {+ super(program, groupInfoStructAddr, groupInfoStruct);++ this.mainTestControlBlock = mainTestControlBlock;++ readControlBlock(applyStruct);++ if (getNumberFunctions() < 1) {+ throw new InvalidControlBlockException("GroupInfo @ " + infoStructAddr.toString(true) ++ " does not define any functions: " + infoStructAddr);+ }++ testGroupName = getFunctionInfo(0).functionName;+ if (!testGroupName.endsWith(TEST_GROUP_NAME_SUFFIX)) {+ throw new InvalidControlBlockException("GroupInfo @ " + infoStructAddr.toString(true) ++ " does not define <group>_main function as first function");+ }+ testGroupName =+ testGroupName.substring(0, testGroupName.length() - TEST_GROUP_NAME_SUFFIX.length());+ testGroupMainAddr = getFunctionInfo(0).functionAddr;++ }++ public String getTestGroupName() {+ return testGroupName;+ }++ public Address getTestGroupMainAddress() {+ return testGroupMainAddr;+ }++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestResults.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestResults.javanew file mode 100644index 0000000000..6db03c1b22--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/PCodeTestResults.java@@ -0,0 +1,334 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.text.DateFormat;+import java.text.SimpleDateFormat;+import java.util.*;++import org.jdom.Attribute;+import org.jdom.Element;++public class PCodeTestResults {++ private String jUnitName;++ boolean summaryHasIngestErrors;+ boolean summaryHasRelocationErrors;+ boolean summaryHasDisassemblyErrors;++ int summaryTotalAsserts;+ int summaryPassCount;+ int summaryFailCount;+ int summaryCallOtherCount;+ int summarySevereFailures;++ long time;++ // map keys formed with "<groupName>.<testName>" string+ private Map<String, TestResults> results = new HashMap<>();++ PCodeTestResults(String jUnitName) {+ this.jUnitName = jUnitName;+ time = System.currentTimeMillis();+ }++ public String getJUnitName() {+ return jUnitName;+ }++ private static DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");++ public String getTime() {+ if (time == 0) {+ return null;+ }+ Date d = new Date(time);+ return dateFormat.format(d);+ }++ public int getNumberOfTests() {+ return results.size();+ }++ /**+ * @return collection of group/testNames in the form "<groupName>.<testName>"+ */+ public Collection<String> getGroupTestNames() {+ return results.keySet();+ }++ /**+ * Get groupName.testName combined into single string+ * @param groupName+ * @param testName+ * @return+ */+ private String getGroupTestName(String groupName, String testName) {+ if (testName.endsWith(PCodeTestGroupControlBlock.TEST_GROUP_FUNCTION_SUFFIX)) {+ testName = testName.substring(0,+ testName.length() - PCodeTestGroupControlBlock.TEST_GROUP_FUNCTION_SUFFIX.length());+ }+ // Exclude any trailing digits from groupName which may have been appended to filename+ return groupName.replaceAll("\\d*$", "") + "." + testName;+ }++ /**+ * Get results entry keyed by "<groupName>.<testName>"+ * @param groupTestName+ * @param create+ * @return+ */+ TestResults getTestResults(String groupTestName, boolean create) {+ TestResults testResults = results.get(groupTestName);+ if (testResults == null && create) {+ testResults = new TestResults();+ results.put(groupTestName, testResults);+ }+ return testResults;+ }++ void declareTest(String groupName, String testName, int totalAsserts) {+ String groupTestName = getGroupTestName(groupName, testName);+ getTestResults(groupTestName, true).totalAsserts = totalAsserts;+ summaryTotalAsserts += totalAsserts;+ }++ public int getTotalAsserts(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ TestResults testResults = getTestResults(groupTestName, false);+ if (testResults != null) {+ return testResults.totalAsserts;+ }+ return 0;+ }++ void addPassResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ getTestResults(groupTestName, true).passCount++;+ ++summaryPassCount;+ }++ public int getPassResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ TestResults testResults = getTestResults(groupTestName, false);+ if (testResults != null) {+ return testResults.passCount;+ }+ return 0;+ }++ void addFailResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ getTestResults(groupTestName, true).failCount++;+ summaryFailCount++;+ }++ public int getFailResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ TestResults testResults = getTestResults(groupTestName, false);+ if (testResults != null) {+ return testResults.failCount;+ }+ return 0;+ }++ void addSevereFailResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ getTestResults(groupTestName, true).severeFailure = true;+ summarySevereFailures++;+ }++ public boolean hadSevereFailure(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ TestResults testResults = getTestResults(groupTestName, false);+ if (testResults != null) {+ return testResults.severeFailure;+ }+ return false;+ }++ void addCallOtherResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ getTestResults(groupTestName, true).callOtherCount++;+ summaryCallOtherCount++;+ }++ public int getCallOtherResult(String groupName, String testName) {+ String groupTestName = getGroupTestName(groupName, testName);+ TestResults testResults = getTestResults(groupTestName, false);+ if (testResults != null) {+ return testResults.callOtherCount;+ }+ return 0;+ }++ void clear() {+ results.clear();+ summaryHasIngestErrors = false;+ summaryHasRelocationErrors = false;+ summaryHasDisassemblyErrors = false;+ summaryTotalAsserts = 0;+ summaryPassCount = 0;+ summaryFailCount = 0;+ summaryCallOtherCount = 0;+ summarySevereFailures = 0;+ time = System.currentTimeMillis();+ }++ private static String XML_VERSION = "1";++ public static String TAG_NAME = "PCodeTestResults";++ public PCodeTestResults(Element root) {++ if (!TAG_NAME.equals(root.getName())) {+ throw new IllegalArgumentException("Unsupported root element: " + root.getName());+ }+ String ver = root.getAttributeValue("VERSION");+ if (!XML_VERSION.equals(ver)) {+ throw new IllegalArgumentException(+ "Unsupported XML format version " + ver + ", required format is " + XML_VERSION);+ }++ jUnitName = root.getAttributeValue("JUNIT");++ time = 0;+ String timeStr = root.getAttributeValue("TIME");+ if (timeStr != null) {+ try {+ time = Long.parseLong(timeStr);+ }+ catch (NumberFormatException e) {+ // ignore+ }+ }++ summaryHasIngestErrors = getAttributeValue(root, "INGEST_ERR", false);+ summaryHasRelocationErrors = getAttributeValue(root, "RELOC_ERR", false);+ summaryHasDisassemblyErrors = getAttributeValue(root, "DIS_ERR", false);++ @SuppressWarnings("unchecked")+ List<Element> elementList = root.getChildren("TestResults");+ for (Element element : elementList) {++ String testName = element.getAttributeValue("NAME");+ if (testName == null) {+ throw new IllegalArgumentException("Invalid TestResults element in XML");+ }+ TestResults testResults = new TestResults();+ testResults.totalAsserts = getAttributeValue(element, "TOTAL_ASSERTS", 0);+ testResults.passCount = getAttributeValue(element, "PASS", 0);+ testResults.failCount = getAttributeValue(element, "FAIL", 0);+ testResults.callOtherCount = getAttributeValue(element, "CALLOTHER", 0);+ testResults.severeFailure = getAttributeValue(element, "SEVERE_FAILURE", false);++ summaryTotalAsserts += testResults.totalAsserts;+ summaryPassCount += testResults.passCount;+ summaryFailCount += testResults.failCount;+ summaryCallOtherCount += testResults.callOtherCount;+ if (testResults.severeFailure) {+ ++summarySevereFailures;+ }++ results.put(testName, testResults);+ }+ }++ int getAttributeValue(Element element, String attrName, int defaultValue) {+ String val = element.getAttributeValue(attrName);+ if (val == null) {+ return defaultValue;+ }+ try {+ return Integer.parseInt(val);+ }+ catch (NumberFormatException e) {+ return 0;+ }+ }++ boolean getAttributeValue(Element element, String attrName, boolean defaultValue) {+ String val = element.getAttributeValue(attrName);+ if (val == null) {+ return defaultValue;+ }+ try {+ return Boolean.valueOf(val);+ }+ catch (NumberFormatException e) {+ return false;+ }+ }++ Element saveToXml() {++ Element root = new Element("PCodeTestResults");+ root.setAttribute(new Attribute("VERSION", XML_VERSION));+ root.setAttribute(new Attribute("JUNIT", jUnitName));+ if (time != 0) {+ root.setAttribute(new Attribute("TIME", Long.toString(time)));+ }++ if (summaryHasIngestErrors) {+ root.setAttribute(new Attribute("INGEST_ERR", "TRUE"));+ }++ if (summaryHasRelocationErrors) {+ root.setAttribute(new Attribute("RELOC_ERR", "TRUE"));+ }++ if (summaryHasDisassemblyErrors) {+ root.setAttribute(new Attribute("DIS_ERR", "TRUE"));+ }++ ArrayList<String> testNames = new ArrayList<>(results.keySet());+ Collections.sort(testNames);++ for (String testName : testNames) {+ TestResults testResults = results.get(testName);+ Element element = new Element("TestResults");+ element.setAttribute(new Attribute("NAME", testName));+ element.setAttribute(+ new Attribute("TOTAL_ASSERTS", Integer.toString(testResults.totalAsserts)));+ element.setAttribute(new Attribute("PASS", Integer.toString(testResults.passCount)));+ element.setAttribute(new Attribute("FAIL", Integer.toString(testResults.failCount)));+ element.setAttribute(+ new Attribute("CALLOTHER", Integer.toString(testResults.callOtherCount)));+ if (testResults.severeFailure) {+ element.setAttribute(new Attribute("SEVERE_FAILURE", "TRUE"));+ }+ root.addContent(element);+ }+ return root;+ }++ static class TestResults {+ int totalAsserts;+ int passCount;+ int failCount;+ int callOtherCount;++ boolean severeFailure = false;++ @Override+ public String toString() {+ // TODO Auto-generated method stub+ return "{" + passCount + "/" + failCount + "/" + callOtherCount + "(" + totalAsserts ++ ")}";+ }+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.javanew file mode 100644index 0000000000..721237b014--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java@@ -0,0 +1,2214 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import java.io.*;+import java.lang.reflect.Constructor;+import java.lang.reflect.InvocationTargetException;+import java.math.BigDecimal;+import java.math.BigInteger;+import java.util.*;+import java.util.regex.Matcher;+import java.util.regex.Pattern;++import generic.jar.ResourceFile;+import generic.test.AbstractGTest;+import ghidra.GhidraTestApplicationLayout;+import ghidra.app.cmd.disassemble.DisassembleCommand;+import ghidra.app.cmd.function.ApplyFunctionDataTypesCmd;+import ghidra.app.cmd.function.CreateFunctionCmd;+import ghidra.app.plugin.core.analysis.AutoAnalysisManager;+import ghidra.app.plugin.processors.sleigh.SleighDebugLogger;+import ghidra.app.plugin.processors.sleigh.SleighDebugLogger.SleighDebugMode;+import ghidra.app.util.PseudoDisassembler;+import ghidra.app.util.opinion.Loader;+import ghidra.framework.*;+import ghidra.framework.options.Options;+import ghidra.framework.store.LockException;+import ghidra.pcode.floatformat.FloatFormat;+import ghidra.pcode.floatformat.FloatFormatFactory;+import ghidra.program.database.ProgramDB;+import ghidra.program.disassemble.DisassemblerContextImpl;+import ghidra.program.model.address.*;+import ghidra.program.model.data.*;+import ghidra.program.model.lang.*;+import ghidra.program.model.listing.*;+import ghidra.program.model.listing.Function.FunctionUpdateType;+import ghidra.program.model.mem.*;+import ghidra.program.model.symbol.*;+import ghidra.program.util.DefaultLanguageService;+import ghidra.program.util.GhidraProgramUtilities;+import ghidra.test.TestEnv;+import ghidra.test.TestProgramManager;+import ghidra.test.processors.support.EmulatorTestRunner.DumpFormat;+import ghidra.test.processors.support.PCodeTestAbstractControlBlock.FunctionInfo;+import ghidra.test.processors.support.PCodeTestAbstractControlBlock.InvalidControlBlockException;+import ghidra.util.*;+import ghidra.util.exception.*;+import ghidra.util.task.TaskMonitor;+import junit.framework.*;+import utilities.util.FileUtilities;+import utility.application.ApplicationLayout;++/**+ * <code>ProcessorEmulatorTestAdapter</code> provides an abstract JUnit test implementation+ * for processor-specific test cases. All test cases which extend this class must have a+ * class name which ends with 'EmulatorTest' and starts with the processor designator which+ * will be used to identify associated test binaries within either the processor module's+ * data/pcodetests/ directory or the Ghidra/Test/TestResources/data/pcodetests/ directory generally+ * contained within the binary repository (e.g., ghidra.bin).+ * <p>+ * Within the pcodetests directory all files and folders which start with the prefix+ * <processor-designator>_pcodetest* will be processed. All files contained within a matching+ * subdirectory will be treated as related binaries and imported. Any *.gzf file will be+ * imported but assumed to be pre-analyzed. Binary files to be imported and analyzed must+ * utilize the *.out file extension.+ * <p>+ * JUnit X86EmulatorTest could utilize the following binary file naming strategy:+ * <pre>+ * pcodetests/X86_PCodeTests+ * - binary1.o+ * - binary2.o+ * - binary3.gzf+ * pcodetests/X86_PCodeTests/data (could be used for any associated files not to be imported)+ * - binary3.o+ * - binary3.d+ *+ * or, a single binary file could suffice:+ * - pcodetests/X86_PCodeTest.out+ * </pre>+ *+ * Any *.out binary found will be imported and analyzed. The resulting program will+ * be stored as a gzf in the test-output cache directory. These cached files will be used+ * instead of a test resource binary if that binary's md5 checksum has not changed since its cached+ * gzf was created. This use of cache files will allow the tests to run quickly on subsequent+ * executions. If re-analysis is required, the cache will need to be cleared manually.+ *+ * NOTES:+ * 1. Dummy Test Methods must be added for all known test groups. See bottom of this file. This+ * all allows for the single test trace mode execution to work within Eclipse.+ * 2. Trace logging disabled by default when all test groups are run (see buildEmulatorTestSuite method).+ * Specific traceLevel and traceLog file controlled via environment properties+ * EmuTestTraceLevel and EmuTestTraceFile.+ * 3. The TestInfo structure must be properly maintained within the datatype archive EmuTesting.gdt+ * and field naming consistent with use in PCodeTestControlBlock.java+ * 4. The {@link #initializeState(EmulatorTestRunner, Program)} may be overriden to initialize the+ * register values if needed. This should be based upon symbols or other program information+ * if possible since hardcoded constants may not track future builds of a test binaries.+ * An attempt is made to initialize the stack pointer automatically based upon well known+ * stack initialization symbols.+ */+public abstract class ProcessorEmulatorTestAdapter extends TestCase implements ExecutionListener {++ public final static String BATCH_MODE_OUTPUT_DIR =+ System.getProperty("ghidra.test.property.output.dir");++ // If pcodetests data directory can not be found for the module containing the junit,+ // This default ProcessorTest module will be searched instead.+ private static final String DEFAULT_PROCESSOR_TEST_MODULE = "Test/TestResources"; // module path relative to the Ghidra directory++ // TODO: Add support for duplicate test-group name within different test binaries.+ // must enumerate CUint binaries and reflect in test name somehow ??++ private static final String TEST_INFO_STRUCT_NAME = "TestInfo";+ private static final String GROUP_INFO_STRUCT_NAME = "GroupInfo";++ private static final String PCODE_TEST_FILE_BASE_REGEX = "_PCodeTest.*";++ private static final String EMULATOR_TEST_SUFFIX = "EmulatorTest";++ private static final String EMULATOR_TRACE_LEVEL_PROPERTY = "EmuTestTraceLevel";+ private static int traceLevel = 3; // 0:disabled 1:Instruction 2:RegisterState 3:Reads-n-Writes++ private static Map<Class<?>, LogData> logDataMap = new HashMap<>();++ private static Class<?> lastTestClass;++ private static final String EMULATOR_TRACE_DISABLE_PROPERTY = "EmuTestTraceDisable";+ public static boolean traceDisabled = false;+ static {+ if (System.getProperty(EMULATOR_TRACE_DISABLE_PROPERTY) != null) {+ traceDisabled = Boolean.getBoolean(EMULATOR_TRACE_DISABLE_PROPERTY);+ }+ }++ private static final int MAX_REGDUMP_WIDTH = 80;++ private static final int EXECUTION_TIMEOUT_MS = 4 * 60000;+ private static final int MAX_EXECUTION_STEPS = 2000000;++ private static final String GZF_FILE_EXT = ".gzf";+ private static final String BINARY_FILE_EXT = ".out";++ //private static final String MODULE_NAME = "ProcessorTest2";++ // directory above application root which will contain the following outputs: cache, logs, results+ private static final String TEST_OUTPUT_PATH = "test-output";++ private static final String GZF_CACHEDIR_NAME = "cache";++ private static final String LOG_DIR_NAME = "logs";++ private static final String RESULTS_DIR_NAME = "results";++ static {+ File testDir = new File(TestProgramManager.getDbTestDir(), "PCodeTest");+ TestProgramManager.setDbTestDir(testDir);+ cleanupTempData();+ }++ private static final String TEST_RESOURCE_PATH = "data/pcodetests";++ private static final String FAILURE_RESULT_NAME = "failure";++ private static final String TEST_PREFIX = "test_";++// static {+// forceProgramCaching();+// }++ private static File outputDir;+ private static File resourcesCacheDir;+ private static File logDir;+ private static File resultsDir;++ private static PCodeTestCombinedTestResults combinedResults;+ private static Runnable resultsWriter;++ private static boolean initialized = false;++ protected String processorDesignator;++ private static Map<String, List<PCodeTestControlBlock>> testControlBlocksMap = new HashMap<>();++ private List<PCodeTestControlBlock> testControlBlocks;+ private HashMap<String, PCodeTestGroup> testGroupMap; // group-name -> TestGroup++ protected Language language;+ protected CompilerSpec compilerSpec;+ protected Register[] regDumpSet;+ protected Set<Register> floatRegSet;++ // set of blocks which should not be searched when looking for control structures+ protected Set<String> ignoredBlocks;++ private TestEnv env;+ private LogData logData;++ private ResourceFile myModuleRootDirectory;+ private Collection<ResourceFile> applicationRootDirectories;+ private File resourcesTestDataDir;++ private FileDataTypeManager archiveDtMgr;+ private Structure testInfoStruct;+ private Structure groupInfoStruct;++ private ParallelInstructionLanguageHelper parallelHelper;++ private static boolean deleteResultFilesOnStartup = false;++ private static void cleanupTempData() {+ FileUtilities.deleteDir(TestProgramManager.getDbTestDir());+ FileUtilities.deleteDir(new File(AbstractGTest.getTestDirectoryPath()));+ }++ public static void deleteResultFilesOnStartup() {+ deleteResultFilesOnStartup = true;+ }++ private static synchronized void initializeSharedResources() {++ if (initialized) {+ return;+ }++ System.setProperty(SystemUtilities.TESTING_PROPERTY, "true");++ try {+ ApplicationLayout layout =+ new GhidraTestApplicationLayout((new File(AbstractGTest.getTestDirectoryPath())));+ ApplicationConfiguration configuration = new HeadlessGhidraApplicationConfiguration();+ Application.initializeApplication(layout, configuration);+ initialized = true;+ }+ catch (IOException e) {+ throw new RuntimeException(e);+ }++ String outputRoot;+ if (BATCH_MODE_OUTPUT_DIR != null) {+ // Use explicit output directory root if specified+ outputRoot = BATCH_MODE_OUTPUT_DIR;+ }+ else {+ try {+ // By default, create test output within a directory at the same level as the+ // development repositories+ outputRoot =+ Application.getApplicationRootDirectory().getParentFile().getParentFile().getCanonicalPath();+ }+ catch (IOException e) {+ throw new RuntimeException(e);+ }+ }+ if (!(new File(outputRoot)).isDirectory()) {+ throw new RuntimeException("Output directory not found: " + BATCH_MODE_OUTPUT_DIR);+ }++ outputDir = new File(outputRoot, TEST_OUTPUT_PATH);++ Msg.info(ProcessorEmulatorTestAdapter.class,+ "Using test output directory: " + outputDir.getAbsolutePath());++ resourcesCacheDir = new File(outputDir, GZF_CACHEDIR_NAME);++ logDir = new File(outputDir, LOG_DIR_NAME);+ FileUtilities.mkdirs(logDir);++ resultsDir = new File(outputDir, RESULTS_DIR_NAME);++ if (deleteResultFilesOnStartup) {+ File xmlFile = new File(resultsDir, PCodeTestCombinedTestResults.FILENAME + ".xml");+ File htmlFile = new File(resultsDir, PCodeTestCombinedTestResults.FILENAME + ".html");+ xmlFile.delete();+ htmlFile.delete();+ }++ String levelStr = System.getProperty(EMULATOR_TRACE_LEVEL_PROPERTY);+ if (levelStr != null) {+ traceLevel = Integer.parseInt(levelStr);+ }++ try {+ combinedResults = new PCodeTestCombinedTestResults(resultsDir, true);+ }+ catch (IOException e) {+ Msg.error(ProcessorEmulatorTestAdapter.class,+ "Error occurred reading previous XML P-Code test results, file will be re-written");+ try {+ combinedResults = new PCodeTestCombinedTestResults(resultsDir, true);+ }+ catch (IOException e1) {+ throw new AssertException(); // unexpected+ }+ }++ // resultWriter now invoked by EmulationTestSuite run instead of shutdown hook+ resultsWriter = () -> {+ if (combinedResults == null) {+ return;+ }+ try {+ combinedResults.saveToXml();+ combinedResults.saveToHTML();++ // cleanup+ //TestEnv.+ }+ catch (IOException e) {+ e.printStackTrace();+ }+ };++ // Runtime.getRuntime().addShutdownHook(new Thread(resultsWriter, "Results Writer"));+ }++ public ProcessorEmulatorTestAdapter(String name, String languageID, String compilerSpecID,+ String[] regDumpSetNames)+ throws LanguageNotFoundException, CompilerSpecNotFoundException {+ this(name, languageID, compilerSpecID, regDumpSetNames, null);+ }++ public ProcessorEmulatorTestAdapter(String name, String languageID, String compilerSpecID,+ String[] regDumpSetNames, String[] floatRegSetNames)+ throws LanguageNotFoundException, CompilerSpecNotFoundException {+ super(name);++ if (FAILURE_RESULT_NAME.equals(name)) {+ return; // simple construction for failure case+ }++ initializeSharedResources();++ try {+ processorDesignator = getProcessorDesignator();++ LanguageService languageService = DefaultLanguageService.getLanguageService();+ language = languageService.getLanguage(new LanguageID(languageID));+ compilerSpec = language.getCompilerSpecByID(new CompilerSpecID(compilerSpecID));++ Register pcReg = language.getProgramCounter();+ if (pcReg == null ||+ pcReg.getMinimumByteSize() < language.getDefaultSpace().getPointerSize()) {+ throw new AssertException(+ "Language must define properly sized program-counter register in pspec");+ }++ parallelHelper = language.getParallelInstructionHelper();++ // build register dump set+ regDumpSet = getRegisters(regDumpSetNames);++ // build floatRegSet+ floatRegSet = new HashSet<>(Arrays.asList(getRegisters(floatRegSetNames)));++ }+ catch (LanguageNotFoundException e) {+ Msg.error(this, getClass().getSimpleName() + " instantiation error", e);+ throw e;+ }+ catch (CompilerSpecNotFoundException e) {+ Msg.error(this, getClass().getSimpleName() + " instantiation error", e);+ throw e;+ }+ catch (RuntimeException e) {+ Msg.error(this, getClass().getSimpleName() + " instantiation error", e);+ throw e;+ }+ }++ private Register[] getRegisters(String[] regNames) {+ if (regNames == null) {+ return new Register[0];+ }+ Register[] regs = new Register[regNames.length];+ for (int i = 0; i < regNames.length; i++) {+ Register reg = language.getRegister(regNames[i]);+ if (reg == null) {+ throw new IllegalArgumentException("Undefined " + processorDesignator + " (" ++ language.getLanguageID() + ") dump register: " + regNames[i]);+ }+ regs[i] = reg;+ }+ return regs;+ }++ protected final void setIgnoredBlocks(String... blockNames) {+ ignoredBlocks = new HashSet<>();+ for (String name : blockNames) {+ ignoredBlocks.add(name);+ }+ }++ private AddressSetView getRestrictedSearchSet(Program program) {+ if (ignoredBlocks == null) {+ return program.getMemory().getLoadedAndInitializedAddressSet();+ }+ AddressSet set = new AddressSet();+ for (MemoryBlock block : program.getMemory().getBlocks()) {+ if (block.isInitialized() && !ignoredBlocks.contains(block.getName())) {+ set.add(block.getStart(), block.getEnd());+ }+ }+ return set;+ }++// /**+// * Force use of program DB cache to avoid re-import and analysis of binaries+// * during single run.+// */+// private static void forceProgramCaching() {+//+// String dirPath = System.getProperty(TEST_DB_PARM);+// if (dirPath != null) {+// return; // already enabled by batch test environment+// }+//+// String tmpDir = System.getProperty("java.io.tmpdir");+// File cacheDir = new File(tmpDir, "EmulatorDBTestCache");+// if (cacheDir.exists() && !FileUtilities.deleteDir(cacheDir)) {+// Msg.warn(ProcessorEmulatorTestAdapter.class,+// "Unable to remove existing program cache: " + cacheDir);+// return;+// }+// if (!cacheDir.mkdir()) {+// Msg.warn(ProcessorEmulatorTestAdapter.class, "Unable to create program cache: " ++// cacheDir);+// return;+// }+//+// String cachePath = cacheDir.getAbsolutePath();+// Msg.info(ProcessorEmulatorTestAdapter.class, "Forcing use of program DB cache: " ++// cachePath);+// System.setProperty(TEST_DB_PARM, cachePath);+//+// Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {+// public void run() {+// // try to remove program cache+// FileUtilities.deleteDir(getDbTestDir());+// }+// }));+//+// }++ private static Map<Class<?>, MyTestFailure> testFailureMap = new HashMap<>();++ private static Throwable getCause(Throwable t) {+ if (t instanceof InvocationTargetException) {+ t = ((InvocationTargetException) t).getCause();+ }+ return t;+ }++ private static class MyTestFailure extends TestSuite {++ private Throwable failure;++ MyTestFailure(Class<?> emulatorTestClass, Throwable failure) {+ this.failure = failure;+ addTest(TestSuite.createTest(emulatorTestClass, FAILURE_RESULT_NAME));+ }++ void throwFailure() throws Exception {+ if (failure instanceof Error) {+ throw (Error) failure;+ }+ if (failure instanceof Exception) {+ throw (Exception) failure;+ }+ AssertionFailedError error = new AssertionFailedError("Severe Failure");+ error.initCause(failure);+ }+ }++ public static Test getTestFailure(Class<?> emulatorTestClass, String message, Throwable t) {+ if (t == null) {+ t = new AssertionFailedError(message);+ }+ MyTestFailure testFailure = new MyTestFailure(emulatorTestClass, getCause(t));+ testFailureMap.put(emulatorTestClass, testFailure);+ return testFailure;+ }++ /**+ * Create TestSuite based upon available test groups contained within binary+ * test files associated with target processor.+ * @param emulatorTestClass test which extends <code>ProcessorEmulatorTestAdapter</code>+ * and whose name ends with "EmulatorTest".+ * @return test suite+ */+ public static final Test buildEmulatorTestSuite(Class<?> emulatorTestClass) {++ // Method currently only gets invoked when running all test groups+ // For now lets limit dumping of execution state to single+ // test only, unless the property was give on command line.++ if (System.getProperty(EMULATOR_TRACE_DISABLE_PROPERTY) == null) {+ traceDisabled = true;+ }++ if (!emulatorTestClass.getSimpleName().endsWith(EMULATOR_TEST_SUFFIX)) {+ return getTestFailure(emulatorTestClass,+ "Invalid emulator test classname, must end with '" + EMULATOR_TEST_SUFFIX + "'",+ null);+ }++ if (!ProcessorEmulatorTestAdapter.class.isAssignableFrom(emulatorTestClass)) {+ return getTestFailure(emulatorTestClass,+ "Test class does not extend " + ProcessorEmulatorTestAdapter.class.getSimpleName(),+ null);+ }++ Constructor<?> constructor;+ try {+ constructor = emulatorTestClass.getConstructor(String.class);+ }+ catch (NoSuchMethodException e) {+ return getTestFailure(emulatorTestClass,+ "Class has no public constructor TestCase(String name)", null);+ }++ ProcessorEmulatorTestAdapter instance = null;+ try {+ instance = (ProcessorEmulatorTestAdapter) constructor.newInstance((String) null);+ }+ catch (Exception e) {+ return getTestFailure(emulatorTestClass, "Cannot instantiate test class", e);+ }++ try {+ instance.setUp();+ if (instance.testGroupMap == null || instance.testGroupMap.size() == 0) {+ return getTestFailure(emulatorTestClass, "No test binaries found", null);+ }+ ArrayList<PCodeTestGroup> testGroups = new ArrayList<>(instance.testGroupMap.values());+ Collections.sort(testGroups);+// TODO: May need custom test suite and implement+// public void run(TestResult result) -- which can do something after invoking super.run+ TestSuite suite = new EmulationTestSuite();+ for (PCodeTestGroup testGroup : testGroups) {+ // TODO: HACK! must prefix each test name with "test" to allow for+ // running single test within Eclipse+ suite.addTest(+ TestSuite.createTest(emulatorTestClass, TEST_PREFIX + testGroup.testGroupName));+ }+ return suite;+ }+ catch (Exception e) {+ e.printStackTrace();+ return getTestFailure(emulatorTestClass, "Exception during trial test setup", e);+ }+ finally {+ try {+ instance.tearDown();+ }+ catch (Exception e) {+ e.printStackTrace();+ }+ }+ }++ private static class EmulationTestSuite extends TestSuite {+ @Override+ public void run(TestResult result) {+ super.run(result);++ // Dump XML and HTML when suite done runnings+ resultsWriter.run();+ }+ }++ @Override+ public void log(PCodeTestGroup testGroup, String msg) {+ int index = 0;+ while (index < msg.length()) {+ int nextIndex = msg.indexOf('\n', index);+ String text;+ if (nextIndex >= 0) {+ text = msg.substring(index, nextIndex);+ index = nextIndex + 1;+ }+ else {+ text = msg.substring(index);+ index = msg.length();+ }+ if (testGroup != null) {+ text = testGroup.testGroupName + ": " + text;+ }+ if (logData.traceLog != null) {+ logData.traceLog.println(text);+ }+ System.out.println(text);+ }+ }++ @Override+ public void log(PCodeTestGroup testGroup, String msg, Throwable t) {+ log(testGroup, msg);+ log(testGroup, exceptionToString(t));+ }++ private Address getCallAddress(Instruction instr) {+ for (Reference ref : instr.getReferencesFrom()) {+ if (ref.getReferenceType().isCall()) {+ return ref.getToAddress();+ }+ }+ return null;+ }++ @Override+ public void logState(EmulatorTestRunner testRunner) {+ if (traceDisabled || traceLevel <= 0) {+ return;+ }+ if (traceLevel >= 1) {+ StringBuilder buf = new StringBuilder();+ Address curAddr = testRunner.getCurrentAddress();+ SymbolTable symbolTable = testRunner.getProgram().getSymbolTable();+ Symbol s = symbolTable.getPrimarySymbol(curAddr);+ if (s != null) {+ buf.append("<<");+ buf.append(s.getName());+ }+ Instruction instr = testRunner.getCurrentInstruction();+ buf.append(">> ");+ buf.append(curAddr.toString(true));+ buf.append(" ");+ if (instr != null) {++ if (parallelHelper != null) {+ String prefix = parallelHelper.getMnemonicPrefix(instr);+ if (prefix != null) {+ buf.append(prefix);+ buf.append(' ');+ }+ }++ buf.append(instr.toString());++ if (instr.getDelaySlotDepth() != 0) {+ buf.append(" (delay-slots not shown)");+ }+ if (instr.getFlowType().isCall()) {+ // output call reference+ Address callAddr = getCallAddress(instr);+ if (callAddr != null) {+ s = symbolTable.getPrimarySymbol(callAddr);+ if (s != null) {+ buf.append(" (call -> ");+ buf.append(s.getName());+ buf.append(")");+ }+ }+ }+ }+ log(testRunner.getTestGroup(), buf.toString());+ }+ if (traceLevel >= 2) {+ StringBuilder buf1 = new StringBuilder(" ");+ StringBuilder buf2 = new StringBuilder(" ");+ int width = 0;+ for (Register reg : regDumpSet) {+ String regName = reg.getName();+ int len = Math.max(regName.length(), (reg.getMinimumByteSize() * 2));+ width += len;+ if (width > MAX_REGDUMP_WIDTH) {+ log(testRunner.getTestGroup(), buf1.toString());+ log(testRunner.getTestGroup(), buf2.toString());+ buf1 = new StringBuilder(" ");+ buf2 = new StringBuilder(" ");+ width = len;+ }+ buf1.append(regName);+ buf1.append(' ');+ buf2.append(testRunner.getRegisterValueString(reg));+ buf2.append(' ');+ int diff = buf1.length() - buf2.length();+ for (int n = diff; n < 0; n++) {+ buf1.append(' ');+ }+ for (int n = diff; n > 0; n--) {+ buf2.append(' ');+ }+ }+ if (buf1.length() > 1) {+ log(testRunner.getTestGroup(), buf1.toString());+ log(testRunner.getTestGroup(), buf2.toString());+ }+ }+ }++ private static abstract class DumpFormatter {+ final int elementSize;+ final boolean bigEndian;++ DumpFormatter(int elementSize, boolean bigEndian) {+ this.elementSize = elementSize;+ this.bigEndian = bigEndian;+ }++ abstract int getMaxWidth();++ abstract String getString(byte[] bytes, int index);+ }++ private static class HexFormatter extends DumpFormatter {+ HexFormatter(int elementSize, boolean bigEndian) {+ super(elementSize, bigEndian);+ }++ @Override+ int getMaxWidth() {+ return 2 * elementSize;+ }++ @Override+ String getString(byte[] bytes, int index) {+ BigInteger val = bigEndian+ ? BigEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize,+ false)+ : LittleEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize,+ false);+ String valStr = val.toString(16);+ return StringUtilities.pad(valStr, '0', 2 * elementSize);+ }+ }++ private static class DecimalFormatter extends DumpFormatter {+ DecimalFormatter(int elementSize, boolean bigEndian) {+ super(elementSize, bigEndian);+ }++ @Override+ int getMaxWidth() {+ byte[] sampleBytes = new byte[elementSize];+ sampleBytes[0] = (byte) 0x80;+ BigInteger sample = new BigInteger(-1, sampleBytes);+ return sample.toString().length();+ }++ @Override+ String getString(byte[] bytes, int index) {+ BigInteger val = bigEndian+ ? BigEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize, true)+ : LittleEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize,+ true);+ return val.toString();+ }+ }++ private static class FloatFormatter extends DumpFormatter {+ private final FloatFormat ff;++ FloatFormatter(int elementSize, boolean bigEndian) {+ super(elementSize, bigEndian);+ ff = FloatFormatFactory.getFloatFormat(elementSize);+ }++ @Override+ int getMaxWidth() {+ return ff.maxValue.negate().toString().length();+ }++ @Override+ String getString(byte[] bytes, int index) {+ BigInteger encoding = bigEndian+ ? BigEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize,+ false)+ : LittleEndianDataConverter.INSTANCE.getBigInteger(bytes, index, elementSize,+ false);+ BigDecimal val = ff.getHostFloat(encoding);+ return val.toString();+ }+ }++ @Override+ public void logState(EmulatorTestRunner emulatorTestRunner, Address dumpAddr, int dumpSize,+ int elementSize, DumpFormat elementFormat, String comment) {++ if (dumpSize == 0) {+ return;+ }++ DumpFormatter dumpFormatter;+ if (elementFormat == DumpFormat.FLOAT) {+ dumpFormatter = new FloatFormatter(elementSize, language.isBigEndian());+ }+ else if (elementFormat == DumpFormat.DECIMAL) {+ dumpFormatter = new DecimalFormatter(elementSize, language.isBigEndian());+ }+ else {+ dumpFormatter = new HexFormatter(elementSize, language.isBigEndian());+ }++ int maxElementWidth = dumpFormatter.getMaxWidth();+ int elementsPerRow = (80 - dumpAddr.toString().length()) / (maxElementWidth + 1);+ if (elementsPerRow > 16) {+ elementsPerRow = 16;+ }+ else if (elementsPerRow > 8) {+ elementsPerRow = 8;+ }+ else if (elementsPerRow > 4) {+ elementsPerRow = 4;+ }+ else if (elementsPerRow == 0) {+ elementsPerRow = 1;+ }++ int byteCount = dumpSize * elementSize;++ byte[] bytes = emulatorTestRunner.getEmulatorHelper().readMemory(dumpAddr, byteCount);+ int index = 0;++ log(null, "MEMORY DUMP (" + elementFormat + "): " + comment);+ while (index < byteCount) {+ StringBuilder buf = new StringBuilder();+ buf.append(" ");+ buf.append(dumpAddr.toString(true));+ buf.append(":");+ for (int i = 0; i < elementsPerRow && index < byteCount; i++) {+ String valStr = dumpFormatter.getString(bytes, index);+ index += elementSize;+ valStr = StringUtilities.pad(valStr, ' ', maxElementWidth + 1);+ buf.append(valStr);+ }+ log(null, buf.toString());+ if (index < byteCount) {+ dumpAddr = dumpAddr.add(elementsPerRow * elementSize);+ }+ }+ }++ private void logUnimplemented(TreeSet<String> unimplementedSet) {+ if (unimplementedSet.isEmpty()) {+ return;+ }+ log(null, "Summary of Unimplemented Pcodeops encountered (CALLOTHER):");+ for (String name : unimplementedSet) {+ log(null, " " + name);+ }+ }++ private byte[] flipBytes(byte[] bytes) {+ int index = bytes.length;+ byte[] flippedBytes = new byte[bytes.length];+ for (byte b : bytes) {+ flippedBytes[--index] = b;+ }+ return flippedBytes;+ }++ private String formatAssignmentString(Address address, int size, byte[] values) {+ if (!language.isBigEndian()) {+ values = flipBytes(values);+ }++ Register reg = language.getRegister(address, size);++ String name = reg != null ? reg.getName() : (address.toString(true) + ":" + size);++ String floatStr = "";+ if (reg != null && floatRegSet.contains(reg)) {+ FloatFormat floatFormat = FloatFormatFactory.getFloatFormat(size);+ BigDecimal hostFloat = floatFormat.getHostFloat(new BigInteger(1, values));+ floatStr = " (" + hostFloat.toString() + ")";+ }++ return name + "=0x" + NumericUtilities.convertBytesToString(values, "") + floatStr;+ }++ @Override+ public void logRead(EmulatorTestRunner testRunner, Address address, int size, byte[] values) {+ if (traceLevel < 3) {+ return;+ }+ log(testRunner.getTestGroup(), " Read " + formatAssignmentString(address, size, values));+ }++ @Override+ public void logWrite(EmulatorTestRunner testRunner, Address address, int size, byte[] values) {+ if (traceLevel < 3) {+ return;+ }+ log(testRunner.getTestGroup(), " Write " + formatAssignmentString(address, size, values));+ }++ @Override+ public void stepCompleted(EmulatorTestRunner testRunner) {+ logState(testRunner);+ }++ /**+ * Converts the stack trace into a string+ */+ private static String exceptionToString(Throwable t) {+ StringWriter stringWriter = new StringWriter();+ PrintWriter writer = new PrintWriter(stringWriter);+ t.printStackTrace(writer);+ return stringWriter.toString();+ }++ private void findTestResourceDirectory(String relativeModulePath) {+ for (ResourceFile appRoot : applicationRootDirectories) {+ File moduleRoot = new File(appRoot.getAbsolutePath(), relativeModulePath);+ File dir = new File(moduleRoot, TEST_RESOURCE_PATH);+ if (dir.isDirectory()) {+ resourcesTestDataDir = dir;+ break;+ }+ }+ }++ @Override+ protected void setUp() throws Exception {++ env = new TestEnv();++ myModuleRootDirectory = Application.getModuleContainingClass(getClass().getName());+ applicationRootDirectories = Application.getApplicationRootDirectories();++ String relativeModulePath = getRelativeModulePath();++ resourcesTestDataDir = new File(myModuleRootDirectory.getFile(true), TEST_RESOURCE_PATH);++ if (!resourcesTestDataDir.isDirectory()) {+ findTestResourceDirectory(relativeModulePath);+ }++ if (!resourcesTestDataDir.isDirectory()) {+ findTestResourceDirectory(DEFAULT_PROCESSOR_TEST_MODULE);+ }++ if (!resourcesTestDataDir.isDirectory()) {+ throw new RuntimeException(+ "Failed to locate test resource directory: " + relativeModulePath);+ }++ logData = initializeLog(getClass());++ if (FAILURE_RESULT_NAME.equals(getName())) {+ // running a failure case so we can produce junit failure result+ logData.testResults.summaryHasIngestErrors = true;+ testFailureMap.get(getClass()).throwFailure();+ }++ ResourceFile emuTestingArchive = Application.getModuleDataFile("pcodetest/EmuTesting.gdt");+ archiveDtMgr = FileDataTypeManager.openFileArchive(emuTestingArchive, false);+ DataType dt = archiveDtMgr.getDataType(CategoryPath.ROOT, TEST_INFO_STRUCT_NAME);+ if (dt == null || !(dt instanceof Structure)) {+ fail(TEST_INFO_STRUCT_NAME ++ " structure data-type not found in resource EmuTesting.gdt");+ }+ testInfoStruct = (Structure) dt;++ dt = archiveDtMgr.getDataType(CategoryPath.ROOT, GROUP_INFO_STRUCT_NAME);+ if (dt == null || !(dt instanceof Structure)) {+ fail(GROUP_INFO_STRUCT_NAME ++ " structure data-type not found in resource EmuTesting.gdt");+ }+ groupInfoStruct = (Structure) dt;++ testControlBlocks = testControlBlocksMap.get(processorDesignator);+ if (testControlBlocks == null) {+ try {+ ingestTestBinaries();+ }+ catch (RuntimeException e) {+ e.printStackTrace(logData.traceLog);+ logData.testResults.addSevereFailResult("", "TestFileIngest");+ throw e;+ }+ testControlBlocksMap.put(processorDesignator, testControlBlocks);+ }++ testGroupMap = new HashMap<>();+ for (PCodeTestControlBlock testControlBlock : testControlBlocks) {+ for (PCodeTestGroup testGroup : testControlBlock.getTestGroups()) {+ testGroupMap.put(testGroup.testGroupName, testGroup);+ //System.out.println("test_" + testGroup.testGroupName);+ }+ }+ }++ private String getRelativeModulePath() {+ String absolutePath = myModuleRootDirectory.getAbsolutePath();+ for (ResourceFile appRoot : applicationRootDirectories) {+ String rootPath = appRoot.getAbsolutePath();+ if (absolutePath.startsWith(rootPath)) {+ return absolutePath.substring(rootPath.length() + 1);+ }+ }+ throw new RuntimeException("Failed to resolve relative module path");+ }++ private static class LogData {+ File traceFile;+ PrintWriter traceLog;+ PCodeTestResults testResults;+ private TreeSet<String> unimplementedSet = new TreeSet<>();+ }++ private static LogData initializeLog(Class<?> testClass) throws FileNotFoundException {++ try {+ LogData data = logDataMap.get(testClass);+ if (data == null) {+ data = new LogData();+ logDataMap.put(testClass, data);++ data.testResults = combinedResults.getTestResults(testClass.getSimpleName(), true);+ data.testResults.clear();++ data.traceFile = new File(logDir, testClass.getSimpleName() + ".log");+ if (data.traceFile.exists()) {+ data.traceFile.delete();+ }++ }+ else {++ // Test has previously been run so we know ingest initialization has already been+ // completed. If test class is switching we can flush that tests results to HTML+ // file.+ if (lastTestClass != null && !lastTestClass.equals(testClass)) {+ resultsWriter.run(); // write out html results on test change+ }++ if (data.traceLog != null) {+ return data;+ }+ }++ data.traceLog = new PrintWriter(new BufferedWriter(+ new OutputStreamWriter(new FileOutputStream(data.traceFile, true))));++ data.traceLog.println((new Date()).toString());++ return data;+ }+ finally {+ lastTestClass = testClass;+ }+ }++ @Override+ protected void tearDown() throws Exception {+ if (logData != null && logData.traceLog != null) {+ logUnimplemented(logData.unimplementedSet);+ logData.traceLog.flush();+ logData.traceLog.close();+ logData.traceLog = null;+ }+ if (archiveDtMgr != null) {+ archiveDtMgr.close();+ }+ if (env != null) {+ env.dispose();+ }+ super.tearDown();+ }++ /**+ * Single unit test which handles named test group specified during test+ * instantiation.+ */+ @Override+ public final void runTest() {++ String testGroupName = getName();++ // TODO: HACK! Must strip "test" prefix which was added to original group name+ // to facilitate running single test in Eclipse+ if (testGroupName != null) {+ if (testGroupName.startsWith(TEST_PREFIX)) {+ testGroupName = testGroupName.substring(TEST_PREFIX.length());+ }+ else {+ fail("Expected test name to start with " + TEST_PREFIX);+ }+ }++ if (testGroupName == null || testGroupName.length() == 0) {+ fail("Empty test group name");+ }++ PCodeTestGroup testGroup = testGroupMap.get(testGroupName);+ assertNotNull("TestGroup not found for '" + testGroupName + "'", testGroup);++ log(testGroup, "Prepare for executing group test '" + testGroup.testGroupName + "' at: " ++ testGroup.functionEntryPtr.toString(true));++ log(testGroup,+ "Loading test binary: " + testGroup.mainTestControlBlock.testFile.fileReferencePath);++ log(testGroup, "Using cached program: " + testGroup.mainTestControlBlock.cachedProgramPath);++ Program program = null;+ EmulatorTestRunner testRunner = null;+ try {+ program = getGzfProgram(testGroup.mainTestControlBlock.cachedProgramPath);++ assertNotNull(+ "Failed to open test program: " + testGroup.mainTestControlBlock.cachedProgramPath,+ program);++ if (program.isChanged()) {+ // update cached program+ String fpath = testGroup.mainTestControlBlock.testFile.fileReferencePath;+ Msg.info(ProcessorEmulatorTestAdapter.class,+ "Updating cached gzf file following program upgrade: " + fpath);+ File gzfFile = new File(resourcesCacheDir, fpath + GZF_FILE_EXT);+ env.getGhidraProject().saveAsPackedFile(program, gzfFile, true);+ if (!gzfFile.exists()) {+ throw new IOException("Failed to cache gzf file: " + gzfFile);+ }+ }++ assertFalse(+ "Program contains severe disassembly/relocation errors: " ++ testGroup.mainTestControlBlock.cachedProgramPath,+ logData.testResults.summaryHasRelocationErrors ||+ logData.testResults.summaryHasDisassemblyErrors);++ testRunner = new EmulatorTestRunner(program, testGroup, this);++ // Clear hard-coded stack pointer value established by SimpleProgramLoadData.+ // If not set by initializeState checkStackPointerValue will attempt to initialize+ // TODO: not required if use of SimpleProgramLoadData eliminated+ testRunner.setRegister(compilerSpec.getStackPointer().getName(), 0);++ // Initialize context register based upon function entry within listing+ Address address = EmulatorTestRunner.alignAddress(testGroup.functionEntryPtr,+ language.getInstructionAlignment());+ ProgramContext programContext = program.getProgramContext();+ Register contextRegister = programContext.getBaseContextRegister();+ if (contextRegister != null) {+ testRunner.setContextRegister(+ programContext.getRegisterValue(contextRegister, address));+ }++ initializeState(testRunner, program);++ checkStackPointerValue(testRunner);++ int totalExpectedAsserts = 0;+ int numSubTests = testGroup.controlBlock.getNumberFunctions();+ for (int i = 1; i < numSubTests; i++) {+ FunctionInfo functionInfo = testGroup.controlBlock.getFunctionInfo(i);+ String name = functionInfo.functionName;+ logData.testResults.declareTest(testGroup.testGroupName, name,+ functionInfo.numberOfAsserts);+ totalExpectedAsserts += functionInfo.numberOfAsserts;+ }++ // Initialize pass/fail counts at runtime to detect severe failure+ testGroup.mainTestControlBlock.setNumberPassed(testRunner, Integer.MIN_VALUE);+ testGroup.mainTestControlBlock.setNumberFailed(testRunner, Integer.MIN_VALUE);++ boolean done;+ if (traceDisabled) {+ done = testRunner.execute(EXECUTION_TIMEOUT_MS, TaskMonitor.DUMMY);+ }+ else {+ done = testRunner.executeSingleStep(MAX_EXECUTION_STEPS);+ }++ int pass = testGroup.mainTestControlBlock.getNumberPassed(testRunner);+ int callOtherErrors = testRunner.getCallOtherErrors();+ int fail = testGroup.mainTestControlBlock.getNumberFailed(testRunner);++ if (pass < 0 || fail < 0) {+ failTest(testRunner,+ "ERROR Invalid pass/fail counts - test may not have run properly or improper TestInfo structure updates occured: pass " ++ pass + " fail " + fail);+ }++ pass -= callOtherErrors;++ String passFailText = "Passed: " + pass + " Failed: " + fail;+ if (callOtherErrors != 0) {+ passFailText += " Passed(w/CALLOTHER): " + callOtherErrors;+ }+ passFailText += " Expected Assertions: " + totalExpectedAsserts;+ log(testGroup, passFailText);++ List<String> testFailures = testGroup.getTestFailures();+ if (!testFailures.isEmpty()) {+ log(testGroup, "TEST FAILURES:");+ for (String testFailure : testFailures) {+ log(testGroup, " >>> " + testFailure);+ }+ }++ if (!done) {+ StringBuilder msg = new StringBuilder("ERROR Test execution failed");++ // TODO: not currently set until assert function has been emulated+ //String lastFunction = testGroup.mainTestControlBlock.getLastFunctionName(testRunner);++ String emuError = testRunner.getEmuError();+ if (emuError != null) {+ msg.append(" - ");+ msg.append(emuError);+ }+ Address pcAddr = testRunner.getCurrentAddress();+ String pcStr = Long.toHexString(pcAddr.getOffset());+ if ((emuError == null) || (emuError.indexOf(pcStr) < 0)) {+ msg.append(", pc=0x");+ msg.append(pcStr);+ }+ failTest(testRunner, msg.toString());+ }+ int ranCnt = pass + fail + callOtherErrors;+ if ((totalExpectedAsserts != 0) && (totalExpectedAsserts != ranCnt)) {+ failTest(testRunner,+ "ERROR Unexpected number of assertions ( " + passFailText + " )");+ }+ if (fail != 0 || callOtherErrors != 0 || testFailures.size() != 0) {+ failTest(testRunner,+ "ERROR One or more group tests failed ( " + passFailText + " )");+ }++ }+ catch (Exception e) {+ log(testGroup, "Exception occured during test", e);+ fail("Exception occured during test: " + e.getMessage());+ }+ finally {+ if (testRunner != null) {+ logData.unimplementedSet.addAll(testRunner.getUnimplementedPcodeops());+ testRunner.dispose();+ }+ if (program != null) {+ env.release(program);+ }+ }+ }++ private void checkStackPointerValue(EmulatorTestRunner testRunner) {+ Program program = testRunner.getProgram();+ Register spReg = compilerSpec.getStackPointer();+ if (spReg != null) {+ RegisterValue spValue = testRunner.getRegisterValue(spReg);+ long stackOffset = spValue.getUnsignedValue().longValue();+ if (stackOffset == 0) { // default uninitialized value is 0+ initStackPointer(testRunner, spReg);+ }+ AddressSpace stackSpace = compilerSpec.getStackBaseSpace();+ if (stackSpace != null) {+ Address stackPtr = stackSpace.getAddress(stackOffset);+ if (program.getMemory().getLoadedAndInitializedAddressSet().contains(stackPtr)) {+ fail("Stack pointer defined within initialized memory region: " + stackPtr);+ }+ }+ }+ }++ private Symbol findAnyMatchingSymbol(Program program, String... names) {+ for (String name : names) {+ if (name == null) {+ continue;+ }+ Symbol s =+ SymbolUtilities.getExpectedLabelOrFunctionSymbol(program, name, m -> m.toString()); // error ignored+ if (s != null) {+ return s;+ }+ }+ return null;+ }++ private void initStackPointer(EmulatorTestRunner testRunner, Register spReg) {+ Program program = testRunner.getProgram();+ Symbol stackSymbol = findAnyMatchingSymbol(program, getPreferredStackSymbolName(), "_stack",+ "stack", "__STACK_START");+ if (stackSymbol != null) {+ long stackOffset = stackSymbol.getAddress().getAddressableWordOffset();+ testRunner.setRegister(spReg.getName(), stackOffset);+ log(null, "Stack Pointer (" + spReg.getName() + ") auto-assigned using symbol '" ++ stackSymbol.getName() + "' offset: 0x" + Long.toHexString(stackOffset));+ }+ else {+ log(null, "Stack Pointer (" + spReg.getName() + ") using default offset: 0");+ }+ }++ /**+ * Get symbol name which defines initial stack pointer offset+ * @return stack symbol or null+ */+ protected String getPreferredStackSymbolName() {+ return null;+ }++ private void failTest(EmulatorTestRunner testRunner, String msg) {+ log(testRunner.getTestGroup(), msg);+ checkInstructionDecodeFailure(testRunner);+ fail(msg);+ }++ private void checkInstructionDecodeFailure(EmulatorTestRunner testRunner) {+ // assume general error has already been logged+ String emuError = testRunner.getEmuError();+ if (emuError == null || (emuError.indexOf("Instruction decode failed") < 0) ||+ (emuError.indexOf("Uninitialized Memory") > 0)) {+ return;+ }++ Address currentAddr = testRunner.getCurrentAddress();++ // dump context register state if decode failure+ RegisterValue contextRegValue =+ testRunner.getEmulatorHelper().getEmulator().getContextRegisterValue();+ if (contextRegValue == null) {+ return;+ }+ StringBuilder buf = new StringBuilder("Context register state at: ");+ buf.append(currentAddr.toString(true));+ for (Register contextField : contextRegValue.getRegister().getChildRegisters()) {+ RegisterValue ctxValue = contextRegValue.getRegisterValue(contextField);+ String valueStr = ctxValue.getUnsignedValueIgnoreMask().toString(16);+ buf.append("\n ");+ buf.append(contextField.getName());+ buf.append(" = 0x");+ buf.append(valueStr);+ }+ log(testRunner.getTestGroup(), buf.toString());++ // If parse OK within program - check for modified bytes within emu memory state+ Program program = testRunner.getProgram();+ boolean inDelaySlot = false;+ DumbMemBufferImpl memBuf = new DumbMemBufferImpl(program.getMemory(), currentAddr);+ DisassemblerContextImpl context = new DisassemblerContextImpl(program.getProgramContext());+ try {+ context.flowStart(currentAddr);+ context.setRegisterValue(contextRegValue);+ InstructionPrototype proto = language.parse(memBuf, context, false);+ int len = proto.getLength();+ if (proto.hasDelaySlots()) {+ // TODO: Avoid use of InstructionContext by just guessing at potential byte count+ len *= 3;+ }++ // check for memory modification+ byte[] emuBytes = testRunner.getEmulatorHelper().readMemory(currentAddr, len);+ byte[] programBytes = new byte[emuBytes.length];+ program.getMemory().getBytes(currentAddr, programBytes);+ if (!Arrays.equals(emuBytes, programBytes)) {+ buf = new StringBuilder(+ "Instruction bytes differ between program and emulator state at: ");+ buf.append(currentAddr.toString(true));+ if (inDelaySlot) {+ buf.append(" (includes delay-slots)");+ }+ buf.append("\n");+ buf.append(" Program Bytes: ");+ buf.append(NumericUtilities.convertBytesToString(programBytes, " "));+ buf.append("\n");+ buf.append(" Emulator Bytes: ");+ buf.append(NumericUtilities.convertBytesToString(emuBytes, " "));+ log(testRunner.getTestGroup(), buf.toString());+ }+ else {+ log(testRunner.getTestGroup(),+ "Test unable to determine cause of instruction parse failure");+ }+ return; // if not byte difference - not sure what cause is+ }+ catch (UsrException e) {+ if (inDelaySlot) {+ log(testRunner.getTestGroup(),+ "Instruction parse error occured in delay-slot at: " ++ memBuf.getAddress().toString(true));+ }+ // parse failed+ }++ // Run parse debug+ SleighDebugLogger logger =+ new SleighDebugLogger(memBuf, context, language, SleighDebugMode.VERBOSE);+ log(testRunner.getTestGroup(), logger.toString());++ }++ /**+ * Get the maximum defined memory address ignoring any overlays which have been defined.+ * @return max defined physical address+ */+ protected static final Address getMaxDefinedMemoryAddress(Program program) {+ Address maxAddr = null;+ for (MemoryBlock block : program.getMemory().getBlocks()) {+ if (block.getStart().getAddressSpace().isOverlaySpace()) {+ continue;+ }+ if (maxAddr == null || maxAddr.compareTo(block.getEnd()) < 0) {+ maxAddr = block.getEnd();+ }+ }+ return maxAddr;+ }++ //+ // Protected helper methods which may be overriden+ //++ /**+ * Get the processor designator used to identify test binary files/folder.+ * The default implementation requires the JUnit test class name to end with+ * "EmulatorTest" where the portion of the name proceeding this suffix will be+ * used as the processor designator+ * @return processor designator+ */+ protected String getProcessorDesignator() {+ String className = getClass().getSimpleName();+ if (!className.endsWith(EMULATOR_TEST_SUFFIX)) {+ throw new RuntimeException(+ "Invalid emulator test classname, must end with '" + EMULATOR_TEST_SUFFIX + "'");+ }+ return className.substring(0, className.length() - EMULATOR_TEST_SUFFIX.length());+ }++ /**+ * Get CUint file designator if use of A, B, C... is not suitable.+ * @param fileIndex file index within sorted list+ * @param filePath binary file path+ * @return short file designator for use in qualified test name+ */+ protected String buildTestFileDesignator(int fileIndex, String filePath) {+ return null;+ }++ /**+ * Invoked for each program immediately prior to executing a test group.+ * By default this method will initialize the register states based upon the+ * specific register values/context stored at the test group function entry point.+ * Such register values may have been established via the processor specification,+ * loader or analyzers. A specific test may override or extend+ * this behavior for other registers as needed.+ * @param testRunner emulator group test runner/facilitator+ * @param program+ * @throws Exception if initialization criteria has not been satisfied+ */+ protected void initializeState(EmulatorTestRunner testRunner, Program program)+ throws Exception {+ Address addr = testRunner.getTestGroup().functionEntryPtr;+ addr = PseudoDisassembler.getNormalizedDisassemblyAddress(program, addr);+ ProgramContext programContext = program.getProgramContext();+ for (Register reg : programContext.getRegisters()) {+ if (reg.isProcessorContext() || reg.isProgramCounter()) {+ continue;+ }+ RegisterValue value = programContext.getRegisterValue(reg, addr);+ if (value != null && value.hasValue()) {+ log(testRunner.getTestGroup(),+ "Initialized register " + reg.getName() + "=0x" ++ value.getUnsignedValue().toString(16) + " using context at " ++ addr.toString(true));+ testRunner.setRegister(reg.getName(), value.getUnsignedValue());+ }+ }+ }++ /**+ * Invoked immediately following import allow byte processing prior to+ * control structure identification.+ * NOTE: This method will only be invoked once during the first test setup+ * for all test binaries found. This method will not be invoked+ * during subsequent tests since the analyzed program will be cached.+ * @param program+ * @throws Exception+ */+ protected void postImport(Program program) throws Exception {+ // optional: may be implemented by test+ }++ /**+ * Invoked prior to analysis to allow analysis options or other pre-analysis+ * inspection/modification to be performed.+ * NOTE: This method will only be invoked once during the first test setup+ * for all test binaries found. This method will not be invoked+ * during subsequent tests since the analyzed program will be cached.+ * @param program+ * @throws Exception+ */+ protected void preAnalyze(Program program) throws Exception {+ // optional: may be implemented by test+ }++ /**+ * Invoked for non-gzf files immediately after the analyze method to+ * perform any follow-up changes of inspection of the program.+ * NOTE: This method will only be invoked once during the first test setup+ * for all test binaries found. This method will not be invoked+ * during subsequent tests since the analyzed program will be cached.+ * @param program+ * @throws Exception+ */+ protected void postAnalyze(Program program) throws Exception {+ // optional: may be implemented by test+ }++ /**+ * Invoked for non-gzf files to perform auto-analysis.+ * NOTE: This method will only be invoked once during the first test setup+ * for all test binaries found. This method will not be invoked+ * during subsequent tests since the analyzed program will be cached.+ * @param program+ * @throws Exception+ */+ protected void analyze(Program program, PCodeTestControlBlock testControlBlock)+ throws Exception {++ setAnalysisOptions(program.getOptions(Program.ANALYSIS_PROPERTIES));++ GhidraProgramUtilities.setAnalyzedFlag(program, true);++ // Remove all single-byte functions created by Elf importer+ // NOTE: This is a known issues with optimized code and symbols marked as ElfSymbol.STT_FUNC+ for (Function function : program.getFunctionManager().getFunctions(true)) {+ if (function.getBody().getNumAddresses() == 1) {+ function.getSymbol().delete();+ }+ }++ AutoAnalysisManager analysisMgr = AutoAnalysisManager.getAnalysisManager(program);+ analysisMgr.cancelQueuedTasks(); // GhidraProject import utility jumped the gun with analysis initialization+ analysisMgr.initializeOptions();++ // ensure that all known functions have been disassembled+ AddressSet disassembleStarts = new AddressSet();++ addFunctionStartDisassemblyPoint(testControlBlock.getBreakOnDoneAddress(), "breakOnDone",+ disassembleStarts, program);+ addFunctionStartDisassemblyPoint(testControlBlock.getBreakOnPassAddress(), "breakOnPass",+ disassembleStarts, program);+ addFunctionStartDisassemblyPoint(testControlBlock.getBreakOnErrorAddress(), "breakOnError",+ disassembleStarts, program);+ addFunctionStartDisassemblyPoint(testControlBlock.getSprintf5Address(), "printf5",+ disassembleStarts, program);++ int functionCnt = testControlBlock.getNumberFunctions();+ for (int i = 0; i < functionCnt; i++) {+ FunctionInfo functionInfo = testControlBlock.getFunctionInfo(i);+ addFunctionStartDisassemblyPoint(functionInfo.functionAddr, functionInfo.functionName,+ disassembleStarts, program);+ }++ for (PCodeTestGroup testGroup : testControlBlock.getTestGroups()) {+ functionCnt = testGroup.controlBlock.getNumberFunctions();+ for (int i = 0; i < functionCnt; i++) {+ FunctionInfo functionInfo = testGroup.controlBlock.getFunctionInfo(i);+ addFunctionStartDisassemblyPoint(functionInfo.functionAddr,+ functionInfo.functionName, disassembleStarts, program);+ }+ }++ new DisassembleCommand(disassembleStarts, null).applyTo(program);++ new CreateFunctionCmd(disassembleStarts).applyTo(program);++ analysisMgr.reAnalyzeAll(null);+ analysisMgr.startAnalysis(TaskMonitor.DUMMY); // method blocks during analysis++ // Apply known function signatures+ // Signatures with Float types have been excluded due to limited calling convention support+ ArrayList<DataTypeManager> dtMgrList = new ArrayList<>();+ dtMgrList.add(archiveDtMgr);+ ApplyFunctionDataTypesCmd cmd =+ new ApplyFunctionDataTypesCmd(dtMgrList, null, SourceType.ANALYSIS, true, false);+ cmd.applyTo(program);++ // Apply various *_main and *_Main test function signatures+ Pointer testInfoStructPtrType = new PointerDataType(testInfoStruct);+ for (Function func : program.getFunctionManager().getFunctions(true)) {+ String name = func.getName();+ if (name.endsWith("_Main")) {+ func.setReturnType(VoidDataType.dataType, SourceType.ANALYSIS);+ }+ else if (name.endsWith("_main")) {+ func.setReturnType(VoidDataType.dataType, SourceType.ANALYSIS);+ func.replaceParameters(FunctionUpdateType.DYNAMIC_STORAGE_ALL_PARAMS, false,+ SourceType.ANALYSIS, new ParameterImpl("ti", testInfoStructPtrType, program));+ }+ }++ }++ protected void setAnalysisOptions(Options analysisOptions) {+ analysisOptions.setBoolean("Stack", false);+ analysisOptions.setBoolean("DWARF", false);+ analysisOptions.setBoolean("Create Address Tables", false);+ }++ private void addFunctionStartDisassemblyPoint(Address functionAddr, String functionName,+ AddressSet disassembleStarts, Program program) {++ Symbol s = program.getSymbolTable().getPrimarySymbol(functionAddr);+ if (s == null || s.isDynamic() ||+ s.getName().equals(SymbolUtilities.getDefaultFunctionName(functionAddr))) {+ createSymbol(functionAddr, functionName, program);+ }++ Listing listing = program.getListing();++ CodeUnit cu = listing.getCodeUnitAt(functionAddr);+ if (cu instanceof Instruction) {+ return;+ }+ if (cu == null || ((Data) cu).isDefined()) {+ Msg.warn(this, "Unexpected code unit or bad test-group function pointer: " ++ functionName + " at " + functionAddr);+ }++ String processor = program.getLanguage().getProcessor().toString();++ if ("ARM".equals(processor)) {+ Register tReg = program.getRegister("T");+ long offset = functionAddr.getOffset();+ if (tReg != null && (offset & 1) == 1) {+ RegisterValue thumbMode = new RegisterValue(tReg, BigInteger.ONE);+ try {+ program.getProgramContext().setRegisterValue(functionAddr, functionAddr,+ thumbMode);+ }+ catch (ContextChangeException e) {+ throw new AssertException(e);+ }+ }+ }+ else if ("MIPS".equals(processor)) {+ Register isaModeReg = program.getRegister("ISA_MODE");+ long offset = functionAddr.getOffset();+ if (isaModeReg != null && (offset & 1) == 1) {+ RegisterValue thumbMode = new RegisterValue(isaModeReg, BigInteger.ONE);+ try {+ program.getProgramContext().setRegisterValue(functionAddr, functionAddr,+ thumbMode);+ }+ catch (ContextChangeException e) {+ throw new AssertException(e);+ }+ }+ }++ functionAddr = alignAddress(functionAddr, program.getLanguage().getInstructionAlignment());++ disassembleStarts.add(functionAddr);+ }++ /**+ * Create symbol at known function location if missing+ */+ private void createSymbol(Address functionAddr, String functionName, Program program) {+ SymbolTable symbolTable = program.getSymbolTable();+ try {+ symbolTable.createLabel(functionAddr, functionName, SourceType.ANALYSIS);+ }+ catch (InvalidInputException e) {+ // ignore+ }+ }++ /**+ * Get the loader class which should be used. A null value should be+ * return to use the preferred loader.+ * @return loader class or null+ */+ protected Class<? extends Loader> getLoaderClass() {+ return null;+ }++ //+ // Private helper methods+ //++ private List<PCodeTestFile> findBinaryTestFiles(File testResourceDir) {++ ArrayList<PCodeTestFile> testFiles = new ArrayList<>();+ ArrayList<String> list = new ArrayList<>();++ String escapedProcessorDesignator = processorDesignator.replace("+", "\\+");+ Pattern pattern = Pattern.compile(escapedProcessorDesignator + PCODE_TEST_FILE_BASE_REGEX,+ Pattern.CASE_INSENSITIVE);++ File[] listFiles = testResourceDir.listFiles();+ if (listFiles == null) {+ return testFiles;+ }++ for (File f : testResourceDir.listFiles()) {+ String name = f.getName();+ Matcher matcher = pattern.matcher(name);+ if (!matcher.matches()) {+ continue;+ }+ if (f.isDirectory()) {+ getFiles(f, list, name + "/");+ }+ else {+ list.add(name);+ }+ }+ Collections.sort(list);+ for (int i = 0; i < list.size(); i++) {+ String relativePath = list.get(i);+ testFiles.add(new PCodeTestFile(new File(testResourceDir, relativePath), relativePath));+ }+ return testFiles;+ }++ private void getFiles(File dir, List<String> list, String pathPrefix) {+ // do not recurse down+ for (File f : dir.listFiles()) {+ if (f.isFile() && !f.getName().startsWith(".")) {+ list.add(pathPrefix + f.getName());+ }+ }+ }++ private Program getGzfProgram(String gzfProgName) throws IOException {+ // It is assumed that program has been added to TestEnv short-term cache before this method+ // is invoked, if not resourcesTestDataDir will be checked for gzfProgName+ return getGzfProgram(resourcesTestDataDir, gzfProgName);+ }++ private Program getGzfProgram(File dir, String gzfProgName) throws IOException {+ if (!gzfProgName.endsWith(GZF_FILE_EXT)) {+ throw new IllegalArgumentException();+ }+ String progName = gzfProgName.substring(0, gzfProgName.length() - GZF_FILE_EXT.length());+ try {+ ProgramDB program = env.getProgram(progName); // ignores .gzf extension+ if (program != null) {+ Msg.info(ProcessorEmulatorTestAdapter.class,+ "Loaded program from TestEnv cache: " + progName);+ program.addConsumer(this);+ env.release(program);+ return program;+ }+ if (dir != null) {+ Msg.info(ProcessorEmulatorTestAdapter.class, "Import program: " + gzfProgName);+ program =+ (ProgramDB) env.getGhidraProject().importProgram(new File(dir, gzfProgName));+ program.addConsumer(this);+ env.getGhidraProject().close(program);+ env.saveToCache(progName, program, true, TaskMonitor.DUMMY); // ignores .gzf extension+ return program;+ }+ }+ catch (Exception e) {+ throw new IOException(e);+ }+ throw new FileNotFoundException("Program file not found: " + gzfProgName);+ }++ /**+ * @return true if test run should fail up-front if binary contains disassembly errors+ */+ public boolean failOnDisassemblyErrors() {+ return true;+ }++ /**+ * @return true if test run should fail up-front if binary contains relocation errors+ */+ public boolean failOnRelocationErrors() {+ return false;+ }++ private void checkForProgramIssues(Program program, String resourceFilePath,+ PCodeTestControlBlock testControlBlock, PCodeTestResults testResults) {++ BookmarkManager bookmarkManager = program.getBookmarkManager();+ Iterator<Bookmark> iter = bookmarkManager.getBookmarksIterator(BookmarkType.ERROR);++ boolean hasDisassemblyErrors = false;+ boolean hasRelocationErrors = false;+ while (iter.hasNext()) {+ Bookmark bookmark = iter.next();+ if ("Bad Instruction".equals(bookmark.getCategory())) {+ hasDisassemblyErrors = true;+ }+ if ("Relocation".equals(bookmark.getCategory())) {+ hasRelocationErrors = true;+ }+ }+ if (hasDisassemblyErrors) {+ boolean fail = failOnDisassemblyErrors();+ log(null,+ (fail ? "ERROR" : "WARNING") ++ ": Program contains one or more Bad Instruction Error bookmarks - " ++ resourceFilePath);+ if (fail) {+ testResults.summaryHasDisassemblyErrors = true;+ }++ }+ if (hasRelocationErrors) {+ boolean fail = failOnRelocationErrors();+ log(null, (fail ? "ERROR" : "WARNING") ++ ": Program contains one or more Relocation Error bookmarks - " + resourceFilePath);+ if (fail) {+ testResults.summaryHasRelocationErrors = true;+ }+ }+ }++ private void ingestTestBinaries() throws Exception {++ if (!resourcesCacheDir.exists() && !FileUtilities.mkdirs(resourcesCacheDir)) {+ throw new IOException("Failed to create GZF cache: " + resourcesCacheDir);+ }++ //+ // Use of TestEnv and GhidraProject+ // - Since we are not based upon GenericTestCase due to the manner in which test+ // resources/programs are managed we only rely on it for its program cache+ // which we must populate directly+ // - GhidraProject is used for its ability to import programs, unfortunately it+ // is a little forceful with imposing a open transaction on all programs so we+ // take control by becoming a consumer and forcing GhidraProject to release it.+ //++ testControlBlocks = new ArrayList<>();++ List<PCodeTestFile> testFiles = null;++ Msg.info(this, "Locating " + processorDesignator + " P-Code test binaries in: " ++ resourcesTestDataDir);+ testFiles = findBinaryTestFiles(resourcesTestDataDir);++ if (testFiles.size() == 0) {+ throw new AssertException("No test binaries found");+ }++ Msg.info(this, "Processing " + testFiles.size() + " P-Code test binaries");++ int txId = -1;+ HashSet<String> duplicateTests = new HashSet<>();+ HashMap<String, PCodeTestGroup> map = new HashMap<>();+ for (PCodeTestFile testFile : testFiles) {+ String fileReferencePath = testFile.fileReferencePath; // relative resource filepath+ Program program = null;+ boolean usingCachedGZF = false;+ try {+ File absoluteGzfFilePath = null;+ boolean analyze = false; // if true program will be analyzed and cached+ if (fileReferencePath.endsWith(GZF_FILE_EXT)) {+ // TODO: this does not benefit from TestEnv DB cache+ absoluteGzfFilePath = new File(outputDir, fileReferencePath);+ program = getGzfProgram(resourcesTestDataDir, fileReferencePath); // gzf assumed to be pre-analyzed+ }+ else if (testFile.fileReferencePath.endsWith(BINARY_FILE_EXT)) {+ // check for gzf in persistent cache+ absoluteGzfFilePath =+ new File(resourcesCacheDir, fileReferencePath + GZF_FILE_EXT); // persistent cache gzf+ String gzfCachePath =+ GZF_CACHEDIR_NAME + "/" + fileReferencePath + GZF_FILE_EXT; //+ if (absoluteGzfFilePath.exists()) {+ program = getGzfProgram(outputDir, gzfCachePath);+ if (program != null && !MD5Utilities.getMD5Hash(testFile.file).equals(+ program.getExecutableMD5())) {+ // remove obsolete GZF cache file+ env.release(program);+ program = null;+ }+ if (program == null) {+ absoluteGzfFilePath.delete();+ env.removeFromProgramCache(gzfCachePath);+ }+ else {+ usingCachedGZF = true;+ }+ }+ if (program == null) {+ // import binary from scratch - will be stored in persistent cache as gzf when done+ log(null, "Importing and Analyzing " + testFile.file);+ log(null, "Using language/compiler spec: " + language.getLanguageID() ++ " / " + compilerSpec.getCompilerSpecID());+ Class<? extends Loader> loaderClass = getLoaderClass();+ if (loaderClass != null) {+ program =+ env.getGhidraProject().importProgram(testFile.file, loaderClass);+ }+ else {+ program = env.getGhidraProject().importProgram(testFile.file, language,+ compilerSpec);+ }+ program.addConsumer(this);+ env.getGhidraProject().close(program);+ analyze = true; // must analyze if not a gzf import+ }+ fileReferencePath = gzfCachePath; // use gzf cache when re-opening+ }+ else {+ Msg.warn(this, "Ignoring P-Code test file - unsupported file extension: " ++ fileReferencePath);+ continue;+ }+ if (program == null) {+ throw new IOException("Failed to open program: " + fileReferencePath);+ }++ txId = program.startTransaction("Analyze");++ if (!program.getLanguageID().equals(language.getLanguageID()) ||+ !program.getCompilerSpec().getCompilerSpecID().equals(+ compilerSpec.getCompilerSpecID())) {+ throw new IOException((usingCachedGZF ? "Cached " : "") ++ "Program has incorrect language/compiler spec (" + program.getLanguageID() ++ "/" + program.getCompilerSpec().getCompilerSpecID() + "): " ++ absoluteGzfFilePath);+ }++ if (analyze) {++ // discard residual ElfLoader segment data which can result in+ // duplication of data+ cleanupResidualSegmentData(program);++ log(null, "Post-Import processing of " + fileReferencePath);+ postImport(program);+ }++ PCodeTestControlBlock testControlBlock = PCodeTestControlBlock.getMainControlBlock(+ program, testFile, getRestrictedSearchSet(program), fileReferencePath,+ testInfoStruct, groupInfoStruct, analyze, logData.testResults);++ for (PCodeTestGroup testGroup : testControlBlock.getTestGroups()) {+ if (map.containsKey(testGroup.testGroupName)) {+ duplicateTests.add(testGroup.testGroupName);+ }+ else {+ map.put(testGroup.testGroupName, testGroup);+ }+ }++ testControlBlocks.add(testControlBlock);++ if (analyze) {+ log(null, "Analyzing " + fileReferencePath);+ preAnalyze(program);+ analyze(program, testControlBlock);+ postAnalyze(program);++ program.endTransaction(txId, true);+ txId = -1;++ // store to persistent cache as gzf+ Msg.info(ProcessorEmulatorTestAdapter.class,+ "Storing analyzed program in persistent cache: " + absoluteGzfFilePath);+ FileUtilities.mkdirs(absoluteGzfFilePath.getParentFile());+ env.getGhidraProject().saveAsPackedFile(program, absoluteGzfFilePath, true);+ if (!absoluteGzfFilePath.exists()) {+ throw new IOException("Failed to cache gzf file: " + absoluteGzfFilePath);+ }++ // store to short-term TestEnv cache+ env.saveToCache(fileReferencePath, (ProgramDB) program, true,+ TaskMonitor.DUMMY); // ignores .gzf extension on file name/path+ }++ // Check for program errors+ checkForProgramIssues(program, fileReferencePath, testControlBlock,+ logData.testResults);++ }+ catch (InvalidControlBlockException e) {+ throw new RuntimeException(+ "Test control block error (TestInfo structure): " + fileReferencePath, e);+ }+ catch (LanguageNotFoundException e) {+ throw new RuntimeException("Unexpected Error", e); // we already found language+ }+ catch (CancelledException e) {+ throw new RuntimeException("Unexpected Error", e); // Cancel not used+ }+ catch (DuplicateNameException e) {+ throw new RuntimeException("Test file naming conflict: " + fileReferencePath, e); // Must be avoided with naming of binary files+ }+ catch (InvalidNameException e) {+ throw new RuntimeException("Unsupported test filename: " + fileReferencePath, e); // Must be avoided with naming of binary files+ }+ catch (VersionException e) {+ throw new RuntimeException(+ "Unsupported Ghidra database version: " + fileReferencePath, e); // Must be avoided with *.gzf compatibility+ }+ catch (IOException e) {+ throw new RuntimeException(+ "IO Error during P-Code test processing: " + fileReferencePath, e);+ }+ finally {+ if (program != null) {+ if (txId != -1) {+ program.endTransaction(txId, false);+ }+ env.release(program);+ }+ }+ }++ // Sort testControlBlocks+ sortTestControlBlocks();++ // Log file digest details+ log(null, buildTestFileDigest(duplicateTests));++ if (!duplicateTests.isEmpty()) {+ log(null, "ERROR! One or more test groups have been duplicated");+ throw new RuntimeException(+ processorDesignator + " Test files contain duplicate test groups");+ }+ }++ private void cleanupResidualSegmentData(Program program) throws LockException {+ Memory memory = program.getMemory();+ MemoryBlock[] blocks = memory.getBlocks();+ for (MemoryBlock block : blocks) {+ if (block.getName().startsWith("segment_")) {+ log(null,+ "WARNING! Removing residual segment block to avoid possible duplication: " ++ block);+ memory.removeBlock(block, TaskMonitor.DUMMY);+ }+ }+ }++ private void sortTestControlBlocks() {+ Collections.sort(testControlBlocks, (o1, o2) -> {+ String cf1 = o1.testFile.fileReferencePath;+ String cf2 = o2.testFile.fileReferencePath;+ return cf1.compareTo(cf2);+ });+ }++ public Symbol getUniqueGlobalSymbol(Program program, String name) {+ return SymbolUtilities.getLabelOrFunctionSymbol(program, name, err -> Msg.error(this, err));+ }++ private String buildTestFileDigest(HashSet<String> duplicateTests) {++ StringBuilder testFileDigest = new StringBuilder();+ String title = "*** " + getClass().getSimpleName() + " P-Code Test Suite (" ++ processorDesignator + ") ";+ title = StringUtilities.pad(title, '*', -80);+ testFileDigest.append(title);+ testFileDigest.append("\n");+ for (PCodeTestControlBlock controlBlock : testControlBlocks) {+ testFileDigest.append("* ");+ testFileDigest.append(controlBlock.testFile.fileReferencePath);+ testFileDigest.append(" (TestInfo @ ");+ testFileDigest.append(controlBlock.getInfoStructureAddress().toString(true));+ testFileDigest.append(")\n");++ // compute column width for group function name and address+ int paddedLen = 0;+ for (PCodeTestGroup testGroup : controlBlock.getTestGroups()) {+ int len = testGroup.testGroupName.length() ++ testGroup.functionEntryPtr.toString(true).length() + 3;+ if (len > paddedLen) {+ paddedLen = len;+ }+ }++ for (PCodeTestGroup testGroup : controlBlock.getTestGroups()) {+ testFileDigest.append("* - ");+ String nameAndAddr =+ testGroup.testGroupName + " @ " + testGroup.functionEntryPtr.toString(true);+ nameAndAddr = StringUtilities.pad(nameAndAddr, ' ', -paddedLen);+ testFileDigest.append(nameAndAddr);+ testFileDigest.append(" (GroupInfo @ ");+ testFileDigest.append(+ testGroup.controlBlock.getInfoStructureAddress().toString(true));+ testFileDigest.append(")");+ if (duplicateTests.contains(testGroup.testGroupName)) {+ testFileDigest.append(" *DUPLICATE*");+ }+ testFileDigest.append("\n");+ }+ }+ testFileDigest.append(StringUtilities.pad("", '*', 80));++ return testFileDigest.toString();+ }++ /**+ * Force proper code address alignment to compensate for address encoding schemes (e.g., Thumb mode)+ * @param offset+ * @param alignment+ * @return+ */+ static long alignAddressOffset(long offset, int alignment) {+ return (offset / alignment) * alignment;+ }++ /**+ * Force proper code address alignment to compensate for address encoding schemes (e.g., Thumb mode)+ * @param addr+ * @param alignment+ * @return+ */+ static Address alignAddress(Address addr, int alignment) {+ Address alignedAddr = addr;+ long offset = addr.getOffset();+ long alignedOffset = alignAddressOffset(offset, alignment);+ if (offset != alignedOffset) {+ alignedAddr = addr.getNewAddress(alignedOffset);+ }+ return alignedAddr;+ }++ //+ // TODO: Eclipse HACK!+ //+ // Dummy Test Methods - these methods are needed to fake-out Eclipse and allow+ // individual tests to be run. These methods are not needed if running all+ // test groups.+ //+ // All known test group names must be included here and preceded by "test_".+ // For a test group named 'IterativeProcessingDoWhile' (as it appears in+ // the binary test file), an empty test method named 'test_IterativeProcessingDoWhile'+ // must be specified below.+ //+ // All tests are actually performed by the runTest method.+ //+ // The test_asm group is added for experimental assembly-level testing and+ // is not part of normal C source-based p-code testing.+ public final void test_asm() {+ // stub+ }++ public final void test_BIOPS_DOUBLE() {+ // stub+ }++ public final void test_BIOPS_FLOAT() {+ // stub+ }++ public final void test_BIOPS_LONGLONG() {+ // stub+ }++ public final void test_BIOPS() {+ // stub+ }++ public final void test_BIOPS2() {+ // stub+ }++ public final void test_BitManipulation() {+ // stub+ }++ public final void test_DecisionMaking() {+ // stub+ }++ public final void test_GlobalVariables() {+ // stub+ }++ public final void test_IterativeProcessingDoWhile() {+ // stub+ }++ public final void test_IterativeProcessingFor() {+ // stub+ }++ public final void test_IterativeProcessingWhile() {+ // stub+ }++ public final void test_misc() {+ // stub+ }++ public final void test_ParameterPassing1() {+ // stub+ }++ public final void test_ParameterPassing2() {+ // stub+ }++ public final void test_ParameterPassing3() {+ // stub+ }++ public final void test_PointerManipulation() {+ // stub+ }++ public final void test_StructUnionManipulation() {+ // stub+ }++}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/TestLogger.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/TestLogger.javanew file mode 100644index 0000000000..d26ff735ab--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/TestLogger.java@@ -0,0 +1,32 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors.support;++import ghidra.program.model.address.Address;+import ghidra.test.processors.support.EmulatorTestRunner.DumpFormat;++interface TestLogger {++ void logState(EmulatorTestRunner testRunner);++ public void logState(EmulatorTestRunner emulatorTestRunner, Address dumpAddr, int dumpSize,+ int elementSize, DumpFormat elementFormat, String comment);++ void log(PCodeTestGroup testGroup, String msg);++ void log(PCodeTestGroup testGroup, String msg, Throwable t);++}diff --git a/Ghidra/Features/Base/src/main/resources/pcodetest/chunk1.hinc b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk1.hincnew file mode 100644index 0000000000..b7e0616b96--- /dev/null+++ b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk1.hinc@@ -0,0 +1,148 @@+<HTML>+<HEAD>+ <META http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">+ <TITLE>CUnit Processor Emulation Test Results"</TITLE>++ <STYLE TYPE="text/css">++ div { font-family: verdana; }+ td { background-color: white; font-family: verdana; }++ .r90 { -moz-transform: rotate(-90deg); -webkit-transform: rotate(-90deg); margin-bottom: 8; width: 1em; line-height: 1ex; }++ .shade { background-color:#f0f8ff; }+ .bad { background-color:#ffefef; }+ .good { background-color:#efffef; }++ .TestNameHead { width: 300; background-color:#efefef; font-weight: bold; font-family: verdana; }+ .DateTimeHead { width: 80; background-color:#efefef; font-weight: bold; font-family: verdana; }+ .ResultSummaryHead { width: 80; background-color:#efefef; font-weight: bold; font-family: verdana; }++ .ResultHead { background-color:#efefef; font-family: verdana; font-size: 90%; }+ .GroupHead { height: 30; background-color:#efefef; font-weight: bold; font-family: verdana; text-align: left; overflow: hidden; text-overflow: ellipsis; }++ .TestName { height: 35; width: 295; padding-left: 5; font-family: verdana; font-size: 90%; }+ .DateTime { height: 35; width: 80; font-family: verdana; font-size: 75%; text-align: center; }+ .ResultSummary { height: 35; width: 80; font-family: verdana; font-size: 75%; text-align: center; }++ .Result { height: 35; font-family: verdana; font-size: 75%; text-align: center; }++ .message { font-family: verdana; font-style: italic; font-size: 75%; padding-left: 5; background-color:#efef00; }++ </STYLE>++ <SCRIPT>++ headerMinHeight = 250;+ headerMaxHeight = 450;++ function pageInit() {+ topLeftTable = document.getElementById("topLeftTable");+ hsTableTop = document.getElementById("hsTableTop");+ vsTableLeft = document.getElementById("vsTableLeft");+ sTableRight = document.getElementById("sTableRight");++ headerTable1 = document.getElementById("headerTable1");+ headerTable2 = document.getElementById("headerTable2");++ messageLayer = document.getElementById("messageLayer");++ setHeaderHeight(headerMinHeight);++ setLayerPositions();++ window.addEventListener("resize", onResize, false);++ onResize();+ }++ function setLayerPositions() {+ // set top/left corner of each layer++ vsTableLeft.style.top = topLeftTable.offsetTop + topLeftTable.offsetHeight;+ vsTableLeft.style.left = topLeftTable.offsetLeft;++ hsTableTop.style.top = topLeftTable.offsetTop;+ hsTableTop.style.left = topLeftTable.offsetLeft + topLeftTable.offsetWidth;++ sTableRight.style.top = vsTableLeft.offsetTop;+ sTableRight.style.left = hsTableTop.offsetLeft;+ }++ function onResize() {+ // adjust layer viewport dimensions++ sTableRight.style.width = window.innerWidth - sTableRight.offsetLeft;+ sTableRight.style.height = window.innerHeight - sTableRight.offsetTop;++ var pad = sTableRight.offsetHeight - sTableRight.clientHeight;+ var vsTableLeftHeight = window.innerHeight - vsTableLeft.offsetTop - pad;+ vsTableLeft.style.height = vsTableLeftHeight;++ pad = sTableRight.offsetWidth - sTableRight.clientWidth;+ hsTableTop.style.width = window.innerWidth - hsTableTop.offsetLeft - pad;++ // NOTE: The -4 adjustment resolved scrollbar problem+ messageLayer.style.top = vsTableLeft.offsetTop + vsTableLeftHeight - 4;+ messageLayer.style.width = vsTableLeft.offsetWidth;+ messageLayer.style.height = pad;+ }++ function onScrollDiv() {+ // perform synchronized scroll+ vsTableLeft.scrollTop = sTableRight.scrollTop;+ hsTableTop.scrollLeft = sTableRight.scrollLeft;+ }++ function toggleHeaderHeight() {+ var h = headerTable1.offsetHeight <= headerMinHeight ? headerMaxHeight : headerMinHeight;+ setHeaderHeight(h);+ }++ function setHeaderHeight(h) {+ headerTable1.style.height = h;+ headerTable2.style.height = h;++ setLayerPositions();++ onResize();+ }++ function mouseOverHeader() {+ showMessage("<font>Click header to shrink/expand</font>");+ }++ function mouseOutHeader() {+ hideMessage();+ }++ function showMessage(msg) {+ //window.alert(messageLayer.offsetTop + " " + messageLayer.offsetLeft + " " + messageLayer.innerHTML);+ messageLayer.innerHTML=msg;+ messageLayer.style.visibility = "visible";+ }++ function hideMessage() {+ messageLayer.style.visibility = "hidden";+ }++ </SCRIPT>++ </HEAD>+ <BODY onLoad="pageInit()">++ <DIV ID="messageLayer" CLASS="message" STYLE="position: absolute; top: 0; left: 0; z-index: 2; visibility: hidden;">MESSAGE</DIV>++ <DIV ID="topLeftTable" STYLE="position: absolute; top: 0; left: 0;">+ <TABLE ID="headerTable1" BORDER=1 CELLSPACING=0 CELLPADDING=0 style="height: 100; cursor: pointer;" onclick="toggleHeaderHeight()" onmouseover="mouseOverHeader()" onmouseout="mouseOutHeader()">+ <TR>+ <TD CLASS="TestNameHead"><DIV STYLE="position:absolute; left: 8px; top: 5px; ">P-Code Test Results</DIV><DIV STYLE="position:absolute; left: 140px; bottom: 5px; "><font color="green" size="2">Pass</font>/<font color="red" size="2">Fail</font>/<font color="orange" size="2">CallOther</font></DIV></TD>+ <TD CLASS="DateTimeHead" ALIGN="center" VALIGN="bottom"><DIV CLASS="r90">DATE/TIME</DIV></TD>+ <TD CLASS="ResultSummaryHead" ALIGN="center" VALIGN="bottom"><DIV CLASS="r90">SUMMARY</DIV></TD>+ </TR>+ </TABLE>+ </DIV>++ <DIV ID="hsTableTop" STYLE="position: absolute; overflow-x: hidden;">+ <TABLE ID="headerTable2" BORDER=1 CELLSPACING=0 CELLPADDING=0 style="height: 100; cursor: pointer;" onclick="toggleHeaderHeight()" onmouseover="mouseOverHeader()" onmouseout="mouseOutHeader()">+ <!-- top of hsTableTop (p-code test/group headers) -->diff --git a/Ghidra/Features/Base/src/main/resources/pcodetest/chunk2.hinc b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk2.hincnew file mode 100644index 0000000000..eee0e7ba06--- /dev/null+++ b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk2.hinc@@ -0,0 +1,8 @@+ <!-- end of hsTableTop (p-code test/group headers) -->+ </TABLE>+ </DIV>++ <DIV ID="vsTableLeft" STYLE="position: absolute; overflow-y: hidden;">+ <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>+ <!-- top of vsTableLeft (p-code test/group names, date/time, and summary) -->+diff --git a/Ghidra/Features/Base/src/main/resources/pcodetest/chunk3.hinc b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk3.hincnew file mode 100644index 0000000000..0c1c9940e4--- /dev/null+++ b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk3.hinc@@ -0,0 +1,7 @@+ <!-- end of vsTableLeft (p-code test/group names, date/time, and summary) -->+ </TABLE>+ </DIV>++ <DIV ID="sTableRight" STYLE="position: absolute; overflow: scroll;" onscroll="onScrollDiv()">+ <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>+ <!-- top of sTableRight (test results) -->diff --git a/Ghidra/Features/Base/src/main/resources/pcodetest/chunk4.hinc b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk4.hincnew file mode 100644index 0000000000..bcd383d3d6--- /dev/null+++ b/Ghidra/Features/Base/src/main/resources/pcodetest/chunk4.hinc@@ -0,0 +1,6 @@+ <!-- bottom of sTableRight (test results) -->+ </TABLE>+ </DIV>+ </BODY>+ </HTML>+diff --git a/Ghidra/Features/BytePatterns/ghidra_scripts/DumpMissedStarts.java b/Ghidra/Features/BytePatterns/ghidra_scripts/DumpMissedStarts.javaindex 5a733e3959..60e463bfcb 100644--- a/Ghidra/Features/BytePatterns/ghidra_scripts/DumpMissedStarts.java+++ b/Ghidra/Features/BytePatterns/ghidra_scripts/DumpMissedStarts.java@@ -15,6 +15,9 @@*///@category CodeAnalysis+import java.io.*;+import java.util.ArrayList;+import generic.jar.ResourceFile;import ghidra.app.analyzers.Patterns;import ghidra.app.script.GhidraScript;@@ -24,9 +27,6 @@ import ghidra.program.model.mem.Memory;import ghidra.util.bytesearch.*;import ghidra.util.constraint.ProgramDecisionTree;-import java.io.*;-import java.util.ArrayList;-public class DumpMissedStarts extends GhidraScript implements PatternFactory {private static int bufsize = 20;private DummyMatchAction dummyaction;@@ -43,10 +43,10 @@ public class DumpMissedStarts extends GhidraScript implements PatternFactory {return false;}- private boolean detectThunk(Function func, CodeUnit cunit) {- if (cunit == null)+ private boolean detectThunk(Function func, CodeUnit cu) {+ if (cu == null)return true;- if (cunit instanceof Data)+ if (cu instanceof Data)return true;return false;}@@ -65,12 +65,12 @@ public class DumpMissedStarts extends GhidraScript implements PatternFactory {File file =Application.getModuleDataFile("BytePatterns", "funcstartsamples.txt").getFile(true);dummyaction = new DummyMatchAction();- matchlist = new ArrayList<Match>();+ matchlist = new ArrayList<>();memory = currentProgram.getMemory();bytebuffer = new byte[bufsize];ProgramDecisionTree patternDecisionTree = Patterns.getPatternDecisionTree();ResourceFile[] fileList = Patterns.findPatternFiles(currentProgram, patternDecisionTree);- ArrayList<Pattern> patternlist = new ArrayList<Pattern>();+ ArrayList<Pattern> patternlist = new ArrayList<>();for (int i = 0; i < fileList.length; ++i)Pattern.readPostPatterns(fileList[i].getFile(true), patternlist, this);FileWriter fileWriter = new FileWriter(file);@@ -80,8 +80,8 @@ public class DumpMissedStarts extends GhidraScript implements PatternFactory {FunctionIterator iter = functionManager.getFunctions(true);while (iter.hasNext()) {Function func = iter.next();- CodeUnit cunit = listing.getCodeUnitAt(func.getEntryPoint());- if (detectThunk(func, cunit))+ CodeUnit cu = listing.getCodeUnitAt(func.getEntryPoint());+ if (detectThunk(func, cu))continue;int numbytes = memory.getBytes(func.getEntryPoint(), bytebuffer);if ((numbytes > 0) && (!functionMatchesPattern(bytebuffer, numbytes))) {diff --git a/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O0_EmulatorTest.java b/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O0_EmulatorTest.javanew file mode 100644index 0000000000..e7e693390a--- /dev/null+++ b/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class m68000_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "68000:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public m68000_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "m68000_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(m68000_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O3_EmulatorTest.java b/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O3_EmulatorTest.javanew file mode 100644index 0000000000..9845cec6d7--- /dev/null+++ b/Ghidra/Processors/68000/src/test.processors/java/ghidra/test/processors/m68000_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class m68000_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "68000:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public m68000_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "m68000_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(m68000_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O0_EmulatorTest.java b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O0_EmulatorTest.javanew file mode 100644index 0000000000..e29757430b--- /dev/null+++ b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AARCH64_BE_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "AARCH64:BE:64:v8A";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AARCH64_BE_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AARCH64_BE_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ AARCH64_BE_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O3_EmulatorTest.java b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O3_EmulatorTest.javanew file mode 100644index 0000000000..9ead7fc173--- /dev/null+++ b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_BE_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AARCH64_BE_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "AARCH64:BE:64:v8A";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AARCH64_BE_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AARCH64_BE_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ AARCH64_BE_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O0_EmulatorTest.java b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O0_EmulatorTest.javanew file mode 100644index 0000000000..f916d9ddcc--- /dev/null+++ b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AARCH64_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "AARCH64:LE:64:v8A";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AARCH64_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AARCH64_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AARCH64_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O3_EmulatorTest.java b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O3_EmulatorTest.javanew file mode 100644index 0000000000..73fe8a29df--- /dev/null+++ b/Ghidra/Processors/AARCH64/src/test.processors/java/ghidra/test/processors/AARCH64_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AARCH64_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "AARCH64:LE:64:v8A";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AARCH64_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AARCH64_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AARCH64_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O0_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O0_EmulatorTest.javanew file mode 100644index 0000000000..6be91653ec--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM10e_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM10e_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM10e_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM10e_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O3_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O3_EmulatorTest.javanew file mode 100644index 0000000000..ff09840df0--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM10e_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM10e_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM10e_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM10e_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM10e_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O0_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O0_EmulatorTest.javanew file mode 100644index 0000000000..b0046db960--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_BE_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:BE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_BE_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_BE_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_BE_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O3_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O3_EmulatorTest.javanew file mode 100644index 0000000000..b2f7f14396--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_BE_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:BE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_BE_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_BE_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_BE_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O0_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O0_EmulatorTest.javanew file mode 100644index 0000000000..92ca1e8a76--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_BE_thumb_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:BE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_BE_thumb_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_BE_thumb_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ ARM_BE_thumb_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O3_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O3_EmulatorTest.javanew file mode 100644index 0000000000..c7d6fc690f--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_BE_thumb_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_BE_thumb_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:BE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_BE_thumb_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_BE_thumb_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ ARM_BE_thumb_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O0_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O0_EmulatorTest.javanew file mode 100644index 0000000000..a40605baa0--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O3_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O3_EmulatorTest.javanew file mode 100644index 0000000000..b1fc3958db--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O0_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O0_EmulatorTest.javanew file mode 100644index 0000000000..b7556b33f9--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_thumb_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_thumb_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_thumb_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_thumb_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O3_EmulatorTest.java b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O3_EmulatorTest.javanew file mode 100644index 0000000000..f58ba1a93c--- /dev/null+++ b/Ghidra/Processors/ARM/src/test.processors/java/ghidra/test/processors/ARM_thumb_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class ARM_thumb_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "ARM:LE:32:v8";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public ARM_thumb_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ARM_thumb_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(ARM_thumb_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O0_EmulatorTest.javanew file mode 100644index 0000000000..bb772bf487--- /dev/null+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O0_EmulatorTest.java@@ -0,0 +1,48 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.framework.options.Options;+import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AVR32_BE_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "avr32:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AVR32_BE_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AVR_GCC_O0";+ }++ @Override+ protected void setAnalysisOptions(Options analysisOptions) {+ super.setAnalysisOptions(analysisOptions);+ analysisOptions.setBoolean("Reference", false); // too many bad disassemblies+ analysisOptions.setBoolean("Data Reference", false);+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR32_BE_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O3_EmulatorTest.javanew file mode 100644index 0000000000..c90f066c8b--- /dev/null+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR32_BE_O3_EmulatorTest.java@@ -0,0 +1,48 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.framework.options.Options;+import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AVR32_BE_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "avr32:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AVR32_BE_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AVR_GCC_O3";+ }++ @Override+ protected void setAnalysisOptions(Options analysisOptions) {+ super.setAnalysisOptions(analysisOptions);+ analysisOptions.setBoolean("Reference", false); // too many bad disassemblies+ analysisOptions.setBoolean("Data Reference", false); // too many bad disassemblies+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR32_BE_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O0_EmulatorTest.java b/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O0_EmulatorTest.javanew file mode 100644index 0000000000..28e05c3aa0--- /dev/null+++ b/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class CR16C_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "CR16C:LE:16:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public CR16C_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "CR16C_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(CR16C_O0_EmulatorTest.class);+ }++}diff --git a/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O3_EmulatorTest.java b/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O3_EmulatorTest.javanew file mode 100644index 0000000000..9c0f6ba0f8--- /dev/null+++ b/Ghidra/Processors/CR16/src/test.processors/java/ghidra/test/processors/CR16C_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class CR16C_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "CR16C:LE:16:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public CR16C_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "CR16C_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(CR16C_O3_EmulatorTest.class);+ }++}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O0_EmulatorTest.javanew file mode 100644index 0000000000..3ad576a831--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS16MIX_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS16MIX_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS16MIX_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS16MIX_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O3_EmulatorTest.javanew file mode 100644index 0000000000..5655633058--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16MIX_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS16MIX_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS16MIX_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS16MIX_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS16MIX_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O0_EmulatorTest.javanew file mode 100644index 0000000000..05dfcb7bff--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS16_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS16_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS16_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS16_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O3_EmulatorTest.javanew file mode 100644index 0000000000..b2cf9286c0--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS16_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS16_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS16_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS16_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS16_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O0_EmulatorTest.javanew file mode 100644index 0000000000..48df8b7a3f--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O0_EmulatorTest.java@@ -0,0 +1,45 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64R6_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:R6";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64R6_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64R6_GCC_O0";+ }++ @Override+ public boolean failOnDisassemblyErrors() {+ return false;+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS64R6_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O3_EmulatorTest.javanew file mode 100644index 0000000000..15fc71deeb--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64R6_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64R6_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:R6";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64R6_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64R6_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS64R6_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O0_EmulatorTest.javanew file mode 100644index 0000000000..4672978a89--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64_32addr_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:64-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64_32addr_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64_32addr_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPS64_32addr_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O3_EmulatorTest.javanew file mode 100644index 0000000000..ee7a2ba47a--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_32addr_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64_32addr_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:64-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64_32addr_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64_32addr_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPS64_32addr_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O0_EmulatorTest.javanew file mode 100644index 0000000000..13e6345577--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64_64addr_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64_64addr_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64_64addr_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPS64_64addr_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O3_EmulatorTest.javanew file mode 100644index 0000000000..554fcee7a1--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS64_64addr_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS64_64addr_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:64:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS64_64addr_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS64_64addr_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPS64_64addr_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O0_EmulatorTest.javanew file mode 100644index 0000000000..40009e243f--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSEL_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:LE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSEL_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSEL_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O3_EmulatorTest.javanew file mode 100644index 0000000000..20453eec36--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSEL_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSEL_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:LE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSEL_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSEL_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O0_EmulatorTest.javanew file mode 100644index 0000000000..7d32eddb33--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O0_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSMICROMIX_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:micro";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSMICROMIX_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSMICMIX_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPSMICROMIX_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O3_EmulatorTest.javanew file mode 100644index 0000000000..7d1fe8890b--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICROMIX_O3_EmulatorTest.java@@ -0,0 +1,41 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSMICROMIX_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:micro";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSMICROMIX_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSMICMIX_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(+ MIPSMICROMIX_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O0_EmulatorTest.javanew file mode 100644index 0000000000..35011ad6e1--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSMICRO_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:micro";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSMICRO_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSMIC_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPSMICRO_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O3_EmulatorTest.javanew file mode 100644index 0000000000..80c4541bfe--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSMICRO_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSMICRO_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:micro";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSMICRO_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSMIC_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPSMICRO_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O0_EmulatorTest.javanew file mode 100644index 0000000000..2bc7104f6d--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSR6_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:R6";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSR6_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSR6_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPSR6_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O3_EmulatorTest.javanew file mode 100644index 0000000000..34e8f42519--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPSR6_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPSR6_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:R6";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPSR6_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPSR6_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPSR6_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O0_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O0_EmulatorTest.javanew file mode 100644index 0000000000..0d87816339--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O3_EmulatorTest.java b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O3_EmulatorTest.javanew file mode 100644index 0000000000..5d14b675d5--- /dev/null+++ b/Ghidra/Processors/MIPS/src/test.processors/java/ghidra/test/processors/MIPS_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class MIPS_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "MIPS:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public MIPS_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "MIPS_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(MIPS_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O0_EmulatorTest.java b/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O0_EmulatorTest.javanew file mode 100644index 0000000000..4494c4a2e7--- /dev/null+++ b/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O0_EmulatorTest.java@@ -0,0 +1,64 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.program.model.address.AddressSetView;+import ghidra.program.model.lang.Register;+import ghidra.program.model.lang.RegisterValue;+import ghidra.program.model.listing.Program;+import ghidra.program.model.mem.MemoryBlock;+import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PARISC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "pa-risc:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PARISC_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "HPPA1.1_GCC_O0";+ }++ @Override+ protected void preAnalyze(Program program) throws Exception {+ MemoryBlock block = program.getMemory().getBlock(".data");+ if (block != null) {+ Register dpReg = program.getRegister("dp");+ RegisterValue value =+ new RegisterValue(dpReg, block.getStart().getOffsetAsBigInteger());+ AddressSetView loadedMemory = program.getMemory().getLoadedAndInitializedAddressSet();+ program.getProgramContext().setRegisterValue(loadedMemory.getMinAddress(),+ loadedMemory.getMaxAddress(), value);+ }+ super.preAnalyze(program);+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PARISC_O0_EmulatorTest.class);+ }++ @Override+ public boolean failOnDisassemblyErrors() {+ return false;+ }+}diff --git a/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O3_EmulatorTest.java b/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O3_EmulatorTest.javanew file mode 100644index 0000000000..f64d50e063--- /dev/null+++ b/Ghidra/Processors/PA-RISC/src/test.processors/java/ghidra/test/processors/PARISC_O3_EmulatorTest.java@@ -0,0 +1,64 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.program.model.address.AddressSetView;+import ghidra.program.model.lang.Register;+import ghidra.program.model.lang.RegisterValue;+import ghidra.program.model.listing.Program;+import ghidra.program.model.mem.MemoryBlock;+import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PARISC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "pa-risc:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PARISC_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "HPPA1.1_GCC_O3";+ }++ @Override+ protected void preAnalyze(Program program) throws Exception {+ MemoryBlock block = program.getMemory().getBlock(".data");+ if (block != null) {+ Register dpReg = program.getRegister("dp");+ RegisterValue value =+ new RegisterValue(dpReg, block.getStart().getOffsetAsBigInteger());+ AddressSetView loadedMemory = program.getMemory().getLoadedAndInitializedAddressSet();+ program.getProgramContext().setRegisterValue(loadedMemory.getMinAddress(),+ loadedMemory.getMaxAddress(), value);+ }+ super.preAnalyze(program);+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PARISC_O3_EmulatorTest.class);+ }++ @Override+ public boolean failOnDisassemblyErrors() {+ return false;+ }+}diff --git a/Ghidra/Processors/PIC/src/test.processors/java/ghidra/test/processors/PIC30_O0_EmulatorTest.java b/Ghidra/Processors/PIC/src/test.processors/java/ghidra/test/processors/PIC30_O0_EmulatorTest.javanew file mode 100644index 0000000000..a6484a1008--- /dev/null+++ b/Ghidra/Processors/PIC/src/test.processors/java/ghidra/test/processors/PIC30_O0_EmulatorTest.java@@ -0,0 +1,45 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PIC30_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "dsPIC30F:LE:24:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PIC30_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "PIC30_GCC_O0";+ }++ @Override+ protected String getPreferredStackSymbolName() {+ return "__SP_init";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PIC30_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O0_EmulatorTest.javanew file mode 100644index 0000000000..8165ce7ba0--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPC64_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPC64_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "powerpc64_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPC64_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O3_EmulatorTest.javanew file mode 100644index 0000000000..4ab136fda7--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC64_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPC64_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPC64_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "powerpc64_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPC64_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O0_EmulatorTest.javanew file mode 100644index 0000000000..8844daee42--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCA2Alt_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCA2Alt_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcA2Alt_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCA2Alt_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O3_EmulatorTest.javanew file mode 100644index 0000000000..2aebeb2bbb--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2Alt_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCA2Alt_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCA2Alt_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcA2Alt_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCA2Alt_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O0_EmulatorTest.javanew file mode 100644index 0000000000..18084d511b--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCA2_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCA2_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcA2_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCA2_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O3_EmulatorTest.javanew file mode 100644index 0000000000..0b340c7b93--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCA2_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCA2_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCA2_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcA2_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCA2_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O0_EmulatorTest.javanew file mode 100644index 0000000000..4d92e30dc7--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCP8Alt_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCP8Alt_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcP8Alt_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCP8Alt_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O3_EmulatorTest.javanew file mode 100644index 0000000000..3f9030b85f--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP8Alt_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCP8Alt_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCP8Alt_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcP8Alt_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCP8Alt_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O0_EmulatorTest.javanew file mode 100644index 0000000000..877c33aaba--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCP9Alt_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCP9Alt_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcP9Alt_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCP9Alt_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O3_EmulatorTest.javanew file mode 100644index 0000000000..18b713943f--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPCP9Alt_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPCP9Alt_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:64:A2ALT-32addr";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPCP9Alt_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "ppcP9Alt_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPCP9Alt_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O0_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O0_EmulatorTest.javanew file mode 100644index 0000000000..8268bf8402--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPC_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "powerpc32_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPC_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O3_EmulatorTest.java b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O3_EmulatorTest.javanew file mode 100644index 0000000000..e6c5784fb1--- /dev/null+++ b/Ghidra/Processors/PowerPC/src/test.processors/java/ghidra/test/processors/PPC_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class PPC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "PowerPC:BE:32:default";+ private static final String COMPILER_SPEC_ID = "default";++ private static final String[] REG_DUMP_SET = new String[] {};++ public PPC_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "powerpc32_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(PPC_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O0_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O0_EmulatorTest.javanew file mode 100644index 0000000000..ae70c0f4c8--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AVX2_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:64:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AVX2_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AVX2_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVX2_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O3_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O3_EmulatorTest.javanew file mode 100644index 0000000000..f2080e0707--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/AVX2_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class AVX2_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:64:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public AVX2_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "AVX2_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVX2_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O0_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O0_EmulatorTest.javanew file mode 100644index 0000000000..970bb06bc5--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class X86m32_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:32:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public X86m32_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "pentium_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(X86m32_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O3_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O3_EmulatorTest.javanew file mode 100644index 0000000000..3fa1caf4ee--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m32_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class X86m32_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:32:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public X86m32_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "pentium_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(X86m32_O3_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O0_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O0_EmulatorTest.javanew file mode 100644index 0000000000..5b265f4eb4--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O0_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class X86m64_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:64:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public X86m64_O0_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "x86_m64_GCC_O0";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(X86m64_O0_EmulatorTest.class);+ }+}diff --git a/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O3_EmulatorTest.java b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O3_EmulatorTest.javanew file mode 100644index 0000000000..029fbd3b51--- /dev/null+++ b/Ghidra/Processors/x86/src/test.processors/java/ghidra/test/processors/X86m64_O3_EmulatorTest.java@@ -0,0 +1,40 @@+/* ###+ * IP: GHIDRA+ *+ * 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.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.test.processors;++import ghidra.test.processors.support.ProcessorEmulatorTestAdapter;+import junit.framework.Test;++public class X86m64_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {++ private static final String LANGUAGE_ID = "x86:LE:64:default";+ private static final String COMPILER_SPEC_ID = "gcc";++ private static final String[] REG_DUMP_SET = new String[] {};++ public X86m64_O3_EmulatorTest(String name) throws Exception {+ super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET);+ }++ @Override+ protected String getProcessorDesignator() {+ return "x86_m64_GCC_O3";+ }++ public static Test suite() {+ return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(X86m64_O3_EmulatorTest.class);+ }+}diff --git a/gradle/javaProject.gradle b/gradle/javaProject.gradleindex 9721941f8e..309fd5b7e4 100644--- a/gradle/javaProject.gradle+++ b/gradle/javaProject.gradle@@ -83,7 +83,7 @@ sourceSets {runtimeClasspath += main.output}}- cunitTest {+ pcodeTest {java {srcDir 'src/test.processors/java'compileClasspath += main.output@@ -104,7 +104,7 @@ sourceSets {configurations {integrationTestCompile.extendsFrom testCompileintegrationTestRuntime.extendsFrom testRuntime, integrationTestCompile- cunitTestCompile.extendsFrom compile+ pcodeTestCompile.extendsFrom compiletestArtifacts.extendsFrom testRuntimeintegrationTestArtifacts.extendsFrom integrationTestRuntime}@@ -135,6 +135,7 @@ dependencies {testCompile "org.jmockit:jmockit:1.44"testCompile "junit:junit:4.12"+ pcodeTestCompile "junit:junit:4.12"}// For Java 9, we must explicitly export references to the internal classes we are using.diff --git a/gradle/javaTestProject.gradle b/gradle/javaTestProject.gradleindex 5a972df379..ebcee0f6a8 100644--- a/gradle/javaTestProject.gradle+++ b/gradle/javaTestProject.gradle@@ -64,16 +64,16 @@ task integrationTest (type: Test) { t ->}}-task cunitTest (type: Test) { t ->- group "cunit"+task pcodeTest (type: Test) { t ->+ group "pcodeTest"dependsOn { project(":FunctionID").unpackFidDatabases }- testClassesDirs = files sourceSets.cunitTest.output.classesDirs- classpath = sourceSets.cunitTest.runtimeClasspath+ testClassesDirs = files sourceSets.pcodeTest.output.classesDirs+ classpath = sourceSets.pcodeTest.runtimeClasspath// Enable if you want to force Gradle to launch a new JVM for each test.forkEvery 1- initTestJVM(t, rootProject.ext.cunitTestRootDirName)+ initTestJVM(t, rootProject.ext.pcodeTestRootDirName)doFirst {startTestTimer(t)@@ -86,8 +86,8 @@ task cunitTest (type: Test) { t ->rootProject.unitTestReport {reportOn this.project.test}-rootProject.cunitTestReport {- reportOn this.project.cunitTest+rootProject.pcodeTestReport {+ reportOn this.project.pcodeTest}rootProject.combinedTestReport {reportOn this.project.testdiff --git a/gradle/root/test.gradle b/gradle/root/test.gradleindex 947fd7f107..015b77424c 100644--- a/gradle/root/test.gradle+++ b/gradle/root/test.gradle@@ -56,17 +56,17 @@ if (!project.hasProperty('srcTreeName')) {}project.ext.testRootDirName = "JunitTest_" + srcTreeName-project.ext.cunitTestRootDirName = "CunitTest_" + srcTreeName+project.ext.pcodeTestRootDirName = "PCodeTest_" + srcTreeNameproject.ext.shareDir = System.properties.get('share.dir')if (project.ext.shareDir != null) {// add src tree name to machine specified share pathproject.ext.testShareDir = shareDir + "/" + testRootDirName- project.ext.cunitTestShareDir = shareDir + "/" + cunitTestRootDirName+ project.ext.pcodeTestShareDir = shareDir + "/" + pcodeTestRootDirName}else {project.ext.testShareDir = "$rootTestDir" + "/JUnit"- project.ext.cunitTestShareDir = "$rootTestDir" + "/CUnit"+ project.ext.pcodeTestShareDir = "$rootTestDir" + "/PCodeTest"}project.ext.upgradeProgramErrorMessage = "WARNING! Attempting data upgrade for "@@ -454,27 +454,27 @@ task combinedTestReport(type: TestReport) { t ->}/*********************************************************************************- * CUNIT TEST REPORT+ * P-CODE TEST REPORT*- * Summary: Runs all CUNIT tests+ * Summary: Runs all P-Code Tests**********************************************************************************/-task cunitTestReport(type: TestReport) { t ->- group "cunit"- destinationDir = file("$cunitTestShareDir" + "/reports")+task pcodeTestReport(type: TestReport) { t ->+ group "pcodeTest"+ destinationDir = file("$pcodeTestShareDir" + "/reports")}/*********************************************************************************- * CUNIT TEST REPORT w/ CUNIT MATRIX REPORT+ * P-CODE TEST REPORT w/ MATRIX REPORT*- * Summary: Runs all CUNIT tests and consolidate JUnit and Matrix report in+ * Summary: Runs all P-Code Tests and consolidates JUnit and Matrix report in* results directory.**********************************************************************************/-task cunitConsolidatedTestReport(type: Copy) {- group "cunit"- dependsOn ':cunitTestReport'- into (cunitTestShareDir + "/reports")+task pcodeConsolidatedTestReport(type: Copy) {+ group "pcodeTest"+ dependsOn ':pcodeTestReport'+ into (pcodeTestShareDir + "/reports")from (testOutputDir + "/test-output") {exclude '**/*.xml', 'cache/**'}