| 61 | } |
| 62 | |
| 63 | void test_plan() { |
| 64 | uint8_t* a = map_pages(2 * MiB, 1); |
| 65 | uint8_t* b = map_pages(8 * MiB, 2); |
| 66 | auto parts = two_parts(a, 2 * MiB, b, 8 * MiB); |
| 67 | std::vector<uint64_t> t; |
| 68 | LockEnv e; // nothing limits |
| 69 | CHECK(plan_lock(parts, e, t) == 10 * MiB && t[0] == 2 * MiB && t[1] == 8 * MiB); |
| 70 | e.limit = 1 * MiB; // the limit cuts inside the first part: the second gets nothing |
| 71 | CHECK(plan_lock(parts, e, t) == 1 * MiB && t[0] == 1 * MiB && t[1] == 0); |
| 72 | e.limit = 5 * MiB; // the first whole, the second its start |
| 73 | CHECK(plan_lock(parts, e, t) == 5 * MiB && t[0] == 2 * MiB && t[1] == 3 * MiB); |
| 74 | e.limit = 0; |
| 75 | CHECK(plan_lock(parts, e, t) == 0); |
| 76 | e = LockEnv{}; |
| 77 | e.avail = 12 * MiB; e.reserve = 9 * MiB; // the free RAM leaves 3 MiB |
| 78 | bool ram = false; |
| 79 | CHECK(plan_lock(parts, e, t, &ram) == 3 * MiB && ram); |
| 80 | e.avail = 4 * MiB; // below the reserve: nothing |
| 81 | CHECK(plan_lock(parts, e, t, &ram) == 0 && ram); |
| 82 | munmap(a, 2 * MiB); munmap(b, 8 * MiB); |
| 83 | } |
| 84 | |
| 85 | void test_fake() { |
| 86 | uint8_t* a = map_pages(2 * MiB + 100, 3); // not a whole number of pages: the piece edges must still work |