2015-04-10 00:30:05 -04:00
|
|
|
#include "PS2VM.h"
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include "StdStream.h"
|
2015-04-18 22:17:45 -04:00
|
|
|
#include "StdStreamUtils.h"
|
|
|
|
#include "Utils.h"
|
2015-05-05 00:12:39 -04:00
|
|
|
#include "JUnitTestReportWriter.h"
|
2015-04-18 22:17:45 -04:00
|
|
|
|
|
|
|
std::vector<std::string> ReadLines(Framework::CStream& inputStream)
|
|
|
|
{
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
lines.push_back(Utils::GetLine(&inputStream));
|
|
|
|
while(!inputStream.IsEOF())
|
|
|
|
{
|
|
|
|
lines.push_back(Utils::GetLine(&inputStream));
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2015-07-03 03:21:48 -04:00
|
|
|
TESTRESULT GetTestResult(const boost::filesystem::path& testFilePath)
|
2015-04-18 22:17:45 -04:00
|
|
|
{
|
2015-07-03 03:21:48 -04:00
|
|
|
TESTRESULT result;
|
|
|
|
result.succeeded = false;
|
2015-04-18 22:17:45 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
auto resultFilePath = testFilePath;
|
|
|
|
resultFilePath.replace_extension(".result");
|
|
|
|
auto expectedFilePath = testFilePath;
|
|
|
|
expectedFilePath.replace_extension(".expected");
|
|
|
|
auto resultStream = Framework::CreateInputStdStream(resultFilePath.string());
|
|
|
|
auto expectedStream = Framework::CreateInputStdStream(expectedFilePath.string());
|
|
|
|
|
|
|
|
auto resultLines = ReadLines(resultStream);
|
|
|
|
auto expectedLines = ReadLines(expectedStream);
|
|
|
|
|
2015-07-03 03:21:48 -04:00
|
|
|
if(resultLines.size() != expectedLines.size()) return result;
|
2015-04-18 22:17:45 -04:00
|
|
|
|
|
|
|
for(unsigned int i = 0; i < resultLines.size(); i++)
|
|
|
|
{
|
2015-07-03 03:21:48 -04:00
|
|
|
if(resultLines[i] != expectedLines[i])
|
|
|
|
{
|
|
|
|
LINEDIFF lineDiff;
|
|
|
|
lineDiff.expected = expectedLines[i];
|
|
|
|
lineDiff.result = resultLines[i];
|
|
|
|
result.lineDiffs.push_back(lineDiff);
|
|
|
|
}
|
2015-04-18 22:17:45 -04:00
|
|
|
}
|
|
|
|
|
2015-07-03 03:21:48 -04:00
|
|
|
result.succeeded = result.lineDiffs.empty();
|
|
|
|
return result;
|
2015-04-18 22:17:45 -04:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2015-07-03 03:21:48 -04:00
|
|
|
|
2015-04-18 22:17:45 -04:00
|
|
|
}
|
2015-07-03 03:21:48 -04:00
|
|
|
return result;
|
2015-04-18 22:17:45 -04:00
|
|
|
}
|
2015-04-10 00:30:05 -04:00
|
|
|
|
|
|
|
void ExecuteTest(const boost::filesystem::path& testFilePath)
|
|
|
|
{
|
|
|
|
auto resultFilePath = testFilePath;
|
|
|
|
resultFilePath.replace_extension(".result");
|
|
|
|
auto resultStream = new Framework::CStdStream(resultFilePath.string().c_str(), "wb");
|
|
|
|
|
|
|
|
bool executionOver = false;
|
|
|
|
|
|
|
|
//Setup virtual machine
|
|
|
|
CPS2VM virtualMachine;
|
|
|
|
virtualMachine.Initialize();
|
|
|
|
virtualMachine.Reset();
|
|
|
|
virtualMachine.m_ee->m_os->OnRequestExit.connect(
|
|
|
|
[&executionOver] ()
|
|
|
|
{
|
|
|
|
executionOver = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
virtualMachine.m_ee->m_os->BootFromFile(testFilePath.string().c_str());
|
2015-07-03 22:18:29 -04:00
|
|
|
virtualMachine.m_iopOs->GetIoman()->SetFileStream(Iop::CIoman::FID_STDOUT, resultStream);
|
2015-04-10 00:30:05 -04:00
|
|
|
virtualMachine.Resume();
|
|
|
|
|
|
|
|
while(!executionOver)
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtualMachine.Pause();
|
|
|
|
virtualMachine.Destroy();
|
|
|
|
}
|
|
|
|
|
2015-05-05 00:12:39 -04:00
|
|
|
void ScanAndExecuteTests(const boost::filesystem::path& testDirPath, const TestReportWriterPtr& testReportWriter)
|
2015-04-10 00:30:05 -04:00
|
|
|
{
|
|
|
|
boost::filesystem::directory_iterator endIterator;
|
|
|
|
for(auto testPathIterator = boost::filesystem::directory_iterator(testDirPath);
|
|
|
|
testPathIterator != endIterator; testPathIterator++)
|
|
|
|
{
|
|
|
|
auto testPath = testPathIterator->path();
|
|
|
|
if(boost::filesystem::is_directory(testPath))
|
|
|
|
{
|
2015-05-05 00:12:39 -04:00
|
|
|
ScanAndExecuteTests(testPath, testReportWriter);
|
2015-04-10 00:30:05 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(testPath.extension() == ".elf")
|
|
|
|
{
|
2015-04-18 22:17:45 -04:00
|
|
|
printf("Testing '%s': ", testPath.string().c_str());
|
2015-04-10 00:30:05 -04:00
|
|
|
ExecuteTest(testPath);
|
2015-07-03 03:21:48 -04:00
|
|
|
auto result = GetTestResult(testPath);
|
|
|
|
printf("%s.\r\n", result.succeeded ? "SUCCEEDED" : "FAILED");
|
2015-05-05 00:12:39 -04:00
|
|
|
if(testReportWriter)
|
|
|
|
{
|
2015-07-03 03:21:48 -04:00
|
|
|
testReportWriter->ReportTestEntry(testPath.string(), result);
|
2015-05-05 00:12:39 -04:00
|
|
|
}
|
2015-04-10 00:30:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char** argv)
|
|
|
|
{
|
|
|
|
if(argc < 2)
|
|
|
|
{
|
2015-05-05 00:12:39 -04:00
|
|
|
printf("Usage: AutoTest [options] testDir\r\n");
|
|
|
|
printf("Options: \r\n");
|
|
|
|
printf("\t --junitreport <path>\t Writes JUnit format report at <path>.\r\n");
|
2015-04-10 00:30:05 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2015-05-05 00:12:39 -04:00
|
|
|
|
|
|
|
TestReportWriterPtr testReportWriter;
|
|
|
|
boost::filesystem::path autoTestRoot;
|
|
|
|
boost::filesystem::path reportPath;
|
|
|
|
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if(!strcmp(argv[i], "--junitreport"))
|
|
|
|
{
|
|
|
|
if((i + 1) >= argc)
|
|
|
|
{
|
|
|
|
printf("Error: Path must be specified for --junitreport option.\r\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
testReportWriter = std::make_shared<CJUnitTestReportWriter>();
|
|
|
|
reportPath = boost::filesystem::path(argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
autoTestRoot = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(autoTestRoot.empty())
|
|
|
|
{
|
|
|
|
printf("Error: No test directory specified.\r\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScanAndExecuteTests(autoTestRoot, testReportWriter);
|
|
|
|
|
|
|
|
if(testReportWriter)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
testReportWriter->Write(reportPath);
|
|
|
|
}
|
|
|
|
catch(const std::exception& exception)
|
|
|
|
{
|
|
|
|
printf("Error: Failed to write test report: %s\r\n", exception.what());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-10 00:30:05 -04:00
|
|
|
return 0;
|
|
|
|
}
|