code wiki / (root) / nx_gather_journal_test.nx

nx_gather_journal_test.nx source

↩ module page · 79 lines · 3245 B

1// nx_gather_journal_test.nx -- smoke for nx_gather_journal + session-audit. 2 3import "nx_syscalls.nx" 4import "nx_gatherer.nx" 5import "nx_hunter.nx" 6import "nx_hunt_journal.nx" 7import "nx_gather_journal.nx" 8 9func main() -> i64 { 10 // 1: kind enum 11 if NX_GEV_N_KINDS != 4 { return 1 } 12 if nx_gev_kind_is_valid(NX_GEV_HARVESTED) != 1 { return 2 } 13 if nx_gev_kind_is_valid(4) != 0 { return 3 } 14 15 // 2: empty journal 16 let g: *NxGatherJournalRing = nx_gather_journal_new(16) 17 if nx_gather_journal_event_count(g) != 0 { return 4 } 18 19 // 3: log sown + harvested 20 nx_gather_journal_log(g, 1000, 10, NX_GEV_SOWN, 21 NX_GFK_PRIMITIVE, NX_GYK_N_KINDS, 0) 22 nx_gather_journal_log(g, 1100, 10, NX_GEV_HARVESTED, 23 NX_GFK_PRIMITIVE, NX_GYK_MS_SAVED, 200) 24 nx_gather_journal_log(g, 1200, 20, NX_GEV_SOWN, 25 NX_GFK_SMOKE, NX_GYK_N_KINDS, 0) 26 if nx_gather_journal_event_count(g) != 3 { return 5 } 27 28 // 4: count by kind 29 if nx_gather_journal_count_kind(g, NX_GEV_SOWN) != 2 { return 6 } 30 if nx_gather_journal_count_kind(g, NX_GEV_HARVESTED) != 1 { return 7 } 31 if nx_gather_journal_count_kind(g, NX_GEV_COMPOSTED) != 0 { return 8 } 32 33 // 5: session-audit gate -- valid when both journals have events 34 let hj: *NxHuntJournalRing = nx_hunt_journal_new(16) 35 if nx_session_audit_valid(hj, g) != 0 { return 9 } // hunt empty 36 nx_hunt_journal_log(hj, 1300, 100, NX_HEV_SCOUTED, 37 NX_HK_BUG_CLASS, NX_KP_NONE) 38 if nx_session_audit_valid(hj, g) != 1 { return 10 } // both have events 39 40 // 6: imbalance ratio -- 1 hunt : 3 gather -> Q10 256. 41 // 256 within balanced band [171, 853] -> NOT imbalanced. 42 let q10: nx_int = nx_session_imbalance_q10(hj, g) 43 if q10 != 256 { return 11 } 44 if nx_session_is_imbalanced(hj, g) != 0 { return 12 } 45 if q10 < 171 { return 13 } 46 47 // 7: extreme imbalance -- 10 hunts vs 0 gather -> Q10 1024 = above 853 48 let hj2: *NxHuntJournalRing = nx_hunt_journal_new(16) 49 let gj2: *NxGatherJournalRing = nx_gather_journal_new(16) 50 var i: nx_int = 0 51 while i < 10 { 52 nx_hunt_journal_log(hj2, 1000 + i, i, NX_HEV_SCOUTED, 53 NX_HK_BUG_CLASS, NX_KP_NONE) 54 i = i + 1 55 } 56 // 10 hunts, 0 gather -- session is invalid (gather_count == 0) 57 if nx_session_audit_valid(hj2, gj2) != 0 { return 14 } 58 59 // 8: 5x ratio: 5 hunts : 1 gather -> q10 (5*1024)/6 = 853. Should be imbalanced at boundary. 60 let hj3: *NxHuntJournalRing = nx_hunt_journal_new(16) 61 let gj3: *NxGatherJournalRing = nx_gather_journal_new(16) 62 var k: nx_int = 0 63 while k < 5 { 64 nx_hunt_journal_log(hj3, 2000 + k, k, NX_HEV_SCOUTED, 65 NX_HK_BUG_CLASS, NX_KP_NONE) 66 k = k + 1 67 } 68 nx_gather_journal_log(gj3, 3000, 50, NX_GEV_SOWN, 69 NX_GFK_PRIMITIVE, NX_GYK_N_KINDS, 0) 70 // 5/(5+1) = 0.833 Q10 853. Boundary is "> 853" so 853 itself is NOT imbalanced. 71 // Let me extend to 6/1 = 6/7 = q10 877 to clearly trigger imbalance. 72 nx_hunt_journal_log(hj3, 2500, 99, NX_HEV_SCOUTED, 73 NX_HK_BUG_CLASS, NX_KP_NONE) 74 let q10_imb: nx_int = nx_session_imbalance_q10(hj3, gj3) 75 if q10_imb <= 853 { return 15 } 76 if nx_session_is_imbalanced(hj3, gj3) != 1 { return 16 } 77 78 return 0 79}