nx_evict_journal_test.nx source
↩ module page · 60 lines · 1958 B
1// nx_evict_journal_test.nx -- smoke for nx_evict_journal.
2
3import "nx_syscalls.nx"
4import "nx_evict_journal.nx"
5
6func main() -> i64 {
7 // 1: construction
8 let j: *NxEvictJournal = nx_evict_journal_new(8)
9 if j.capacity != 8 { return 1 }
10 if j.head != 0 { return 2 }
11 if j.count != 0 { return 3 }
12
13 // 2: reason validation
14 if nx_evr_is_valid(NX_EVR_BUDGET_DENIED) != 1 { return 4 }
15 if nx_evr_is_valid(NX_EVR_TERMINATED) != 1 { return 5 }
16 if nx_evr_is_valid(-1) != 0 { return 6 }
17 if nx_evr_is_valid(5) != 0 { return 7 }
18
19 // 3: append entry
20 let rc1: nx_int = nx_evict_log(j, 12345, 42,
21 NX_EVR_BUDGET_DENIED, 0, 3, 99)
22 if rc1 != 0 { return 8 }
23 if j.head != 1 { return 9 }
24 if j.count != 1 { return 10 }
25
26 // 4: read back
27 let e: *NxEvictEntry = nx_evict_at(j, 0)
28 if e.ts_us != 12345 { return 11 }
29 if e.cell_id != 42 { return 12 }
30 if e.reason != NX_EVR_BUDGET_DENIED { return 13 }
31 if e.displaced_by != 99 { return 14 }
32
33 // 5: bad reason rejected
34 let rc_bad: nx_int = nx_evict_log(j, 1, 1, 99, 0, 0, 0)
35 if rc_bad != 1 { return 15 }
36
37 // 6: out-of-range nx_evict_at returns NULL
38 let none: *NxEvictEntry = nx_evict_at(j, 99)
39 if (none as i64) != 0 { return 16 }
40
41 // 7: count for specific cell
42 nx_evict_log(j, 1, 7, NX_EVR_MIGRATED, 0, 3, 0)
43 nx_evict_log(j, 2, 7, NX_EVR_YIELD_DEMOTED, 2, 3, 0)
44 nx_evict_log(j, 3, 8, NX_EVR_TERMINATED, 0, 3, 7)
45 nx_evict_log(j, 4, 7, NX_EVR_YIELD_THROTTLED, 2, 3, 0)
46 if nx_evict_count_for_cell(j, 7) != 3 { return 17 }
47 if nx_evict_count_for_cell(j, 8) != 1 { return 18 }
48 if nx_evict_count_for_cell(j, 99) != 0 { return 19 }
49
50 // 8: ring wraps cleanly
51 var k: nx_int = 0
52 while k < 10 {
53 nx_evict_log(j, k, 1, NX_EVR_BUDGET_DENIED, 0, 0, 0)
54 k = k + 1
55 }
56 if j.head >= j.capacity { return 20 }
57 if j.count != 15 { return 21 } // 5 prior + 10 here
58
59 return 0
60}