okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-eng: GitHub engine items for 0.2.76ca60e9a0

main
1.3 KiB33 linesraw
1// pick_window_victim (include/strata/core/window_evict.hpp): CPU only (#3702).
2#include "strata/core/window_evict.hpp"
3
4#include <cstdio>
5#include <cstdlib>
6
7using strata::core::pick_window_victim;
8
9namespace {
10int checks = 0;
11void check(bool ok, const char* label) {
12    ++checks;
13    if (!ok) { std::fprintf(stderr, "FAIL: %s\n", label); std::exit(1); }
14}
15}  // namespace
16
17int main() {
18    bool have[9] = {};
19    check(pick_window_victim(have, 8, 5, 0) == 0, "nothing captured: nothing to free");
20    have[2] = have[3] = have[5] = true;
21    check(pick_window_victim(have, 8, 6, 0) == 5, "the largest captured size goes first");
22    check(pick_window_victim(have, 8, 5, 0) == 3, "never the size being captured");
23    check(pick_window_victim(have, 8, 5, 3) == 2, "never the prelaunched size");
24    check(pick_window_victim(have, 4, 1, 0) == 3, "sizes above max_t are not considered");
25    have[5] = false;
26    check(pick_window_victim(have, 8, 3, 2) == 0, "only the kept and the pinned sizes are left: nothing");
27    have[2] = have[3] = false;
28    have[1] = true;
29    check(pick_window_victim(have, 8, 7, 0) == 1, "size 1 can be freed");
30    check(pick_window_victim(have, 8, 1, 0) == 0, "size 1 kept");
31    std::printf("window_evict_test: %d checks passed\n", checks);
32    return 0;
33}