upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/xgameruntime_test.cpp
diff options
context:
space:
mode:
authorVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-23 00:19:13 +0100
committerVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-23 00:19:13 +0100
commitfcda84bb0d2c6abb99e42409f413025d00ddb4be (patch)
tree27a5ee092be10547ffa5b4447ee050c623c62850 /runtime/test/xgameruntime_test.cpp
parent3a1ed28bebf374321149bc4bbffc005ea6f691c4 (diff)
parent3986b50821272791333c00df80bdb8526a8fdb9c (diff)
Merge hw4-ps-oracle into hw4-ps-formats (#3499)
docs/shader_validation.md tools/ps_oracle.py AI-assisted.
Diffstat (limited to 'runtime/test/xgameruntime_test.cpp')
-rw-r--r--runtime/test/xgameruntime_test.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp
index c5a0e988e..6464b4907 100644
--- a/runtime/test/xgameruntime_test.cpp
+++ b/runtime/test/xgameruntime_test.cpp
@@ -12,11 +12,16 @@
12#include <cstdio> 12#include <cstdio>
13#include <cstdlib> 13#include <cstdlib>
14#include <cstring> 14#include <cstring>
15#include <filesystem>
16#include <fstream>
17#include <string>
18#include <system_error>
15 19
16#include <XAsync.h> 20#include <XAsync.h>
17#include <XAsyncProvider.h> 21#include <XAsyncProvider.h>
18#include <XTaskQueue.h> 22#include <XTaskQueue.h>
19 23
24#include "file_system.h"
20#include "shims.h" 25#include "shims.h"
21 26
22namespace { 27namespace {
@@ -279,6 +284,20 @@ void check_run_time_load() {
279 reinterpret_cast<SetSensitive>(slot(t, 27))(t, false) == S_OK && 284 reinterpret_cast<SetSensitive>(slot(t, 27))(t, false) == S_OK &&
280 !reinterpret_cast<IsSensitive>(slot(t, 30))(t), 285 !reinterpret_cast<IsSensitive>(slot(t, 30))(t),
281 "slots 27 and 30 set and read this thread's time-sensitive flag"); 286 "slots 27 and 30 set and read this thread's time-sensitive flag");
287 // Slot 8 (XAsyncBeginAlloc, private, signature not measured) must not report a begun call whose provider
288 // never received XAsyncOp::Begin: either it refuses, or the provider saw Begin exactly once.
289 static std::atomic<int> s_begins{0};
290 XAsyncProvider* provider = [](XAsyncOp op, const XAsyncProviderData*) -> HRESULT {
291 if (op == XAsyncOp::Begin) s_begins.fetch_add(1);
292 return S_OK;
293 };
294 XAsyncBlock alloc_block{};
295 using BeginAlloc = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, const void*, const char*, XAsyncProvider*,
296 size_t, size_t, void*);
297 const HRESULT alloc_hr =
298 reinterpret_cast<BeginAlloc>(slot(t, 8))(t, &alloc_block, nullptr, "test", provider, 16, 0, nullptr);
299 check(FAILED(alloc_hr) || s_begins.load() == 1,
300 "slot 8 (XAsyncBeginAlloc) never reports success for a call whose provider did not begin");
282 void* unk = nullptr; 301 void* unk = nullptr;
283 const GUID iunknown = {0, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46}}; 302 const GUID iunknown = {0, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46}};
284 using QI = HRESULT(STDMETHODCALLTYPE*)(void*, REFIID, void**); 303 using QI = HRESULT(STDMETHODCALLTYPE*)(void*, REFIID, void**);
@@ -373,6 +392,79 @@ void check_run_time_load() {
373 release(n); 392 release(n);
374 } 393 }
375 394
395 // XPersistentLocalStorageImpl (RT-219): the class id with IXPersistentLocalStorageImpl3's interface id, over a
396 // temporary overlay. The storage folder is <overlay>\persistent.
397 const GUID pls_class = {0xf4faf4d4, 0x2d04, 0x4fce, {0xb3, 0xe0, 0x47, 0x4a, 0x71, 0x3a, 0x3e, 0x84}};
398 const GUID pls3 = {0x41a4e10c, 0x5a7e, 0x41d9, {0x8c, 0x37, 0x37, 0xbd, 0xe6, 0x2a, 0x07, 0xd6}};
399 const std::filesystem::path scratch =
400 std::filesystem::temp_directory_path() / (L"gta6rt_pls_test_" + std::to_wstring(GetCurrentProcessId()));
401 std::error_code scratch_ec;
402 std::filesystem::remove_all(scratch, scratch_ec);
403 rt::fs::configure(scratch / L"game", scratch / L"overlay");
404 void* pls = nullptr;
405 check(query(&pls_class, pls3, &pls) == S_OK && pls, "QueryApiImpl hands out XPersistentLocalStorageImpl for IXPersistentLocalStorageImpl3");
406 if (pls) {
407 using GetPathSize = HRESULT(STDMETHODCALLTYPE*)(void*, size_t*);
408 using GetPath = HRESULT(STDMETHODCALLTYPE*)(void*, size_t, char*, size_t*);
409 using GetSpaceInfo = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t*);
410 using PromptAsync = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t, XAsyncBlock*);
411 using PromptResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*);
412 using Mount = HRESULT(STDMETHODCALLTYPE*)(void*, const char*, void**);
413
414 size_t size = 0;
415 check(reinterpret_cast<GetPathSize>(slot(pls, 3))(pls, &size) == S_OK && size > 1,
416 "slot 3 (GetPathSize) reports the length of the path with its NUL");
417 std::string path(size, '\xA5');
418 size_t used = 0;
419 check(reinterpret_cast<GetPath>(slot(pls, 4))(pls, size, path.data(), &used) == S_OK && used == size &&
420 path[size - 1] == '\0',
421 "slot 4 (GetPath) fills the buffer and reports the bytes used");
422 const std::filesystem::path folder = std::filesystem::path(path.c_str());
423 check(folder == scratch / L"overlay" / L"persistent" && std::filesystem::is_directory(folder),
424 "the path is <overlay>\\persistent and the folder exists");
425 char tiny[2] = {'x', 'x'};
426 used = 99;
427 check(reinterpret_cast<GetPath>(slot(pls, 4))(pls, 2, tiny, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) &&
428 used == 0,
429 "slot 4 refuses a buffer that is too small");
430
431 {
432 std::ofstream cache_file(folder / L"cache.bin", std::ios::binary);
433 const std::string kilobyte(1024, 'z');
434 cache_file << kilobyte;
435 }
436 uint64_t info[4] = {9, 9, 9, 9}; // available free, total free, used, total
437 const HRESULT info_hr = reinterpret_cast<GetSpaceInfo>(slot(pls, 5))(pls, info);
438 check(info_hr == S_OK && info[3] == 2048ull * 1024 * 1024 && info[2] == 1024 && info[1] == info[3] - 1024 &&
439 info[0] > 0 && info[0] <= info[1],
440 "slot 5 (GetSpaceInfo): the 2048 MB quota, the bytes used, and what is left");
441
442 XAsyncBlock fits{};
443 check(reinterpret_cast<PromptAsync>(slot(pls, 6))(pls, 1024, &fits) == S_OK &&
444 XAsyncGetStatus(&fits, true) == S_OK && reinterpret_cast<PromptResult>(slot(pls, 7))(pls, &fits) == S_OK,
445 "slots 6/7: a prompt for space the quota can hold succeeds");
446 XAsyncBlock too_big{};
447 check(reinterpret_cast<PromptAsync>(slot(pls, 6))(pls, 4096ull * 1024 * 1024, &too_big) == S_OK &&
448 XAsyncGetStatus(&too_big, true) == HRESULT_FROM_WIN32(ERROR_DISK_FULL) &&
449 reinterpret_cast<PromptResult>(slot(pls, 7))(pls, &too_big) == HRESULT_FROM_WIN32(ERROR_DISK_FULL),
450 "slots 6/7: a prompt for more than the quota fails with ERROR_DISK_FULL");
451
452 void* handle = reinterpret_cast<void*>(1);
453 check(reinterpret_cast<Mount>(slot(pls, 8))(pls, "pkg", &handle) == E_NOTIMPL && handle == nullptr,
454 "slot 8 (MountForPackage) is E_NOTIMPL and leaves no handle");
455 release(pls);
456 }
457 rt::fs::configure({}, {});
458 check(query(&pls_class, pls_class, &pls) == S_OK, "the class answers with its own id too");
459 if (pls) {
460 using GetPathSize = HRESULT(STDMETHODCALLTYPE*)(void*, size_t*);
461 size_t size = 99;
462 check(reinterpret_cast<GetPathSize>(slot(pls, 3))(pls, &size) == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) && size == 0,
463 "with no overlay configured the path size fails instead of answering S_OK with nothing");
464 release(pls);
465 }
466 std::filesystem::remove_all(scratch, scratch_ec);
467
376 // XSystemImpl, asked for as libHttpClient.GDK.dll does: the class id with IXSystemImpl5's interface id. 468 // XSystemImpl, asked for as libHttpClient.GDK.dll does: the class id with IXSystemImpl5's interface id.
377 const GUID system_cls = {0xe349bd1a, 0xfc20, 0x4e40, {0xb9, 0x9c, 0x41, 0x78, 0xcc, 0x6b, 0x40, 0x9f}}; 469 const GUID system_cls = {0xe349bd1a, 0xfc20, 0x4e40, {0xb9, 0x9c, 0x41, 0x78, 0xcc, 0x6b, 0x40, 0x9f}};
378 const GUID system5 = {0x1861cf2e, 0xe18b, 0x4834, {0xa9, 0xf5, 0xb4, 0xa4, 0xe6, 0xef, 0xb4, 0xcf}}; 470 const GUID system5 = {0x1861cf2e, 0xe18b, 0x4834, {0xa9, 0xf5, 0xb4, 0xa4, 0xe6, 0xef, 0xb4, 0xcf}};