From 01cde4562be14b518a15b7b7b964cb5dcc65474e Mon Sep 17 00:00:00 2001 From: Zebraine Date: Sun, 22 Nov 2026 17:45:13 +0800 Subject: Verify the exact tiny game exit code in runtime tests --- runtime/test/tiny_game_exit_code_test.cpp | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 runtime/test/tiny_game_exit_code_test.cpp (limited to 'runtime/test/tiny_game_exit_code_test.cpp') diff --git a/runtime/test/tiny_game_exit_code_test.cpp b/runtime/test/tiny_game_exit_code_test.cpp new file mode 100644 index 000000000..9208c78b8 --- /dev/null +++ b/runtime/test/tiny_game_exit_code_test.cpp @@ -0,0 +1,37 @@ +// Check the exact process exit code returned by gta6rt after the synthetic guest exits. +#include + +#include +#include + +int wmain(int argc, wchar_t** argv) { + if (argc != 3) { + std::fprintf(stderr, "usage: tiny_game_exit_code_test \n"); + return 1; + } + + std::wstring command = L"\"" + std::wstring(argv[1]) + L"\" --run \"" + argv[2] + L"\" -- hello 42 exit-code"; + STARTUPINFOW startup{}; + startup.cb = sizeof(startup); + PROCESS_INFORMATION child{}; + if (!CreateProcessW(argv[1], command.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &startup, &child)) { + std::fprintf(stderr, "could not start gta6rt (Win32 error %lu)\n", GetLastError()); + return 1; + } + CloseHandle(child.hThread); + DWORD code = 0; + const DWORD wait = WaitForSingleObject(child.hProcess, 30000); + const bool exited = wait == WAIT_OBJECT_0 && GetExitCodeProcess(child.hProcess, &code); + if (wait == WAIT_TIMEOUT) TerminateProcess(child.hProcess, 1); + CloseHandle(child.hProcess); + if (!exited) { + std::fprintf(stderr, "could not collect gta6rt's exit code (wait result %#lx)\n", wait); + return 1; + } + if (code != 42) { + std::fprintf(stderr, "gta6rt exited with code %lu, expected guest exit code 42\n", code); + return 1; + } + std::printf("gta6rt returned the expected guest exit code 42\n"); + return 0; +} -- cgit v1.2.3