upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/tiny_game_exit_code_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/tiny_game_exit_code_test.cpp')
-rw-r--r--runtime/test/tiny_game_exit_code_test.cpp37
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
7int 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}