code wiki / (root) / nx_chunk_paginate_test.nx

nx_chunk_paginate_test.nx source

↩ module page · 58 lines · 2159 B

1// nx_chunk_paginate_test.nx -- smoke for nx_chunk_paginate. 2 3import "nx_syscalls.nx" 4import "nx_palette.nx" 5import "nx_tissue.nx" 6import "nx_chunk_paginate.nx" 7 8func main() -> i64 { 9 // 4-slot LRU cache 10 let p: *NxChunkPaginator = nx_chunk_paginator_new(4) 11 if p.capacity != 4 { return 1 } 12 if p.n_loaded != 0 { return 2 } 13 if nx_chunk_hit_count(p) != 0 { return 3 } 14 if nx_chunk_miss_count(p) != 0 { return 4 } 15 16 // Allocate 5 distinct tissues to test eviction 17 let t1: *NxTissue = nx_tissue_new(4, 4, 4, NX_BPP_3) 18 let t2: *NxTissue = nx_tissue_new(4, 4, 4, NX_BPP_3) 19 let t3: *NxTissue = nx_tissue_new(4, 4, 4, NX_BPP_3) 20 let t4: *NxTissue = nx_tissue_new(4, 4, 4, NX_BPP_3) 21 let t5: *NxTissue = nx_tissue_new(4, 4, 4, NX_BPP_3) 22 23 let verdict: *i64 = (sys_mmap(8)) as *i64 24 25 // 4 MISSes fill the cache 26 nx_chunk_request(p, 101, t1, 1000, verdict) 27 if verdict[0] != NX_CP_CACHE_MISS { return 5 } 28 nx_chunk_request(p, 102, t2, 1100, verdict) 29 nx_chunk_request(p, 103, t3, 1200, verdict) 30 nx_chunk_request(p, 104, t4, 1300, verdict) 31 if p.n_loaded != 4 { return 6 } 32 if nx_chunk_miss_count(p) != 4 { return 7 } 33 if nx_chunk_evict_count(p) != 0 { return 8 } 34 35 // Re-request 101 -> HIT, updates LRU 36 nx_chunk_request(p, 101, t1, 1400, verdict) 37 if verdict[0] != NX_CP_CACHE_HIT { return 9 } 38 if nx_chunk_hit_count(p) != 1 { return 10 } 39 40 // 5th distinct chunk -> MISS, evicts LRU (102 -- 101 was just touched) 41 nx_chunk_request(p, 105, t5, 1500, verdict) 42 if verdict[0] != NX_CP_CACHE_MISS { return 11 } 43 if nx_chunk_evict_count(p) != 1 { return 12 } 44 // 102 should now be GONE; 101/103/104/105 loaded 45 if nx_chunk_is_loaded(p, 101) != 1 { return 13 } 46 if nx_chunk_is_loaded(p, 102) != 0 { return 14 } 47 if nx_chunk_is_loaded(p, 103) != 1 { return 15 } 48 if nx_chunk_is_loaded(p, 104) != 1 { return 16 } 49 if nx_chunk_is_loaded(p, 105) != 1 { return 17 } 50 51 // Hit rate 52 let total_q10: nx_int = nx_chunk_hit_rate_q10(p) 53 // 1 hit, 5 misses -> 1/6 = 170 Q10 54 if total_q10 > 200 { return 18 } 55 if total_q10 < 100 { return 19 } 56 57 return 0 58}