Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/rx/test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / rx / test.om` 331 lines ยท 8689 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/rx/test.om: comprehensive positive & negative-control test suite for gpu/rx (regulate + skillroute). 3 note Compose: si/directives/om2.om gpu/rx/regulate.om gpu/rx/skillroute.om gpu/rx/test.om 4 5 text t_ok1 "PASS rx_regulate envelope validation + negative controls (8/8)\n" 6 text t_ok2 "PASS rx_regulate hysteresis, dwell, PROTECT precedence & idempotency\n" 7 text t_ok3 "PASS rx_regulate authority-independent apply, fairness & halt refusal\n" 8 text t_ok4 "PASS sr_route admissibility-before-ranking, local_only, pins & SR_WHY\n" 9 text t_ok5 "PASS sr_route_check fail-closed revalidation (WITHDRAWN, UNAVAILABLE, STALE, MACHINE)\n" 10 text t_all "ALL PASS gpu-rx\n" 11 text t_fail "FAIL gpu-rx\n" 12 13 fn rx_puts s view uchar * to void 14 k = write 1 s 0 len s 15 if lt k 0 16 exit 2 17 end 18 ret 19 end 20 21 fn test_reg_envelope to int 22 e = new RxEnv 2 8 1024 4096 100 500 80 30 90 60 3 23 base = new RxBudget 4 2048 250 16 1 24 if ne rx_regulate_envelope_ok view e view base RX_OK 25 ret 1 26 end 27 note negative controls: smin=0, smin>smax, base outside, clo>=chi, phi>100, dwell=0 28 put e smin uint 0 29 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 30 ret 2 31 end 32 put e smin uint 10 33 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 34 ret 3 35 end 36 put e smin uint 2 37 put base slots uint 9 38 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 39 ret 4 40 end 41 put base slots uint 4 42 put e clo ulong 80 43 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 44 ret 5 45 end 46 put e clo ulong 30 47 put e phi ulong 101 48 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 49 ret 6 50 end 51 put e phi ulong 90 52 put e dwell ulong 0 53 if ne rx_regulate_envelope_ok view e view base RX_ERR_ARG 54 ret 7 55 end 56 ret 0 57 end 58 59 fn test_reg_hysteresis to int 60 e = new RxEnv 2 8 1024 4096 100 500 80 30 90 60 2 61 base = new RxBudget 4 2048 250 16 1 62 pol = new RxPolicy 1 4 2048 250 0 0 0 0 63 note 1. Contention hits 85 -> immediately enters EXPAND (ver=2, slots=8, flips=1) 64 if ne rx_regulate_step view e view base edit pol 1 85 10 RX_OK 65 ret 10 66 end 67 if or ne get pol regime ulong RX_REG_EXPAND ne get pol slots 8 68 ret 11 69 end 70 note 2. Idempotent re-run on same cseq=1 -> RX_NOOP, dwell unchanged 71 if ne rx_regulate_step view e view base edit pol 1 0 0 RX_NOOP 72 ret 12 73 end 74 note 3. Contention drops to 10 (<= clo=30), but dwell=0 < min_dwell=2 -> stays EXPAND, dwell=1 75 if ne rx_regulate_step view e view base edit pol 2 10 10 RX_OK 76 ret 13 77 end 78 if or ne get pol regime ulong RX_REG_EXPAND ne get pol dwell 1 79 ret 14 80 end 81 note 4. Contention=10 again, dwell=1 < 2 -> stays EXPAND, dwell=2 82 if ne rx_regulate_step view e view base edit pol 3 10 10 RX_OK 83 ret 15 84 end 85 if or ne get pol regime ulong RX_REG_EXPAND ne get pol dwell 2 86 ret 16 87 end 88 note 5. Contention=50 (in dead band > clo=30), dwell=2 -> stays EXPAND (anti-chatter) 89 if ne rx_regulate_step view e view base edit pol 4 50 10 RX_OK 90 ret 17 91 end 92 if ne get pol regime ulong RX_REG_EXPAND 93 ret 18 94 end 95 note 6. Pressure spikes to 95 while contention=90 -> PROTECT wins immediately over EXPAND! 96 if ne rx_regulate_step view e view base edit pol 5 90 95 RX_OK 97 ret 19 98 end 99 if or ne get pol regime ulong RX_REG_PROTECT ne get pol slots 2 100 ret 20 101 end 102 note 7. Pressure drops to 40, needs dwell=2 to leave PROTECT -> enters NOMINAL on seq 8 103 if ne rx_regulate_step view e view base edit pol 6 10 40 RX_OK 104 ret 21 105 end 106 if ne rx_regulate_step view e view base edit pol 7 10 40 RX_OK 107 ret 22 108 end 109 if ne get pol regime ulong RX_REG_PROTECT 110 ret 23 111 end 112 if ne rx_regulate_step view e view base edit pol 8 10 40 RX_OK 113 ret 24 114 end 115 if or ne get pol regime ulong RX_REG_NOMINAL ne get pol slots 4 116 ret 25 117 end 118 ret 0 119 end 120 121 fn test_reg_apply to int 122 e = new RxEnv 2 8 1024 4096 100 500 80 30 90 60 2 123 base = new RxBudget 4 2048 250 42 7 124 pol = new RxPolicy 1 8 4096 500 1 1 0 1 125 st = new RxRegState 0 0 0 126 app = new RxBudget 0 0 0 0 0 127 note 1. Valid apply installs EXPAND budget and preserves base fairness (starv=42, loc=7) 128 if ne rx_regulate_apply view e view base view pol edit st edit app RX_OK 129 ret 30 130 end 131 if or ne get app slots 8 ne get app starv 42 132 ret 31 133 end 134 if ne get app loc 7 135 ret 32 136 end 137 note 2. Re-applying same version -> RX_NOOP 138 if ne rx_regulate_apply view e view base view pol edit st edit app RX_NOOP 139 ret 33 140 end 141 note 3. Tampered policy (slots=99 > smax=8) -> RX_ERR_BOUNDS, applied budget untouched, refused=1 142 put pol ver ulong 2 143 put pol slots ulong 99 144 if ne rx_regulate_apply view e view base view pol edit st edit app RX_ERR_BOUNDS 145 ret 34 146 end 147 if or ne get app slots 8 ne get st refused 1 148 ret 35 149 end 150 note 4. Invalid regime=9 -> RX_ERR_BOUNDS 151 put pol slots ulong 4 152 put pol regime ulong 9 153 if ne rx_regulate_apply view e view base view pol edit st edit app RX_ERR_BOUNDS 154 ret 36 155 end 156 note 5. Emergency stop halted=1 -> RX_ERR_HALTED, budget untouched 157 put pol regime ulong 0 158 put st halted int 1 159 if ne rx_regulate_apply view e view base view pol edit st edit app RX_ERR_HALTED 160 ret 37 161 end 162 if or ne get app slots 8 ne get st refused 3 163 ret 38 164 end 165 ret 0 166 end 167 168 fn test_sr_routing to int 169 sr_reset 170 note Machines: 1=local self, 2=remote leased until t=1000, 3=remote expired at t=100 171 if ne sr_add_machine 1 1 1 0 SR_OK 172 ret 40 173 end 174 if ne sr_add_machine 2 0 1 1000 SR_OK 175 ret 41 176 end 177 if ne sr_add_machine 3 0 1 100 SR_OK 178 ret 42 179 end 180 note Local executables: skill 10 (digest 0xaa,0xbb), skill 20 (digest 0x11,0x22) 181 if ne sr_add_exec 10 0xaa 0xbb SR_OK 182 ret 43 183 end 184 if ne sr_add_exec 20 0x11 0x22 SR_OK 185 ret 44 186 end 187 note Entry 0: cheapest (lat=5) local skill 10, BUT digest mismatch -> inadmissible! 188 e0 = sr_add_entry 7 10 1 1 5 5 189 sr_set_entry_digest ulong e0 0xdead 0xbeef 190 note Entry 1: cheap (lat=10) remote skill 30 on machine 2 (leased) 191 e1 = sr_add_entry 7 30 1 2 10 10 192 sr_set_entry_digest ulong e1 0x33 0x44 193 note Entry 2: local skill 20 (lat=20) with matching digest -> admissible local! 194 e2 = sr_add_entry 7 20 2 1 20 20 195 sr_set_entry_digest ulong e2 0x11 0x22 196 note Entry 3: remote skill 40 on expired machine 3 (lat=1) -> inadmissible (GONE) 197 e3 = sr_add_entry 7 40 1 3 1 1 198 sr_set_entry_digest ulong e3 0x55 0x66 199 200 rt = new SrRoute 0 -1 0 0 0 0 0 0 0 201 note 1. local_only=0 at now_us=500 -> remote skill 30 (lat=10) beats local skill 20 (lat=20) -> SR_E_REMOTE 202 req = new SrReq 7 1 0 0 0 0 0 0 0 203 if ne sr_route view req 500 edit rt SR_E_REMOTE 204 ret 45 205 end 206 if or ne get rt skill_id 30 ne get rt remote 1 207 ret 46 208 end 209 if ne get rt n_adm 2 210 ret 47 211 end 212 note 2. local_only=1 -> remote refused, local skill 20 wins (SR_OK); cheaper digest-mismatched e0 did not hide it! 213 put req local_only int 1 214 if ne sr_route view req 500 edit rt SR_OK 215 ret 48 216 end 217 if or ne get rt skill_id 20 ne get rt remote 0 218 ret 49 219 end 220 if eq and get rt why SR_WHY_DIGEST 0 221 ret 50 222 end 223 if eq and get rt why SR_WHY_REMOTE_REFUSED 0 224 ret 51 225 end 226 note 3. Pin unknown machine 99 -> SR_E_MACHINE 227 put req local_only int 0 228 put req pin_mset int 1 229 put req pin_mid uint 99 230 if ne sr_route view req 500 edit rt SR_E_MACHINE 231 ret 52 232 end 233 note 4. Pin version=99 (none match) -> SR_E_NO_CANDIDATE with SR_WHY_PIN 234 put req pin_mset int 0 235 put req pin_ver uint 99 236 if ne sr_route view req 500 edit rt SR_E_NO_CANDIDATE 237 ret 53 238 end 239 if eq and get rt why SR_WHY_PIN 0 240 ret 54 241 end 242 ret 0 243 end 244 245 fn test_sr_revalidate to int 246 sr_reset 247 rc = sr_add_machine 1 1 1 0 248 rc = sr_add_machine 2 0 1 1000 249 rc = sr_add_exec 20 0x11 0x22 250 e0 = sr_add_entry 9 20 2 1 15 15 251 sr_set_entry_digest ulong e0 0x11 0x22 252 e1 = sr_add_entry 9 30 1 2 10 10 253 sr_set_entry_digest ulong e1 0x33 0x44 254 req = new SrReq 9 0 1 0 0 0 0 0 0 255 rt = new SrRoute 0 -1 0 0 0 0 0 0 0 256 if ne sr_route view req 500 edit rt SR_OK 257 ret 60 258 end 259 note 1. Fresh route validates SR_OK 260 if ne sr_route_check view rt 500 SR_OK 261 ret 61 262 end 263 note 2. Local executable digest drifts -> SR_E_STALE 264 put g_ex_dlo 0 ulong 0x9999 265 if ne sr_route_check view rt 500 SR_E_STALE 266 ret 62 267 end 268 put g_ex_dlo 0 ulong 0x11 269 note 3. Entry becomes unavailable -> SR_E_UNAVAILABLE 270 sr_set_entry_flags ulong e0 1 0 1 271 if ne sr_route_check view rt 500 SR_E_UNAVAILABLE 272 ret 63 273 end 274 note 4. Entry withdrawn -> SR_E_WITHDRAWN 275 sr_set_entry_flags ulong e0 0 1 1 276 if ne sr_route_check view rt 500 SR_E_WITHDRAWN 277 ret 64 278 end 279 note 5. Remote route validates before lease expiry and fails SR_E_MACHINE after expiry 280 put req local_only int 0 281 if ne sr_route view req 500 edit rt SR_E_REMOTE 282 ret 65 283 end 284 if ne sr_route_check view rt 999 SR_OK 285 ret 66 286 end 287 if ne sr_route_check view rt 1000 SR_E_MACHINE 288 ret 67 289 end 290 ret 0 291 end 292 293 fn main to int 294 rc = test_reg_envelope 295 if ne rc 0 296 rx_puts t_fail 297 ret rc 298 end 299 rx_puts t_ok1 300 301 rc = test_reg_hysteresis 302 if ne rc 0 303 rx_puts t_fail 304 ret rc 305 end 306 rx_puts t_ok2 307 308 rc = test_reg_apply 309 if ne rc 0 310 rx_puts t_fail 311 ret rc 312 end 313 rx_puts t_ok3 314 315 rc = test_sr_routing 316 if ne rc 0 317 rx_puts t_fail 318 ret rc 319 end 320 rx_puts t_ok4 321 322 rc = test_sr_revalidate 323 if ne rc 0 324 rx_puts t_fail 325 ret rc 326 end 327 rx_puts t_ok5 328 329 rx_puts t_all 330 ret 0 331 end