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 / orig4 / shadow-test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note omega-mv#731 ORIG-4 in-process tests of native/orig4/shadow.om (same unit, this caller |
| 3 | note in place of main). stdin: the candidate MLP image (11560 bytes), then the candidate |
| 4 | note affine image (1816 bytes). Records: the SYNTHETIC |
| 5 | note fixture sxgen 7 780 (allow-list hash 626048380840256264). Groups: tadmit (the real |
| 6 | note candidate is admitted, bound_matches=no, and the advice equals selmain E-mode's slpick |
| 7 | note after slbest for 20 records), trefuse (every refusal class through the same functions |
| 8 | note the advisor calls, state unchanged), tpred (non-finite score, out-of-distribution and |
| 9 | note budget predicates), tnarrow (50 records: the advised arm always satisfies oxcand and |
| 10 | note costs no less than the oracle), tnaff (the same over 780 records with the affine image). |
| 11 | global HT ulong 2 |
| 12 | global HI uchar 11560 |
| 13 | text TALW "626048380840256264 SYNTHETIC fixture-seed7-780-records\n" |
| 14 | text TREV "626048380840256264 REVOKED fixture-seed7-780-records\n" |
| 15 | text TABS "1 SYNTHETIC not-this-fixture\n" |
| 16 | text TPASS "ORIG4_SHADOW_TEST_PASS checks=" |
| 17 | text TFAIL "ORIG4_SHADOW_TEST_FAIL check=" |
| 18 | text TNL "\n" |
| 19 | |
| 20 | fn tck ok bool to void |
| 21 | put HT 0 add get HT 0 1 |
| 22 | if not ok |
| 23 | w = write 1 TFAIL 0 len TFAIL |
| 24 | wnum get HT 0 |
| 25 | w = write 1 TNL 0 1 |
| 26 | exit 1 |
| 27 | end |
| 28 | end |
| 29 | |
| 30 | fn timg to void |
| 31 | note The candidate image from stdin into SI and a pristine copy into HI. |
| 32 | tck eq hvrdimg 11560 11560 |
| 33 | for i ulong 11560 |
| 34 | put HI i get SI i |
| 35 | end |
| 36 | end |
| 37 | |
| 38 | fn trestore to void |
| 39 | for i ulong 11560 |
| 40 | put SI i get HI i |
| 41 | end |
| 42 | end |
| 43 | |
| 44 | fn tlb n ulong to void |
| 45 | note Allow-list text n: 0 the fixture SYNTHETIC line, 1 the same hash REVOKED, 2 absent. |
| 46 | for i ulong 4096 |
| 47 | put LB i 0 |
| 48 | end |
| 49 | if eq n 0 |
| 50 | for i ulong len TALW |
| 51 | put LB i get TALW i |
| 52 | end |
| 53 | end |
| 54 | if eq n 1 |
| 55 | for i ulong len TREV |
| 56 | put LB i get TREV i |
| 57 | end |
| 58 | end |
| 59 | if eq n 2 |
| 60 | for i ulong len TABS |
| 61 | put LB i get TABS i |
| 62 | end |
| 63 | end |
| 64 | end |
| 65 | |
| 66 | fn tlbn to ulong |
| 67 | n = ulong 0 |
| 68 | for i ulong 4096 |
| 69 | if ne get LB i 0 |
| 70 | n = add i 1 |
| 71 | end |
| 72 | end |
| 73 | ret n |
| 74 | end |
| 75 | |
| 76 | fn tfix to ulong |
| 77 | note Regenerate and admit the fixture; returns the byte count. |
| 78 | n = sxgen 7 780 |
| 79 | tck eq oxfnv n 626048380840256264 |
| 80 | tck eq oxload n 0 |
| 81 | tck eq get RC 0 780 |
| 82 | ret n |
| 83 | end |
| 84 | |
| 85 | fn trbput r ulong i ulong v ulong to void |
| 86 | note Word i of raw record r in RB (little-endian), for the record refusal tests. |
| 87 | p = add mul r 256 mul i 8 |
| 88 | for k ulong 8 |
| 89 | put RB add p k uchar and shr v mul k 8 255 |
| 90 | end |
| 91 | end |
| 92 | |
| 93 | fn tadmit to void |
| 94 | note The real candidate: admitted, bound_matches=no (trained on the owner records, not the |
| 95 | note fixture), and for 20 records the advice is slpick's choice with the same score bits. |
| 96 | tlb 0 |
| 97 | tck eq oxallow tlbn oxfnv get RC 1 2 |
| 98 | tck eq hvimage 11560 0 |
| 99 | tck not slbound 0 |
| 100 | tck eq get SS 0 2 |
| 101 | tck eq get SS 15 705 |
| 102 | tck eq get SS 11 16622604375676129865 |
| 103 | tck ne get SS 11 get RC 2 |
| 104 | tck eq siget 11552 9232652764948363499 |
| 105 | slbest |
| 106 | for r ulong 20 |
| 107 | c = hvscore r |
| 108 | tck ge c 0 |
| 109 | tck eq ulong c slpick r |
| 110 | tck eq get HV 0 slfwd r ulong c |
| 111 | end |
| 112 | end |
| 113 | |
| 114 | fn tref1 to void |
| 115 | note Image refusals through the advisor's admission (sladmit) with the current params left |
| 116 | note untouched; the resume-mode slload additionally refuses the unbound candidate (-8). |
| 117 | f = slfnvp 705 |
| 118 | put SI 300 xor get SI 300 1 |
| 119 | tck eq hvimage 11560 -5 |
| 120 | trestore |
| 121 | tck eq hvimage 11559 -1 |
| 122 | tck eq hvimage 1816 -4 |
| 123 | put SI 0 xor get SI 0 1 |
| 124 | tck eq hvimage 11560 -2 |
| 125 | trestore |
| 126 | put SI 8 2 |
| 127 | tck eq hvimage 11560 -3 |
| 128 | trestore |
| 129 | tck eq slload 0 11560 -8 |
| 130 | tck eq slfnvp 705 f |
| 131 | tck eq hvimage 11560 0 |
| 132 | tck not slbound 0 |
| 133 | end |
| 134 | |
| 135 | fn tref2 to void |
| 136 | note Record refusals through oxload: wrong profile (cache bytes), forged outcome word, |
| 137 | note unknown arm bits; each refusal leaves nothing admitted (RC[0] = 0). |
| 138 | n = get RC 1 |
| 139 | trbput 0 10 1048576 |
| 140 | tck eq oxload n -9 |
| 141 | tck eq get RC 0 0 |
| 142 | n = tfix |
| 143 | trbput 3 31 1 |
| 144 | tck eq oxload n -7 |
| 145 | tck eq get RC 0 0 |
| 146 | n = tfix |
| 147 | trbput 5 12 159 |
| 148 | tck eq oxload n -5 |
| 149 | tck eq get RC 0 0 |
| 150 | n = tfix |
| 151 | end |
| 152 | |
| 153 | fn tref3 to void |
| 154 | note Allow-list: REVOKED and absent refuse; SYNTHETIC admits. |
| 155 | h = oxfnv get RC 1 |
| 156 | tlb 1 |
| 157 | tck eq oxallow tlbn h -12 |
| 158 | tlb 2 |
| 159 | tck eq oxallow tlbn h -13 |
| 160 | tlb 0 |
| 161 | tck eq oxallow tlbn h 2 |
| 162 | end |
| 163 | |
| 164 | fn tpred to void |
| 165 | note A non-finite parameter makes the score non-finite and the advice a fallback; core |
| 166 | note class 2 or pressure 2 is out of distribution; the budget predicate. |
| 167 | slbest |
| 168 | tck ge hvscore 0 0 |
| 169 | put SP 704 2139095040 |
| 170 | tck eq hvscore 0 -3 |
| 171 | tck not affinite get HV 0 |
| 172 | slbest |
| 173 | tck ge hvscore 0 0 |
| 174 | tck not hvood 0 |
| 175 | put RW 3 2 |
| 176 | tck hvood 0 |
| 177 | tck eq hvscore 0 -1 |
| 178 | put RW 3 0 |
| 179 | put RW 4 2 |
| 180 | tck hvood 0 |
| 181 | tck eq hvscore 0 -1 |
| 182 | put RW 4 1 |
| 183 | tck not hvood 0 |
| 184 | put RW 4 0 |
| 185 | put HV 6 10 |
| 186 | tck hvbudget 10 |
| 187 | tck not hvbudget 9 |
| 188 | tck hvbudget 2047 |
| 189 | end |
| 190 | |
| 191 | fn tsingle to void |
| 192 | note With only the reference arm admissible there is nothing to rank. |
| 193 | e = get RW 12 |
| 194 | put RW 12 1 |
| 195 | tck eq hvnarms 0 1 |
| 196 | tck eq hvscore 0 -2 |
| 197 | put RW 12 e |
| 198 | tck eq hvnarms 0 5 |
| 199 | end |
| 200 | |
| 201 | fn tnarrow to void |
| 202 | note The advice never widens the candidate set: the advised arm satisfies oxcand, and its |
| 203 | note recorded cost is never below the oracle's. |
| 204 | slbest |
| 205 | for r ulong 50 |
| 206 | c = hvscore r |
| 207 | tck ge c 0 |
| 208 | tck oxcand r ulong c |
| 209 | tck lt ulong c oxword r 13 |
| 210 | tck ge oxcost r ulong c oxcost r oxbest r |
| 211 | end |
| 212 | end |
| 213 | |
| 214 | fn tnaff to void |
| 215 | note tnarrow on the affine candidate (the next 1816 stdin bytes) over all 780 fixture |
| 216 | note records under v1 admission: every record is scored, the advised arm satisfies oxcand, |
| 217 | note is one of the fixture's measured arms 0..4, and costs no less than the oracle. |
| 218 | n = tfix |
| 219 | tck eq hvrdimg 1816 1816 |
| 220 | tck eq hvimage 1816 0 |
| 221 | tck eq get SS 0 1 |
| 222 | tck eq get SS 15 96 |
| 223 | slbest |
| 224 | for r ulong 780 |
| 225 | c = hvscore r |
| 226 | tck ge c 0 |
| 227 | tck oxcand r ulong c |
| 228 | tck le ulong c 4 |
| 229 | tck ge oxcost r ulong c oxcost r oxbest r |
| 230 | end |
| 231 | end |
| 232 | |
| 233 | fn tv2 to void |
| 234 | note v2 admission (oxadm2) and the retrieval advisor kind: refused records are in no split |
| 235 | note (oxpart 3); retrieval advice is select.om's slnear; the image scorer is still slpick. |
| 236 | n = sxgen 7 780 |
| 237 | tck eq oxadm2 n 0 |
| 238 | tck eq get RC 10 468 |
| 239 | k = ulong 0 |
| 240 | for r ulong 780 |
| 241 | if eq oxpart r 3 |
| 242 | k = add k 1 |
| 243 | end |
| 244 | end |
| 245 | tck eq k 312 |
| 246 | put HV 7 1 |
| 247 | k = ulong 0 |
| 248 | for r ulong 200 |
| 249 | if lt oxpart r 3 |
| 250 | c = hvscore r |
| 251 | tck ge c 0 |
| 252 | tck eq ulong c slnear r |
| 253 | tck eq get HV 0 0 |
| 254 | k = add k 1 |
| 255 | end |
| 256 | end |
| 257 | tck gt k 0 |
| 258 | put HV 7 0 |
| 259 | slbest |
| 260 | for r ulong 200 |
| 261 | if lt oxpart r 3 |
| 262 | c = hvscore r |
| 263 | tck eq ulong c slpick r |
| 264 | end |
| 265 | end |
| 266 | end |
| 267 | |
| 268 | fn main to int |
| 269 | timg |
| 270 | n = tfix |
| 271 | tadmit |
| 272 | tref1 |
| 273 | tref2 |
| 274 | tref3 |
| 275 | tpred |
| 276 | tsingle |
| 277 | tnarrow |
| 278 | tv2 |
| 279 | tnaff |
| 280 | w = write 1 TPASS 0 len TPASS |
| 281 | wnum get HT 0 |
| 282 | w = write 1 TNL 0 1 |
| 283 | ret 0 |
| 284 | end |