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 / bridge / core / test.om

218 lines · 5999 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note bridge/core/test.om: positive & negative control test suite for
3note omega-bridge Native ABI v2 and ggml-omega tensor-bridge descriptor/op dispatch.
4note Compose with: si/directives/om2.om bridge/core/abi_ggml.om bridge/core/test.om
5
6text t_pass "PASS "
7text t_fail "FAIL "
8text t_nl "\n"
9
10text t_c1 "abi_v2_param_slot_budget_and_overflow_controls"
11text t_c2 "abi_v2_layout_bounds_and_field_disjointness"
12text t_c3 "abi_v2_single_edit_aliasing_and_trap_status"
13text t_c4 "ggml_row_bytes_and_q8_0_block_alignment"
14text t_c5 "ggml_tensor_stride_validation_and_negative_controls"
15text t_c6 "ggml_supports_op_dispatch_and_refusals"
16text t_c7 "ggml_tile_plan_exact_reconstruction"
17text t_done "PASS bridge-abi-ggml all 7 test suites passed\n"
18
19fn report_case name view uchar * ok bool to int
20if ok
21w1 = br_write_all int 1 t_pass
22w2 = br_write_all int 1 name
23w3 = br_write_all int 1 t_nl
24if and w1 and w2 w3
25ret int 0
26end
27ret int 1
28end
29w4 = br_write_all int 1 t_fail
30w5 = br_write_all int 1 name
31w6 = br_write_all int 1 t_nl
32if and w4 and w5 w6
33ret int 1
34end
35ret int 1
36end
37
38fn test_slot_budget to bool
39if ne br_check_param_slots ulong 2 ulong 0 ulong 2 BR_OK
40ret false
41end
42if ne br_check_param_slots ulong 0 ulong 0 ulong 3 BR_OK
43ret false
44end
45note Negative controls: 2 unsized views + 3 scalars = 7 slots (error 9 in omc)
46if ne br_check_param_slots ulong 3 ulong 0 ulong 2 BR_ERR_SLOT_OVERFLOW
47ret false
48end
49if ne br_check_param_slots ulong 7 ulong 0 ulong 0 BR_ERR_SLOT_OVERFLOW
50ret false
51end
52ret true
53end
54
55fn test_layout_bounds to bool
56if ne br_validate_layout_field ulong 64 ulong 0 ulong 8 ulong 4 BR_OK
57ret false
58end
59if ne br_validate_layout_field ulong 64 ulong 32 ulong 4 ulong 8 BR_OK
60ret false
61end
62note Negative controls: zero layout, >4096 layout, zero count, field OOB
63if ne br_validate_layout_field ulong 0 ulong 0 ulong 4 ulong 1 BR_ERR_BAD_LAYOUT_SIZE
64ret false
65end
66if ne br_validate_layout_field ulong 4097 ulong 0 ulong 4 ulong 1 BR_ERR_BAD_LAYOUT_SIZE
67ret false
68end
69if ne br_validate_layout_field ulong 64 ulong 0 ulong 4 ulong 0 BR_ERR_BAD_FIELD_COUNT
70ret false
71end
72if ne br_validate_layout_field ulong 64 ulong 60 ulong 8 ulong 1 BR_ERR_FIELD_OOB
73ret false
74end
75if not br_spans_disjoint ulong 0 ulong 32 ulong 32 ulong 32
76ret false
77end
78if br_spans_disjoint ulong 0 ulong 33 ulong 32 ulong 32
79ret false
80end
81ret true
82end
83
84fn test_aliasing_and_traps to bool
85if ne br_check_single_edit ulong 1000 ulong 64 ulong 1064 ulong 64 BR_OK
86ret false
87end
88if ne br_check_single_edit ulong 1000 ulong 64 ulong 1032 ulong 64 BR_ERR_ALIAS_OVERLAP
89ret false
90end
91if ne br_check_single_edit ulong 1000 ulong 64 ulong 1000 ulong 64 BR_ERR_ALIAS_OVERLAP
92ret false
93end
94if ne br_check_exit_status ulong 0 BR_OK
95ret false
96end
97if ne br_check_exit_status ulong 103 BR_ERR_OMEGA_TRAP
98ret false
99end
100if ne br_check_exit_status ulong 114 BR_ERR_OMEGA_TRAP
101ret false
102end
103if ne br_check_exit_status ulong 1 BR_ERR_HOST_FAILURE
104ret false
105end
106ret true
107end
108
109fn test_ggml_row_bytes to bool
110if ne ggml_row_bytes GGML_F32 ulong 128 ulong 512
111ret false
112end
113if ne ggml_row_bytes GGML_F16 ulong 128 ulong 256
114ret false
115end
116if ne ggml_row_bytes GGML_Q8_0 ulong 64 ulong 68
117ret false
118end
119note Negative controls: misaligned Q8_0 (not multiple of 32), zero ne0, unknown dtype
120if ne ggml_row_bytes GGML_Q8_0 ulong 33 ulong 0
121ret false
122end
123if ne ggml_row_bytes GGML_F32 ulong 0 ulong 0
124ret false
125end
126if ne ggml_row_bytes ulong 99 ulong 32 ulong 0
127ret false
128end
129ret true
130end
131
132fn test_ggml_strides to bool
133if ne ggml_validate_tensor GGML_F32 ulong 64 ulong 4 ulong 4 ulong 256 BR_OK
134ret false
135end
136if ne ggml_validate_tensor GGML_Q8_0 ulong 64 ulong 4 ulong 34 ulong 68 BR_OK
137ret false
138end
139note Negative controls: nb1 < row_bytes (overlapping rows!), nb0 < elem_size, misaligned Q8_0
140if ne ggml_validate_tensor GGML_F32 ulong 64 ulong 4 ulong 4 ulong 200 BR_ERR_BAD_STRIDE
141ret false
142end
143if ne ggml_validate_tensor GGML_F32 ulong 64 ulong 4 ulong 2 ulong 256 BR_ERR_BAD_STRIDE
144ret false
145end
146if ne ggml_validate_tensor GGML_Q8_0 ulong 30 ulong 4 ulong 34 ulong 68 BR_ERR_BAD_BLOCK_ALIGN
147ret false
148end
149if ne ggml_validate_tensor ulong 77 ulong 64 ulong 4 ulong 4 ulong 256 BR_ERR_BAD_DTYPE
150ret false
151end
152ret true
153end
154
155fn test_ggml_ops to bool
156if ne ggml_supports_op GGML_OP_ADD GGML_F32 GGML_F32 GGML_F32 ulong 64 BR_OK
157ret false
158end
159if ne ggml_supports_op GGML_OP_MUL_MAT GGML_Q8_0 GGML_F32 GGML_F32 ulong 256 BR_OK
160ret false
161end
162if ne ggml_supports_op GGML_OP_MUL_MAT GGML_F16 GGML_F32 GGML_F32 ulong 128 BR_OK
163ret false
164end
165if ne ggml_supports_op GGML_OP_CPY GGML_Q8_0 GGML_F32 GGML_F32 ulong 64 BR_OK
166ret false
167end
168note Negative controls: F16 ADD unsupported, CPY to Q8_0 unsupported, misaligned Q8_0 MUL_MAT, unknown op
169if ne ggml_supports_op GGML_OP_ADD GGML_F16 GGML_F16 GGML_F16 ulong 64 BR_ERR_UNSUPPORTED_OP
170ret false
171end
172if ne ggml_supports_op GGML_OP_CPY GGML_F32 GGML_F32 GGML_Q8_0 ulong 64 BR_ERR_UNSUPPORTED_OP
173ret false
174end
175if ne ggml_supports_op GGML_OP_MUL_MAT GGML_Q8_0 GGML_F32 GGML_F32 ulong 30 BR_ERR_BAD_BLOCK_ALIGN
176ret false
177end
178if ne ggml_supports_op ulong 99 GGML_F32 GGML_F32 GGML_F32 ulong 64 BR_ERR_UNSUPPORTED_OP
179ret false
180end
181ret true
182end
183
184fn test_ggml_tiling to bool
185plan = new ulong 2 0
186if ne ggml_tile_plan ulong 100 ulong 32 plan BR_OK
187ret false
188end
189if or ne get plan 0 ulong 3 ne get plan 1 ulong 4
190ret false
191end
192if ne add mul get plan 0 ulong 32 get plan 1 ulong 100
193ret false
194end
195if ne ggml_tile_plan ulong 100 ulong 0 plan BR_ERR_BAD_TILE
196ret false
197end
198ret true
199end
200
201fn main to int
202fail = int 0
203fail = add fail report_case t_c1 test_slot_budget
204fail = add fail report_case t_c2 test_layout_bounds
205fail = add fail report_case t_c3 test_aliasing_and_traps
206fail = add fail report_case t_c4 test_ggml_row_bytes
207fail = add fail report_case t_c5 test_ggml_strides
208fail = add fail report_case t_c6 test_ggml_ops
209fail = add fail report_case t_c7 test_ggml_tiling
210if ne fail int 0
211ret int 1
212end
213ok = br_write_all int 1 t_done
214if not ok
215ret int 1
216end
217ret int 0
218end