/
Headless.cpp
598 lines (524 loc) · 19.7 KB
/
Headless.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// Headless version of PPSSPP, for testing using http://code.google.com/p/pspautotests/ .
// See headless.txt.
// To build on non-windows systems, just run CMake in the SDL directory, it will build both a normal ppsspp and the headless version.
// Example command line to run a test in the VS debugger (useful to debug failures):
// > --root pspautotests/tests/../ --compare --timeout=5 --graphics=software pspautotests/tests/cpu/cpu_alu/cpu_alu.prx
#include "ppsspp_config.h"
#include <cstdio>
#include <cstdlib>
#include <limits>
#if PPSSPP_PLATFORM(ANDROID)
#include <jni.h>
#endif
#include "Common/Profiler/Profiler.h"
#include "Common/System/NativeApp.h"
#include "Common/System/System.h"
#include "Common/CommonWindows.h"
#if PPSSPP_PLATFORM(WINDOWS)
#include <timeapi.h>
#else
#include <csignal>
#endif
#include "Common/CPUDetect.h"
#include "Common/File/VFS/VFS.h"
#include "Common/File/VFS/ZipFileReader.h"
#include "Common/File/VFS/DirectoryReader.h"
#include "Common/File/FileUtil.h"
#include "Common/GraphicsContext.h"
#include "Common/TimeUtil.h"
#include "Common/Thread/ThreadManager.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/System.h"
#include "Core/WebServer.h"
#include "Core/HLE/sceUtility.h"
#include "Core/Host.h"
#include "Core/SaveState.h"
#include "GPU/Common/FramebufferManagerCommon.h"
#include "Log.h"
#include "LogManager.h"
#include "Compare.h"
#include "StubHost.h"
#if defined(_WIN32)
#include "WindowsHeadlessHost.h"
#elif defined(SDL)
#include "SDLHeadlessHost.h"
#endif
#if PPSSPP_PLATFORM(ANDROID)
JNIEnv *getEnv() {
return nullptr;
}
jclass findClass(const char *name) {
return nullptr;
}
bool System_AudioRecordingIsAvailable() { return false; }
bool System_AudioRecordingState() { return false; }
#endif
class PrintfLogger : public LogListener {
public:
void Log(const LogMessage &message) override {
switch (message.level) {
case LogTypes::LVERBOSE:
fprintf(stderr, "V %s", message.msg.c_str());
break;
case LogTypes::LDEBUG:
fprintf(stderr, "D %s", message.msg.c_str());
break;
case LogTypes::LINFO:
fprintf(stderr, "I %s", message.msg.c_str());
break;
case LogTypes::LERROR:
fprintf(stderr, "E %s", message.msg.c_str());
break;
case LogTypes::LWARNING:
fprintf(stderr, "W %s", message.msg.c_str());
break;
case LogTypes::LNOTICE:
default:
fprintf(stderr, "N %s", message.msg.c_str());
break;
}
}
};
// Temporary hacks around annoying linking errors.
void NativeUpdate() { }
void NativeRender(GraphicsContext *graphicsContext) { }
void NativeResized() { }
std::string System_GetProperty(SystemProperty prop) { return ""; }
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) { return std::vector<std::string>(); }
int System_GetPropertyInt(SystemProperty prop) {
if (prop == SYSPROP_SYSTEMVERSION)
return 31;
return -1;
}
float System_GetPropertyFloat(SystemProperty prop) { return -1.0f; }
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_CAN_JIT:
return true;
case SYSPROP_SKIP_UI:
return true;
default:
return false;
}
}
void System_Notify(SystemNotification notification) {}
void System_SendMessage(const char *command, const char *parameter) {}
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) { cb(false, ""); }
void System_AskForPermission(SystemPermission permission) {}
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
int printUsage(const char *progname, const char *reason)
{
if (reason != NULL)
fprintf(stderr, "Error: %s\n\n", reason);
fprintf(stderr, "PPSSPP Headless\n");
fprintf(stderr, "This is primarily meant as a non-interactive test tool.\n\n");
fprintf(stderr, "Usage: %s file.elf... [options]\n\n", progname);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -m, --mount umd.cso mount iso on umd1:\n");
fprintf(stderr, " -r, --root some/path mount path on host0: (elfs must be in here)\n");
fprintf(stderr, " -l, --log full log output, not just emulated printfs\n");
fprintf(stderr, " --debugger=PORT enable websocket debugger and break at start\n");
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, " --max-mse=NUMBER maximum allowed MSE error for 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");
fprintf(stderr, " -i use the interpreter\n");
fprintf(stderr, " --ir use ir interpreter\n");
fprintf(stderr, " -j use jit (default)\n");
fprintf(stderr, " -c, --compare compare with output in file.expected\n");
fprintf(stderr, " --bench run multiple times and output speed\n");
fprintf(stderr, "\nSee headless.txt for details.\n");
return 1;
}
static HeadlessHost *getHost(GPUCore gpuCore) {
switch (gpuCore) {
case GPUCORE_SOFTWARE:
return new HeadlessHost();
#ifdef HEADLESSHOST_CLASS
default:
return new HEADLESSHOST_CLASS();
#else
default:
return new HeadlessHost();
#endif
}
}
struct AutoTestOptions {
double timeout;
double maxScreenshotError;
bool compare : 1;
bool verbose : 1;
bool bench : 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 (opt.compare || opt.bench)
coreParameter.collectEmuLog = &output;
std::string error_string;
if (!PSP_InitStart(coreParameter, &error_string)) {
fprintf(stderr, "Failed to start '%s'. Error: %s\n", coreParameter.fileToStart.c_str(), error_string.c_str());
printf("TESTERROR\n");
TeamCityPrint("testIgnored name='%s' message='PRX/ELF missing'", currentTestName.c_str());
GitHubActionsPrint("error", "PRX/ELF missing for %s", currentTestName.c_str());
return false;
}
TeamCityPrint("testStarted name='%s' captureStandardOutput='true'", currentTestName.c_str());
if (opt.compare)
headlessHost->SetComparisonScreenshot(ExpectedScreenshotFromFilename(coreParameter.fileToStart), opt.maxScreenshotError);
while (!PSP_InitUpdate(&error_string))
sleep_ms(1);
if (!PSP_IsInited()) {
TeamCityPrint("testFailed name='%s' message='Startup failed'", currentTestName.c_str());
TeamCityPrint("testFinished name='%s'", currentTestName.c_str());
GitHubActionsPrint("error", "Test init failed for %s", currentTestName.c_str());
return false;
}
System_Notify(SystemNotification::BOOT_DONE);
Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops);
PSP_BeginHostFrame();
Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;
if (draw)
draw->BeginFrame();
bool passed = true;
double deadline = time_now_d() + opt.timeout;
coreState = coreParameter.startBreak ? CORE_STEPPING : CORE_RUNNING;
while (coreState == CORE_RUNNING || coreState == CORE_STEPPING)
{
int blockTicks = (int)usToCycles(1000000 / 10);
PSP_RunLoopFor(blockTicks);
// If we were rendering, this might be a nice time to do something about it.
if (coreState == CORE_NEXTFRAME) {
coreState = CORE_RUNNING;
headlessHost->SwapBuffers();
}
if (coreState == CORE_STEPPING && !coreParameter.startBreak) {
break;
}
if (time_now_d() > deadline) {
// Don't compare, print the output at least up to this point, and bail.
if (!opt.bench) {
printf("%s", output.c_str());
host->SendDebugOutput("TIMEOUT\n");
TeamCityPrint("testFailed name='%s' message='Test timeout'", currentTestName.c_str());
GitHubActionsPrint("error", "Test timeout for %s", currentTestName.c_str());
}
passed = false;
Core_Stop();
}
}
PSP_EndHostFrame();
if (draw) {
draw->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Headless");
// Vulkan may get angry if we don't do a final present.
if (gpu)
gpu->CopyDisplayToOutput(true);
draw->EndFrame();
}
PSP_Shutdown();
if (!opt.bench)
headlessHost->FlushDebugOutput();
if (opt.compare && passed)
passed = CompareOutput(coreParameter.fileToStart, output, opt.verbose);
TeamCityPrint("testFinished name='%s'", currentTestName.c_str());
return passed;
}
std::vector<std::string> ReadFromListFile(const std::string &listFilename) {
std::vector<std::string> testFilenames;
char temp[2048]{};
if (listFilename == "-") {
while (scanf("%2047s", temp) == 1)
testFilenames.push_back(temp);
} else {
FILE *fp = File::OpenCFile(Path(listFilename), "rt");
if (!fp) {
fprintf(stderr, "Unable to open '%s' as a list file\n", listFilename.c_str());
return testFilenames;
}
while (fscanf(fp, "%2047s", temp) == 1)
testFilenames.push_back(temp);
fclose(fp);
}
return testFilenames;
}
int main(int argc, const char* argv[])
{
PROFILE_INIT();
#if PPSSPP_PLATFORM(WINDOWS)
timeBeginPeriod(1);
#else
// Ignore sigpipe.
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
perror("Unable to ignore SIGPIPE");
}
#endif
#if defined(_DEBUG) && defined(_MSC_VER)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
AutoTestOptions testOptions{};
testOptions.timeout = std::numeric_limits<double>::infinity();
bool fullLog = false;
const char *stateToLoad = 0;
GPUCore gpuCore = GPUCORE_SOFTWARE;
CPUCore cpuCore = CPUCore::JIT;
int debuggerPort = -1;
std::vector<std::string> testFilenames;
const char *mountIso = nullptr;
const char *mountRoot = nullptr;
const char *screenshotFilename = nullptr;
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--mount"))
{
if (++i >= argc)
return printUsage(argv[0], "Missing argument after -m");
mountIso = argv[i];
}
else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--root"))
{
if (++i >= argc)
return printUsage(argv[0], "Missing argument after -r");
mountRoot = argv[i];
}
else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--log"))
fullLog = true;
else if (!strcmp(argv[i], "-i"))
cpuCore = CPUCore::INTERPRETER;
else if (!strcmp(argv[i], "-j"))
cpuCore = CPUCore::JIT;
else if (!strcmp(argv[i], "--ir"))
cpuCore = CPUCore::IR_JIT;
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare"))
testOptions.compare = true;
else if (!strcmp(argv[i], "--bench"))
testOptions.bench = true;
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))
testOptions.verbose = true;
else if (!strncmp(argv[i], "--graphics=", strlen("--graphics=")) && strlen(argv[i]) > strlen("--graphics="))
{
const char *gpuName = argv[i] + strlen("--graphics=");
if (!strcasecmp(gpuName, "gles"))
gpuCore = GPUCORE_GLES;
// There used to be a separate "null" rendering core - just use software.
else if (!strcasecmp(gpuName, "software") || !strcasecmp(gpuName, "null"))
gpuCore = GPUCORE_SOFTWARE;
else if (!strcasecmp(gpuName, "directx9"))
gpuCore = GPUCORE_DIRECTX9;
else if (!strcasecmp(gpuName, "directx11"))
gpuCore = GPUCORE_DIRECTX11;
else if (!strcasecmp(gpuName, "vulkan"))
gpuCore = GPUCORE_VULKAN;
else
return printUsage(argv[0], "Unknown gpu backend specified after --graphics=. Allowed: software, directx9, directx11, vulkan, gles, null.");
}
// Default to GLES if no value selected.
else if (!strcmp(argv[i], "--graphics")) {
#if PPSSPP_API(ANY_GL)
gpuCore = GPUCORE_GLES;
#else
gpuCore = GPUCORE_DIRECTX11;
#endif
} 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="))
testOptions.timeout = strtod(argv[i] + strlen("--timeout="), nullptr);
else if (!strncmp(argv[i], "--max-mse=", strlen("--max-mse=")) && strlen(argv[i]) > strlen("--max-mse="))
testOptions.maxScreenshotError = strtod(argv[i] + strlen("--max-mse="), 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"))
teamCityMode = true;
else if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state="))
stateToLoad = argv[i] + strlen("--state=");
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
return printUsage(argv[0], NULL);
else
testFilenames.push_back(argv[i]);
}
if (testFilenames.size() == 1 && testFilenames[0][0] == '@')
testFilenames = ReadFromListFile(testFilenames[0].substr(1));
if (testFilenames.empty())
return printUsage(argv[0], argc <= 1 ? NULL : "No executables specified");
LogManager::Init(&g_Config.bEnableLogging);
LogManager *logman = LogManager::GetInstance();
PrintfLogger *printfLogger = new PrintfLogger();
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) {
LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i;
logman->SetEnabled(type, fullLog);
logman->SetLogLevel(type, LogTypes::LDEBUG);
}
logman->AddListener(printfLogger);
// Needs to be after log so we don't interfere with test output.
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
HeadlessHost *headlessHost = getHost(gpuCore);
host = headlessHost;
std::string error_string;
GraphicsContext *graphicsContext = nullptr;
bool glWorking = ((HeadlessHost *)host)->InitGraphics(&error_string, &graphicsContext, gpuCore);
CoreParameter coreParameter;
coreParameter.cpuCore = cpuCore;
coreParameter.gpuCore = glWorking ? gpuCore : GPUCORE_SOFTWARE;
coreParameter.graphicsContext = graphicsContext;
coreParameter.enableSound = false;
coreParameter.mountIso = mountIso ? Path(std::string(mountIso)) : Path();
coreParameter.mountRoot = mountRoot ? Path(std::string(mountRoot)) : Path();
coreParameter.startBreak = false;
coreParameter.printfEmuLog = !testOptions.compare;
coreParameter.headLess = true;
coreParameter.renderScaleFactor = 1;
coreParameter.renderWidth = 480;
coreParameter.renderHeight = 272;
coreParameter.pixelWidth = 480;
coreParameter.pixelHeight = 272;
coreParameter.fastForward = true;
g_Config.bEnableSound = false;
g_Config.bFirstRun = false;
g_Config.bIgnoreBadMemAccess = true;
// Never report from tests.
g_Config.sReportHost.clear();
g_Config.bAutoSaveSymbolMap = false;
g_Config.bSkipBufferEffects = false;
g_Config.bSkipGPUReadbacks = false;
g_Config.bHardwareTransform = true;
g_Config.iAnisotropyLevel = 0; // When testing mipmapping we really don't want this.
g_Config.iMultiSampleLevel = 0;
g_Config.bVertexCache = false;
g_Config.iLanguage = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
g_Config.iTimeFormat = PSP_SYSTEMPARAM_TIME_FORMAT_24HR;
g_Config.bEncryptSave = true;
g_Config.sNickName = "shadow";
g_Config.iTimeZone = 60;
g_Config.iDateFormat = PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY;
g_Config.iButtonPreference = PSP_SYSTEMPARAM_BUTTON_CROSS;
g_Config.iLockParentalLevel = 9;
g_Config.iInternalResolution = 1;
g_Config.iFastForwardMode = (int)FastForwardMode::CONTINUOUS;
g_Config.bEnableLogging = fullLog;
g_Config.bSoftwareSkinning = true;
g_Config.bVertexDecoderJit = true;
g_Config.bSoftwareRendering = coreParameter.gpuCore == GPUCORE_SOFTWARE;
g_Config.bSoftwareRenderingJit = true;
g_Config.iSplineBezierQuality = 2;
g_Config.bHighQualityDepth = true;
g_Config.bMemStickInserted = true;
g_Config.iMemStickSizeGB = 16;
g_Config.bEnableWlan = true;
g_Config.sMACAddress = "12:34:56:78:9A:BC";
g_Config.iFirmwareVersion = PSP_DEFAULT_FIRMWARE;
g_Config.iPSPModel = PSP_MODEL_SLIM;
g_Config.iGlobalVolume = VOLUME_FULL;
g_Config.iReverbVolume = VOLUME_FULL;
#if PPSSPP_PLATFORM(WINDOWS)
g_Config.internalDataDirectory.clear();
InitSysDirectories();
#endif
Path executablePath = File::GetExeDirectory();
#if !PPSSPP_PLATFORM(ANDROID) && !PPSSPP_PLATFORM(WINDOWS)
g_Config.memStickDirectory = Path(std::string(getenv("HOME"))) / ".ppsspp";
g_Config.flash0Directory = executablePath / "assets/flash0";
#endif
// Try to find the flash0 directory. Often this is from a subdirectory.
Path nextPath = executablePath;
for (int i = 0; i < 5; ++i) {
if (File::Exists(nextPath / "assets/flash0")) {
g_Config.flash0Directory = nextPath / "assets/flash0";
#if !PPSSPP_PLATFORM(ANDROID)
g_VFS.Register("", new DirectoryReader(nextPath / "assets"));
#endif
break;
}
if (!nextPath.CanNavigateUp())
break;
nextPath = nextPath.NavigateUp();
}
if (screenshotFilename)
headlessHost->SetComparisonScreenshot(Path(std::string(screenshotFilename)), testOptions.maxScreenshotError);
headlessHost->SetWriteFailureScreenshot(!teamCityMode && !getenv("GITHUB_ACTIONS") && !testOptions.bench);
#if PPSSPP_PLATFORM(ANDROID)
// For some reason the debugger installs it with this name?
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp-2.apk"))) {
g_VFS.Register("", ZipFileReader::Create(Path("/data/app/org.ppsspp.ppsspp-2.apk"), "assets/"));
}
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp.apk"))) {
g_VFS.Register("", ZipFileReader::Create(Path("/data/app/org.ppsspp.ppsspp.apk"), "assets/"));
}
#elif PPSSPP_PLATFORM(LINUX)
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/games/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/share/ppsspp/assets")));
g_VFS.Register("", new DirectoryReader(Path("/usr/share/games/ppsspp/assets")));
#endif
UpdateUIState(UISTATE_INGAME);
if (debuggerPort > 0) {
g_Config.iRemoteISOPort = debuggerPort;
coreParameter.startBreak = true;
StartWebServer(WebServerFlags::DEBUGGER);
}
if (stateToLoad != NULL)
SaveState::Load(Path(stateToLoad), -1);
std::vector<std::string> failedTests;
std::vector<std::string> passedTests;
for (size_t i = 0; i < testFilenames.size(); ++i)
{
coreParameter.fileToStart = Path(testFilenames[i]);
if (testOptions.compare)
printf("%s:\n", coreParameter.fileToStart.c_str());
bool passed = RunAutoTest(headlessHost, coreParameter, testOptions);
if (testOptions.bench) {
double st = time_now_d();
double deadline = st + testOptions.timeout;
double runs = 0.0;
for (int i = 0; i < 100; ++i) {
RunAutoTest(headlessHost, coreParameter, testOptions);
runs++;
if (time_now_d() > deadline)
break;
}
double et = time_now_d();
std::string testName = GetTestName(coreParameter.fileToStart);
printf(" %s - %f seconds average\n", testName.c_str(), (et - st) / runs);
}
if (testOptions.compare) {
std::string testName = GetTestName(coreParameter.fileToStart);
if (passed) {
passedTests.push_back(testName);
printf(" %s - passed!\n", testName.c_str());
}
else
failedTests.push_back(testName);
}
}
if (testOptions.compare) {
printf("%d tests passed, %d tests failed.\n", (int)passedTests.size(), (int)failedTests.size());
if (!failedTests.empty())
{
printf("Failed tests:\n");
for (size_t i = 0; i < failedTests.size(); ++i) {
printf(" %s\n", failedTests[i].c_str());
}
}
}
if (debuggerPort > 0) {
ShutdownWebServer();
}
((HeadlessHost *)host)->ShutdownGraphics();
delete host;
host = nullptr;
headlessHost = nullptr;
g_VFS.Clear();
LogManager::Shutdown();
delete printfLogger;
#if PPSSPP_PLATFORM(WINDOWS)
timeEndPeriod(1);
#endif
g_threadManager.Teardown();
if (!failedTests.empty() && !teamCityMode)
return 1;
return 0;
}