From 76ef95a8410aa9896ccea7953cd6c99cd565f86d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 26 Mar 2023 10:17:34 -0700 Subject: [PATCH 1/2] headless: Remove printfEmuLog, simplify output. --- Common/System/Request.h | 4 ++-- Core/CoreParameter.h | 1 - Core/HLE/sceIo.cpp | 13 ++++--------- UI/EmuScreen.cpp | 1 - android/jni/TestRunner.cpp | 1 - headless/Headless.cpp | 2 +- headless/HeadlessHost.cpp | 16 +++------------- headless/HeadlessHost.h | 19 ++++++++++--------- headless/WindowsHeadlessHost.cpp | 6 +++--- libretro/libretro.cpp | 1 - 10 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Common/System/Request.h b/Common/System/Request.h index 3f7d1c0bc1..75a236cb14 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -142,8 +142,8 @@ inline void System_SetWindowTitle(const std::string ¶m) { g_requestManager.MakeSystemRequest(SystemRequestType::SET_WINDOW_TITLE, nullptr, nullptr, param, "", 0); } -inline void System_SendDebugOutput(const std::string &string) { - g_requestManager.MakeSystemRequest(SystemRequestType::SEND_DEBUG_OUTPUT, nullptr, nullptr, string, "", 0); +inline bool System_SendDebugOutput(const std::string &string) { + return g_requestManager.MakeSystemRequest(SystemRequestType::SEND_DEBUG_OUTPUT, nullptr, nullptr, string, "", 0); } inline void System_SendDebugScreenshot(const std::string &data, int height) { diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index 9ef01c4d9b..c0811b9509 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -61,7 +61,6 @@ struct CoreParameter { std::string errorString; bool startBreak; - bool printfEmuLog; // writes "emulator:" logging to stdout std::string *collectEmuLog = nullptr; bool headLess; // Try to avoid messageboxes etc diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 55766694f0..65b004ea9a 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -2012,15 +2012,10 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o case EMULATOR_DEVCTL__SEND_OUTPUT: { std::string data(Memory::GetCharPointer(argAddr), argLen); - if (PSP_CoreParameter().printfEmuLog) { - System_SendDebugOutput(data); - } else { - if (PSP_CoreParameter().collectEmuLog) { - *PSP_CoreParameter().collectEmuLog += data; - } else { - DEBUG_LOG(SCEIO, "%s", data.c_str()); - } - } + if (!System_SendDebugOutput(data)) + DEBUG_LOG(SCEIO, "%s", data.c_str()); + if (PSP_CoreParameter().collectEmuLog) + *PSP_CoreParameter().collectEmuLog += data; return 0; } case EMULATOR_DEVCTL__IS_EMULATOR: diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 9ffa65d8a6..532ed0d3db 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -305,7 +305,6 @@ void EmuScreen::bootGame(const Path &filename) { coreParam.mountIso.clear(); coreParam.mountRoot.clear(); coreParam.startBreak = !g_Config.bAutoRun; - coreParam.printfEmuLog = false; coreParam.headLess = false; if (g_Config.iInternalResolution == 0) { diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp index 1b9a8acb52..206c7ebf22 100644 --- a/android/jni/TestRunner.cpp +++ b/android/jni/TestRunner.cpp @@ -95,7 +95,6 @@ bool RunTests() { coreParam.mountIso.clear(); coreParam.mountRoot = baseDirectory / "pspautotests"; coreParam.startBreak = false; - coreParam.printfEmuLog = false; coreParam.headLess = true; coreParam.renderWidth = 480; coreParam.renderHeight = 272; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 2650272f9b..f91ad9b126 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -446,7 +446,6 @@ 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 = !testOptions.compare; coreParameter.headLess = true; coreParameter.renderScaleFactor = 1; coreParameter.renderWidth = 480; @@ -523,6 +522,7 @@ int main(int argc, const char* argv[]) if (screenshotFilename) headlessHost->SetComparisonScreenshot(Path(std::string(screenshotFilename)), testOptions.maxScreenshotError); headlessHost->SetWriteFailureScreenshot(!teamCityMode && !getenv("GITHUB_ACTIONS") && !testOptions.bench); + headlessHost->SetWriteDebugOutput(!testOptions.compare && !testOptions.bench); #if PPSSPP_PLATFORM(ANDROID) // For some reason the debugger installs it with this name? diff --git a/headless/HeadlessHost.cpp b/headless/HeadlessHost.cpp index a18fd63abf..7a88ca5bb3 100644 --- a/headless/HeadlessHost.cpp +++ b/headless/HeadlessHost.cpp @@ -24,16 +24,6 @@ #include "headless/Compare.h" #include "headless/HeadlessHost.h" -void HeadlessHost::SendOrCollectDebugOutput(const std::string &data) -{ - if (PSP_CoreParameter().printfEmuLog) - SendDebugOutput(data); - else if (PSP_CoreParameter().collectEmuLog) - *PSP_CoreParameter().collectEmuLog += data; - else - DEBUG_LOG(COMMON, "%s", data.c_str()); -} - void HeadlessHost::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) { // Only if we're actually comparing. if (comparisonScreenshot_.empty()) { @@ -52,14 +42,14 @@ void HeadlessHost::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) { ScreenshotComparer comparer(pixels, FRAME_STRIDE, FRAME_WIDTH, FRAME_HEIGHT); double errors = comparer.Compare(comparisonScreenshot_); if (errors < 0) - SendOrCollectDebugOutput(comparer.GetError() + "\n"); + SendDebugOutput(comparer.GetError() + "\n"); if (errors > maxScreenshotError_) - SendOrCollectDebugOutput(StringFromFormat("Screenshot MSE: %f\n", errors)); + SendDebugOutput(StringFromFormat("Screenshot MSE: %f\n", errors)); if (errors > maxScreenshotError_ && writeFailureScreenshot_) { if (comparer.SaveActualBitmap(Path("__testfailure.bmp"))) - SendOrCollectDebugOutput("Actual output written to: __testfailure.bmp\n"); + SendDebugOutput("Actual output written to: __testfailure.bmp\n"); comparer.SaveVisualComparisonPNG(Path("__testcompare.png")); } } diff --git a/headless/HeadlessHost.h b/headless/HeadlessHost.h index 3be7bc38c5..a40c8ff191 100644 --- a/headless/HeadlessHost.h +++ b/headless/HeadlessHost.h @@ -29,23 +29,26 @@ public: virtual void ShutdownGraphics() {} virtual void SendDebugOutput(const std::string &output) { + if (!writeDebugOutput_) + return; if (output.find('\n') != output.npos) { - DoFlushDebugOutput(); + FlushDebugOutput(); fwrite(output.data(), sizeof(char), output.length(), stdout); } else { debugOutputBuffer_ += output; } } - virtual void FlushDebugOutput() { - DoFlushDebugOutput(); - } - inline void DoFlushDebugOutput() { + void FlushDebugOutput() { if (!debugOutputBuffer_.empty()) { fwrite(debugOutputBuffer_.data(), sizeof(char), debugOutputBuffer_.length(), stdout); debugOutputBuffer_.clear(); } } + void SetWriteDebugOutput(bool flag) { + writeDebugOutput_ = flag; + } + void SetComparisonScreenshot(const Path &filename, double maxError) { comparisonScreenshot_ = filename; maxScreenshotError_ = maxError; @@ -54,18 +57,16 @@ public: writeFailureScreenshot_ = flag; } - virtual void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h); + void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h); - // Unique for HeadlessHost virtual void SwapBuffers() {} protected: - void SendOrCollectDebugOutput(const std::string &output); - Path comparisonScreenshot_; double maxScreenshotError_ = 0.0; std::string debugOutputBuffer_; GPUCore gpuCore_; GraphicsContext *gfx_ = nullptr; bool writeFailureScreenshot_ = true; + bool writeDebugOutput_ = true; }; diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index 6d7d58da6a..3aef27028a 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -66,9 +66,9 @@ HWND CreateHiddenWindow() { return CreateWindowEx(0, L"PPSSPPHeadless", L"PPSSPPHeadless", style, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, NULL, NULL); } -void WindowsHeadlessHost::SendDebugOutput(const std::string &output) -{ - fwrite(output.data(), sizeof(char), output.length(), stdout); +void WindowsHeadlessHost::SendDebugOutput(const std::string &output) { + if (writeDebugOutput_) + fwrite(output.data(), sizeof(char), output.length(), stdout); OutputDebugStringUTF8(output.c_str()); } diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 476d66ccc4..2038e43bd5 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1434,7 +1434,6 @@ bool retro_load_game(const struct retro_game_info *game) coreParam.fileToStart = Path(std::string(game->path)); coreParam.mountIso.clear(); coreParam.startBreak = false; - coreParam.printfEmuLog = true; coreParam.headLess = true; coreParam.graphicsContext = ctx; coreParam.gpuCore = ctx->GetGPUCore(); From 00d84695d8ad8ba93a200c43282d876ecec91d24 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 26 Mar 2023 10:21:07 -0700 Subject: [PATCH 2/2] headless: Rename collectEmuLog for clarity. This is still used when running tests outside headless, so leaving in CoreParameter. --- Core/CoreParameter.h | 2 +- Core/HLE/sceIo.cpp | 4 ++-- Core/HLE/sceKernelModule.cpp | 4 ++++ android/jni/TestRunner.cpp | 2 +- headless/Headless.cpp | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index c0811b9509..afa15412a9 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -61,7 +61,7 @@ struct CoreParameter { std::string errorString; bool startBreak; - std::string *collectEmuLog = nullptr; + std::string *collectDebugOutput = nullptr; bool headLess; // Try to avoid messageboxes etc // Internal PSP rendering resolution and scale factor. diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 65b004ea9a..8b85bce7c5 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -2014,8 +2014,8 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o std::string data(Memory::GetCharPointer(argAddr), argLen); if (!System_SendDebugOutput(data)) DEBUG_LOG(SCEIO, "%s", data.c_str()); - if (PSP_CoreParameter().collectEmuLog) - *PSP_CoreParameter().collectEmuLog += data; + if (PSP_CoreParameter().collectDebugOutput) + *PSP_CoreParameter().collectDebugOutput += data; return 0; } case EMULATOR_DEVCTL__IS_EMULATOR: diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 3133e65b09..5f13243d06 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1208,6 +1208,10 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load ptr = newptr; magicPtr = (u32_le *)ptr; int ret = pspDecryptPRX(in, (u8*)ptr, head->psp_size); + if (ret <= 0 && *(u32_le *)&ptr[0x150] == 0x464c457f) { + ret = head->psp_size - 0x150; + memcpy(newptr, in + 0x150, ret); + } if (reportedModule) { // This should happen for all "kernel" modules. *error_string = "Missing key"; diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp index 206c7ebf22..8b5a2ec5b6 100644 --- a/android/jni/TestRunner.cpp +++ b/android/jni/TestRunner.cpp @@ -100,7 +100,7 @@ bool RunTests() { coreParam.renderHeight = 272; coreParam.pixelWidth = 480; coreParam.pixelHeight = 272; - coreParam.collectEmuLog = &output; + coreParam.collectDebugOutput = &output; coreParam.fastForward = true; coreParam.updateRecent = false; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index f91ad9b126..44b7bb81f8 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -201,7 +201,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const std::string output; if (opt.compare || opt.bench) - coreParameter.collectEmuLog = &output; + coreParameter.collectDebugOutput = &output; std::string error_string; if (!PSP_InitStart(coreParameter, &error_string)) {