upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/xmem_test.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 18:48:08 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 18:48:08 -0500
commit864337351bc11a250db77c2fcdd3ba6f1d0f455f (patch)
tree1b9fb69662877977ec6b5da697206fd1bdcf929f /runtime/test/xmem_test.cpp
parent54ed404defd035465ece0f2beeb792cf51179691 (diff)
parentb06d096ad0943d5eda9bf1b17b3c3346688fc1f6 (diff)
Merge main into RT-LIST139 (#396)
Merged on top of the merge made for #395 (main 507029d1e plus RT-QUEUE35 and RT-ALLOC9). No conflicts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/xmem_test.cpp')
-rw-r--r--runtime/test/xmem_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp
index bf5bd3638..0c151bb9c 100644
--- a/runtime/test/xmem_test.cpp
+++ b/runtime/test/xmem_test.cpp
@@ -98,6 +98,10 @@ void test_alloc(XMemAllocFn alloc, XMemFreeFn free_mem) {
98} 98}
99 99
100void test_working_set(XMemGetWorkingSetStatisticsFn get_stats) { 100void test_working_set(XMemGetWorkingSetStatisticsFn get_stats) {
101 char saved_env[64]{};
102 const DWORD saved_n = GetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", saved_env, sizeof(saved_env));
103 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", nullptr);
104
101 alignas(64) uint8_t stats[64]; 105 alignas(64) uint8_t stats[64];
102 std::memset(stats, 0xa5, sizeof(stats)); 106 std::memset(stats, 0xa5, sizeof(stats));
103 // The pointer is the second argument: the first (0x20000001 here, as the FSR DLL passes it) must never be written 107 // The pointer is the second argument: the first (0x20000001 here, as the FSR DLL passes it) must never be written
@@ -134,6 +138,31 @@ void test_working_set(XMemGetWorkingSetStatisticsFn get_stats) {
134 } 138 }
135 check(ok != FALSE && tail_untouched, "XMemGetWorkingSetStatistics leaves bytes 16..63 untouched"); 139 check(ok != FALSE && tail_untouched, "XMemGetWorkingSetStatistics leaves bytes 16..63 untouched");
136 140
141 // LEONIDA_TITLE_MEMORY_MB override and clamping (matches XSystemGetAppMemoryUsageLimit).
142 auto query_total = [&]() -> uint64_t {
143 alignas(64) uint8_t buf[64]{};
144 if (!get_stats(kMeasuredKind, buf)) return 0;
145 uint64_t out = 0;
146 std::memcpy(&out, buf, sizeof(out));
147 return out;
148 };
149 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", "6144");
150 check(query_total() == 6144ULL * 1024ULL * 1024ULL,
151 "XMemGetWorkingSetStatistics honors LEONIDA_TITLE_MEMORY_MB=6144");
152 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", "512");
153 check(query_total() == 2048ULL * 1024ULL * 1024ULL,
154 "XMemGetWorkingSetStatistics clamps LEONIDA_TITLE_MEMORY_MB below 2048 MiB");
155 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", "131072");
156 check(query_total() == 65536ULL * 1024ULL * 1024ULL,
157 "XMemGetWorkingSetStatistics clamps LEONIDA_TITLE_MEMORY_MB above 65536 MiB");
158 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", "invalid");
159 check(query_total() == total_memory,
160 "XMemGetWorkingSetStatistics ignores invalid LEONIDA_TITLE_MEMORY_MB");
161 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", "-4096");
162 check(query_total() == total_memory,
163 "XMemGetWorkingSetStatistics ignores negative LEONIDA_TITLE_MEMORY_MB");
164 SetEnvironmentVariableA("LEONIDA_TITLE_MEMORY_MB", (saved_n > 0 && saved_n < sizeof(saved_env)) ? saved_env : nullptr);
165
137 check(get_stats(kMeasuredKind, nullptr) == FALSE, 166 check(get_stats(kMeasuredKind, nullptr) == FALSE,
138 "XMemGetWorkingSetStatistics(kind, nullptr) returns FALSE without crashing"); 167 "XMemGetWorkingSetStatistics(kind, nullptr) returns FALSE without crashing");
139} 168}