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