decompiler  1.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::FunctionTestCollection Class Reference

A collection of tests around a single program/function. More...

#include <testfunction.hh>

Public Member Functions

 FunctionTestCollection (ostream &s)
 Constructor. More...
 
 FunctionTestCollection (IfaceStatus *con)
 Constructor with preexisting console.
 
 ~FunctionTestCollection (void)
 Destructor.
 
int4 getTestsApplied (void) const
 Get the number of tests executed.
 
int4 getTestsSucceeded (void) const
 Get the number of tests that passed.
 
int4 numCommands (void) const
 Get the number of commands in the current script.
 
string getCommand (int4 i) const
 Get the i-th command.
 
void loadTest (const string &filename)
 Load a test program, tests, and script. More...
 
void restoreXml (DocumentStorage &store, const Element *el)
 Load tests from a <decompilertest> tag.
 
void restoreXmlOldForm (DocumentStorage &store, const Element *el)
 Load tests from <binaryimage> tag. More...
 
void runTests (list< string > &lateStream)
 Run the script and perform the tests. More...
 

Static Public Member Functions

static int runTestFiles (const vector< string > &testFiles, ostream &s)
 Run tests for each listed file. More...
 

Private Member Functions

void clear (void)
 Clear any previous architecture and function.
 
void restoreXmlCommands (const Element *el)
 Reconstruct commands from an XML tag. More...
 
void buildProgram (DocumentStorage &store)
 Build program (Architecture) from <binaryimage> tag. More...
 
void startTests (void) const
 Initialize each FunctionTestProperty. More...
 
void passLineToTests (const string &line) const
 Let all tests analyze a line of the results. More...
 
void evaluateTests (list< string > &lateStream) const
 Do the final evaluation of each test. More...
 

Private Attributes

IfaceDecompDatadcp
 Program data for the test collection.
 
string fileName
 Name of the file containing test data.
 
list< FunctionTestPropertytestList
 List of tests for this collection.
 
vector< string > commands
 Sequence of commands for current test.
 
IfaceStatusconsole
 Decompiler console for executing scripts.
 
bool consoleOwner
 Set to true if this object owns the console.
 
int4 numTestsApplied
 Count of tests that were executed.
 
int4 numTestsSucceeded
 Count of tests that passed.
 

Detailed Description

A collection of tests around a single program/function.

The collection of tests is loaded from a single XML file via loadTest(), and the tests are run by calling runTests(). An entire program is loaded and possibly annotated by a series of console command lines. Decompiler output is also triggered by a command, and then the output is scanned for by the test objects (FunctionTestProperty). Results of passed/failed tests are collected. If the command line script does not complete properly, this is considered a special kind of failure.

Constructor & Destructor Documentation

◆ FunctionTestCollection()

ghidra::FunctionTestCollection::FunctionTestCollection ( ostream &  s)

Constructor.

Parameters
sis the stream where output is sent during tests

References ghidra::ConsoleCommands::commands, and ghidra::ConsoleCommands::ConsoleCommands().

Member Function Documentation

◆ buildProgram()

void ghidra::FunctionTestCollection::buildProgram ( DocumentStorage store)
private

◆ evaluateTests()

void ghidra::FunctionTestCollection::evaluateTests ( list< string > &  lateStream) const
private

Do the final evaluation of each test.

This is called after each test has been fed all lines of output. The result of each test is printed to the midStream, and then failures are written to the lateStream in order to see a summary.

Parameters
lateStreamcollects failures to display as a summary

◆ loadTest()

void ghidra::FunctionTestCollection::loadTest ( const string &  filename)

Load a test program, tests, and script.

Load the architecture based on the discovered <binaryimage> tag. Collect the script commands and the specific tests.

Parameters
filenameis the XML file holding the test data

References ghidra::Element::getName(), ghidra::Document::getRoot(), and ghidra::DocumentStorage::openDocument().

Referenced by runTestFiles().

◆ passLineToTests()

void ghidra::FunctionTestCollection::passLineToTests ( const string &  line) const
private

Let all tests analyze a line of the results.

Each test gets a chance to process a line of output

Parameters
lineis the given line of output

◆ restoreXmlCommands()

void ghidra::FunctionTestCollection::restoreXmlCommands ( const Element el)
private

Reconstruct commands from an XML tag.

Parameters
elis the root <script> tag

References ghidra::ConsoleCommands::commands, ghidra::Element::getChildren(), and ghidra::Element::getContent().

◆ restoreXmlOldForm()

void ghidra::FunctionTestCollection::restoreXmlOldForm ( DocumentStorage store,
const Element el 
)

Load tests from <binaryimage> tag.

Pull the script and tests from a comment in <binaryimage>

◆ runTestFiles()

int ghidra::FunctionTestCollection::runTestFiles ( const vector< string > &  testFiles,
ostream &  s 
)
static

Run tests for each listed file.

Run through all XML files in the given list, processing each in turn.

Parameters
testFilesis the given list of test files
sis the output stream to print results to

References clear(), ghidra::IfaceError::explain, getTestsApplied(), getTestsSucceeded(), loadTest(), and runTests().

Referenced by ghidra::UnitTest::run().

◆ runTests()

void ghidra::FunctionTestCollection::runTests ( list< string > &  lateStream)

Run the script and perform the tests.

Run the script commands on the current program. Collect any bulk output, and run tests over the output. Report test failures back to the caller

Parameters
lateStreamcollects messages for a final summary

References ghidra::ConsoleCommands::pos.

Referenced by runTestFiles().

◆ startTests()

void ghidra::FunctionTestCollection::startTests ( void  ) const
private

Initialize each FunctionTestProperty.

Let each test initialize itself thru its startTest() method.


The documentation for this class was generated from the following files: