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 / head-to-head / test.om

428 lines · 10081 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/head-to-head/test.om: comprehensive verification tests for gpu/head-to-head/lib.om.
3note Compose with: si/directives/om2.om gpu/head-to-head/lib.om gpu/head-to-head/test.om
4
5text h2h_ts_pass "PASS "
6text h2h_ts_fail "FAIL "
7text h2h_ts_nl "\n"
8text h2h_ts_sum_ok "HEAD_TO_HEAD_TEST PASS passed="
9text h2h_ts_sum_fl "HEAD_TO_HEAD_TEST FAIL passed="
10text h2h_ts_fld " failed="
11
12text h2h_tn_1 "exact_parity"
13text h2h_tn_2 "tolerance_boundary_pass"
14text h2h_tn_3 "tolerance_boundary_fail"
15text h2h_tn_4 "nan_rejection_both_arms"
16text h2h_tn_5 "inf_rejection_pos_and_neg"
17text h2h_tn_6 "stats_sort_odd_even_p95"
18text h2h_tn_7 "speedup_bandwidth_iqr_calls"
19text h2h_tn_8 "mutant_control_caught_pass"
20text h2h_tn_9 "mutant_control_escaped_fail"
21text h2h_tn_10 "not_run_and_zero_timing_refusal"
22text h2h_tn_11 "number_parser_u64_f64_sci"
23
24text h2h_tp_u64 "123456789"
25text h2h_tp_f1 "-42.125"
26text h2h_tp_f2 "1.5e-3"
27text h2h_tp_bad "12.3.4"
28
29fn h2h_f64_near a f64 b f64 eps f64 to bool
30if not h2h_f64_is_finite a
31ret false
32end
33if not h2h_f64_is_finite b
34ret false
35end
36ret le fabs sub a b eps
37end
38
39fn h2h_rec_case name view uchar * ok bool tally edit ulong 2 to void
40w = false
41if ok
42put tally 0 add get tally 0 1
43w = h2h_write_all 1 h2h_ts_pass
44else
45put tally 1 add get tally 1 1
46w = h2h_write_all 1 h2h_ts_fail
47end
48w = and w h2h_write_all 1 name
49w = and w h2h_write_all 1 h2h_ts_nl
50if w
51ret
52end
53end
54
55fn test_exact_parity to bool
56a = new f64 4 0.0f64
57b = new f64 4 0.0f64
58put a 0 1.25f64
59put a 1 -3.5f64
60put a 2 0.0f64
61put a 3 1024.75f64
62put b 0 1.25f64
63put b 1 -3.5f64
64put b 2 0.0f64
65put b 3 1024.75f64
66tol = new H2hTol 0.0f64 0.0f64
67res = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
68h2h_check_parity a b tol res
69if ne get res ok 1
70ret false
71end
72if ne get res elem_n 4
73ret false
74end
75if ne get res mismatches 0
76ret false
77end
78if ne get res nan_cnt 0
79ret false
80end
81if ne get res inf_cnt 0
82ret false
83end
84if ne get res max_abs 0.0f64
85ret false
86end
87ret eq get res max_rel 0.0f64
88end
89
90fn test_tol_pass to bool
91a = new f64 2 0.0f64
92b = new f64 2 0.0f64
93note atol=1e-4, rtol=1e-3: at 0.0 limit=1e-4; at 100.0 limit=1e-4 + 0.1 = 0.1001
94put a 0 0.0f64
95put b 0 0.00009f64
96put a 1 100.0f64
97put b 1 100.05f64
98tol = new H2hTol 0.0001f64 0.001f64
99res = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
100h2h_check_parity a b tol res
101if ne get res ok 1
102ret false
103end
104if ne get res mismatches 0
105ret false
106end
107if not h2h_f64_near get res max_abs 0.05f64 0.000001f64
108ret false
109end
110ret gt get res max_rel 0.0f64
111end
112
113fn test_tol_fail to bool
114a = new f64 2 0.0f64
115b = new f64 2 0.0f64
116note atol=1e-4, rtol=1e-3: at 100.0 limit=0.1001; diff=0.2 must FAIL
117put a 0 1.0f64
118put b 0 1.0f64
119put a 1 100.0f64
120put b 1 100.2f64
121tol = new H2hTol 0.0001f64 0.001f64
122res = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
123h2h_check_parity a b tol res
124if ne get res ok 0
125ret false
126end
127if ne get res mismatches 1
128ret false
129end
130ret h2h_f64_near get res max_abs 0.2f64 0.000001f64
131end
132
133fn test_nan_rejection to bool
134a = new f64 3 1.0f64
135b = new f64 3 1.0f64
136qnan = bitcast f64 ulong 0x7ff8000000000000
137put b 1 qnan
138note Even with huge tolerances, NaN MUST be refused
139tol = new H2hTol 1000000.0f64 1000000.0f64
140res = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
141h2h_check_parity a b tol res
142if ne get res ok 0
143ret false
144end
145if ne get res nan_cnt 1
146ret false
147end
148if ne get res mismatches 1
149ret false
150end
151put a 0 qnan
152h2h_check_parity a b tol res
153if ne get res ok 0
154ret false
155end
156if ne get res nan_cnt 2
157ret false
158end
159ret eq get res mismatches 2
160end
161
162fn test_inf_rejection to bool
163a = new f64 2 2.0f64
164b = new f64 2 2.0f64
165pinf = bitcast f64 ulong 0x7ff0000000000000
166ninf = bitcast f64 ulong 0xfff0000000000000
167put a 0 pinf
168put b 0 pinf
169put b 1 ninf
170tol = new H2hTol 1000.0f64 1000.0f64
171res = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
172h2h_check_parity a b tol res
173if ne get res ok 0
174ret false
175end
176if ne get res inf_cnt 3
177ret false
178end
179ret eq get res mismatches 2
180end
181
182fn test_stats_sort to bool
183note Unsorted 20 values: 100..2000 step 100 shuffled
184raw = new ulong 20 0
185scr = new ulong 20 0
186put raw 0 ulong 2000
187put raw 1 ulong 100
188put raw 2 ulong 1500
189put raw 3 ulong 400
190put raw 4 ulong 1900
191put raw 5 ulong 200
192put raw 6 ulong 1800
193put raw 7 ulong 300
194put raw 8 ulong 1700
195put raw 9 ulong 500
196put raw 10 ulong 1600
197put raw 11 ulong 600
198put raw 12 ulong 1400
199put raw 13 ulong 700
200put raw 14 ulong 1300
201put raw 15 ulong 800
202put raw 16 ulong 1200
203put raw 17 ulong 900
204put raw 18 ulong 1100
205put raw 19 ulong 1000
206st = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
207if not h2h_compute_stats raw scr st
208ret false
209end
210if ne get st min_ns 100
211ret false
212end
213if ne get st max_ns 2000
214ret false
215end
216note Even n=20: median = (1000 + 1100) / 2 = 1050.0
217if not h2h_f64_near get st med_ns 1050.0f64 0.000001f64
218ret false
219end
220note Nearest-rank for n=20: q1=idx 4 (500), q3=idx 14 (1500), iqr=1000, p95=idx 18 (1900)
221if ne get st q1_ns 500
222ret false
223end
224if ne get st q3_ns 1500
225ret false
226end
227if ne get st iqr_ns 1000
228ret false
229end
230if ne get st p95_ns 1900
231ret false
232end
233note Odd n=5: [50, 10, 40, 20, 30] -> median=30.0, p95=50
234odd = new ulong 5 0
235put odd 0 ulong 50
236put odd 1 ulong 10
237put odd 2 ulong 40
238put odd 3 ulong 20
239put odd 4 ulong 30
240sto = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
241if not h2h_compute_stats odd scr sto
242ret false
243end
244if not h2h_f64_near get sto med_ns 30.0f64 0.000001f64
245ret false
246end
247ret eq get sto p95_ns 50
248end
249
250fn test_speedup_bw_iqr to bool
251ta = new ulong 4 0
252tb = new ulong 4 0
253scr = new ulong 4 0
254put ta 0 ulong 2000000
255put ta 1 ulong 2000000
256put ta 2 ulong 2000000
257put ta 3 ulong 2000000
258put tb 0 ulong 500000
259put tb 1 ulong 500000
260put tb 2 ulong 500000
261put tb 3 ulong 500000
262sa = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
263sb = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
264oka = h2h_compute_stats ta scr sa
265okb = h2h_compute_stats tb scr sb
266if not and oka okb
267ret false
268end
269sp = h2h_speedup get sa med_ns get sb med_ns
270if not h2h_f64_near sp 4.0f64 0.000001f64
271ret false
272end
273note 4000000 bytes in 500000 ns = 8.0 GB/s; in 2000000 ns = 2.0 GB/s
274bwa = h2h_bw_gbps ulong 4000000 get sa med_ns
275bwb = h2h_bw_gbps ulong 4000000 get sb med_ns
276if not h2h_f64_near bwa 2.0f64 0.000001f64
277ret false
278end
279if not h2h_f64_near bwb 8.0f64 0.000001f64
280ret false
281end
282if ne h2h_iqr_call sa sb H2H_CALL_B_FASTER
283ret false
284end
285if ne h2h_iqr_call sb sa H2H_CALL_A_FASTER
286ret false
287end
288sc = new H2hStats 1 4 2000000 2000000 2000000.0f64 2000000 0 2000000 2000000
289ret eq h2h_iqr_call sa sc H2H_CALL_OVERLAPPING
290end
291
292fn make_test_pair_stats sa edit H2hStats sb edit H2hStats to bool
293ta = new ulong 3 1000000
294tb = new ulong 3 500000
295scr = new ulong 3 0
296oka = h2h_compute_stats ta scr sa
297okb = h2h_compute_stats tb scr sb
298ret and oka okb
299end
300
301fn test_mutant_caught to bool
302sa = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
303sb = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
304if not make_test_pair_stats sa sb
305ret false
306end
307fa = new f64 4 2.5f64
308fb = new f64 4 2.5f64
309fm = new f64 4 0.0f64
310tol = new H2hTol 0.000001f64 0.00001f64
311par = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
312mpar = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
313h2h_check_parity fa fb tol par
314mn = h2h_make_wrong_kernel_mutant fa fm
315if ne mn 4
316ret false
317end
318if not h2h_verify_mutant fa fm tol mpar
319ret false
320end
321sum = new H2hSummary 2 0 4096 0.0f64 0.0f64 0.0f64 0 0 0 0
322h2h_finalize_summary sa sb par 1 1 sum
323if ne get sum verdict H2H_VERDICT_PASS
324ret false
325end
326ret eq get sum reason H2H_REASON_OK
327end
328
329fn test_mutant_escaped_fails to bool
330sa = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
331sb = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
332if not make_test_pair_stats sa sb
333ret false
334end
335fa = new f64 4 2.5f64
336fb = new f64 4 2.5f64
337note Escaping mutant: identical to reference, so parity gate does NOT reject it!
338fm = new f64 4 2.5f64
339tol = new H2hTol 0.000001f64 0.00001f64
340par = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
341mpar = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
342h2h_check_parity fa fb tol par
343if h2h_verify_mutant fa fm tol mpar
344ret false
345end
346sum = new H2hSummary 2 0 4096 0.0f64 0.0f64 0.0f64 0 0 0 0
347h2h_finalize_summary sa sb par 1 0 sum
348if ne get sum verdict H2H_VERDICT_FAIL
349ret false
350end
351ret eq get sum reason H2H_REASON_MUTANT_ESCAPED
352end
353
354fn test_not_run_and_zero_time to bool
355sa = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
356sb = new H2hStats 0 0 0 0 0.0f64 0 0 0 0
357par = new H2hParity 0 0 0 0 0 0.0f64 0.0f64
358sum = new H2hSummary 0 0 0 0.0f64 0.0f64 0.0f64 0 0 0 0
359h2h_finalize_summary sa sb par 0 0 sum
360if ne get sum verdict H2H_VERDICT_NOT_RUN
361ret false
362end
363if ne get sum reason H2H_REASON_NO_PAIRS
364ret false
365end
366note Zero-ns sample MUST be refused by h2h_compute_stats
367bad = new ulong 2 0
368put bad 0 ulong 100
369put bad 1 ulong 0
370scr = new ulong 2 0
371if h2h_compute_stats bad scr sa
372ret false
373end
374ret eq get sa ok 0
375end
376
377fn test_parsers to bool
378if not h2h_parse_u64_ok h2h_tp_u64 0 len h2h_tp_u64
379ret false
380end
381if ne h2h_parse_u64_val h2h_tp_u64 0 len h2h_tp_u64 123456789
382ret false
383end
384if not h2h_parse_f64_ok h2h_tp_f1 0 len h2h_tp_f1
385ret false
386end
387if not h2h_f64_near h2h_parse_f64_val h2h_tp_f1 0 len h2h_tp_f1 -42.125f64 0.000001f64
388ret false
389end
390if not h2h_parse_f64_ok h2h_tp_f2 0 len h2h_tp_f2
391ret false
392end
393if not h2h_f64_near h2h_parse_f64_val h2h_tp_f2 0 len h2h_tp_f2 0.0015f64 0.0000001f64
394ret false
395end
396ret not h2h_parse_f64_ok h2h_tp_bad 0 len h2h_tp_bad
397end
398
399fn main to int
400tally = new ulong 2 0
401h2h_rec_case h2h_tn_1 test_exact_parity tally
402h2h_rec_case h2h_tn_2 test_tol_pass tally
403h2h_rec_case h2h_tn_3 test_tol_fail tally
404h2h_rec_case h2h_tn_4 test_nan_rejection tally
405h2h_rec_case h2h_tn_5 test_inf_rejection tally
406h2h_rec_case h2h_tn_6 test_stats_sort tally
407h2h_rec_case h2h_tn_7 test_speedup_bw_iqr tally
408h2h_rec_case h2h_tn_8 test_mutant_caught tally
409h2h_rec_case h2h_tn_9 test_mutant_escaped_fails tally
410h2h_rec_case h2h_tn_10 test_not_run_and_zero_time tally
411h2h_rec_case h2h_tn_11 test_parsers tally
412passed = get tally 0
413failed = get tally 1
414ok = false
415if eq failed 0
416ok = h2h_write_all 1 h2h_ts_sum_ok
417else
418ok = h2h_write_all 1 h2h_ts_sum_fl
419end
420h2h_write_u64 1 passed
421ok = and ok h2h_write_all 1 h2h_ts_fld
422h2h_write_u64 1 failed
423ok = and ok h2h_write_all 1 h2h_ts_nl
424if and ok eq failed 0
425ret 0
426end
427ret 1
428end