| 102 | } |
| 103 | |
| 104 | int main() { |
| 105 | int fail_keeps = file_cache_keeps_cases() | file_tier_prefers_direct_cases(); |
| 106 | const uint64_t bytes = 256ull << 20; |
| 107 | void* p = std::malloc(bytes); |
| 108 | if (p == nullptr) return 2; |
| 109 | std::memset(p, 1, bytes); |
| 110 | const strata::platform::LockResult r = strata::platform::lock_resident(p, bytes); |
| 111 | std::printf("lock_resident: ok=%d locked=%llu MiB (%s)\n", (int) r.ok, (unsigned long long) (r.locked_bytes >> 20), |
| 112 | r.note.c_str()); |
| 113 | // The system refused the lock (a container or a shell with a small `ulimit -l`: RLIMIT_MEMLOCK of 8 MiB, no CAP_IPC_LOCK): nothing was locked, so the |
| 114 | // lock itself cannot be tested here. The cases above still count; the test then reports "skipped" (exit 77) with the reason, not a failure. |
| 115 | const bool lock_refused = !r.ok && r.locked_bytes == 0; |
| 116 | int fail = (lock_refused ? 0 : !(r.ok && r.locked_bytes == bytes)) | fail_keeps; |
| 117 | #if defined(_WIN32) |
| 118 | PROCESS_MEMORY_COUNTERS pmc{}; |
| 119 | GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof pmc); |
| 120 | std::printf("working set %llu MiB\n", (unsigned long long) (pmc.WorkingSetSize >> 20)); |
| 121 | fail |= pmc.WorkingSetSize < bytes; |
| 122 | #endif |
| 123 | strata::platform::unlock_resident(p, bytes); |
| 124 | std::free(p); |
| 125 | if (!fail && lock_refused) { |
| 126 | std::printf("platform_memory_test: SKIPPED, the system refused to lock %llu MiB (%s); raise the memory-lock limit to run it\n", |
| 127 | (unsigned long long) (bytes >> 20), r.note.c_str()); |
| 128 | return 77; |
| 129 | } |
| 130 | std::printf("platform_memory_test: %s\n", fail ? "FAILED" : "OK"); |
| 131 | return fail; |
| 132 | } |
nothing calls this directly
no test coverage detected