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 / turing / test_tc_produce.om

229 lines · 4449 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note tests/turing/test_tc_produce.om: EXP-001 producer test in pure seeded OM-2.
5note Ports 100% of tests/turing/test_tc_produce.c (60 checks).
6note Composed after seed/ng/sha256.om, tc_pstream.om, tc_range_lib.om, tc_rans.om, tc_produce.om.
7
8text TTP_FIX0 "tests/turing/fixtures/ctr1_seed1_crumbs05-07.ctr"
9text TTP_FIX1 "tests/turing/fixtures/ctr1_seed1_crumbs10-12.ctr"
10text TTP_MOD0 "evidence/TURING_YIELD/ty2_baseline.tym"
11text TTP_MOD1 "evidence/TURING_YIELD/ty2_candidate.tym"
12text TTP_DIG0 "59ae9398da24e809d92ab39e7456382a0a4b7e93e203862be6d2ca55450dfd04"
13text TTP_DIG1 "64a57ba9cf6f8b6e4558751ef2145ae2aa729c5214bfa29373eabfa220a57bc7"
14text TTP_DET_EXT ".det"
15text TTP_S_FIX "fixture="
16text TTP_S_MOD " model="
17text TTP_S_N " n="
18text TTP_S_TPS " tps1="
19text TTP_S_UB " ideal_ub="
20text TTP_S_COD " coder="
21text TTP_S_BYT " bytes="
22text TTP_S_HDR "test_tc_produce: "
23text TTP_S_PAS " passed, "
24text TTP_S_FAI " failed\n"
25text TTP_S_F "FAIL: "
26
27global ttp_pass ulong 1
28global ttp_fail ulong 1
29global ttp_det_fd int 1
30global ttp_arg uchar 1024
31
32fn ttp_chk cond bool msg view uchar * to void
33if cond
34put ttp_pass 0 add get ttp_pass 0 1
35ret
36end
37put ttp_fail 0 add get ttp_fail 0 1
38tc_out_reset
39tc_out_str TTP_S_F
40tc_out_str msg
41tc_out_byte 10
42z = tc_out_flush 1
43end
44
45fn ttp_load_fix f ulong to int
46if eq f 0
47rc = tp_ctr1_read TTP_FIX0 0 len TTP_FIX0
48if ne rc TC_OK
49ret rc
50end
51ret tc_file_sha256 TTP_FIX0 0 len TTP_FIX0
52end
53rc = tp_ctr1_read TTP_FIX1 0 len TTP_FIX1
54if ne rc TC_OK
55ret rc
56end
57ret tc_file_sha256 TTP_FIX1 0 len TTP_FIX1
58end
59
60fn ttp_check_mdig mi ulong to bool
61if eq mi 0
62if ne tc_unhex_to_exp TTP_DIG0 0 len TTP_DIG0 1 TC_OK
63ret false
64end
65else
66if ne tc_unhex_to_exp TTP_DIG1 0 len TTP_DIG1 1 TC_OK
67ret false
68end
69end
70for i ulong 32
71if ne get tp_mdig i get tc_exp_mod i
72ret false
73end
74end
75ret true
76end
77
78fn ttp_run_coder f ulong c ulong ub long to void
79rc = int 0
80if eq c 1
81rc = tc_range_encode
82else
83rc = tc_rans_encode
84end
85ttp_chk eq rc TC_OK TTP_S_COD
86if ne rc TC_OK
87ret
88end
89cn = get tc_cb_len 0
90if eq c 1
91rc = tc_range_decode cn
92else
93rc = tc_rans_decode cn
94end
95ok = eq rc TC_OK
96if ok
97n = get tc_sy_n 0
98if ne get tc_dsy_n 0 n
99ok = false
100else
101for i ulong n bound 500000
102if ne get tc_dsy_sym i get tc_sy_sym i
103ok = false
104break
105end
106end
107end
108end
109ttp_chk ok TTP_S_COD
110tc_out_reset
111tc_out_str TTP_S_FIX
112tc_out_u64 f
113tc_out_str TTP_S_MOD
114for i ulong 8
115tc_out_hex_byte get tp_mdig i
116end
117tc_out_str TTP_S_N
118tc_out_u64 get tc_ps_n 0
119tc_out_str TTP_S_TPS
120tc_out_hex_ps_dig 32
121tc_out_str TTP_S_UB
122tc_out_i64 ub
123tc_out_str TTP_S_COD
124tc_out_u64 c
125tc_out_str TTP_S_BYT
126tc_out_u64 cn
127tc_out_byte 10
128z = tc_out_flush get ttp_det_fd 0
129end
130
131fn ttp_run_model f ulong mi ulong to void
132if lt mi 2
133rc = int 0
134if eq mi 0
135rc = tc_load_model TTP_MOD0 0 len TTP_MOD0
136else
137rc = tc_load_model TTP_MOD1 0 len TTP_MOD1
138end
139ttp_chk eq rc TC_OK TTP_S_MOD
140ttp_chk ttp_check_mdig mi TTP_S_MOD
141else
142rc = tp_model_uniform 9
143if ne rc TC_OK
144ret
145end
146end
147rc = tc_produce
148ttp_chk eq rc TC_OK TTP_S_TPS
149if ne rc TC_OK
150ret
151end
152rc1 = tc_ps_serialize
153rc2 = tc_sy_serialize 0
154rc3 = int -1
155rc4 = int -1
156if eq rc1 TC_OK
157if eq rc2 TC_OK
158rc3 = tc_ps_parse get tc_pb_len 0
159rc4 = tc_sy_parse get tc_sb_len 0
160end
161end
162ok = false
163if eq rc1 TC_OK
164if eq rc2 TC_OK
165if eq rc3 TC_OK
166if eq rc4 TC_OK
167ok = true
168end
169end
170end
171end
172ttp_chk ok TTP_S_TPS
173for i ulong 32
174put tc_exp_prof i get tp_prof_d i
175put tc_exp_mod i get tp_mdig i
176put tc_exp_dat i get tp_dat_d i
177end
178ttp_chk eq tc_ps_expect 1 1 1 TC_OK TTP_S_MOD
179put tc_exp_mod 0 xor get tc_exp_mod 0 1
180ttp_chk eq tc_ps_expect 1 1 1 TC_E_MODEL TTP_S_MOD
181ub = tc_ideal_ub 0 get tc_ps_n 0
182ttp_run_coder f 1 ub
183ttp_run_coder f 2 ub
184end
185
186fn main to int
187if ne argcnt 2
188ret 2
189end
190alen = argread 1 ttp_arg 0 900
191if le alen 0
192ret 2
193end
194ap = ulong alen
195for i ulong 4
196put ttp_arg add ap i get TTP_DET_EXT i
197end
198fd = fopen ttp_arg 0 add ap 4 577 420
199if lt fd 0
200ret 2
201end
202put ttp_det_fd 0 int fd
203for i ulong 32
204put tp_prof_d i 0
205end
206for f ulong 2
207rc = ttp_load_fix f
208ttp_chk and eq rc TC_OK gt get tp_ev_n 0 0 TTP_S_FIX
209ttp_chk eq rc TC_OK TTP_S_FIX
210for i ulong 32
211put tp_dat_d i get tc_sh_out i
212end
213for mi ulong 3
214ttp_run_model f mi
215end
216end
217z = fclose get ttp_det_fd 0
218tc_out_reset
219tc_out_str TTP_S_HDR
220tc_out_u64 get ttp_pass 0
221tc_out_str TTP_S_PAS
222tc_out_u64 get ttp_fail 0
223tc_out_str TTP_S_FAI
224z2 = tc_out_flush 1
225if ne get ttp_fail 0 0
226ret 1
227end
228ret 0
229end