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 / tests / dagsim / dagsim_unit.om

808 lines · 32197 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note tests/dagsim/dagsim_unit.om -- Pure seeded OM-2 analytical unit tests for dagsim (omega-mv#583).
3note Composed after tools/dagsim/dagsim.om:
4note cat tools/dagsim/dagsim.om tests/dagsim/dagsim_unit.om | seed/out/omc > dagsim_unit
5
6global u_checks ulong 1
7global u_fail ulong 1
8global u_sc2 ulong 8192
9global u_rsn2 uchar 256
10global u_rsn2_len ulong 1
11
12text u_hdr "oev version=1\nmachine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\nbuild repo=omega-mv sha=0000000000000000000000000000000000000000\ncalibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\nresource id=mem kind=capacity cap=1000 prov=specified src=test\nenergy instrument=none\n"
13text u_d20 "2026-10-20"
14text u_d24 "2026-10-24"
15text u_dnov18 "2026-11-18"
16text u_dnov19 "2026-11-19"
17text u_fail_pfx " FAIL "
18text u_sum1 "dagsim_unit: "
19text u_sum2 " checks, "
20text u_sum3 " failed\n"
21
22fn u_check cond bool msg view uchar * to void
23put u_checks 0 add get u_checks 0 1
24if not cond
25put u_fail 0 add get u_fail 0 1
26ds_out_reset
27ds_out_text u_fail_pfx
28ds_out_text msg
29ds_out_ch uchar 10
30ds_out_flush 2
31end
32end
33
34fn u_near a f64 b f64 tol f64 to bool
35ret le fabs sub a b tol
36end
37
38fn u_day s view uchar * to long
39ret ds_day_from_slice s len s
40end
41
42fn u_set_txt1 side ulong h view uchar * to void
43nh = len h
44if eq side 0
45for i ulong nh bound 8192
46put ds_txt i get h i
47end
48put ds_txt_len 0 nh
49else
50for i ulong nh bound 8192
51put ds_txt2 i get h i
52end
53put ds_txt2_len 0 nh
54end
55end
56
57fn u_set_txt side ulong h view uchar * b view uchar * to void
58nh = len h
59nb = len b
60if eq side 0
61for i ulong nh bound 1024
62put ds_txt i get h i
63end
64for i ulong nb bound 8192
65put ds_txt add nh i get b i
66end
67put ds_txt_len 0 add nh nb
68else
69for i ulong nh bound 1024
70put ds_txt2 i get h i
71end
72for i ulong nb bound 8192
73put ds_txt2 add nh i get b i
74end
75put ds_txt2_len 0 add nh nb
76end
77end
78
79fn u_rsn_has sub_s view uchar * to bool
80ns = len sub_s
81nr = get ds_reason_len 0
82if gt ns nr
83ret false
84end
85lim = add sub nr ns 1
86for i ulong lim bound 256
87ok = true
88for j ulong ns bound 128
89if ne get ds_reason add i j get sub_s j
90ok = false
91break
92end
93end
94if ok
95ret true
96end
97end
98ret false
99end
100
101fn u_err_has sub_s view uchar * to bool
102ns = len sub_s
103nr = ulong 0
104while lt nr 255 bound 256
105if eq get ds_err nr 0
106break
107end
108nr = add nr 1
109end
110if gt ns nr
111ret false
112end
113lim = add sub nr ns 1
114for i ulong lim bound 256
115ok = true
116for j ulong ns bound 128
117if ne get ds_err add i j get sub_s j
118ok = false
119break
120end
121end
122if ok
123ret true
124end
125end
126ret false
127end
128
129text u_inv_bnd "makespan below bound"
130text u_inv_cp "below critical path bound"
131text u_inv_attr "attribution does not sum to makespan"
132text u_inv_det "not deterministic"
133
134fn u_check_invariants asof long hasm ulong to void
135mk = bitcast f64 get ds_sc 3
136bnd = bitcast f64 get ds_sc 19
137cpb = bitcast f64 get ds_sc 20
138u_check ge add mk 0.000001f64 bnd u_inv_bnd
139u_check ge add mk 0.000001f64 cpb u_inv_cp
140s = f64 0.0f64
141for i ulong 7
142s = add s bitcast f64 get ds_sc add 5824 i
143end
144u_check u_near s mk 0.000001f64 u_inv_attr
145for i ulong 8192
146put u_sc2 i get ds_sc i
147end
148rc2 = ds_eval_current 0 asof hasm bitcast ulong 0.9f64
149same = eq rc2 0
150if same
151for i ulong 8192
152if ne get u_sc2 i get ds_sc i
153same = false
154break
155end
156end
157end
158u_check same u_inv_det
159end
160
161fn u_eval_body body view uchar * asof long hasm ulong to ulong
162u_set_txt 0 u_hdr body
163if ne ds_parse_side 0 0
164ret 9
165end
166rc = ds_eval_current 0 asof hasm bitcast ulong 0.9f64
167if eq rc 0
168u_check_invariants asof hasm
169end
170ret rc
171end
172
173fn u_eval_file path view uchar * asof long to ulong
174if ne ds_read_file_side 0 path len path 0
175ret 9
176end
177ret ds_eval_current 0 asof 0 bitcast ulong 0.9f64
178end
179
180note ---- 1. test_serial_chain ----
181text t1_body "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A B\ndep B C\n"
182text t1_m1 "serial chain status"
183text t1_m2 "serial makespan"
184text t1_m3 "critical path bound"
185text t1_m4 "critical path length"
186text t1_m5 "compute attribution"
187text t1_m6 "residual"
188text t1_m7 "C window"
189text t1_m8 "prov mask"
190text t1_m9 "conservation"
191
192fn test_serial_chain to void
193rc = u_eval_body t1_body u_day u_d20 0
194u_check eq rc 0 t1_m1
195u_check u_near bitcast f64 get ds_sc 3 60.0f64 1.0e-9f64 t1_m2
196u_check u_near bitcast f64 get ds_sc 20 60.0f64 1.0e-9f64 t1_m3
197u_check eq get ds_sc 21 3 t1_m4
198u_check u_near bitcast f64 get ds_sc 5824 60.0f64 1.0e-9f64 t1_m5
199u_check u_near bitcast f64 get ds_sc 5830 0.0f64 1.0e-9f64 t1_m6
200u_check and u_near bitcast f64 get ds_sc 4514 30.0f64 1.0e-9f64 u_near bitcast f64 get ds_sc 4770 60.0f64 1.0e-9f64 t1_m7
201u_check eq get ds_sc 11 24 t1_m8
202u_check and eq get ds_pm 12 3 u_near bitcast f64 get ds_sc 16 60.0f64 1.0e-9f64 t1_m9
203end
204
205note ---- 2. test_perfect_overlap ----
206text t2_b1 "resource id=cpu kind=compute slots=4 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
207text t2_b2 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
208text t2_m1 "overlap status"
209text t2_m2 "independent overlap makespan"
210text t2_m3 "no serialization when slots suffice"
211text t2_m4 "one slot status"
212text t2_m5 "one-slot makespan"
213text t2_m6 "critical path stays 30"
214text t2_m7 "resource bound 60"
215text t2_m8 "serialization 30"
216
217fn test_perfect_overlap to void
218d = u_day u_d20
219rc = u_eval_body t2_b1 d 0
220u_check eq rc 0 t2_m1
221u_check u_near bitcast f64 get ds_sc 3 30.0f64 1.0e-9f64 t2_m2
222u_check u_near bitcast f64 get ds_sc 5828 0.0f64 1.0e-9f64 t2_m3
223rc = u_eval_body t2_b2 d 0
224u_check eq rc 0 t2_m4
225u_check u_near bitcast f64 get ds_sc 3 60.0f64 1.0e-9f64 t2_m5
226u_check u_near bitcast f64 get ds_sc 20 30.0f64 1.0e-9f64 t2_m6
227u_check u_near bitcast f64 get ds_sc 19 60.0f64 1.0e-9f64 t2_m7
228u_check u_near bitcast f64 get ds_sc 5828 30.0f64 1.0e-9f64 t2_m8
229end
230
231note ---- 3. test_shared_bandwidth ----
232text t3_b1 "resource id=cpu kind=compute slots=2 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\nop id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\nop id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
233text t3_b2 "resource id=cpu kind=compute slots=2 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\nop id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\nop id=B kind=copy engine=cpu bytes=5e8 bw=pipe prov=measured src=t\n"
234text t3_b3 "resource id=cpu kind=compute slots=1 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\nop id=A kind=compute engine=cpu t_ns=5e8 bytes=1e9 bw=pipe prov=measured src=t\n"
235text t3_b4 "resource id=cpu kind=compute slots=1 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\nop id=A kind=compute engine=cpu t_ns=4e9 bytes=1e9 bw=pipe prov=measured src=t\n"
236text t3_b5 "resource id=cpu kind=compute slots=1 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\nop id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\nop id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
237text t3_m1 "bw status"
238text t3_m2 "two concurrent copies 2e9"
239text t3_m3 "both end at 2 s"
240text t3_m4 "A contention 1e9"
241text t3_m5 "cp bound 1 s"
242text t3_m6 "pipe work bound 2 s"
243text t3_m7 "bw+contention = 2 s"
244text t3_m8 "contention attributed 1 s"
245text t3_m9 "bw2 status"
246text t3_m10 "B ends at 1 s"
247text t3_m11 "A ends at 1.5 s"
248text t3_m12 "max(F/P,Q/B) floor"
249text t3_m13 "op floor"
250text t3_m14 "compute-bound op alone"
251text t3_m15 "attributed as compute"
252text t3_m16 "serialized copies no contention"
253
254fn test_shared_bandwidth to void
255d = u_day u_d20
256rc = u_eval_body t3_b1 d 0
257u_check eq rc 0 t3_m1
258u_check u_near bitcast f64 get ds_sc 3 2.0e9f64 1.0e-3f64 t3_m2
259u_check and u_near bitcast f64 get ds_sc 4768 2.0e9f64 1.0e-3f64 u_near bitcast f64 get ds_sc 4769 2.0e9f64 1.0e-3f64 t3_m3
260u_check u_near bitcast f64 get ds_sc 5536 1.0e9f64 1.0e-3f64 t3_m4
261u_check u_near bitcast f64 get ds_sc 20 1.0e9f64 1.0e-3f64 t3_m5
262u_check u_near bitcast f64 get ds_sc 19 2.0e9f64 1.0e-3f64 t3_m6
263u_check u_near add bitcast f64 get ds_sc 5825 bitcast f64 get ds_sc 5826 2.0e9f64 1.0e-3f64 t3_m7
264u_check u_near bitcast f64 get ds_sc 5826 1.0e9f64 1.0e-3f64 t3_m8
265rc = u_eval_body t3_b2 d 0
266u_check eq rc 0 t3_m9
267u_check u_near bitcast f64 get ds_sc 4769 1.0e9f64 1.0e-3f64 t3_m10
268u_check u_near bitcast f64 get ds_sc 4768 1.5e9f64 1.0e-3f64 t3_m11
269rc = u_eval_body t3_b3 d 0
270u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 1.0e9f64 1.0e-3f64 t3_m12
271u_check u_near bitcast f64 get ds_sc 5280 1.0e9f64 1.0e-3f64 t3_m13
272rc = u_eval_body t3_b4 d 0
273u_check and eq rc 0 and u_near bitcast f64 get ds_sc 3 4.0e9f64 1.0e-3f64 u_near bitcast f64 get ds_sc 5536 0.0f64 1.0e-3f64 t3_m14
274u_check u_near bitcast f64 get ds_sc 5824 4.0e9f64 1.0e-3f64 t3_m15
275rc = u_eval_body t3_b5 d 0
276u_check and eq rc 0 and u_near bitcast f64 get ds_sc 3 2.0e9f64 1.0e-3f64 u_near bitcast f64 get ds_sc 5826 0.0f64 1.0e-3f64 t3_m16
277end
278
279note ---- 4. test_capacity_refusal ----
280text t4_b1 "resource id=cpu kind=compute slots=2 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nbuffer id=x bytes=600 cap=mem first=A last=A\nbuffer id=y bytes=600 cap=mem first=A last=A\n"
281text t4_b2 "resource id=cpu kind=compute slots=2 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\ndep A B\nbuffer id=x bytes=600 cap=mem first=A last=A\nbuffer id=y bytes=600 cap=mem first=B last=B\n"
282text t4_b3 "resource id=cpu kind=compute slots=2 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nbuffer id=big bytes=2000 cap=mem\n"
283text t4_sx "x"
284text t4_sy "y"
285text t4_m1 "1200 live bytes in 1000 refuses"
286text t4_m2 "reason names x and y"
287text t4_m3 "disjoint lifetimes fit"
288text t4_m4 "peak 600"
289text t4_m5 "oversized resident refuses"
290
291fn test_capacity_refusal to void
292d = u_day u_d20
293rc = u_eval_body t4_b1 d 0
294u_check eq rc 4 t4_m1
295u_check and u_rsn_has t4_sx u_rsn_has t4_sy t4_m2
296rc = u_eval_body t4_b2 d 0
297u_check eq rc 0 t4_m3
298u_check u_near bitcast f64 get ds_sc 6344 600.0f64 1.0e-9f64 t4_m4
299rc = u_eval_body t4_b3 d 0
300u_check eq rc 4 t4_m5
301end
302
303note ---- 5. test_lifetimes ----
304text t5_b1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=10 prov=measured src=t\ndep A B\ndep B C\nbuffer id=resident bytes=100 cap=mem\nbuffer id=x bytes=300 cap=mem first=A last=B\nbuffer id=y bytes=400 cap=mem first=B last=C\n"
305text t5_m1 "lifetimes status"
306text t5_m2 "peak 800"
307text t5_m3 "peak at 10"
308
309fn test_lifetimes to void
310rc = u_eval_body t5_b1 u_day u_d20 0
311u_check eq rc 0 t5_m1
312u_check u_near bitcast f64 get ds_sc 6344 800.0f64 1.0e-9f64 t5_m2
313u_check u_near bitcast f64 get ds_sc 6376 10.0f64 1.0e-9f64 t5_m3
314end
315
316note ---- 6. test_sync ----
317text t6_b1 "resource id=cpu kind=compute slots=2 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=30 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=5 prov=measured src=t\nsync id=s ops=A,B\ndep s C\n"
318text t6_b2 "resource id=cpu kind=compute slots=2 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=30 prov=measured src=t\nop id=fence kind=barrier t_ns=7 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=5 prov=measured src=t\ndep A fence\ndep B fence\ndep fence C\n"
319text t6_c "C"
320text t6_m1 "sync status"
321text t6_m2 "C waits for slower of A,B"
322text t6_m3 "sync makespan 35"
323text t6_m4 "costed barrier makespan 42"
324text t6_m5 "sync attribution 7"
325
326fn test_sync to void
327d = u_day u_d20
328rc = u_eval_body t6_b1 d 0
329u_check eq rc 0 t6_m1
330ci = ds_find_op_name t6_c
331u_check and ge ci 0 u_near bitcast f64 get ds_sc add 4512 ulong ci 30.0f64 1.0e-9f64 t6_m2
332u_check u_near bitcast f64 get ds_sc 3 35.0f64 1.0e-9f64 t6_m3
333rc = u_eval_body t6_b2 d 0
334u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 42.0f64 1.0e-9f64 t6_m4
335u_check u_near bitcast f64 get ds_sc 5829 7.0f64 1.0e-9f64 t6_m5
336end
337
338note ---- 7. test_launch ----
339text t7_b1 "resource id=gpu kind=compute slots=1 prov=specified src=test\nresource id=L kind=launch prov=measured src=t\nop id=A kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L prov=measured src=t\nop id=B kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L prov=measured src=t\n"
340text t7_b2 "resource id=gpu kind=compute slots=1 prov=specified src=test\nresource id=cpu kind=compute slots=1 prov=specified src=test\nresource id=L1 kind=launch prov=measured src=t\nresource id=L2 kind=launch prov=measured src=t\nop id=A kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L1 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=0 launch_ns=40e6 launcher=L2 prov=measured src=t\n"
341text t7_m1 "serialized launches add"
342text t7_m2 "launch+serialization"
343text t7_m3 "independent launches overlap"
344
345fn test_launch to void
346d = u_day u_d20
347rc = u_eval_body t7_b1 d 0
348u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 80.0e6f64 1.0e-3f64 t7_m1
349u_check u_near add bitcast f64 get ds_sc 5827 bitcast f64 get ds_sc 5828 80.0e6f64 1.0e-3f64 t7_m2
350rc = u_eval_body t7_b2 d 0
351u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 40.0e6f64 1.0e-3f64 t7_m3
352end
353
354note ---- 8. test_calibration ----
355text t8_b1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
356text t8_nocal "oev version=1\nmachine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\nbuild repo=omega-mv sha=0000000000000000000000000000000000000000\nenergy instrument=none\n"
357text t8_unk "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu prov=unknown src=arch-244-not-run\ndep A B\n"
358text t8_syn "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=t\n"
359text t8_sb "B"
360text t8_m1 "31 days stale refuses"
361text t8_m2 "30 days valid OK"
362text t8_m3 "parse without calibration"
363text t8_m4 "measured without calibration refuses"
364text t8_m5 "unknown op refuses"
365text t8_m6 "reason names B"
366text t8_m7 "no makespan on refusal"
367text t8_m8 "synthetic flag"
368
369fn test_calibration to void
370rc = u_eval_body t8_b1 u_day u_dnov19 0
371u_check eq rc 2 t8_m1
372rc = u_eval_body t8_b1 u_day u_dnov18 0
373u_check eq rc 0 t8_m2
374u_set_txt 0 t8_nocal t8_b1
375u_check eq ds_parse_side 0 0 t8_m3
376rc = ds_eval_current 0 u_day u_d20 0 bitcast ulong 0.9f64
377u_check eq rc 3 t8_m4
378rc = u_eval_body t8_unk u_day u_d20 0
379u_check eq rc 1 t8_m5
380u_check u_rsn_has t8_sb t8_m6
381u_check eq get ds_sc 3 0 t8_m7
382rc = u_eval_body t8_syn u_day u_d20 0
383u_check and eq rc 0 eq get ds_sc 26 1 t8_m8
384end
385
386note ---- 9. test_intervals ----
387text t9_b1 "resource id=cpu kind=compute slots=2 prov=specified src=test\nresource id=pipe kind=bandwidth cap=1e9 lo=0.5e9 hi=2e9 prov=measured src=t\nop id=A kind=compute engine=cpu t_ns=100 lo=80 hi=150 prov=measured src=t\nop id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\ndep A B\n"
388text t9_m1 "parse interval"
389text t9_m2 "interval status"
390text t9_m3 "nominal 100+1e9"
391text t9_m4 "optimistic 80+0.5e9"
392text t9_m5 "pessimistic 150+2e9"
393
394fn test_intervals to void
395u_set_txt 0 u_hdr t9_b1
396u_check eq ds_parse_side 0 0 t9_m1
397d = u_day u_d20
398q = bitcast ulong 0.9f64
399rc = ds_eval_current 0 d 0 q
400u_check eq rc 0 t9_m2
401u_check u_near bitcast f64 get ds_sc 3 add 100.0f64 1.0e9f64 1.0e-3f64 t9_m3
402rc = ds_eval_current 1 d 0 q
403u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 add 80.0f64 0.5e9f64 1.0e-3f64 t9_m4
404rc = ds_eval_current -1 d 0 q
405u_check and eq rc 0 u_near bitcast f64 get ds_sc 3 add 150.0f64 2.0e9f64 1.0e-3f64 t9_m5
406end
407
408note ---- 10. test_energy ----
409text t10_b1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\n"
410text t10_syn "oev version=1\nmachine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\nbuild repo=omega-mv sha=0000000000000000000000000000000000000000\ncalibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\nresource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\nenergy instrument=tdp-guess boundary=soc power_w=100 prov=synthetic\n"
411text t10_meas "oev version=1\nmachine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\nbuild repo=omega-mv sha=0000000000000000000000000000000000000000\ncalibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\nresource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\nenergy instrument=cyberpower-ups-nut boundary=wall joules=42.5 prov=measured src=receipt.json\n"
412text t10_bad "oev version=1\nmachine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\nbuild repo=omega-mv sha=0000000000000000000000000000000000000000\nenergy instrument=none joules=42.5 prov=measured src=x\n"
413text t10_empty ""
414text t10_m1 "instrument=none means UNMEASURED"
415text t10_m2 "parse synthetic energy"
416text t10_m3 "synthetic power E=P*T 100 J"
417text t10_m4 "parse measured energy"
418text t10_m5 "measured joules pass through"
419text t10_m6 "joules without instrument refused at parse"
420
421fn test_energy to void
422d = u_day u_d20
423q = bitcast ulong 0.9f64
424rc = u_eval_body t10_b1 d 0
425ok = eq rc 0
426ok = and ok eq get ds_sc 22 0
427ok = and ok eq get ds_sc 23 0
428u_check ok t10_m1
429u_set_txt1 0 t10_syn
430u_check eq ds_parse_side 0 0 t10_m2
431rc = ds_eval_current 0 d 0 q
432ok = eq rc 0
433ok = and ok eq get ds_sc 23 1
434ok = and ok eq get ds_sc 22 0
435ok = and ok u_near bitcast f64 get ds_sc 24 100.0f64 1.0e-9f64
436ok = and ok eq get ds_sc 26 1
437u_check ok t10_m3
438u_set_txt1 0 t10_meas
439u_check eq ds_parse_side 0 0 t10_m4
440rc = ds_eval_current 0 d 0 q
441ok = eq rc 0
442ok = and ok eq get ds_sc 22 1
443ok = and ok u_near bitcast f64 get ds_sc 24 42.5f64 1.0e-9f64
444ok = and ok eq get ds_sc 26 0
445u_check ok t10_m5
446u_set_txt1 0 t10_bad
447u_check eq ds_parse_side 0 9 t10_m6
448end
449
450note ---- 11. test_parse_and_cycles ----
451text t11_b1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nbogus x=1\n"
452text t11_b2 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1 prov=measured src=t typo=3\n"
453text t11_b3 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1 src=t\n"
454text t11_b4 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=1 prov=measured src=t\ndep A B\ndep B A\n"
455text t11_l8 "line 8"
456text t11_fix "tests/dagsim/fixtures/m1_spark_subset.oev"
457text t11_m1 "unknown keyword error with line 8"
458text t11_m2 "unknown field error"
459text t11_m3 "number without prov error"
460text t11_m4 "cycle refuses"
461text t11_m5 "fixture evaluates"
462text t11_m6 "fixture serial makespan"
463text t11_m7 "fixture energy UNMEASURED"
464
465fn test_parse_and_cycles to void
466d = u_day u_d20
467u_set_txt 0 u_hdr t11_b1
468u_check and eq ds_parse_side 0 9 u_err_has t11_l8 t11_m1
469u_set_txt 0 u_hdr t11_b2
470u_check eq ds_parse_side 0 9 t11_m2
471u_set_txt 0 u_hdr t11_b3
472u_check eq ds_parse_side 0 9 t11_m3
473rc = u_eval_body t11_b4 d 0
474u_check eq rc 5 t11_m4
475rc = u_eval_file t11_fix d
476u_check eq rc 0 t11_m5
477u_check u_near bitcast f64 get ds_sc 3 151756700.0f64 1.0e-3f64 t11_m6
478u_check and eq get ds_sc 22 0 eq get ds_sc 23 0 t11_m7
479end
480
481note ---- 12. test_costmodel_reuse ----
482text t12_b1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=mv kind=matvec engine=cpu M=64 N=16 core=0 arm=0 prov=fitted src=rx_costmodel\n"
483text t12_b2 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=mv kind=matvec engine=cpu M=64 N=16 core=0 arm=1 prov=fitted src=rx_costmodel\n"
484text t12_m1 "parse matvec"
485text t12_m2 "matvec with no model refuses"
486text t12_m3 "matvec with model OK"
487text t12_m4 "cell known"
488text t12_m5 "time from rx_cm_predict"
489text t12_m6 "fitted provenance recorded"
490text t12_m7 "parse unobserved arm"
491text t12_m8 "unobserved arm refuses"
492
493fn t12_train_cm to void
494ds_cm_init 2
495rng = or shl ulong 2654435769 32 ulong 2135587861
496for i ulong 200
497rng = xor rng shl rng 13
498rng = xor rng shr rng 7
499rng = xor rng shl rng 17
500M = add 8 rem rng 120
501N = add 4 rem shr rng 20 60
502sb = mul add add mul M N M N 8
503put ds_cm_feat 0 0
504put ds_cm_feat 1 M
505put ds_cm_feat 2 N
506put ds_cm_feat 3 sb
507put ds_cm_feat 4 1048576
508put ds_cm_feat 5 0
509put ds_cm_feat 6 0
510l2 = add 10.0f64 mul 0.95f64 add ds_log2 f64 M ds_log2 f64 N
511ps = ulong ds_exp2 l2
512st = ds_cm_observe_feat 0 ps 0
513end
514end
515
516fn test_costmodel_reuse to void
517t12_train_cm
518d = u_day u_d20
519q = bitcast ulong 0.9f64
520u_set_txt 0 u_hdr t12_b1
521u_check eq ds_parse_side 0 0 t12_m1
522rc = ds_eval_current 0 d 0 q
523u_check eq rc 1 t12_m2
524rc = ds_eval_current 0 d 1 q
525u_check eq rc 0 t12_m3
526put ds_cm_feat 0 0
527put ds_cm_feat 1 64
528put ds_cm_feat 2 16
529put ds_cm_feat 3 mul add add mul ulong 64 16 64 16 8
530put ds_cm_feat 4 1048576
531put ds_cm_feat 5 0
532put ds_cm_feat 6 0
533pst = ds_cm_predict_feat 0
534u_check eq get ds_cm_pred 4 1 t12_m4
535exp_ns = div ds_exp2 bitcast f64 get ds_cm_pred 0 1000.0f64
536u_check u_near bitcast f64 get ds_sc 3 exp_ns 1.0e-6f64 t12_m5
537u_check ne and get ds_sc 11 4 0 t12_m6
538u_set_txt 0 u_hdr t12_b2
539u_check eq ds_parse_side 0 0 t12_m7
540rc = ds_eval_current 0 d 1 q
541u_check eq rc 1 t12_m8
542end
543
544note ---- 13. test_predict_refusal (#934 + mutant_predict.sh) ----
545text t13_m1 "real predict refuses unsupported op"
546text t13_m2 "parse predict refusal"
547text t13_m3 "predict_unsupported_despite_known"
548text t13_m4 "predict_refused_despite_known"
549
550fn test_predict_refusal to void
551ds_cm_init 1
552put ds_cm_feat 0 1
553put ds_cm_feat 1 64
554put ds_cm_feat 2 16
555put ds_cm_feat 3 0
556put ds_cm_feat 4 0
557put ds_cm_feat 5 0
558put ds_cm_feat 6 0
559st = ds_cm_predict_feat 0
560ok0 = eq st -4
561ok0 = and ok0 eq get ds_cm_pred 5 1
562ok0 = and ok0 eq get ds_cm_pred 4 0
563ok0 = and ok0 eq get ds_cm_pred 3 0
564u_check ok0 t13_m1
565d = u_day u_d20
566q = bitcast ulong 0.9f64
567u_set_txt 0 u_hdr t12_b1
568u_check eq ds_parse_side 0 0 t13_m2
569put ds_pred_fault 0 1
570rc = ds_eval_current 0 d 1 q
571put ds_pred_fault 0 0
572u_check and eq rc 1 eq get ds_sc 3 0 t13_m3
573put ds_pred_fault 0 2
574rc = ds_eval_current 0 d 1 q
575put ds_pred_fault 0 0
576u_check and eq rc 1 eq get ds_sc 3 0 t13_m4
577end
578
579note ---- 14. test_counterfactual ----
580text t14_pipe "pipe"
581text t14_cpu "cpu"
582text t14_m1 "cf status"
583text t14_m2 "doubling pipe halves makespan"
584text t14_m3 "doubling slots changes nothing"
585
586fn test_counterfactual to void
587d = u_day u_d20
588q = bitcast ulong 0.9f64
589rc = u_eval_body t3_b1 d 0
590u_check eq rc 0 t14_m1
591pi = ds_find_res_name t14_pipe
592cf1 = ds_counterfactual_idx pi d 0 q
593u_check u_near cf1 1.0e9f64 1.0e-3f64 t14_m2
594ci = ds_find_res_name t14_cpu
595cf2 = ds_counterfactual_idx ci d 0 q
596u_check u_near cf2 2.0e9f64 1.0e-3f64 t14_m3
597end
598
599note ---- 15. test_minimum_work_diff ----
600text t15_base "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A B\ndep B C\n"
601text t15_tr2 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B_lookup kind=compute engine=cpu t_ns=2 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A B_lookup\ndep B_lookup C\nremoved op=B reason=reused ref=B_lookup proof=rx_plan:digest\n"
602text t15_tr3 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A C\nremoved op=B reason=eliminated\n"
603text t15_tr4 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A C\nremoved op=B reason=unchanged_dep ref=A\n"
604text t15_tr5 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\ndep A C\nremoved op=B reason=shared ref=A\nremoved op=B reason=shared ref=C\n"
605text t15_chA "A"
606text t15_m1 "base parse"
607text t15_m2 "tr1 parse"
608text t15_m3 "no-change diff"
609text t15_m4 "tr2 parse"
610text t15_m5 "reuse accounted"
611text t15_m6 "tr3 parse"
612text t15_m7 "unproven elimination refuses"
613text t15_m8 "tr4 parse"
614text t15_m9 "unchanged_dep allows skip"
615text t15_m10 "changed A invalidates skip"
616text t15_m11 "tr5 parse"
617text t15_m12 "double-counted shared detected"
618
619fn u_diff_run to ulong
620ds_pack_side 0
621ds_pack_side 1
622for i ulong 64
623put ds_ra i 0
624end
625ret ds_run_diff
626end
627
628fn test_minimum_work_diff to void
629u_set_txt 0 u_hdr t15_base
630u_check eq ds_parse_side 0 0 t15_m1
631u_set_txt 1 u_hdr t15_base
632u_check eq ds_parse_side 1 0 t15_m2
633rc = u_diff_run
634u_check and eq rc 0 and eq get ds_ra 12 0 and eq get ds_ra 10 0 eq get ds_ra 11 3 t15_m3
635u_set_txt 1 u_hdr t15_tr2
636u_check eq ds_parse_side 1 0 t15_m4
637rc = u_diff_run
638u_check and eq rc 0 and u_near bitcast f64 get ds_ra 34 20.0f64 1.0e-9f64 eq get ds_ra 10 1 t15_m5
639u_set_txt 1 u_hdr t15_tr3
640u_check eq ds_parse_side 1 0 t15_m6
641rc = u_diff_run
642u_check and eq rc 7 ne get ds_ra 14 0 t15_m7
643u_set_txt 1 u_hdr t15_tr4
644u_check eq ds_parse_side 1 0 t15_m8
645rc = u_diff_run
646u_check and eq rc 0 u_near bitcast f64 get ds_ra 35 20.0f64 1.0e-9f64 t15_m9
647ds_pack_side 0
648ds_pack_side 1
649ds_mark_changed t15_chA len t15_chA
650for i ulong 64
651put ds_ra i 0
652end
653rc = ds_run_diff
654u_check eq rc 7 t15_m10
655u_set_txt 1 u_hdr t15_tr5
656u_check eq ds_parse_side 1 0 t15_m11
657rc = u_diff_run
658u_check and ne rc 0 ne get ds_ra 13 0 t15_m12
659end
660
661note ---- 16. test_inverted_lifetimes (#705 + mutant_lifetime.sh) ----
662text t16_f1 "tests/dagsim/fixtures/inverted_masks_overflow.oev"
663text t16_f2 "tests/dagsim/fixtures/inverted_lone.oev"
664text t16_f3 "tests/dagsim/fixtures/capacity_two_80.oev"
665text t16_f4 "tests/dagsim/fixtures/valid_disjoint_80.oev"
666text t16_f5 "tests/dagsim/fixtures/valid_tie_80.oev"
667text t16_s_inv "inverted lifetime for buffer inverted:"
668text t16_s_fc "first=C"
669text t16_s_s20 "start_ns=20"
670text t16_s_la "last=A"
671text t16_s_e10 "end_ns=10"
672text t16_s_neg "went negative"
673text t16_s_r1 "real1"
674text t16_s_r2 "real2"
675text t16_s_mem "mem"
676text t16_s_hbm "hbm"
677text t16_s_fin "finite number >= 0"
678text t16_s_nop "not an op"
679
680text t16_z1 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=Z kind=compute engine=cpu t_ns=0 prov=measured src=t\nbuffer id=z bytes=80 cap=mem first=Z last=Z\n"
681text t16_z2 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=Z kind=compute engine=cpu t_ns=0 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\nbuffer id=z bytes=400 cap=mem first=Z last=Z\nbuffer id=real1 bytes=600 cap=mem first=B last=B\nbuffer id=real2 bytes=600 cap=mem first=B last=B\n"
682text t16_om "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nbuffer id=no_first bytes=100 cap=mem last=A\nbuffer id=no_last bytes=50 cap=mem first=A\nbuffer id=resident bytes=25 cap=mem\n"
683text t16_rnd "resource id=cpu kind=compute slots=1 prov=specified src=test\nresource id=hbm kind=capacity cap=1e30 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\nop id=C kind=compute engine=cpu t_ns=10 prov=measured src=t\ndep A B\ndep B C\nbuffer id=huge bytes=1e20 cap=hbm first=A last=B\nbuffer id=tiny bytes=1 cap=hbm first=B last=C\n"
684text t16_p1 "buffer id=neg bytes=-5 cap=mem\n"
685text t16_p2 "buffer id=inf bytes=inf cap=mem\n"
686text t16_p3 "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\nbuffer id=ghost bytes=10 cap=mem first=nope last=A\n"
687
688text t16_m1 "inverted_lifetime_masks_overflow"
689text t16_m2 "refusal carries no capacity certificate"
690text t16_m3 "rejection text is deterministic"
691text t16_m4 "lone inverted lifetime refused"
692text t16_m5 "two valid 80 B buffers refuse capacity"
693text t16_m6 "disjoint 80 B pair fits"
694text t16_m7 "disjoint peak 80"
695text t16_m8 "disjoint makespan 30"
696text t16_m9 "tie fits"
697text t16_m10 "tie peak 80"
698text t16_m11 "zero-duration status"
699text t16_m12 "zero-duration peak 0"
700text t16_m13 "zero-duration must not hide 1200 B"
701text t16_m14 "omitted endpoints status"
702text t16_m15 "omitted endpoints peak 175"
703text t16_m16 "rounding_drives_live_negative"
704text t16_m17 "negative-ledger carries no capacity certificate"
705text t16_m18 "negative bytes refused at parse"
706text t16_m19 "non-finite bytes refused at parse"
707text t16_m20 "unknown endpoint refused at parse"
708
709fn t16_peak_of s view uchar * to f64
710i = ds_find_res_name s
711if lt i 0
712ret -1.0f64
713end
714ret bitcast f64 get ds_sc add 6344 ulong i
715end
716
717fn test_inverted_part1 to void
718d24 = u_day u_d24
719rc = u_eval_file t16_f1 d24
720ok1 = eq rc 8
721ok1 = and ok1 u_rsn_has t16_s_inv
722ok1 = and ok1 u_rsn_has t16_s_fc
723ok1 = and ok1 u_rsn_has t16_s_s20
724ok1 = and ok1 u_rsn_has t16_s_la
725ok1 = and ok1 u_rsn_has t16_s_e10
726ok1 = and ok1 not u_rsn_has t16_s_neg
727u_check ok1 t16_m1
728u_check and eq get ds_sc 3 0 eq get ds_sc 6344 0 t16_m2
729rlen1 = get ds_reason_len 0
730put u_rsn2_len 0 rlen1
731for i ulong rlen1 bound 256
732put u_rsn2 i get ds_reason i
733end
734rc2 = u_eval_file t16_f1 d24
735same = and eq rc rc2 eq rlen1 get ds_reason_len 0
736if same
737for i ulong rlen1 bound 256
738if ne get u_rsn2 i get ds_reason i
739same = false
740break
741end
742end
743end
744u_check same t16_m3
745rc = u_eval_file t16_f2 d24
746u_check and eq rc 8 and u_rsn_has t16_s_fc u_rsn_has t16_s_la t16_m4
747rc = u_eval_file t16_f3 d24
748u_check and eq rc 4 and u_rsn_has t16_s_r1 u_rsn_has t16_s_r2 t16_m5
749rc = u_eval_file t16_f4 d24
750u_check eq rc 0 t16_m6
751u_check u_near t16_peak_of t16_s_mem 80.0f64 1.0e-9f64 t16_m7
752u_check u_near bitcast f64 get ds_sc 3 30.0f64 1.0e-9f64 t16_m8
753rc = u_eval_file t16_f5 d24
754u_check eq rc 0 t16_m9
755u_check u_near t16_peak_of t16_s_mem 80.0f64 1.0e-9f64 t16_m10
756end
757
758fn test_inverted_part2 to void
759d20 = u_day u_d20
760rc = u_eval_body t16_z1 d20 0
761u_check eq rc 0 t16_m11
762u_check u_near bitcast f64 get ds_sc 6344 0.0f64 1.0e-9f64 t16_m12
763rc = u_eval_body t16_z2 d20 0
764u_check eq rc 4 t16_m13
765rc = u_eval_body t16_om d20 0
766u_check eq rc 0 t16_m14
767u_check u_near bitcast f64 get ds_sc 6344 175.0f64 1.0e-9f64 t16_m15
768rc = u_eval_body t16_rnd d20 0
769u_check and eq rc 8 u_rsn_has t16_s_neg t16_m16
770u_check and u_near t16_peak_of t16_s_hbm 0.0f64 1.0e-9f64 eq get ds_sc 3 0 t16_m17
771u_set_txt 0 u_hdr t16_p1
772u_check and eq ds_parse_side 0 9 u_err_has t16_s_fin t16_m18
773u_set_txt 0 u_hdr t16_p2
774u_check and eq ds_parse_side 0 9 u_err_has t16_s_fin t16_m19
775u_set_txt 0 u_hdr t16_p3
776u_check and eq ds_parse_side 0 9 u_err_has t16_s_nop t16_m20
777end
778
779fn main to int
780test_serial_chain
781test_perfect_overlap
782test_shared_bandwidth
783test_capacity_refusal
784test_lifetimes
785test_sync
786test_launch
787test_calibration
788test_intervals
789test_energy
790test_parse_and_cycles
791test_costmodel_reuse
792test_predict_refusal
793test_counterfactual
794test_minimum_work_diff
795test_inverted_part1
796test_inverted_part2
797ds_out_reset
798ds_out_text u_sum1
799ds_out_u64 get u_checks 0
800ds_out_text u_sum2
801ds_out_u64 get u_fail 0
802ds_out_text u_sum3
803ds_out_flush 1
804if ne get u_fail 0 0
805ret 1
806end
807ret 0
808end