diff options
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 29 |
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 | ||
| 100 | void test_working_set(XMemGetWorkingSetStatisticsFn get_stats) { | 100 | void 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 | } |