interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / rx / test.om

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