diff options
| author | Zebraine <zebrainee@gmail.com> | 2026-11-22 17:45:13 +0800 |
|---|---|---|
| committer | Zebraine <zebrainee@gmail.com> | 2026-11-22 20:38:19 +0800 |
| commit | 01cde4562be14b518a15b7b7b964cb5dcc65474e (patch) | |
| tree | 9e23a4b1847d400d78694bee4ccaf6a9b77f59b2 /runtime/test/tiny_game_exit_code_test.cpp | |
| parent | 41f448261e1de8a410b4d760e69a7e5656cef858 (diff) | |
Verify the exact tiny game exit code in runtime tests
Diffstat (limited to 'runtime/test/tiny_game_exit_code_test.cpp')
| -rw-r--r-- | runtime/test/tiny_game_exit_code_test.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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 @@ | |||
| 1 | // Check the exact process exit code returned by gta6rt after the synthetic guest exits. | ||
| 2 | #include <windows.h> | ||
| 3 | |||
| 4 | #include <cstdio> | ||
| 5 | #include <string> | ||
| 6 | |||
| 7 | int wmain(int argc, wchar_t** argv) { | ||
| 8 | if (argc != 3) { | ||
| 9 | std::fprintf(stderr, "usage: tiny_game_exit_code_test <gta6rt.exe> <tiny_game.exe>\n"); | ||
| 10 | return 1; | ||
| 11 | } | ||
| 12 | |||
| 13 | std::wstring command = L"\"" + std::wstring(argv[1]) + L"\" --run \"" + argv[2] + L"\" -- hello 42 exit-code"; | ||
| 14 | STARTUPINFOW startup{}; | ||
| 15 | startup.cb = sizeof(startup); | ||
| 16 | PROCESS_INFORMATION child{}; | ||
| 17 | if (!CreateProcessW(argv[1], command.data(), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &startup, &child)) { | ||
| 18 | std::fprintf(stderr, "could not start gta6rt (Win32 error %lu)\n", GetLastError()); | ||
| 19 | return 1; | ||
| 20 | } | ||
| 21 | CloseHandle(child.hThread); | ||
| 22 | DWORD code = 0; | ||
| 23 | const DWORD wait = WaitForSingleObject(child.hProcess, 30000); | ||
| 24 | const bool exited = wait == WAIT_OBJECT_0 && GetExitCodeProcess(child.hProcess, &code); | ||
| 25 | if (wait == WAIT_TIMEOUT) TerminateProcess(child.hProcess, 1); | ||
| 26 | CloseHandle(child.hProcess); | ||
| 27 | if (!exited) { | ||
| 28 | std::fprintf(stderr, "could not collect gta6rt's exit code (wait result %#lx)\n", wait); | ||
| 29 | return 1; | ||
| 30 | } | ||
| 31 | if (code != 42) { | ||
| 32 | std::fprintf(stderr, "gta6rt exited with code %lu, expected guest exit code 42\n", code); | ||
| 33 | return 1; | ||
| 34 | } | ||
| 35 | std::printf("gta6rt returned the expected guest exit code 42\n"); | ||
| 36 | return 0; | ||
| 37 | } | ||