Headless: Small cleanup of options handling.

To be able to add additional options.
This commit is contained in:
Unknown W. Brackets 2022-09-17 10:05:11 -07:00
parent cd2c977836
commit d703c934dd

View file

@ -128,13 +128,9 @@ int printUsage(const char *progname, const char *reason)
fprintf(stderr, " -l, --log full log output, not just emulated printfs\n");
fprintf(stderr, " --debugger=PORT enable websocket debugger and break at start\n");
#if defined(HEADLESSHOST_CLASS)
{
fprintf(stderr, " --graphics=BACKEND use the full gpu backend (slower)\n");
fprintf(stderr, " options: gles, software, directx9, etc.\n");
fprintf(stderr, " --screenshot=FILE compare against a screenshot\n");
}
#endif
fprintf(stderr, " --graphics=BACKEND use a different gpu backend\n");
fprintf(stderr, " options: gles, software, directx9, etc.\n");
fprintf(stderr, " --screenshot=FILE compare against a screenshot\n");
fprintf(stderr, " --timeout=SECONDS abort test it if takes longer than SECONDS\n");
fprintf(stderr, " -v, --verbose show the full passed/failed result\n");
@ -161,13 +157,18 @@ static HeadlessHost *getHost(GPUCore gpuCore) {
}
}
bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool autoCompare, bool verbose, double timeout)
{
struct AutoTestOptions {
double timeout;
bool compare : 1;
bool verbose : 1;
};
bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const AutoTestOptions &opt) {
// Kinda ugly, trying to guesstimate the test name from filename...
currentTestName = GetTestName(coreParameter.fileToStart);
std::string output;
if (autoCompare)
if (opt.compare)
coreParameter.collectEmuLog = &output;
std::string error_string;
@ -183,7 +184,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool
host->BootDone();
if (autoCompare)
if (opt.compare)
headlessHost->SetComparisonScreenshot(ExpectedScreenshotFromFilename(coreParameter.fileToStart));
while (!PSP_InitUpdate(&error_string))
@ -196,8 +197,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool
}
bool passed = true;
double deadline;
deadline = time_now_d() + timeout;
double deadline = time_now_d() + opt.timeout;
Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops);
@ -239,8 +239,8 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool
headlessHost->FlushDebugOutput();
if (autoCompare && passed)
passed = CompareOutput(coreParameter.fileToStart, output, verbose);
if (opt.compare && passed)
passed = CompareOutput(coreParameter.fileToStart, output, opt.verbose);
TeamCityPrint("testFinished name='%s'", currentTestName.c_str());
@ -263,9 +263,9 @@ int main(int argc, const char* argv[])
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
AutoTestOptions testOptions{};
testOptions.timeout = std::numeric_limits<double>::infinity();
bool fullLog = false;
bool autoCompare = false;
bool verbose = false;
const char *stateToLoad = 0;
GPUCore gpuCore = GPUCORE_SOFTWARE;
CPUCore cpuCore = CPUCore::JIT;
@ -275,7 +275,6 @@ int main(int argc, const char* argv[])
const char *mountIso = nullptr;
const char *mountRoot = nullptr;
const char *screenshotFilename = nullptr;
float timeout = std::numeric_limits<float>::infinity();
for (int i = 1; i < argc; i++)
{
@ -300,9 +299,9 @@ int main(int argc, const char* argv[])
else if (!strcmp(argv[i], "--ir"))
cpuCore = CPUCore::IR_JIT;
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare"))
autoCompare = true;
testOptions.compare = true;
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))
verbose = true;
testOptions.verbose = true;
else if (!strncmp(argv[i], "--graphics=", strlen("--graphics=")) && strlen(argv[i]) > strlen("--graphics="))
{
const char *gpuName = argv[i] + strlen("--graphics=");
@ -330,7 +329,7 @@ int main(int argc, const char* argv[])
} else if (!strncmp(argv[i], "--screenshot=", strlen("--screenshot=")) && strlen(argv[i]) > strlen("--screenshot="))
screenshotFilename = argv[i] + strlen("--screenshot=");
else if (!strncmp(argv[i], "--timeout=", strlen("--timeout=")) && strlen(argv[i]) > strlen("--timeout="))
timeout = (float)strtod(argv[i] + strlen("--timeout="), NULL);
testOptions.timeout = strtod(argv[i] + strlen("--timeout="), nullptr);
else if (!strncmp(argv[i], "--debugger=", strlen("--debugger=")) && strlen(argv[i]) > strlen("--debugger="))
debuggerPort = (int)strtoul(argv[i] + strlen("--debugger="), NULL, 10);
else if (!strcmp(argv[i], "--teamcity"))
@ -388,7 +387,7 @@ int main(int argc, const char* argv[])
coreParameter.mountIso = mountIso ? Path(std::string(mountIso)) : Path();
coreParameter.mountRoot = mountRoot ? Path(std::string(mountRoot)) : Path();
coreParameter.startBreak = false;
coreParameter.printfEmuLog = !autoCompare;
coreParameter.printfEmuLog = !testOptions.compare;
coreParameter.headLess = true;
coreParameter.renderScaleFactor = 1;
coreParameter.renderWidth = 480;
@ -487,11 +486,10 @@ int main(int argc, const char* argv[])
for (size_t i = 0; i < testFilenames.size(); ++i)
{
coreParameter.fileToStart = Path(testFilenames[i]);
if (autoCompare)
if (testOptions.compare)
printf("%s:\n", coreParameter.fileToStart.c_str());
bool passed = RunAutoTest(headlessHost, coreParameter, autoCompare, verbose, timeout);
if (autoCompare)
{
bool passed = RunAutoTest(headlessHost, coreParameter, testOptions);
if (testOptions.compare) {
std::string testName = GetTestName(coreParameter.fileToStart);
if (passed)
{
@ -503,8 +501,7 @@ int main(int argc, const char* argv[])
}
}
if (autoCompare)
{
if (testOptions.compare) {
printf("%d tests passed, %d tests failed.\n", (int)passedTests.size(), (int)failedTests.size());
if (!failedTests.empty())
{