File size: 1,213 Bytes
bbb6388 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // src/platform/memory_test.cpp - plan v0.3 P0.1: lock_resident on a 256 MiB region (CPU only, no GPU, no model).
#include "strata/platform/memory.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
#endif
int main() {
const uint64_t bytes = 256ull << 20;
void* p = std::malloc(bytes);
if (p == nullptr) return 2;
std::memset(p, 1, bytes);
const strata::platform::LockResult r = strata::platform::lock_resident(p, bytes);
std::printf("lock_resident: ok=%d locked=%llu MiB (%s)\n", (int) r.ok, (unsigned long long) (r.locked_bytes >> 20),
r.note.c_str());
int fail = !(r.ok && r.locked_bytes == bytes);
#if defined(_WIN32)
PROCESS_MEMORY_COUNTERS pmc{};
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof pmc);
std::printf("working set %llu MiB\n", (unsigned long long) (pmc.WorkingSetSize >> 20));
fail |= pmc.WorkingSetSize < bytes;
#endif
strata::platform::unlock_resident(p, bytes);
std::free(p);
std::printf("platform_memory_test: %s\n", fail ? "FAILED" : "OK");
return fail;
}
|