code wiki / (root) / nx_perf_pathology_test.nx

nx_perf_pathology_test.nx source

↩ module page · 142 lines · 5222 B

1// nx_perf_pathology_test.nx -- KAT for B1 pathology classifier. 2 3import "nx_syscalls.nx" 4import "nx_perf_pathology.nx" 5 6func main() -> i64 { 7 // ----- T1 Sealed-enum completeness ----- 8 var i: i64 = 0 9 while i < NX_PERF_PATH_N { 10 if nx_perf_path_is_valid(i) != 1 { return 1 + i } 11 i = i + 1 12 } 13 if nx_perf_path_is_valid(0 - 1) != 0 { return 100 } 14 if nx_perf_path_is_valid(NX_PERF_PATH_N) != 0 { return 101 } 15 if nx_perf_path_is_valid(9999) != 0 { return 102 } 16 17 // ----- T2 Waste/non-waste partition ----- 18 if nx_perf_path_is_waste(NX_PERF_PATH_OPTIMAL) != 0 { return 110 } 19 if nx_perf_path_is_waste(NX_PERF_PATH_NONE) != 0 { return 111 } 20 if nx_perf_path_is_waste(NX_PERF_PATH_INCONCLUSIVE) != 0 { return 112 } 21 if nx_perf_path_is_waste(NX_PERF_PATH_BOTTLENECK_CPU) != 1 { return 113 } 22 if nx_perf_path_is_waste(NX_PERF_PATH_BLEEDING_LEAKAGE) != 1 { return 114 } 23 if nx_perf_path_is_waste(NX_PERF_PATH_SECOND_CLASS_RESOURCE) != 1 { return 115 } 24 if nx_perf_path_is_waste(NX_PERF_PATH_VENDOR_PAYWALL_HONORED) != 1 { return 116 } 25 26 // ----- Build a signals struct for each scenario ----- 27 let s_buf: *u8 = sys_mmap(256) 28 let s: *NxPerfSignals = s_buf as *NxPerfSignals 29 30 // ----- T3 OPTIMAL: in band, no waste signals ----- 31 nx_perf_signals_init(s) 32 s.cpu_pct = 60 33 s.mem_bw_pct = 40 34 let r3: i64 = nx_perf_classify(s, 1) 35 if r3 != NX_PERF_PATH_OPTIMAL { return 120 } 36 37 // ----- T4 BOTTLENECK_CPU: out of band + CPU saturated ----- 38 nx_perf_signals_init(s) 39 s.cpu_pct = 99 40 s.mem_bw_pct = 10 41 s.io_pct = 5 42 let r4: i64 = nx_perf_classify(s, 0) 43 if r4 != NX_PERF_PATH_BOTTLENECK_CPU { return 130 } 44 45 // ----- T5 BOTTLENECK_MEM_BW: out of band + RAM BW saturated ----- 46 nx_perf_signals_init(s) 47 s.cpu_pct = 40 48 s.mem_bw_pct = 95 49 let r5: i64 = nx_perf_classify(s, 0) 50 if r5 != NX_PERF_PATH_BOTTLENECK_MEM_BW { return 140 } 51 52 // ----- T6 BOTTLENECK_MEM_LAT: out of band + RAM lat saturated ----- 53 nx_perf_signals_init(s) 54 s.mem_lat_pct = 95 55 let r6: i64 = nx_perf_classify(s, 0) 56 if r6 != NX_PERF_PATH_BOTTLENECK_MEM_LAT { return 150 } 57 58 // ----- T7 BOTTLENECK_IO ----- 59 nx_perf_signals_init(s) 60 s.io_pct = 92 61 let r7: i64 = nx_perf_classify(s, 0) 62 if r7 != NX_PERF_PATH_BOTTLENECK_IO { return 160 } 63 64 // ----- T8 BLEEDING_LEAKAGE: growth > 0 dominates ----- 65 nx_perf_signals_init(s) 66 s.cpu_pct = 99 // would be CPU bottleneck if not for leak 67 s.growth_pct_per_min = 5 68 let r8: i64 = nx_perf_classify(s, 1) 69 if r8 != NX_PERF_PATH_BLEEDING_LEAKAGE { return 170 } 70 71 // ----- T9 LATENCY_SPIKE: tail p99/p50 >= 10x ----- 72 nx_perf_signals_init(s) 73 s.tail_p99_over_p50 = 1500 // 15x tail 74 let r9: i64 = nx_perf_classify(s, 1) 75 if r9 != NX_PERF_PATH_LATENCY_SPIKE { return 180 } 76 77 // ----- T10 SECOND_CLASS_RESOURCE: conductor cardinal ----- 78 nx_perf_signals_init(s) 79 s.second_class_idle_count = 3 80 s.gpu_pct = 95 81 s.cpu_pct = 5 82 s.mem_bw_pct = 3 83 s.io_pct = 2 84 let r10: i64 = nx_perf_classify(s, 1) 85 if r10 != NX_PERF_PATH_SECOND_CLASS_RESOURCE { return 190 } 86 87 // ----- T11 VENDOR_PAYWALL_HONORED: reclamation cardinal ----- 88 nx_perf_signals_init(s) 89 s.paywall_responsive = 1 90 let r11: i64 = nx_perf_classify(s, 1) 91 if r11 != NX_PERF_PATH_VENDOR_PAYWALL_HONORED { return 200 } 92 93 // ----- T12 SINGLE_ARCH_OVERFIT: cross-arch ratio > 2x ----- 94 nx_perf_signals_init(s) 95 s.isa_overfit_ratio = 800 // 8x worse on the other ISA 96 s.cpu_pct = 99 // would be CPU bottleneck if not for ISA overfit 97 let r12: i64 = nx_perf_classify(s, 1) 98 if r12 != NX_PERF_PATH_SINGLE_ARCH_OVERFIT { return 210 } 99 100 // ----- T13 TOO_FEW_STEPS: out of band + no resource saturated ----- 101 nx_perf_signals_init(s) 102 s.cpu_pct = 30 103 s.mem_bw_pct = 20 104 s.io_pct = 5 105 let r13: i64 = nx_perf_classify(s, 0) 106 if r13 != NX_PERF_PATH_TOO_FEW_STEPS { return 220 } 107 108 // ----- T14 Priority order: SINGLE_ARCH > PAYWALL > SECOND_CLASS ----- 109 nx_perf_signals_init(s) 110 s.isa_overfit_ratio = 500 111 s.paywall_responsive = 1 112 s.second_class_idle_count = 3 113 let r14: i64 = nx_perf_classify(s, 1) 114 if r14 != NX_PERF_PATH_SINGLE_ARCH_OVERFIT { return 230 } 115 116 nx_perf_signals_init(s) 117 s.paywall_responsive = 1 118 s.second_class_idle_count = 3 119 let r14b: i64 = nx_perf_classify(s, 1) 120 if r14b != NX_PERF_PATH_VENDOR_PAYWALL_HONORED { return 231 } 121 122 // ----- T15 Priority: BLEEDING > LATENCY ----- 123 nx_perf_signals_init(s) 124 s.growth_pct_per_min = 1 125 s.tail_p99_over_p50 = 2000 126 let r15: i64 = nx_perf_classify(s, 1) 127 if r15 != NX_PERF_PATH_BLEEDING_LEAKAGE { return 240 } 128 129 // ----- T16 isa_overfit at 200 is borderline (= not overfit; strictly > 200) ----- 130 nx_perf_signals_init(s) 131 s.isa_overfit_ratio = 200 132 s.cpu_pct = 60 133 let r16: i64 = nx_perf_classify(s, 1) 134 if r16 != NX_PERF_PATH_OPTIMAL { return 250 } 135 // 201 triggers 136 nx_perf_signals_init(s) 137 s.isa_overfit_ratio = 201 138 let r16b: i64 = nx_perf_classify(s, 1) 139 if r16b != NX_PERF_PATH_SINGLE_ARCH_OVERFIT { return 251 } 140 141 return 0 142}