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 / aienux / net / wire / test_loopback.om

932 lines · 16755 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/net/wire/test_loopback.om: Host loopback integration test for wire_loop.om + omtk.om + tcp.om.
3note Compose:
4note { printf 'om2\n'; cat aienux/net/tcp/tcp.om aienux/net/wire/omtk.om aienux/net/wire/wire_loop.om aienux/net/wire/test_loopback.om; } | seed/out/omc > /tmp/test_loopback
5note Strictly host-only (NOT_RUN on Spark silicon).
6
7note Simulated hardware & peer state
8note sim_g: 0 cntvct, 1 cntfrq, 2 dsb_cnt, 3 kicks, 4 quar_cnt, 5 sem_ready,
9note 6 irq_rc (signed in sim_irq), 7 ver_rc (signed in sim_ver), 8 next_tok,
10note 9 stop_flag, 10 reset_kicks, 11 stage_cnt, 12 last_reset_keep, 13 reclaim_cnt,
11note 14 out_tok (poisoned to 0xFFFFFFFF on mode=0 MODE_PREFILL per Piece 5 #20)
12global sim_g ulong 16
13global sim_irq long 1
14global sim_ver long 1
15
16note Simulated NIC RX queue (Peer -> Spark): 4 slots of 2048 B
17global srx_buf uchar 8192
18global srx_len ulong 4
19global srx_hd ulong 1
20global srx_cnt ulong 1
21
22note Captured TCP payload bytes sent by Spark -> Peer (reassembled from Ttx frames)
23global cap_buf uchar 65536
24global cap_len ulong 1
25global cap_pos ulong 1
26
27note Peer TCP sequence tracking: 0 peer_seq, 1 peer_ack, 2 peer_port, 3 spark_isn, 4 fin_seen
28global peer_st ulong 8
29global pkt_tmp uchar 2048
30global app_tmp uchar 16400
31
32text Tpass "WIRE_LOOP_LOOPBACK PASS cases=18\n"
33text Tfail "WIRE_LOOP_LOOPBACK FAIL case="
34text Tnl "\n"
35global tnum uchar 32
36
37fn tput_num v ulong to void
38i = ulong 32
39while true bound 21
40i = sub i 1
41put tnum i uchar add 48 rem v 10
42v = div v 10
43if eq v 0
44break
45end
46end
47k = write 1 tnum i sub 32 i
48end
49
50fn tfail c ulong to void
51k = write 1 Tfail 0 len Tfail
52tput_num c
53k = write 1 Tnl 0 len Tnl
54exit int c
55end
56
57note ---- Seam implementations required by wire_loop.om ----
58fn wl_cntvct to ulong
59ret get sim_g 0
60end
61
62fn wl_cntfrq to ulong
63ret get sim_g 1
64end
65
66fn wl_dsb_ish to void
67put sim_g 2 add get sim_g 2 1
68end
69
70fn wl_nic_rx to ulong
71cnt = get srx_cnt 0
72if eq cnt 0
73ret 0
74end
75hd = get srx_hd 0
76n = get srx_len hd
77base = mul hd 2048
78i = ulong 0
79while lt i n bound 2048
80put Trx i get srx_buf add base i
81i = add i 1
82end
83put srx_hd 0 rem add hd 1 4
84put srx_cnt 0 sub cnt 1
85ret n
86end
87
88note Helper: read big-endian u16/u32 from Ttx
89fn tx_r16 off ulong to ulong
90a = ulong get Ttx off
91b = ulong get Ttx add off 1
92ret or shl a 8 b
93end
94
95fn tx_r32 off ulong to ulong
96a = tx_r16 off
97b = tx_r16 add off 2
98ret or shl a 16 b
99end
100
101fn tx_cap doff2 ulong dlen ulong to void
102cl = get cap_len 0
103i = ulong 0
104while lt i dlen bound 2048
105if lt add cl i 65536
106put cap_buf add cl i get Ttx add doff2 i
107end
108i = add i 1
109end
110put cap_len 0 add cl dlen
111end
112
113note Capture Spark -> Peer frames from Ttx: track SYN-ACK ISN, TCP payload bytes, and FIN.
114fn wl_nic_tx n ulong to long
115if lt n 54
116ret 0
117end
118if ne tx_r16 12 2048
119ret 0
120end
121if ne ulong get Ttx 23 6
122ret 0
123end
124tot = tx_r16 16
125ihl = mul and ulong get Ttx 14 15 4
126toff = add 14 ihl
127doff = mul shr ulong get Ttx add toff 12 4 4
128fl = ulong get Ttx add toff 13
129seq = tx_r32 add toff 4
130if ne and fl 2 0
131put peer_st 3 seq
132put peer_st 1 and add seq 1 4294967295
133end
134if ne and fl 1 0
135put peer_st 4 1
136end
137if gt tot add ihl doff
138dlen = sub tot add ihl doff
139tx_cap add toff doff dlen
140put peer_st 1 and add seq dlen 4294967295
141end
142ret 0
143end
144
145fn wl_nic_reclaim to void
146put sim_g 13 add get sim_g 13 1
147end
148
149fn wl_q38_reset_kv keep_pos ulong to long
150put sim_g 12 keep_pos
151if gt keep_pos 0
152ret -2
153end
154put sim_g 10 add get sim_g 10 1
155ret 128
156end
157
158fn wl_q38_stage_step tok_in uint kv_pos uint mode uchar to long
159put sim_g 11 add get sim_g 11 1
160if eq mode 0
161put sim_g 14 4294967295
162else
163t = get sim_g 8
164put sim_g 14 t
165put sim_g 8 add t 1
166end
167ret 256
168end
169
170fn wl_q38_verify_step to long
171ret get sim_ver 0
172end
173
174fn wl_q38_read_tok to uint
175ret uint get sim_g 14
176end
177
178fn wl_gpu_kick pb_words uint to long
179put sim_g 3 add get sim_g 3 1
180ret 0
181end
182
183fn wl_gpu_poll to long
184if eq get sim_g 5 0
185ret 0
186end
187ret 1
188end
189
190fn wl_gpu_irq_check to long
191ret get sim_irq 0
192end
193
194fn wl_gpu_quarantine to void
195put sim_g 4 add get sim_g 4 1
196end
197
198fn wl_should_stop to ulong
199ret get sim_g 9
200end
201
202note ---- Peer Ethernet/IPv4/TCP frame builder ----
203fn pw16 off ulong v ulong to void
204put pkt_tmp off uchar and shr v 8 255
205put pkt_tmp add off 1 uchar and v 255
206end
207
208fn pw32 off ulong v ulong to void
209pw16 off and shr v 16 65535
210pw16 add off 2 and v 65535
211end
212
213fn psum off ulong n ulong to ulong
214s = ulong 0
215while ge n 2 bound 1024
216a = ulong get pkt_tmp off
217b = ulong get pkt_tmp add off 1
218s = add s or shl a 8 b
219off = add off 2
220n = sub n 2
221end
222if eq n 1
223s = add s shl ulong get pkt_tmp off 8
224end
225ret s
226end
227
228fn pfold s ulong to ulong
229while gt s 65535 bound 8
230s = add and s 65535 shr s 16
231end
232ret xor s 65535
233end
234
235note Enqueue pkt_tmp[0..n) into Spark's NIC RX ring.
236fn penq n ulong to void
237cnt = get srx_cnt 0
238if ge cnt 4
239tfail 90
240end
241slot = rem add get srx_hd 0 cnt 4
242base = mul slot 2048
243i = ulong 0
244while lt i n bound 2048
245put srx_buf add base i get pkt_tmp i
246i = add i 1
247end
248put srx_len slot n
249put srx_cnt 0 add cnt 1
250end
251
252note Send one TCP segment from Peer (10.0.0.1:peer_port) to Spark (10.0.0.2:18100).
253note Payload bytes come from app_tmp[off..off+dlen).
254fn psend flags ulong off ulong dlen ulong to void
255note Dst MAC = Spark MAC (02:00:00:00:00:02), Src MAC = Peer MAC (02:00:00:00:00:01)
256put pkt_tmp 0 2
257put pkt_tmp 1 0
258put pkt_tmp 2 0
259put pkt_tmp 3 0
260put pkt_tmp 4 0
261put pkt_tmp 5 2
262put pkt_tmp 6 2
263put pkt_tmp 7 0
264put pkt_tmp 8 0
265put pkt_tmp 9 0
266put pkt_tmp 10 0
267put pkt_tmp 11 1
268pw16 12 2048
269note IPv4 header at 14..34
270tot = add 40 dlen
271put pkt_tmp 14 69
272put pkt_tmp 15 0
273pw16 16 tot
274pw16 18 1
275pw16 20 16384
276put pkt_tmp 22 64
277put pkt_tmp 23 6
278pw16 24 0
279pw32 26 167772161
280pw32 30 167772162
281pw16 24 pfold psum 14 20
282note TCP header at 34..54
283pw16 34 get peer_st 2
284pw16 36 18100
285seq = get peer_st 0
286pw32 38 seq
287pw32 42 get peer_st 1
288put pkt_tmp 46 80
289put pkt_tmp 47 uchar and flags 255
290pw16 48 65535
291pw16 50 0
292pw16 52 0
293i = ulong 0
294while lt i dlen bound 1500
295put pkt_tmp add 54 i get app_tmp add off i
296i = add i 1
297end
298tlen = add 20 dlen
299ps = ulong 5123
300ps = add ps add 6 tlen
301ps = add ps psum 34 tlen
302pw16 50 pfold ps
303if ne and flags 2 0
304put peer_st 0 and add seq 1 4294967295
305else
306put peer_st 0 and add seq dlen 4294967295
307end
308flen = add 54 dlen
309if lt flen 60
310j = flen
311while lt j 60 bound 60
312put pkt_tmp j 0
313j = add j 1
314end
315flen = 60
316end
317penq flen
318end
319
320note Send app_tmp[0..n) over TCP in <= 1024 B chunks, ticking wire_loop after each.
321fn psend_data n ulong to void
322off = ulong 0
323while lt off n bound 32
324ch = sub n off
325if gt ch 1024
326ch = 1024
327end
328psend 24 off ch
329wl_tick
330off = add off ch
331end
332end
333
334note Helper: write LE u16/u32 into app_tmp
335fn aw16 off ulong v ulong to void
336put app_tmp off uchar and v 255
337put app_tmp add off 1 uchar and shr v 8 255
338end
339
340fn aw32 off ulong v ulong to void
341put app_tmp off uchar and v 255
342put app_tmp add off 1 uchar and shr v 8 255
343put app_tmp add off 2 uchar and shr v 16 255
344put app_tmp add off 3 uchar and shr v 24 255
345end
346
347fn amkhdr op ulong flg ulong req ulong plen ulong to void
348aw32 0 OMK_MAGIC
349put app_tmp 4 uchar OMK_VER
350put app_tmp 5 uchar op
351aw16 6 flg
352aw32 8 req
353aw32 12 plen
354end
355
356note Helper: read LE u32 from cap_buf at cap_pos + off
357fn cr32 off ulong to ulong
358p = add get cap_pos 0 off
359a = ulong get cap_buf p
360b = ulong get cap_buf add p 1
361c = ulong get cap_buf add p 2
362d = ulong get cap_buf add p 3
363ret or or or a shl b 8 shl c 16 shl d 24
364end
365
366fn cr16 off ulong to ulong
367p = add get cap_pos 0 off
368a = ulong get cap_buf p
369b = ulong get cap_buf add p 1
370ret or a shl b 8
371end
372
373note Verify next captured OMTK frame has expected op, req_id, plen; advance cap_pos only via cap_adv.
374fn cap_avail to ulong
375ret sub get cap_len 0 get cap_pos 0
376end
377
378fn cap_chk op ulong req ulong plen ulong tc ulong to void
379if lt cap_avail add 16 plen
380tfail tc
381end
382if ne cr32 0 OMK_MAGIC
383tfail tc
384end
385p = get cap_pos 0
386if ne ulong get cap_buf add p 4 OMK_VER
387tfail tc
388end
389if ne ulong get cap_buf add p 5 op
390tfail tc
391end
392if ne cr32 8 req
393tfail tc
394end
395if ne cr32 12 plen
396tfail tc
397end
398end
399
400fn cap_adv n ulong to void
401put cap_pos 0 add get cap_pos 0 n
402end
403
404note Reset simulator + TCP + wire_loop and perform 3-way TCP handshake.
405fn setup_conn port ulong to void
406put sim_g 0 1000000000
407put sim_g 1 1000000000
408put sim_g 2 0
409put sim_g 3 0
410put sim_g 4 0
411put sim_g 5 1
412put sim_g 8 50
413put sim_g 9 0
414put sim_g 10 0
415put sim_g 11 0
416put sim_g 12 0
417put sim_g 13 0
418put sim_irq 0 0
419put sim_ver 0 0
420put srx_hd 0 0
421put srx_cnt 0 0
422put cap_len 0 0
423put cap_pos 0 0
424put peer_st 0 1000
425put peer_st 1 0
426put peer_st 2 port
427put peer_st 3 0
428put peer_st 4 0
429put Tmac 0 2
430put Tmac 1 0
431put Tmac 2 0
432put Tmac 3 0
433put Tmac 4 0
434put Tmac 5 2
435put Tcf 1 167772162
436put Tcf 2 167772161
437put Tcf 3 4294967040
438put Tcf 5 1234567
439tarpset 167772161 2199023255553 true
440wl_init 18100 262144 248320
441psend 2 0 0
442wl_tick
443psend 16 0 0
444wl_tick
445if ne get Tcb kST 4
446tfail 91
447end
448end
449
450note Advance simulated CNTVCT_EL0 by ms milliseconds (at 1 GHz = ms * 1000000).
451fn adv_ms ms ulong to void
452put sim_g 0 add get sim_g 0 mul ms 1000000
453end
454
455fn main to int
456note Case 1: Overflow-safe CNTVCT_EL0 -> ms conversion (5e18 ticks @ 1 GHz = 5e12 ms)
457put sim_g 0 5000000000000000000
458put sim_g 1 1000000000
459if ne wl_now_ms 5000000000000
460tfail 1
461end
462
463note Case 2: TCP handshake + PING -> PONG
464setup_conn 40001
465amkhdr OMK_PING 0 0 0
466psend_data 16
467wl_tick
468cap_chk OMK_PONG 0 16 2
469if ne cr32 16 WL_IDLE
470tfail 2
471end
472if ne cr32 20 0
473tfail 2
474end
475if ne cr32 24 262144
476tfail 2
477end
478cap_adv 32
479
480note Case 3: PREFILL (3 tokens) -> 3 GPU kicks + 3 dsb ish + DONE(kv=3, PREFILL_OK)
481amkhdr OMK_PREFILL 0 101 12
482aw32 16 10
483aw32 20 20
484aw32 24 30
485psend_data 28
486for s ulong 12
487wl_tick
488end
489cap_chk OMK_DONE 101 8 3
490if ne cr32 16 3
491tfail 3
492end
493if ne cr32 20 OMK_RPREF
494tfail 3
495end
496if ne get sim_g 3 3
497tfail 3
498end
499if ne get sim_g 2 3
500tfail 3
501end
502cap_adv 24
503
504note Case 4: DECODE (max=4, eos=52; final prefill produced first token 50 with HASFIRST=1,
505note then 2 GPU decode steps emit 51 and 52(EOS), final kv=5)
506if ne get wl_st WL_S_HASFIRST 1
507tfail 4
508end
509amkhdr OMK_DECODE 0 102 16
510aw32 16 4
511aw32 20 52
512aw32 24 0
513aw32 28 42
514psend_data 32
515for s ulong 12
516wl_tick
517end
518cap_chk OMK_TOKEN 102 8 4
519if ne cr32 16 0
520tfail 4
521end
522if ne cr32 20 50
523tfail 4
524end
525cap_adv 24
526cap_chk OMK_TOKEN 102 8 4
527if ne cr32 16 1
528tfail 4
529end
530if ne cr32 20 51
531tfail 4
532end
533cap_adv 24
534cap_chk OMK_TOKEN 102 8 4
535if ne cr16 6 OMK_FEOS
536tfail 4
537end
538if ne cr32 16 2
539tfail 4
540end
541if ne cr32 20 52
542tfail 4
543end
544cap_adv 24
545cap_chk OMK_DONE 102 8 4
546if ne cr32 16 5
547tfail 4
548end
549if ne cr32 20 OMK_REOS
550tfail 4
551end
552cap_adv 24
553
554note Case 5: RESET_KV(keep_pos=2) -> ERR(E_UNSUP), kv_pos stays 5, 0 extra kicks
555k_before = get sim_g 3
556amkhdr OMK_RESET 0 103 4
557aw32 16 2
558psend_data 20
559wl_tick
560cap_chk OMK_ERR 103 8 5
561if ne cr32 16 OMK_EUNSUP
562tfail 5
563end
564if ne get wl_st WL_S_KVPOS 5
565tfail 5
566end
567if ne get sim_g 3 k_before
568tfail 5
569end
570cap_adv 24
571
572note Case 6: RESET_KV(keep_pos=0) -> MUST wait for GPU semaphore before DONE(kv=0, RESET_OK)
573put sim_g 5 0
574amkhdr OMK_RESET 0 0 4
575aw32 16 0
576psend_data 20
577wl_tick
578wl_tick
579if ne cap_avail 0
580tfail 6
581end
582if ne get wl_st WL_S_STATE WL_WAIT
583tfail 6
584end
585if ne get sim_g 10 1
586tfail 6
587end
588put sim_g 5 1
589wl_tick
590cap_chk OMK_DONE 0 8 6
591if ne cr32 16 0
592tfail 6
593end
594if ne cr32 20 OMK_RRESET
595tfail 6
596end
597cap_adv 24
598
599note Case 7: CANCEL mid-DECODE while in WL_WAIT; PING still responds while waiting
600put wl_st WL_S_KVPOS 1
601put wl_st WL_S_LASTTOK 50
602put sim_g 5 0
603amkhdr OMK_DECODE 0 104 16
604aw32 16 10
605aw32 20 999
606aw32 24 0
607aw32 28 0
608psend_data 32
609wl_tick
610if ne get wl_st WL_S_STATE WL_WAIT
611tfail 7
612end
613amkhdr OMK_PING 0 105 0
614psend_data 16
615wl_tick
616cap_chk OMK_PONG 105 16 7
617if ne cr32 16 WL_WAIT
618tfail 7
619end
620cap_adv 32
621amkhdr OMK_CANCEL 0 104 0
622psend_data 16
623wl_tick
624put sim_g 5 1
625wl_tick
626cap_chk OMK_TOKEN 104 8 7
627cap_adv 24
628cap_chk OMK_DONE 104 8 7
629if ne cr32 20 OMK_RCANCEL
630tfail 7
631end
632cap_adv 24
633
634note Case 8: MAX_CTX overflow-safe refusal + E_BAD_TOK + temp_milli > 0 E_UNSUP
635put wl_st WL_S_KVPOS 262143
636k_b8 = get sim_g 3
637amkhdr OMK_PREFILL 0 106 8
638aw32 16 1
639aw32 20 2
640psend_data 24
641wl_tick
642cap_chk OMK_ERR 106 8 8
643if ne cr32 16 OMK_ERANGE
644tfail 8
645end
646cap_adv 24
647put wl_st WL_S_KVPOS 0
648amkhdr OMK_PREFILL 0 107 4
649aw32 16 248320
650psend_data 20
651wl_tick
652cap_chk OMK_ERR 107 8 8
653if ne cr32 16 OMK_EBADTOK
654tfail 8
655end
656cap_adv 24
657amkhdr OMK_DECODE 0 108 16
658aw32 16 4
659aw32 20 1
660aw32 24 700
661aw32 28 0
662psend_data 32
663wl_tick
664cap_chk OMK_ERR 108 8 8
665if ne cr32 16 OMK_EUNSUP
666tfail 8
667end
668if ne get sim_g 3 k_b8
669tfail 8
670end
671cap_adv 24
672
673note Case 9: Malformed frame (bad magic / reserved flag / >16384 payload) -> ERR + close
674aw32 0 12345
675put app_tmp 4 1
676put app_tmp 5 1
677aw16 6 0
678aw32 8 109
679aw32 12 0
680psend_data 16
681wl_tick
682cap_chk OMK_ERR 109 8 9
683if ne cr32 16 OMK_EBADMAG
684tfail 9
685end
686if eq get peer_st 4 0
687tfail 9
688end
689cap_adv 24
690
691note Case 10: 30s idle timeout -> tdrop + re-arm tlisten(18100)
692setup_conn 40002
693d0 = get wl_st WL_S_DROPS
694adv_ms 29999
695wl_tick
696if ne get wl_st WL_S_DROPS d0
697tfail 10
698end
699adv_ms 2
700wl_tick
701if ne get wl_st WL_S_DROPS add d0 1
702tfail 10
703end
704if ne get Tcb kST 1
705tfail 10
706end
707
708note Case 11: Trap #13 guard (q38_verify_step returns -1) -> NO TOKEN, quarantine, ERR(E_GPU_VERIFY), FAULT
709setup_conn 40003
710put wl_st WL_S_KVPOS 1
711put wl_st WL_S_LASTTOK 50
712put sim_ver 0 -1
713amkhdr OMK_DECODE 0 110 16
714aw32 16 2
715aw32 20 999
716aw32 24 0
717aw32 28 0
718psend_data 32
719for s ulong 6
720wl_tick
721end
722cap_chk OMK_ERR 110 8 11
723if ne cr32 16 OMK_EGVER
724tfail 11
725end
726if ne get sim_g 4 1
727tfail 11
728end
729if ne get wl_st WL_S_STATE WL_FAULT
730tfail 11
731end
732cap_adv 24
733amkhdr OMK_PREFILL 0 111 4
734aw32 16 5
735psend_data 20
736wl_tick
737cap_chk OMK_ERR 111 8 11
738if ne cr32 16 OMK_EFAULT
739tfail 11
740end
741cap_adv 24
742
743note Case 12: GSP HALT (iqservice returns -13) during WL_WAIT -> quarantine + ERR(E_GPU_HALT, 13) + FAULT
744setup_conn 40004
745put wl_st WL_S_KVPOS 1
746put wl_st WL_S_LASTTOK 50
747put sim_g 5 0
748amkhdr OMK_DECODE 0 112 16
749aw32 16 2
750aw32 20 999
751aw32 24 0
752aw32 28 0
753psend_data 32
754wl_tick
755put sim_irq 0 -13
756wl_tick
757cap_chk OMK_ERR 112 8 12
758if ne cr32 16 OMK_EGHALT
759tfail 12
760end
761if ne cr32 20 13
762tfail 12
763end
764if ne get sim_g 4 1
765tfail 12
766end
767if ne get wl_st WL_S_STATE WL_FAULT
768tfail 12
769end
770cap_adv 24
771
772note Case 13: Truncated TCP frame split across 2 segments + wl_run nested bound entry
773setup_conn 40005
774amkhdr OMK_PREFILL 0 113 8
775aw32 16 7
776aw32 20 8
777psend 24 0 10
778wl_tick
779if ne cap_avail 0
780tfail 13
781end
782if ne get sim_g 3 0
783tfail 13
784end
785psend 24 10 14
786for s ulong 8
787wl_tick
788end
789cap_chk OMK_DONE 113 8 13
790if ne cr32 16 2
791tfail 13
792end
793cap_adv 24
794put sim_g 9 1
795wl_run
796
797note Case 14: Reserved flag bit (flags=4 -> E_BAD_FLAGS) and oversize payload (16388 -> E_TOO_BIG)
798setup_conn 40006
799amkhdr OMK_PING 4 114 0
800psend_data 16
801wl_tick
802cap_chk OMK_ERR 114 8 14
803if ne cr32 16 OMK_EBADFLG
804tfail 14
805end
806cap_adv 24
807setup_conn 40007
808aw32 0 OMK_MAGIC
809put app_tmp 4 uchar OMK_VER
810put app_tmp 5 uchar OMK_PREFILL
811aw16 6 0
812aw32 8 115
813aw32 12 16388
814psend_data 16
815wl_tick
816cap_chk OMK_ERR 115 8 14
817if ne cr32 16 OMK_ETOOBIG
818tfail 14
819end
820cap_adv 24
821
822note Case 15: Disconnect during WL_WAIT -> defer tlisten until GPU drains, zero frame leak to next peer
823setup_conn 40008
824put wl_st WL_S_KVPOS 1
825put wl_st WL_S_LASTTOK 50
826put sim_g 5 0
827amkhdr OMK_DECODE 0 116 16
828aw32 16 4
829aw32 20 999
830aw32 24 0
831aw32 28 0
832psend_data 32
833wl_tick
834if ne get wl_st WL_S_STATE WL_WAIT
835tfail 15
836end
837tdrop 0
838wl_tick
839if ne get Tcb kST 0
840tfail 15
841end
842if ne get wl_st WL_S_REARM 1
843tfail 15
844end
845put sim_g 5 1
846wl_tick
847wl_tick
848if ne cap_avail 0
849tfail 15
850end
851if ne get wl_st WL_S_STATE WL_IDLE
852tfail 15
853end
854if ne get wl_st WL_S_REARM 0
855tfail 15
856end
857if ne get Tcb kST 1
858tfail 15
859end
860if ne get wl_st WL_S_CANCEL 0
861tfail 15
862end
863
864note Case 16: wl_txq backpressure -> stay in WL_SUBMIT while < 64 B free, kick once space freed
865setup_conn 40009
866k_b16 = get sim_g 3
867amkhdr OMK_PREFILL 0 117 4
868aw32 16 7
869psend 24 0 20
870n16 = wl_nic_rx
871tinput n16
872wl_pump_tcp wl_now_ms
873if ne get wl_st WL_S_STATE WL_SUBMIT
874tfail 16
875end
876put wl_st WL_S_TXN 4060
877wl_gpu_submit wl_now_ms
878if ne get sim_g 3 k_b16
879tfail 16
880end
881if ne get wl_st WL_S_STATE WL_SUBMIT
882tfail 16
883end
884put wl_st WL_S_TXN 0
885put wl_st WL_S_TXH 0
886for s ulong 6
887wl_tick
888end
889cap_chk OMK_DONE 117 8 16
890if ne cr32 16 1
891tfail 16
892end
893cap_adv 24
894
895note Case 17: RESET_KV(keep > kv_pos) -> ERR(OMK_ERANGE) before calling q38_reset_kv
896put wl_st WL_S_KVPOS 2
897put sim_g 12 0
898amkhdr OMK_RESET 0 118 4
899aw32 16 5
900psend_data 20
901wl_tick
902cap_chk OMK_ERR 118 8 17
903if ne cr32 16 OMK_ERANGE
904tfail 17
905end
906if ne get sim_g 12 0
907tfail 17
908end
909cap_adv 24
910
911note Case 18: Empty-KV DECODE refusal -> ERR(OMK_ERANGE), 0 GPU kicks
912setup_conn 40010
913k_b18 = get sim_g 3
914amkhdr OMK_DECODE 0 119 16
915aw32 16 4
916aw32 20 99
917aw32 24 0
918aw32 28 0
919psend_data 32
920wl_tick
921cap_chk OMK_ERR 119 8 18
922if ne cr32 16 OMK_ERANGE
923tfail 18
924end
925if ne get sim_g 3 k_b18
926tfail 18
927end
928cap_adv 24
929
930k = write 1 Tpass 0 len Tpass
931ret 0
932end