code wiki / (root) / nx_seed_test.nx

nx_seed_test.nx source

↩ module page · 145 lines · 7092 B

1// nx_seed_test.nx -- smoke for nx_seed. 2 3import "nx_syscalls.nx" 4import "nx_seed.nx" 5 6func main() -> i64 { 7 let now: nx_size = 1000 8 9 // 1: bundle enum validity 10 if nx_ob_bundle_is_valid(NX_OB_MINIMAL_CORE) != 1 { return 1 } 11 if nx_ob_bundle_is_valid(NX_OB_3DPRINTER_CNC_LASER) != 1 { return 2 } 12 if nx_ob_bundle_is_valid(-1) != 0 { return 3 } 13 if nx_ob_bundle_is_valid(10) != 0 { return 4 } 14 if NX_OB_N_BUNDLES != 10 { return 5 } 15 16 // 2: state enum validity 17 if nx_se_state_is_valid(NX_SE_PENDING_NICHE) != 1 { return 6 } 18 if nx_se_state_is_valid(NX_SE_FAILED) != 1 { return 7 } 19 if nx_se_state_is_valid(-1) != 0 { return 8 } 20 if nx_se_state_is_valid(7) != 0 { return 9 } 21 22 // 3: verdict enum validity 23 if nx_se_v_is_valid(NX_SE_V_OK) != 1 { return 10 } 24 if nx_se_v_is_valid(NX_SE_V_REFUSED_NICHE) != 1 { return 11 } 25 if nx_se_v_is_valid(-1) != 0 { return 12 } 26 if nx_se_v_is_valid(7) != 0 { return 13 } 27 28 // 4: safety-gate predicates 29 if nx_ob_requires_safety_gate(NX_OB_MEDICAL_SAFETY_GATED) != 1 { return 14 } 30 if nx_ob_requires_safety_gate(NX_OB_AUTOMOTIVE_SAFETY_CRITICAL) != 1 { return 15 } 31 if nx_ob_requires_safety_gate(NX_OB_INDUSTRIAL_REALTIME) != 1 { return 16 } 32 if nx_ob_requires_safety_gate(NX_OB_3DPRINTER_CNC_LASER) != 1 { return 17 } 33 if nx_ob_requires_safety_gate(NX_OB_WORKSTATION_FULL) != 0 { return 18 } 34 if nx_ob_requires_safety_gate(NX_OB_LAPTOP_BATTERY_AWARE) != 0 { return 19 } 35 36 // 5: niche-to-bundle mapping 37 if nx_ob_select_for_niche(0) != NX_OB_WORKSTATION_FULL { return 20 } // GAMING 38 if nx_ob_select_for_niche(1) != NX_OB_WORKSTATION_FULL { return 21 } // DEV 39 if nx_ob_select_for_niche(2) != NX_OB_LAPTOP_BATTERY_AWARE { return 22 } // LAPTOP 40 if nx_ob_select_for_niche(3) != NX_OB_NAS_STORAGE_HEAVY { return 23 } // NAS 41 if nx_ob_select_for_niche(5) != NX_OB_SMARTPHONE_RADIO_AWARE { return 24 } 42 if nx_ob_select_for_niche(7) != NX_OB_3DPRINTER_CNC_LASER { return 25 } // 3D 43 if nx_ob_select_for_niche(10) != NX_OB_INDUSTRIAL_REALTIME { return 26 } // ARM 44 if nx_ob_select_for_niche(20) != NX_OB_MEDICAL_SAFETY_GATED { return 27 } 45 if nx_ob_select_for_niche(30) != NX_OB_AUTOMOTIVE_SAFETY_CRITICAL { return 28 } 46 if nx_ob_select_for_niche(40) != NX_OB_IOT_LIGHTWEIGHT { return 29 } // SENSOR 47 if nx_ob_select_for_niche(99) != NX_OB_MINIMAL_CORE { return 30 } // unknown 48 49 // 6: lifecycle target days (sanity check ordering) 50 let work_days: nx_int = nx_ob_expected_lifecycle_days(NX_OB_WORKSTATION_FULL) 51 let lap_days: nx_int = nx_ob_expected_lifecycle_days(NX_OB_LAPTOP_BATTERY_AWARE) 52 let phone_days: nx_int = nx_ob_expected_lifecycle_days(NX_OB_SMARTPHONE_RADIO_AWARE) 53 let iot_days: nx_int = nx_ob_expected_lifecycle_days(NX_OB_IOT_LIGHTWEIGHT) 54 let ind_days: nx_int = nx_ob_expected_lifecycle_days(NX_OB_INDUSTRIAL_REALTIME) 55 if work_days != 2190 { return 31 } 56 if lap_days != 1825 { return 32 } 57 if phone_days != 1095 { return 33 } 58 if iot_days != 3650 { return 34 } 59 if ind_days != 5475 { return 35 } 60 // Ordering: industrial > IoT > NAS > workstation > laptop > phone 61 if ind_days <= iot_days { return 36 } 62 if iot_days <= work_days { return 37 } 63 if work_days <= lap_days { return 38 } 64 if lap_days <= phone_days { return 39 } 65 66 // 7: thermal budget watts 67 let work_w: nx_int = nx_ob_thermal_budget_w(NX_OB_WORKSTATION_FULL) 68 let iot_w: nx_int = nx_ob_thermal_budget_w(NX_OB_IOT_LIGHTWEIGHT) 69 if work_w != 65 { return 40 } 70 if iot_w != 1 { return 41 } 71 72 // 8: fresh assembly defaults 73 let a: *NxSeedAssembly = nx_se_assembly_new(0, 6) // GAMING + COMMODITY_INTEL 74 if a.niche != 0 { return 42 } 75 if a.silicon_trust_level != 6 { return 43 } 76 if a.state != NX_SE_PENDING_NICHE { return 44 } 77 78 // 9: select bundle from niche 79 let v1: nx_int = nx_se_assembly_select_bundle(a, now) 80 if v1 != NX_SE_V_OK { return 45 } 81 if a.bundle != NX_OB_WORKSTATION_FULL { return 46 } 82 if a.state != NX_SE_BUNDLE_SELECTED { return 47 } 83 if a.expected_lifecycle_days != 2190 { return 48 } 84 if a.thermal_budget_w != 65 { return 49 } 85 if a.requires_safety_gate != 0 { return 50 } 86 87 // 10: refused niche -> REFUSED_NICHE 88 let a_refused: *NxSeedAssembly = nx_se_assembly_new(50, 0) // WEAPONS_PLATFORM 89 let v_ref: nx_int = nx_se_assembly_select_bundle(a_refused, now) 90 if v_ref != NX_SE_V_REFUSED_NICHE { return 51 } 91 92 let a_refused2: *NxSeedAssembly = nx_se_assembly_new(53, 0) // HUMAN_RIGHTS_VIOLATION 93 let v_ref2: nx_int = nx_se_assembly_select_bundle(a_refused2, now) 94 if v_ref2 != NX_SE_V_REFUSED_NICHE { return 52 } 95 96 // 11: medical niche -> safety-gate required 97 let a_med: *NxSeedAssembly = nx_se_assembly_new(20, 6) // MEDICAL_DIAGNOSTIC 98 nx_se_assembly_select_bundle(a_med, now) 99 if a_med.bundle != NX_OB_MEDICAL_SAFETY_GATED { return 53 } 100 if a_med.requires_safety_gate != 1 { return 54 } 101 102 // 12: advance through state machine 103 let v_trust: nx_int = nx_se_assembly_advance(a, NX_SE_TRUST_GATED, now + 10) 104 if v_trust != NX_SE_V_OK { return 55 } 105 if a.state != NX_SE_TRUST_GATED { return 56 } 106 107 let v_fetch: nx_int = nx_se_assembly_advance(a, NX_SE_FETCHING_ORGANELLES, now + 20) 108 if v_fetch != NX_SE_V_OK { return 57 } 109 let v_verif: nx_int = nx_se_assembly_advance(a, NX_SE_VERIFYING_ORGANELLES, now + 30) 110 if v_verif != NX_SE_V_OK { return 58 } 111 let v_done: nx_int = nx_se_assembly_advance(a, NX_SE_ASSEMBLED, now + 40) 112 if v_done != NX_SE_V_OK { return 59 } 113 if a.state != NX_SE_ASSEMBLED { return 60 } 114 if a.assembled_at_us != now + 40 { return 61 } 115 116 // 13: complete predicate 117 if nx_se_assembly_is_complete(a) != 1 { return 62 } 118 if nx_se_assembly_is_complete(a_med) != 0 { return 63 } 119 120 // 14: cannot advance from terminal state 121 let bad_term: nx_int = nx_se_assembly_advance(a, NX_SE_PENDING_NICHE, now + 50) 122 if bad_term != NX_SE_V_ERR_INVALID_TRANSITION { return 64 } 123 124 // 15: invalid skip-transition rejected 125 let a_skip: *NxSeedAssembly = nx_se_assembly_new(0, 6) 126 nx_se_assembly_select_bundle(a_skip, now) 127 // BUNDLE_SELECTED -> FETCHING (must go through TRUST_GATED) -- rejected 128 let v_skip: nx_int = nx_se_assembly_advance(a_skip, NX_SE_FETCHING_ORGANELLES, now) 129 if v_skip != NX_SE_V_ERR_INVALID_TRANSITION { return 65 } 130 131 // 16: failure path -- any state -> FAILED 132 let a_fail: *NxSeedAssembly = nx_se_assembly_new(0, 6) 133 nx_se_assembly_select_bundle(a_fail, now) 134 let v_fail: nx_int = nx_se_assembly_advance(a_fail, NX_SE_FAILED, now + 10) 135 if v_fail != NX_SE_V_OK { return 66 } 136 if a_fail.state != NX_SE_FAILED { return 67 } 137 138 // 17: null input handling 139 let null_a: *NxSeedAssembly = (0 as i64) as *NxSeedAssembly 140 if nx_se_assembly_select_bundle(null_a, now) != NX_SE_V_ERR_NULL_INPUT { return 68 } 141 if nx_se_assembly_advance(null_a, NX_SE_ASSEMBLED, now) != NX_SE_V_ERR_NULL_INPUT { return 69 } 142 if nx_se_assembly_is_complete(null_a) != 0 { return 70 } 143 144 return 0 145}