New tests for data-types, test debugging infrastructure

This commit is contained in:
caheckman 2021-08-04 15:29:02 -04:00
parent 6b04eb793f
commit 1c9913e417
18 changed files with 491 additions and 131 deletions

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "test.hh"
#include "testfunction.hh"
#include "libdecomp.hh"
vector<UnitTest *> UnitTest::tests;
@ -44,6 +44,37 @@ void UnitTest::run(set<string> &testNames)
std::cerr << passed << "/" << total << " tests passed." << std::endl;
}
/// Create list of the absolute path of all tests to be run
/// \param dirname is a directory containing the XML test files
/// \param testNames (if not empty) specifies particular tests to run
/// \param testFiles will hold the resulting list of paths
void gatherDataTests(const string &dirname,set<string> &testNames,vector<string> &testFiles)
{
FileManage fileManage;
set<string> fullNames;
for(set<string>::iterator iter=testNames.begin();iter!=testNames.end();++iter) {
string val = dirname;
if (dirname.back() != '/')
val += '/';
val += *iter;
fullNames.insert(val);
}
fileManage.addDir2Path(dirname);
if (fullNames.empty()) {
fileManage.matchList(testFiles,".xml",true); // Take all test files
return;
}
vector<string> allTestFiles;
fileManage.matchList(allTestFiles,".xml",true);
for(int4 i=0;i<allTestFiles.size();++i) {
if (fullNames.find(allTestFiles[i]) != fullNames.end()) { // Take tests matching into list of basenames
testFiles.push_back(allTestFiles[i]);
}
}
}
int main(int argc, char **argv) {
bool runUnitTests = true;
bool runDataTests = true;
@ -53,6 +84,7 @@ int main(int argc, char **argv) {
set<string> unitTestNames;
set<string> dataTestNames;
string dirname("../datatests");
string sleighdirname("../../../../../../..");
if (argc > 0) {
string command(argv[0]);
if (command == "-path") {
@ -61,6 +93,22 @@ int main(int argc, char **argv) {
argv += 2;
argc -= 2;
}
else if (command == "-sleighpath") {
sleighdirname = argv[1];
argv += 2;
argc -= 2;
}
else if (command == "-usesleighenv") {
const char *sleighhomepath = getenv("SLEIGHHOME");
if (sleighhomepath != (const char *)0) {
cout << "Using SLEIGHHOME=" << sleighhomepath << endl;
sleighdirname = sleighhomepath;
}
else
cout << "No SLEIGHHOME environment variable" << endl;
argv += 1;
argc -= 1;
}
}
if (argc > 0) {
string command(argv[0]);
@ -78,16 +126,13 @@ int main(int argc, char **argv) {
cout << "USAGE: ghidra_test [-path <datatestdir>] [[unittests|datatests] [testname1 testname2 ...]]" << endl;
}
}
startDecompilerLibrary(sleighdirname.c_str());
if (runUnitTests)
UnitTest::run(unitTestNames);
if (runDataTests) {
vector<string> testFiles;
gatherDataTests(dirname,dataTestNames,testFiles);
cout << endl << endl;
const char *sleighhomepath = getenv("SLEIGHHOME");
if (sleighhomepath != (const char *)0)
cout << "Using SLEIGHHOME=" << sleighhomepath << endl;
else
cout << "No SLEIGHHOME environment variable" << endl;
startDecompilerLibrary(sleighhomepath);
FunctionTestCollection::runTestCollections(dirname,dataTestNames);
FunctionTestCollection::runTestFiles(testFiles,cout);
}
}