Class ProcessorEmulatorTestAdapter
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- ghidra.test.processors.support.ProcessorEmulatorTestAdapter
-
- All Implemented Interfaces:
ExecutionListener
,junit.framework.Test
public abstract class ProcessorEmulatorTestAdapter extends junit.framework.TestCase implements ExecutionListener
ProcessorEmulatorTestAdapter
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).Within the pcodetests directory all files and folders which start with the prefix
_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. JUnit X86EmulatorTest could utilize the following binary file naming strategy:
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
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. TheinitializeState(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.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BATCH_MODE_OUTPUT_DIR
protected CompilerSpec
compilerSpec
protected java.util.Set<Register>
floatRegSet
protected java.util.Set<java.lang.String>
ignoredBlocks
protected Language
language
protected java.lang.String
processorDesignator
protected Register[]
regDumpSet
static boolean
traceDisabled
-
Constructor Summary
Constructors Constructor Description ProcessorEmulatorTestAdapter(java.lang.String name, java.lang.String languageID, java.lang.String compilerSpecID, java.lang.String[] regDumpSetNames)
ProcessorEmulatorTestAdapter(java.lang.String name, java.lang.String languageID, java.lang.String compilerSpecID, java.lang.String[] regDumpSetNames, java.lang.String[] floatRegSetNames)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
analyze(Program program, PCodeTestControlBlock testControlBlock)
Invoked for non-gzf files to perform auto-analysis.static junit.framework.Test
buildEmulatorTestSuite(java.lang.Class<?> emulatorTestClass)
Create TestSuite based upon available test groups contained within binary test files associated with target processor.protected java.lang.String
buildTestFileDesignator(int fileIndex, java.lang.String filePath)
Get CUint file designator if use of A, B, C...static void
deleteResultFilesOnStartup()
boolean
failOnDisassemblyErrors()
boolean
failOnRelocationErrors()
protected java.lang.Class<? extends Loader>
getLoaderClass()
Get the loader class which should be used.protected static Address
getMaxDefinedMemoryAddress(Program program)
Get the maximum defined memory address ignoring any overlays which have been defined.protected java.lang.String
getPreferredStackSymbolName()
Get symbol name which defines initial stack pointer offsetprotected java.lang.String
getProcessorDesignator()
Get the processor designator used to identify test binary files/folder.static junit.framework.Test
getTestFailure(java.lang.Class<?> emulatorTestClass, java.lang.String message, java.lang.Throwable t)
Symbol
getUniqueGlobalSymbol(Program program, java.lang.String name)
protected void
initializeState(EmulatorTestRunner testRunner, Program program)
Invoked for each program immediately prior to executing a test group.void
log(PCodeTestGroup testGroup, java.lang.String msg)
void
log(PCodeTestGroup testGroup, java.lang.String msg, java.lang.Throwable t)
void
logRead(EmulatorTestRunner testRunner, Address address, int size, byte[] values)
void
logState(EmulatorTestRunner testRunner)
void
logState(EmulatorTestRunner emulatorTestRunner, Address dumpAddr, int dumpSize, int elementSize, EmulatorTestRunner.DumpFormat elementFormat, java.lang.String comment)
void
logWrite(EmulatorTestRunner testRunner, Address address, int size, byte[] values)
protected void
postAnalyze(Program program)
Invoked for non-gzf files immediately after the analyze method to perform any follow-up changes of inspection of the program.protected void
postImport(Program program)
Invoked immediately following import allow byte processing prior to control structure identification.protected void
preAnalyze(Program program)
Invoked prior to analysis to allow analysis options or other pre-analysis inspection/modification to be performed.void
runTest()
Single unit test which handles named test group specified during test instantiation.protected void
setAnalysisOptions(Options analysisOptions)
protected void
setIgnoredBlocks(java.lang.String... blockNames)
protected void
setUp()
void
stepCompleted(EmulatorTestRunner testRunner)
protected void
tearDown()
void
test_asm()
void
test_BIOPS()
void
test_BIOPS_DOUBLE()
void
test_BIOPS_FLOAT()
void
test_BIOPS_LONGLONG()
void
test_BIOPS2()
void
test_BitManipulation()
void
test_DecisionMaking()
void
test_GlobalVariables()
void
test_IterativeProcessingDoWhile()
void
test_IterativeProcessingFor()
void
test_IterativeProcessingWhile()
void
test_misc()
void
test_ParameterPassing1()
void
test_ParameterPassing2()
void
test_ParameterPassing3()
void
test_PointerManipulation()
void
test_StructUnionManipulation()
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, setName, toString
-
-
-
-
Field Detail
-
BATCH_MODE_OUTPUT_DIR
public static final java.lang.String BATCH_MODE_OUTPUT_DIR
-
traceDisabled
public static boolean traceDisabled
-
processorDesignator
protected java.lang.String processorDesignator
-
language
protected Language language
-
compilerSpec
protected CompilerSpec compilerSpec
-
regDumpSet
protected Register[] regDumpSet
-
floatRegSet
protected java.util.Set<Register> floatRegSet
-
ignoredBlocks
protected java.util.Set<java.lang.String> ignoredBlocks
-
-
Constructor Detail
-
ProcessorEmulatorTestAdapter
public ProcessorEmulatorTestAdapter(java.lang.String name, java.lang.String languageID, java.lang.String compilerSpecID, java.lang.String[] regDumpSetNames) throws LanguageNotFoundException, CompilerSpecNotFoundException
-
ProcessorEmulatorTestAdapter
public ProcessorEmulatorTestAdapter(java.lang.String name, java.lang.String languageID, java.lang.String compilerSpecID, java.lang.String[] regDumpSetNames, java.lang.String[] floatRegSetNames) throws LanguageNotFoundException, CompilerSpecNotFoundException
-
-
Method Detail
-
deleteResultFilesOnStartup
public static void deleteResultFilesOnStartup()
-
setIgnoredBlocks
protected final void setIgnoredBlocks(java.lang.String... blockNames)
-
getTestFailure
public static junit.framework.Test getTestFailure(java.lang.Class<?> emulatorTestClass, java.lang.String message, java.lang.Throwable t)
-
buildEmulatorTestSuite
public static final junit.framework.Test buildEmulatorTestSuite(java.lang.Class<?> emulatorTestClass)
Create TestSuite based upon available test groups contained within binary test files associated with target processor.- Parameters:
emulatorTestClass
- test which extendsProcessorEmulatorTestAdapter
and whose name ends with "EmulatorTest".- Returns:
- test suite
-
log
public void log(PCodeTestGroup testGroup, java.lang.String msg)
-
log
public void log(PCodeTestGroup testGroup, java.lang.String msg, java.lang.Throwable t)
-
logState
public void logState(EmulatorTestRunner testRunner)
-
logState
public void logState(EmulatorTestRunner emulatorTestRunner, Address dumpAddr, int dumpSize, int elementSize, EmulatorTestRunner.DumpFormat elementFormat, java.lang.String comment)
-
logRead
public void logRead(EmulatorTestRunner testRunner, Address address, int size, byte[] values)
- Specified by:
logRead
in interfaceExecutionListener
-
logWrite
public void logWrite(EmulatorTestRunner testRunner, Address address, int size, byte[] values)
- Specified by:
logWrite
in interfaceExecutionListener
-
stepCompleted
public void stepCompleted(EmulatorTestRunner testRunner)
- Specified by:
stepCompleted
in interfaceExecutionListener
-
setUp
protected void setUp() throws java.lang.Exception
- Overrides:
setUp
in classjunit.framework.TestCase
- Throws:
java.lang.Exception
-
tearDown
protected void tearDown() throws java.lang.Exception
- Overrides:
tearDown
in classjunit.framework.TestCase
- Throws:
java.lang.Exception
-
runTest
public final void runTest()
Single unit test which handles named test group specified during test instantiation.- Overrides:
runTest
in classjunit.framework.TestCase
-
getPreferredStackSymbolName
protected java.lang.String getPreferredStackSymbolName()
Get symbol name which defines initial stack pointer offset- Returns:
- stack symbol or null
-
getMaxDefinedMemoryAddress
protected static final Address getMaxDefinedMemoryAddress(Program program)
Get the maximum defined memory address ignoring any overlays which have been defined.- Returns:
- max defined physical address
-
getProcessorDesignator
protected java.lang.String getProcessorDesignator()
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- Returns:
- processor designator
-
buildTestFileDesignator
protected java.lang.String buildTestFileDesignator(int fileIndex, java.lang.String filePath)
Get CUint file designator if use of A, B, C... is not suitable.- Parameters:
fileIndex
- file index within sorted listfilePath
- binary file path- Returns:
- short file designator for use in qualified test name
-
initializeState
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws java.lang.Exception
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.- Parameters:
testRunner
- emulator group test runner/facilitatorprogram
-- Throws:
java.lang.Exception
- if initialization criteria has not been satisfied
-
postImport
protected void postImport(Program program) throws java.lang.Exception
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.- Parameters:
program
-- Throws:
java.lang.Exception
-
preAnalyze
protected void preAnalyze(Program program) throws java.lang.Exception
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.- Parameters:
program
-- Throws:
java.lang.Exception
-
postAnalyze
protected void postAnalyze(Program program) throws java.lang.Exception
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.- Parameters:
program
-- Throws:
java.lang.Exception
-
analyze
protected void analyze(Program program, PCodeTestControlBlock testControlBlock) throws java.lang.Exception
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.- Parameters:
program
-- Throws:
java.lang.Exception
-
setAnalysisOptions
protected void setAnalysisOptions(Options analysisOptions)
-
getLoaderClass
protected java.lang.Class<? extends Loader> getLoaderClass()
Get the loader class which should be used. A null value should be return to use the preferred loader.- Returns:
- loader class or null
-
failOnDisassemblyErrors
public boolean failOnDisassemblyErrors()
- Returns:
- true if test run should fail up-front if binary contains disassembly errors
-
failOnRelocationErrors
public boolean failOnRelocationErrors()
- Returns:
- true if test run should fail up-front if binary contains relocation errors
-
test_asm
public final void test_asm()
-
test_BIOPS_DOUBLE
public final void test_BIOPS_DOUBLE()
-
test_BIOPS_FLOAT
public final void test_BIOPS_FLOAT()
-
test_BIOPS_LONGLONG
public final void test_BIOPS_LONGLONG()
-
test_BIOPS
public final void test_BIOPS()
-
test_BIOPS2
public final void test_BIOPS2()
-
test_BitManipulation
public final void test_BitManipulation()
-
test_DecisionMaking
public final void test_DecisionMaking()
-
test_GlobalVariables
public final void test_GlobalVariables()
-
test_IterativeProcessingDoWhile
public final void test_IterativeProcessingDoWhile()
-
test_IterativeProcessingFor
public final void test_IterativeProcessingFor()
-
test_IterativeProcessingWhile
public final void test_IterativeProcessingWhile()
-
test_misc
public final void test_misc()
-
test_ParameterPassing1
public final void test_ParameterPassing1()
-
test_ParameterPassing2
public final void test_ParameterPassing2()
-
test_ParameterPassing3
public final void test_ParameterPassing3()
-
test_PointerManipulation
public final void test_PointerManipulation()
-
test_StructUnionManipulation
public final void test_StructUnionManipulation()
-
-