Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/headless/Headless.cpp
3185 views
1
2
// Headless version of PPSSPP, for testing using http://code.google.com/p/pspautotests/ .
3
// See headless.txt.
4
// To build on non-windows systems, just run CMake in the SDL directory, it will build both a normal ppsspp and the headless version.
5
// Example command line to run a test in the VS debugger (useful to debug failures):
6
// > --root pspautotests/tests/../ --compare --timeout=5 --graphics=software pspautotests/tests/cpu/cpu_alu/cpu_alu.prx
7
8
#include "ppsspp_config.h"
9
#include <cstdio>
10
#include <cstdlib>
11
#include <limits>
12
#if PPSSPP_PLATFORM(ANDROID)
13
#include <jni.h>
14
#endif
15
16
#include <algorithm>
17
18
#include "Common/Profiler/Profiler.h"
19
#include "Common/System/NativeApp.h"
20
#include "Common/System/Request.h"
21
#include "Common/System/System.h"
22
23
#include "Common/CommonWindows.h"
24
#if PPSSPP_PLATFORM(WINDOWS)
25
#include <timeapi.h>
26
#else
27
#include <csignal>
28
#endif
29
#include "Common/CPUDetect.h"
30
#include "Common/File/VFS/VFS.h"
31
#include "Common/File/VFS/ZipFileReader.h"
32
#include "Common/File/VFS/DirectoryReader.h"
33
#include "Common/File/FileUtil.h"
34
#include "Common/GraphicsContext.h"
35
#include "Common/TimeUtil.h"
36
#include "Common/StringUtils.h"
37
#include "Common/Thread/ThreadManager.h"
38
#include "Core/Config.h"
39
#include "Core/ConfigValues.h"
40
#include "Core/Core.h"
41
#include "Core/CoreTiming.h"
42
#include "Core/System.h"
43
#include "Core/WebServer.h"
44
#include "Core/HLE/sceUtility.h"
45
#include "Core/SaveState.h"
46
#include "GPU/Common/FramebufferManagerCommon.h"
47
#include "Common/Log.h"
48
#include "Common/Log/LogManager.h"
49
50
#include "Compare.h"
51
#include "HeadlessHost.h"
52
#if defined(_WIN32)
53
#include "WindowsHeadlessHost.h"
54
#elif defined(SDL)
55
#include "SDLHeadlessHost.h"
56
#endif
57
58
static HeadlessHost *g_headlessHost;
59
60
#if PPSSPP_PLATFORM(ANDROID)
61
JNIEnv *getEnv() {
62
return nullptr;
63
}
64
65
jclass findClass(const char *name) {
66
return nullptr;
67
}
68
69
bool System_AudioRecordingIsAvailable() { return false; }
70
bool System_AudioRecordingState() { return false; }
71
#endif
72
73
// Temporary hacks around annoying linking errors.
74
void NativeFrame(GraphicsContext *graphicsContext) { }
75
void NativeResized() { }
76
77
std::string System_GetProperty(SystemProperty prop) { return ""; }
78
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) { return std::vector<std::string>(); }
79
int64_t System_GetPropertyInt(SystemProperty prop) {
80
if (prop == SYSPROP_SYSTEMVERSION)
81
return 31;
82
return -1;
83
}
84
float System_GetPropertyFloat(SystemProperty prop) { return -1.0f; }
85
bool System_GetPropertyBool(SystemProperty prop) {
86
switch (prop) {
87
case SYSPROP_CAN_JIT:
88
return true;
89
case SYSPROP_SKIP_UI:
90
return true;
91
default:
92
return false;
93
}
94
}
95
void System_Notify(SystemNotification notification) {}
96
void System_PostUIMessage(UIMessage message, const std::string &param) {}
97
void System_RunOnMainThread(std::function<void()>) {}
98
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int64_t param3, int64_t param4) {
99
switch (type) {
100
case SystemRequestType::SEND_DEBUG_OUTPUT:
101
if (g_headlessHost) {
102
g_headlessHost->SendDebugOutput(param1);
103
return true;
104
}
105
return false;
106
case SystemRequestType::SEND_DEBUG_SCREENSHOT:
107
if (g_headlessHost) {
108
g_headlessHost->SendDebugScreenshot((const u8 *)param1.data(), (uint32_t)(param1.size() / param3), param3);
109
return true;
110
}
111
return false;
112
default:
113
return false;
114
}
115
}
116
void System_AskForPermission(SystemPermission permission) {}
117
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
118
void System_AudioGetDebugStats(char *buf, size_t bufSize) { if (buf) buf[0] = '\0'; }
119
void System_AudioClear() {}
120
void System_AudioPushSamples(const s32 *audio, int numSamples, float volume) {}
121
122
// TODO: To avoid having to define these here, these should probably be turned into system "requests".
123
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data) { return false; }
124
std::string NativeLoadSecret(std::string_view nameOfSecret) {
125
return "";
126
}
127
128
int printUsage(const char *progname, const char *reason)
129
{
130
if (reason != NULL)
131
fprintf(stderr, "Error: %s\n\n", reason);
132
fprintf(stderr, "PPSSPP Headless\n");
133
fprintf(stderr, "This is primarily meant as a non-interactive test tool.\n\n");
134
fprintf(stderr, "Usage: %s file.elf... [options]\n\n", progname);
135
fprintf(stderr, "Options:\n");
136
fprintf(stderr, " -m, --mount umd.cso mount iso on umd1:\n");
137
fprintf(stderr, " -r, --root some/path mount path on host0: (elfs must be in here)\n");
138
fprintf(stderr, " -l, --log full log output, not just emulated printfs\n");
139
fprintf(stderr, " --debugger=PORT enable websocket debugger and break at start\n");
140
141
fprintf(stderr, " --graphics=BACKEND use a different gpu backend\n");
142
fprintf(stderr, " options: gles, software, directx9, etc.\n");
143
fprintf(stderr, " --screenshot=FILE compare against a screenshot\n");
144
fprintf(stderr, " --max-mse=NUMBER maximum allowed MSE error for screenshot\n");
145
fprintf(stderr, " --timeout=SECONDS abort test it if takes longer than SECONDS\n");
146
147
fprintf(stderr, " -v, --verbose show the full passed/failed result\n");
148
fprintf(stderr, " -i use the interpreter\n");
149
fprintf(stderr, " --ir use ir interpreter\n");
150
fprintf(stderr, " -j use jit (default)\n");
151
fprintf(stderr, " -c, --compare compare with output in file.expected\n");
152
fprintf(stderr, " --bench run multiple times and output speed\n");
153
fprintf(stderr, "\nSee headless.txt for details.\n");
154
155
return 1;
156
}
157
158
static HeadlessHost *getHost(GPUCore gpuCore) {
159
switch (gpuCore) {
160
case GPUCORE_SOFTWARE:
161
return new HeadlessHost();
162
#ifdef HEADLESSHOST_CLASS
163
default:
164
return new HEADLESSHOST_CLASS();
165
#else
166
default:
167
return new HeadlessHost();
168
#endif
169
}
170
}
171
172
struct AutoTestOptions {
173
double timeout;
174
double maxScreenshotError;
175
bool compare : 1;
176
bool verbose : 1;
177
bool bench : 1;
178
};
179
180
bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const AutoTestOptions &opt) {
181
// Kinda ugly, trying to guesstimate the test name from filename...
182
currentTestName = GetTestName(coreParameter.fileToStart);
183
184
std::string output;
185
if (opt.compare || opt.bench)
186
coreParameter.collectDebugOutput = &output;
187
188
if (!PSP_InitStart(coreParameter)) {
189
// Shouldn't really happen anymore, the errors happen later in PSP_InitUpdate.
190
fprintf(stderr, "Failed to start '%s'.\n", coreParameter.fileToStart.c_str());
191
printf("TESTERROR\n");
192
TeamCityPrint("testIgnored name='%s' message='PRX/ELF missing'", currentTestName.c_str());
193
GitHubActionsPrint("error", "PRX/ELF missing for %s", currentTestName.c_str());
194
return false;
195
}
196
197
TeamCityPrint("testStarted name='%s' captureStandardOutput='true'", currentTestName.c_str());
198
199
if (opt.compare)
200
headlessHost->SetComparisonScreenshot(ExpectedScreenshotFromFilename(coreParameter.fileToStart), opt.maxScreenshotError);
201
202
std::string error_string;
203
while (PSP_InitUpdate(&error_string) == BootState::Booting)
204
sleep_ms(1, "auto-test");
205
206
if (!PSP_IsInited()) {
207
TeamCityPrint("%s", error_string.c_str());
208
TeamCityPrint("testFailed name='%s' message='Startup failed'", currentTestName.c_str());
209
TeamCityPrint("testFinished name='%s'", currentTestName.c_str());
210
GitHubActionsPrint("error", "Test init failed for %s", currentTestName.c_str());
211
return false;
212
}
213
214
System_Notify(SystemNotification::BOOT_DONE);
215
216
PSP_UpdateDebugStats((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS || g_Config.bLogFrameDrops);
217
218
if (gpu) {
219
gpu->BeginHostFrame();
220
}
221
Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;
222
if (draw) {
223
draw->BeginFrame(Draw::DebugFlags::NONE);
224
}
225
226
bool passed = true;
227
double deadline = time_now_d() + opt.timeout;
228
coreState = coreParameter.startBreak ? CORE_STEPPING_CPU : CORE_RUNNING_CPU;
229
while (coreState == CORE_RUNNING_CPU || coreState == CORE_STEPPING_CPU)
230
{
231
int blockTicks = (int)usToCycles(1000000 / 10);
232
PSP_RunLoopFor(blockTicks);
233
234
// If we were rendering, this might be a nice time to do something about it.
235
if (coreState == CORE_NEXTFRAME) {
236
coreState = CORE_RUNNING_CPU;
237
headlessHost->SwapBuffers();
238
}
239
if (coreState == CORE_STEPPING_CPU && !coreParameter.startBreak) {
240
break;
241
}
242
bool debugger = false;
243
#ifdef _WIN32
244
if (IsDebuggerPresent())
245
debugger = true;
246
#endif
247
if (time_now_d() > deadline && !debugger) {
248
// Don't compare, print the output at least up to this point, and bail.
249
if (!opt.bench) {
250
printf("%s", output.c_str());
251
252
System_SendDebugOutput("TIMEOUT\n");
253
TeamCityPrint("testFailed name='%s' message='Test timeout'", currentTestName.c_str());
254
GitHubActionsPrint("error", "Test timeout for %s", currentTestName.c_str());
255
}
256
257
passed = false;
258
Core_Stop();
259
}
260
}
261
if (gpu) {
262
gpu->EndHostFrame();
263
}
264
265
if (draw) {
266
draw->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Headless");
267
// Vulkan may get angry if we don't do a final present.
268
if (gpu)
269
gpu->CopyDisplayToOutput(true);
270
271
draw->EndFrame();
272
}
273
274
PSP_Shutdown(true);
275
276
if (!opt.bench)
277
headlessHost->FlushDebugOutput();
278
279
if (opt.compare && passed)
280
passed = CompareOutput(coreParameter.fileToStart, output, opt.verbose);
281
282
TeamCityPrint("testFinished name='%s'", currentTestName.c_str());
283
284
return passed;
285
}
286
287
std::vector<std::string> ReadFromListFile(const std::string &listFilename) {
288
std::vector<std::string> testFilenames;
289
char temp[2048]{};
290
291
if (listFilename == "-") {
292
while (scanf("%2047s", temp) == 1)
293
testFilenames.push_back(temp);
294
} else {
295
FILE *fp = File::OpenCFile(Path(listFilename), "rt");
296
if (!fp) {
297
fprintf(stderr, "Unable to open '%s' as a list file\n", listFilename.c_str());
298
return testFilenames;
299
}
300
301
while (fscanf(fp, "%2047s", temp) == 1)
302
testFilenames.push_back(temp);
303
fclose(fp);
304
}
305
306
return testFilenames;
307
}
308
309
static void AddRecursively(std::vector<std::string> *tests, Path actualPath) {
310
// TODO: Some file systems can optimize this.
311
std::vector<File::FileInfo> fileInfo;
312
if (!File::GetFilesInDir(actualPath, &fileInfo, "prx")) {
313
return;
314
}
315
for (const auto &file : fileInfo) {
316
if (file.isDirectory) {
317
AddRecursively(tests, actualPath / file.name);
318
} else if (file.name != "Makefile") { // hack around filter problem
319
tests->push_back((actualPath / file.name).ToString());
320
}
321
}
322
}
323
324
static void AddTestsByPath(std::vector<std::string> *tests, std::string_view path) {
325
if (endsWith(path, "/...")) {
326
path = path.substr(0, path.size() - 4);
327
// Recurse for tests
328
AddRecursively(tests, Path(path));
329
} /* else if (File::IsDirectory(Path(path))) {
330
// Alternate syntax - just specify the path.
331
AddRecursively(tests, Path(path));
332
} */ else {
333
tests->push_back(std::string(path));
334
}
335
}
336
337
int main(int argc, const char* argv[])
338
{
339
PROFILE_INIT();
340
TimeInit();
341
#if PPSSPP_PLATFORM(WINDOWS)
342
if (!IsDebuggerPresent()) {
343
SetCleanExitOnAssert();
344
}
345
#else
346
// Ignore sigpipe.
347
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
348
perror("Unable to ignore SIGPIPE");
349
}
350
#endif
351
352
#if defined(_DEBUG) && defined(_MSC_VER)
353
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
354
#endif
355
356
AutoTestOptions testOptions{};
357
testOptions.timeout = std::numeric_limits<double>::infinity();
358
bool fullLog = false;
359
const char *stateToLoad = 0;
360
GPUCore gpuCore = GPUCORE_SOFTWARE;
361
CPUCore cpuCore = CPUCore::JIT;
362
int debuggerPort = -1;
363
bool oldAtrac = false;
364
bool outputDebugStringLog = false;
365
366
std::vector<std::string> testFilenames;
367
std::vector<std::string> ignoredTests;
368
const char *mountIso = nullptr;
369
const char *mountRoot = nullptr;
370
const char *screenshotFilename = nullptr;
371
372
for (int i = 1; i < argc; i++)
373
{
374
if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--mount"))
375
{
376
if (++i >= argc)
377
return printUsage(argv[0], "Missing argument after -m");
378
mountIso = argv[i];
379
}
380
else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--root"))
381
{
382
if (++i >= argc)
383
return printUsage(argv[0], "Missing argument after -r");
384
mountRoot = argv[i];
385
}
386
else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--log"))
387
fullLog = true;
388
else if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--odslog"))
389
outputDebugStringLog = true;
390
else if (!strcmp(argv[i], "-i"))
391
cpuCore = CPUCore::INTERPRETER;
392
else if (!strcmp(argv[i], "-j"))
393
cpuCore = CPUCore::JIT;
394
else if (!strcmp(argv[i], "--jit-ir"))
395
cpuCore = CPUCore::JIT_IR;
396
else if (!strcmp(argv[i], "--ir"))
397
cpuCore = CPUCore::IR_INTERPRETER;
398
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare"))
399
testOptions.compare = true;
400
else if (!strcmp(argv[i], "--bench"))
401
testOptions.bench = true;
402
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))
403
testOptions.verbose = true;
404
else if (!strcmp(argv[i], "--old-atrac"))
405
oldAtrac = true;
406
else if (!strncmp(argv[i], "--graphics=", strlen("--graphics=")) && strlen(argv[i]) > strlen("--graphics="))
407
{
408
const char *gpuName = argv[i] + strlen("--graphics=");
409
if (!strcasecmp(gpuName, "gles"))
410
gpuCore = GPUCORE_GLES;
411
// There used to be a separate "null" rendering core - just use software.
412
else if (!strcasecmp(gpuName, "software") || !strcasecmp(gpuName, "null"))
413
gpuCore = GPUCORE_SOFTWARE;
414
else if (!strcasecmp(gpuName, "directx11"))
415
gpuCore = GPUCORE_DIRECTX11;
416
else if (!strcasecmp(gpuName, "vulkan"))
417
gpuCore = GPUCORE_VULKAN;
418
else
419
return printUsage(argv[0], "Unknown gpu backend specified after --graphics=. Allowed: software, directx9, directx11, vulkan, gles, null.");
420
}
421
// Default to GLES if no value selected.
422
else if (!strcmp(argv[i], "--graphics")) {
423
#if PPSSPP_API(ANY_GL)
424
gpuCore = GPUCORE_GLES;
425
#else
426
gpuCore = GPUCORE_DIRECTX11;
427
#endif
428
} else if (!strncmp(argv[i], "--screenshot=", strlen("--screenshot=")) && strlen(argv[i]) > strlen("--screenshot="))
429
screenshotFilename = argv[i] + strlen("--screenshot=");
430
else if (!strncmp(argv[i], "--timeout=", strlen("--timeout=")) && strlen(argv[i]) > strlen("--timeout="))
431
testOptions.timeout = strtod(argv[i] + strlen("--timeout="), nullptr);
432
else if (!strncmp(argv[i], "--max-mse=", strlen("--max-mse=")) && strlen(argv[i]) > strlen("--max-mse="))
433
testOptions.maxScreenshotError = strtod(argv[i] + strlen("--max-mse="), nullptr);
434
else if (!strncmp(argv[i], "--debugger=", strlen("--debugger=")) && strlen(argv[i]) > strlen("--debugger="))
435
debuggerPort = (int)strtoul(argv[i] + strlen("--debugger="), NULL, 10);
436
else if (!strcmp(argv[i], "--teamcity"))
437
teamCityMode = true;
438
else if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state="))
439
stateToLoad = argv[i] + strlen("--state=");
440
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
441
return printUsage(argv[0], NULL);
442
else if (!strcmp(argv[i], "--ignore")) {
443
if (++i >= argc)
444
return printUsage(argv[0], "Missing argument after --ignore");
445
ignoredTests.push_back(argv[i]);
446
} else {
447
AddTestsByPath(&testFilenames, argv[i]);
448
}
449
}
450
451
if (testFilenames.size() == 1 && testFilenames[0][0] == '@')
452
testFilenames = ReadFromListFile(testFilenames[0].substr(1));
453
454
// Remove any ignored tests.
455
testFilenames.erase(
456
std::remove_if(
457
testFilenames.begin(),
458
testFilenames.end(),
459
[&ignoredTests](const std::string& item) { return std::find(ignoredTests.begin(), ignoredTests.end(), item) != ignoredTests.end(); }
460
),
461
testFilenames.end()
462
);
463
464
if (testFilenames.empty())
465
return printUsage(argv[0], argc <= 1 ? NULL : "No executables specified");
466
467
g_Config.bEnableLogging = (fullLog || outputDebugStringLog);
468
g_logManager.Init(&g_Config.bEnableLogging, outputDebugStringLog);
469
470
for (int i = 0; i < (int)Log::NUMBER_OF_LOGS; i++) {
471
Log type = (Log)i;
472
g_logManager.SetEnabled(type, (fullLog || outputDebugStringLog));
473
g_logManager.SetLogLevel(type, LogLevel::LDEBUG);
474
}
475
if (fullLog) {
476
// Only with --log, add the printfLogger.
477
g_logManager.EnableOutput(LogOutput::Printf);
478
}
479
480
// Needs to be after log so we don't interfere with test output.
481
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
482
483
HeadlessHost *headlessHost = getHost(gpuCore);
484
g_headlessHost = headlessHost;
485
486
std::string error_string;
487
GraphicsContext *graphicsContext = nullptr;
488
bool glWorking = headlessHost->InitGraphics(&error_string, &graphicsContext, gpuCore);
489
490
CoreParameter coreParameter;
491
coreParameter.cpuCore = cpuCore;
492
coreParameter.gpuCore = glWorking ? gpuCore : GPUCORE_SOFTWARE;
493
coreParameter.graphicsContext = graphicsContext;
494
coreParameter.enableSound = false;
495
coreParameter.mountIso = mountIso ? Path(std::string(mountIso)) : Path();
496
coreParameter.mountRoot = mountRoot ? Path(std::string(mountRoot)) : Path();
497
coreParameter.startBreak = false;
498
coreParameter.headLess = true;
499
coreParameter.renderScaleFactor = 1;
500
coreParameter.renderWidth = 480;
501
coreParameter.renderHeight = 272;
502
coreParameter.pixelWidth = 480;
503
coreParameter.pixelHeight = 272;
504
coreParameter.fastForward = true;
505
506
g_Config.iDumpFileTypes = 0;
507
g_Config.bEnableSound = false;
508
g_Config.bFirstRun = false;
509
g_Config.bIgnoreBadMemAccess = true; // NOTE: A few tests rely on this, which is BAD: threads/mbx/refer/refer , threads/mbx/send/send, threads/vtimers/interrupt
510
// Never report from tests.
511
g_Config.sReportHost.clear();
512
g_Config.bAutoSaveSymbolMap = false;
513
g_Config.bSkipBufferEffects = false;
514
g_Config.iSkipGPUReadbackMode = (int)SkipGPUReadbackMode::NO_SKIP;
515
g_Config.bHardwareTransform = true;
516
g_Config.iAnisotropyLevel = 0; // When testing mipmapping we really don't want this.
517
g_Config.iMultiSampleLevel = 0;
518
g_Config.iLanguage = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
519
g_Config.iTimeFormat = PSP_SYSTEMPARAM_TIME_FORMAT_24HR;
520
g_Config.bEncryptSave = true;
521
g_Config.sNickName = "shadow";
522
g_Config.iTimeZone = 60;
523
g_Config.iDateFormat = PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY;
524
g_Config.iButtonPreference = PSP_SYSTEMPARAM_BUTTON_CROSS;
525
g_Config.iLockParentalLevel = 9;
526
g_Config.iInternalResolution = 1;
527
g_Config.iFastForwardMode = (int)FastForwardMode::CONTINUOUS;
528
g_Config.bEnableLogging = (fullLog || outputDebugStringLog);
529
g_Config.bSoftwareSkinning = true;
530
g_Config.bVertexDecoderJit = true;
531
g_Config.bSoftwareRendering = coreParameter.gpuCore == GPUCORE_SOFTWARE;
532
g_Config.bSoftwareRenderingJit = true;
533
g_Config.iSplineBezierQuality = 2;
534
g_Config.bHighQualityDepth = true;
535
g_Config.bMemStickInserted = true;
536
g_Config.iMemStickSizeGB = 16;
537
g_Config.bEnableWlan = true;
538
g_Config.sMACAddress = "12:34:56:78:9A:BC";
539
g_Config.iFirmwareVersion = PSP_DEFAULT_FIRMWARE;
540
g_Config.iPSPModel = PSP_MODEL_SLIM;
541
g_Config.iGameVolume = VOLUMEHI_FULL;
542
g_Config.iReverbVolume = VOLUMEHI_FULL;
543
g_Config.internalDataDirectory.clear();
544
g_Config.bUseOldAtrac = oldAtrac;
545
g_Config.iForceEnableHLE = 0xFFFFFFFF; // Run all modules as HLE. We don't have anything to load in this context.
546
// g_Config.bUseOldAtrac = true;
547
548
Path exePath = File::GetExeDirectory();
549
g_Config.flash0Directory = exePath / "assets/flash0";
550
551
#if PPSSPP_PLATFORM(WINDOWS)
552
// Mount a filesystem
553
g_Config.memStickDirectory = exePath / "memstick";
554
File::CreateDir(g_Config.memStickDirectory);
555
CreateSysDirectories();
556
#elif !PPSSPP_PLATFORM(ANDROID)
557
g_Config.memStickDirectory = Path(std::string(getenv("HOME"))) / ".ppsspp";
558
#endif
559
560
// Try to find the flash0 directory. Often this is from a subdirectory.
561
Path nextPath = exePath;
562
for (int i = 0; i < 5; ++i) {
563
if (File::Exists(nextPath / "assets/flash0")) {
564
g_Config.flash0Directory = nextPath / "assets/flash0";
565
#if !PPSSPP_PLATFORM(ANDROID)
566
g_VFS.Register("", new DirectoryReader(nextPath / "assets"));
567
#endif
568
break;
569
}
570
571
if (!nextPath.CanNavigateUp())
572
break;
573
nextPath = nextPath.NavigateUp();
574
}
575
576
if (screenshotFilename)
577
headlessHost->SetComparisonScreenshot(Path(std::string(screenshotFilename)), testOptions.maxScreenshotError);
578
headlessHost->SetWriteFailureScreenshot(!teamCityMode && !getenv("GITHUB_ACTIONS") && !testOptions.bench);
579
headlessHost->SetWriteDebugOutput(!testOptions.compare && !testOptions.bench);
580
581
#if PPSSPP_PLATFORM(ANDROID)
582
// For some reason the debugger installs it with this name?
583
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp-2.apk"))) {
584
g_VFS.Register("", ZipFileReader::Create(Path("/data/app/org.ppsspp.ppsspp-2.apk"), "assets/"));
585
}
586
if (File::Exists(Path("/data/app/org.ppsspp.ppsspp.apk"))) {
587
g_VFS.Register("", ZipFileReader::Create(Path("/data/app/org.ppsspp.ppsspp.apk"), "assets/"));
588
}
589
#elif PPSSPP_PLATFORM(LINUX)
590
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/ppsspp/assets")));
591
g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/games/ppsspp/assets")));
592
g_VFS.Register("", new DirectoryReader(Path("/usr/share/ppsspp/assets")));
593
g_VFS.Register("", new DirectoryReader(Path("/usr/share/games/ppsspp/assets")));
594
#endif
595
596
UpdateUIState(UISTATE_INGAME);
597
598
if (debuggerPort > 0) {
599
g_Config.iRemoteISOPort = debuggerPort;
600
coreParameter.startBreak = true;
601
StartWebServer(WebServerFlags::DEBUGGER);
602
}
603
604
if (stateToLoad != NULL)
605
SaveState::Load(Path(stateToLoad), -1);
606
607
std::vector<std::string> failedTests;
608
std::vector<std::string> passedTests;
609
for (size_t i = 0; i < testFilenames.size(); ++i)
610
{
611
coreParameter.fileToStart = Path(testFilenames[i]);
612
if (testOptions.compare)
613
printf("%s:\n", coreParameter.fileToStart.c_str());
614
bool passed = RunAutoTest(headlessHost, coreParameter, testOptions);
615
if (testOptions.bench) {
616
double st = time_now_d();
617
double deadline = st + testOptions.timeout;
618
double runs = 0.0;
619
for (int i = 0; i < 100; ++i) {
620
RunAutoTest(headlessHost, coreParameter, testOptions);
621
runs++;
622
623
if (time_now_d() > deadline)
624
break;
625
}
626
double et = time_now_d();
627
628
std::string testName = GetTestName(coreParameter.fileToStart);
629
printf(" %s - %f seconds average\n", testName.c_str(), (et - st) / runs);
630
}
631
if (testOptions.compare) {
632
std::string testName = GetTestName(coreParameter.fileToStart);
633
if (passed) {
634
passedTests.push_back(testName);
635
printf(" %s - passed!\n", testName.c_str());
636
}
637
else
638
failedTests.push_back(testName);
639
}
640
}
641
642
if (testOptions.compare) {
643
printf("%d tests passed, %d tests failed.\n", (int)passedTests.size(), (int)failedTests.size());
644
if (!failedTests.empty())
645
{
646
printf("Failed tests:\n");
647
for (size_t i = 0; i < failedTests.size(); ++i) {
648
printf(" %s\n", failedTests[i].c_str());
649
}
650
}
651
}
652
653
if (debuggerPort > 0) {
654
ShutdownWebServer();
655
}
656
657
headlessHost->ShutdownGraphics();
658
delete headlessHost;
659
headlessHost = nullptr;
660
g_headlessHost = nullptr;
661
662
g_VFS.Clear();
663
g_logManager.Shutdown();
664
665
#if PPSSPP_PLATFORM(WINDOWS)
666
timeEndPeriod(1);
667
#endif
668
669
g_threadManager.Teardown();
670
671
if (!failedTests.empty() && !teamCityMode)
672
return 1;
673
return 0;
674
}
675
676