code wiki / (root) / nx_safety_critical_grade_test.nx

nx_safety_critical_grade_test.nx source

↩ module page · 59 lines · 3103 B

1// nx_safety_critical_grade_test.nx -- smoke for the 8th grader. 2// 3// Exercises the 4 lexical-scan axes (bounded_loop / assertion_density 4// / sealed_enum / soup_purity) against KNOWN input strings. Verifies 5// the 4 queued axes (mcdc / fault_inj / hazard_reg / iv_and_v) all 6// return NX_SC_VERDICT_UNMEASURED. 7// 8// Requires nxc.elf built with the parser extension that supports 9// &card.field chains (commit 6bdc738f). The C-anchor nxc2.exe will 10// reject this file -- expected per cardinal feedback-no-nxc2-c- 11// extension-only-nishilang-forward. 12 13import "nx_syscalls.nx" 14import "nx_runtime.nx" 15import "nx_types.nx" 16import "nx_tier.nx" 17import "nx_safety_critical_grade.nx" 18 19func main() -> i64 { 20 let card: *SafetyCard = nx_safety_critical_card_alloc() 21 22 // T1: clean input -- bounded loop with iter < BUDGET, dense 23 // assertions, sealed enum constants, license_tier header. 24 // Should hit WIN on the 4 lexical axes. 25 let clean: *u8 = "// license_tier: ORIGINAL\nimport \"nx_syscalls.nx\"\nconst NX_FOO_A: nx_int = 0\nconst NX_FOO_B: nx_int = 1\nconst NX_FOO_C: nx_int = 2\nfunc f() -> i64 { var iter: i64 = 0; while iter < 10 { iter = iter + 1 }; if iter < 0 { return __syscall(93, 1, 0, 0, 0, 0, 0) }; return 0 }\n" as *u8 26 var clen: i64 = 0 27 while clean[clen] != 0 { clen = clen + 1 } 28 nx_safety_critical_scan(clean, clen, card) 29 30 if card.axis_bounded_loop.verdict != NX_SC_VERDICT_WIN { return 10 } 31 if card.axis_assertion.verdict != NX_SC_VERDICT_WIN { return 11 } 32 if card.axis_sealed_enum.verdict != NX_SC_VERDICT_WIN { return 12 } 33 if card.axis_soup_purity.verdict != NX_SC_VERDICT_WIN { return 13 } 34 if card.axis_mcdc.verdict != NX_SC_VERDICT_UNMEASURED { return 14 } 35 if card.axis_fault_inj.verdict != NX_SC_VERDICT_UNMEASURED { return 15 } 36 if card.axis_hazard_reg.verdict != NX_SC_VERDICT_UNMEASURED { return 16 } 37 if card.axis_iv_and_v.verdict != NX_SC_VERDICT_UNMEASURED { return 17 } 38 // Overall = WIN (lose==0, unmeasured>0 -> not WIN_S, just WIN). 39 if card.overall_verdict != NX_SC_VERDICT_WIN { return 18 } 40 41 // T2: anti-pattern input -- sentinel-flag loop, no license_tier, 42 // no assertions, no sealed-enum constants. Should hit LOSE on 43 // bounded_loop + soup_purity, LOSE on assertion_density (no 44 // asserts but has func decl), UNMEASURED on sealed_enum (no 45 // const NX_), UNMEASURED on the queued 4. 46 let dirty: *u8 = "func g() -> i64 { var keep: nx_int = 1; while keep == 1 { keep = 0 }; return 0 }\n" as *u8 47 var dlen: i64 = 0 48 while dirty[dlen] != 0 { dlen = dlen + 1 } 49 let card2: *SafetyCard = nx_safety_critical_card_alloc() 50 nx_safety_critical_scan(dirty, dlen, card2) 51 52 if card2.axis_bounded_loop.verdict != NX_SC_VERDICT_LOSE { return 20 } 53 if card2.axis_assertion.verdict != NX_SC_VERDICT_LOSE { return 21 } 54 if card2.axis_sealed_enum.verdict != NX_SC_VERDICT_UNMEASURED { return 22 } 55 if card2.axis_soup_purity.verdict != NX_SC_VERDICT_LOSE { return 23 } 56 if card2.overall_verdict != NX_SC_VERDICT_LOSE { return 24 } 57 58 return 0 59}