Ghidra Decompiler Analysis Engine
testfunction.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 #ifndef __TESTFUNCTION__
19 #define __TESTFUNCTION__
20 
21 #include "libdecomp.hh"
22 #include <iostream>
23 #include <regex>
24 
31  int4 minimumMatch;
32  int4 maximumMatch;
33  string name;
34  regex pattern;
35  mutable uint4 count;
36 public:
37  string getName(void) const { return name; }
38  void startTest(void) const;
39  void processLine(const string &line) const;
40  bool endTest(void) const;
41  void restoreXml(const Element *el);
42 };
43 
45 class ConsoleCommands : public IfaceStatus {
46  vector<string> commands;
47  uint4 pos;
48  virtual void readLine(string &line);
49 public:
50  ConsoleCommands(void);
51  void reset(void);
52  virtual bool isStreamFinished(void) const { return pos == commands.size(); }
53  void restoreXml(const Element *el);
54 };
55 
66  IfaceDecompData *dcp;
67  string fileName;
68  list<FunctionTestProperty> testList;
69  ConsoleCommands console;
70  mutable int4 numTestsApplied;
71  mutable int4 numTestsSucceeded;
72  void clear(void);
73  void buildProgram(DocumentStorage &store);
74  void startTests(void) const;
75  void passLineToTests(const string &line) const;
76  void evaluateTests(ostream &midStream,list<string> &lateStream) const;
77 public:
79  int4 getTestsApplied(void) const { return numTestsApplied; }
80  int4 getTestsSucceeded(void) const { return numTestsSucceeded; }
81  void loadTest(const string &filename);
82  void restoreXml(DocumentStorage &store,const Element *el);
83  void restoreXmlOldForm(DocumentStorage &store,const Element *el);
84  void runTests(ostream &midStream,list<string> &lateStream);
85  static void runTestCollections(const string &dirname,set<string> &testNames);
86 };
87 
88 #endif
ConsoleCommands
A console command run as part of a test sequence.
Definition: testfunction.hh:45
ConsoleCommands::isStreamFinished
virtual bool isStreamFinished(void) const
Return true if the current stream is finished.
Definition: testfunction.hh:52
FunctionTestProperty::restoreXml
void restoreXml(const Element *el)
Reconstruct the property from an XML tag.
Definition: testfunction.cc:38
IfaceStatus
A generic console mode interface and command executor.
Definition: interface.hh:195
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
IfaceDecompData
Common data shared by decompiler commands.
Definition: ifacedecomp.hh:42
ConsoleCommands::reset
void reset(void)
Reset console for a new program.
Definition: testfunction.cc:67
ConsoleCommands::restoreXml
void restoreXml(const Element *el)
Reconstruct the command from an XML tag.
Definition: testfunction.cc:77
FunctionTestProperty::endTest
bool endTest(void) const
Return results of property search.
Definition: testfunction.cc:32
FunctionTestCollection::loadTest
void loadTest(const string &filename)
Load a test program, tests, and script.
Definition: testfunction.cc:179
FunctionTestCollection::runTestCollections
static void runTestCollections(const string &dirname, set< string > &testNames)
Run test files in a whole directory.
Definition: testfunction.cc:290
FunctionTestCollection::runTests
void runTests(ostream &midStream, list< string > &lateStream)
Run the script and perform the tests.
Definition: testfunction.cc:244
FunctionTestCollection::FunctionTestCollection
FunctionTestCollection(void)
Constructor.
Definition: testfunction.cc:167
ConsoleCommands::ConsoleCommands
ConsoleCommands(void)
Constructor.
Definition: testfunction.cc:60
FunctionTestCollection::restoreXmlOldForm
void restoreXmlOldForm(DocumentStorage &store, const Element *el)
Load tests from <binaryimage> tag.
Definition: testfunction.cc:232
FunctionTestProperty::processLine
void processLine(const string &line) const
Search thru line, update state if match found.
Definition: testfunction.cc:25
DocumentStorage
A container for parsed XML documents.
Definition: xml.hh:249
FunctionTestProperty::startTest
void startTest(void) const
Reset "state", counting number of matching lines.
Definition: testfunction.cc:19
FunctionTestCollection
A collection of tests around a single program/function.
Definition: testfunction.hh:65
FunctionTestProperty
A single property to be searched for in the output of a function decompilation.
Definition: testfunction.hh:30
FunctionTestCollection::restoreXml
void restoreXml(DocumentStorage &store, const Element *el)
Load tests from a <decompilertest> tag.
Definition: testfunction.cc:194