MCPcopy Create free account
hub / github.com/Niko1221/Strata / test_raise

Function test_raise

engine/src/split/tools/memlock_test.cpp:207–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207void test_raise() {
208 // soft 128 KiB, hard 64 MiB, need 10 MiB: the soft limit is raised (privileged or not) and the whole lock succeeds
209 const int rc = in_child([] {
210 struct rlimit lo { 128 * 1024, 64 * MiB };
211 if (setrlimit(RLIMIT_MEMLOCK, &lo) != 0) return 77; // the hard limit of this process is already below 64 MiB (a test run under ulimit -l 8192): it cannot be raised here, the case does not apply
212 const LockEnv e = read_lock_env(10 * MiB);
213 if (!e.raised) return 91;
214 struct rlimit now {};
215 getrlimit(RLIMIT_MEMLOCK, &now);
216 if (now.rlim_cur != 64 * MiB) return 92; // need + 1 GiB, capped at the hard limit
217 uint8_t* a = map_pages(2 * MiB, 7);
218 uint8_t* b = map_pages(8 * MiB, 8);
219 auto parts = two_parts(a, 2 * MiB, b, 8 * MiB);
220 LockOutcome o = lock_parts(parts, e);
221 if (o.locked != o.want && !(e.avail != UINT64_MAX && e.avail < o.want + e.reserve)) return 93; // all locked, unless this PC is short of RAM
222 return 0;
223 });
224 CHECK(rc == 0 || rc == 77);
225}
226
227} // namespace
228

Callers 1

mainFunction · 0.85

Calls 5

in_childFunction · 0.85
read_lock_envFunction · 0.85
map_pagesFunction · 0.85
two_partsFunction · 0.85
lock_partsFunction · 0.85

Tested by

no test coverage detected