Class CSpecPrototypeTest


public abstract class CSpecPrototypeTest extends AbstractGhidraHeadlessIntegrationTest
CSpecPrototypeTest provides an abstract JUnit test implementation for processor-specific and compiler-specific calling convention test cases. Tests which extend this class must implement abstract functions to specify LANGUAGE_ID, COMPILER_SPEC_ID, and CALLING_CONVENTION. An optional list of function names that contain errors can be passed to the constructor to designate those errors as expected. The test will pass as long as only expected errors are found. Source and binary files have a naming scheme. (LANGUAGE_ID)_(COMPILER_SPEC_ID)_(CALLING_CONVENTION) Trace logging is disabled by default. Specific traceLevel and traceLog disabled controlled via environment properties CSpecTestTraceLevel and EmuTestTraceDisable. To create a new CSpecPrototypeTest for a given Module (e.g. Processors x86) complete the following steps: 1. Generate source code using Ghidra and the Ghidra script "GeneratePrototypeTestFileScript". NOTE: Do not rename the generated file; the filename is required for the test suit. 2. Compile the source code using the following recommended GCC flags: gcc -O1 -c -fno-inline -fno-leading-underscore -o filename_without_extension filename.c 3. Place the source code and compiled binary in the module's "data/cspectests" directory or the ghidra.bin repository in the directory: "Ghidra/Test/TestResources/data/cspectests" 4. Add a new package named "ghidra.test.processors.cspec" to the module if it does not exist and place all new CSpecTest's in this package. 5. New CSpecTests should extend this class and have a class name which ends in 'CSpecTest' and starts with processor details that indicate what cspec prototype is being tested. - Implement abstract methods for Language ID, Compiler Spec ID, and Calling Convention. 6. Use Ghidra and the Ghidra script "TestPrototypeScript" to debug errors. - Click function links in the Script Console to jump to the Listing View. - To isolate a single function, highlight it in the Listing and re-run the script for detailed debug output.
  • Constructor Details

  • Method Details

    • setUp

      public void setUp() throws Exception
      Ran before every test to prepare Ghidra for testing.
      Throws:
      Exception - when the test environment fails to be created or the emulator fails to load the program.
    • tearDown

      public void tearDown() throws Exception
      Throws:
      Exception
    • prototypeTest

      public void prototypeTest() throws Exception
      Tests that for a given binary and source code all functions in the binary are interpreted correctly by Ghidra using cspec files for the given calling convention.
      Throws:
      Exception - when the Prototype cannot be established, the source code could not be parsed correctly, or the test could not be completed.
    • getLanguageID

      public abstract String getLanguageID()
      Returns:
      String Language ID
    • getCompilerSpecID

      public abstract String getCompilerSpecID()
      Returns:
      String Compiler Spec ID
    • getCallingConvention

      public abstract String getCallingConvention()
      Returns:
      String Calling Convention