Skip to content

Commit

Permalink
headless: Use requests for debug output.
Browse files Browse the repository at this point in the history
At least this is consistent and gets rid of host usage outside headless.
  • Loading branch information
unknownbrackets committed Mar 26, 2023
1 parent 441c940 commit 4e3ec38
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Common/System/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ inline void System_SetWindowTitle(const std::string &param) {
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 void System_SendDebugScreenshot(const std::string &data, int height) {
g_requestManager.MakeSystemRequest(SystemRequestType::SEND_DEBUG_SCREENSHOT, nullptr, nullptr, data, "", height);
}

// Non-inline to avoid including Path.h
void System_CreateGameShortcut(const Path &path, const std::string &title);

5 changes: 5 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ enum class SystemRequestType {
GRAPHICS_BACKEND_FAILED_ALERT,
CREATE_GAME_SHORTCUT,

// Commonly ignored, used when automated tests generate output.
SEND_DEBUG_OUTPUT,
// Note: height specified as param3, width based on param1.size() / param3.
SEND_DEBUG_SCREENSHOT,

NOTIFY_UI_STATE, // Used on Android only. Not a SystemNotification since it takes a parameter.

// High-level hardware control
Expand Down
10 changes: 4 additions & 6 deletions Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Common/Serialize/SerializeMap.h"
#include "Common/Serialize/SerializeSet.h"
#include "Common/StringUtils.h"
#include "Common/System/Request.h"
#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
Expand All @@ -37,7 +38,6 @@
#include "Core/MemMapHelpers.h"
#include "Core/System.h"
#include "Core/HDRemaster.h"
#include "Core/Host.h"
#include "Core/SaveState.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/HLEHelperThread.h"
Expand Down Expand Up @@ -2012,8 +2012,8 @@ 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 && host) {
host->SendDebugOutput(data);
if (PSP_CoreParameter().printfEmuLog) {
System_SendDebugOutput(data);
} else {
if (PSP_CoreParameter().collectEmuLog) {
*PSP_CoreParameter().collectEmuLog += data;
Expand All @@ -2040,9 +2040,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o

__DisplayGetFramebuf(&topaddr, &linesize, nullptr, 0);
// TODO: Convert based on pixel format / mode / something?
if (host) {
host->SendDebugScreenshot(topaddr, linesize, 272);
}
System_SendDebugScreenshot(std::string((const char *)&topaddr[0], linesize * 272), 272);
return 0;
}
case EMULATOR_DEVCTL__TOGGLE_FASTFORWARD:
Expand Down
6 changes: 2 additions & 4 deletions Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Common/Serialize/SerializeSet.h"
#include "Common/File/FileUtil.h"
#include "Common/StringUtils.h"
#include "Common/System/Request.h"
#include "Common/System/System.h"

#include "Core/Config.h"
Expand All @@ -37,7 +38,6 @@
#include "Core/HLE/ReplaceTables.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/Reporting.h"
#include "Core/Host.h"
#include "Core/Loaders.h"
#include "Core/MIPS/MIPS.h"
#include "Core/MIPS/MIPSAnalyst.h"
Expand Down Expand Up @@ -1934,9 +1934,7 @@ void __KernelGPUReplay() {
PSPPointer<u8> topaddr;
u32 linesize = 512;
__DisplayGetFramebuf(&topaddr, &linesize, nullptr, 0);
if (host) {
host->SendDebugScreenshot(topaddr, linesize, 272);
}
System_SendDebugScreenshot(std::string((const char *)&topaddr[0], linesize * 272), 272);
Core_Stop();
}
}
Expand Down
15 changes: 13 additions & 2 deletions headless/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "Common/Profiler/Profiler.h"
#include "Common/System/NativeApp.h"
#include "Common/System/Request.h"
#include "Common/System/System.h"

#include "Common/CommonWindows.h"
Expand Down Expand Up @@ -117,7 +118,17 @@ bool System_GetPropertyBool(SystemProperty prop) {
void System_Notify(SystemNotification notification) {}
void System_PostUIMessage(const std::string &message, const std::string &param) {}
void System_NotifyUserMessage(const std::string &message, float duration, u32 color, const char *id) {}
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int param3) { return false; }
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int param3) {
switch (type) {
case SystemRequestType::SEND_DEBUG_OUTPUT:
host->SendDebugOutput(param1);
return true;
case SystemRequestType::SEND_DEBUG_SCREENSHOT:
host->SendDebugScreenshot((const u8 *)param1.data(), (uint32_t)(param1.size() / param3), param3);
return true;
}
return false;
}
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; }
Expand Down Expand Up @@ -238,7 +249,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const
if (!opt.bench) {
printf("%s", output.c_str());

host->SendDebugOutput("TIMEOUT\n");
System_SendDebugOutput("TIMEOUT\n");
TeamCityPrint("testFailed name='%s' message='Test timeout'", currentTestName.c_str());
GitHubActionsPrint("error", "Test timeout for %s", currentTestName.c_str());
}
Expand Down

0 comments on commit 4e3ec38

Please sign in to comment.