Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/reservoir/test_res_mat.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / reservoir / test_res_mat.om` 571 lines ยท 12292 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 note 4 note Pure seeded OM-2 Gate 2 tests for res_inflate.om and res_mat.om. 5 note Replaces tests/reservoir/test_res_mat.c. 6 note Concatenated after src/reservoir/reservoir.om, tools/reservoir/res_inflate.om, tools/reservoir/res_mat.om. 7 8 text t_fix5 "tests/reservoir/fixtures/Length5.mat" 9 text t_fix50 "tests/reservoir/fixtures/Length50.mat" 10 text t_absent "tests/reservoir/fixtures/absent.mat" 11 text t_wiki "Wikipedia" 12 text t_conmat "conmat" 13 text t_ground "ground" 14 text t_inex "inex" 15 text t_nosuch "no_such_variable" 16 text t_hdr "test_res_mat: " 17 text t_chks " checks, " 18 text t_fld " failed\n" 19 text t_fail_pfx "FAIL test_res_mat check #" 20 text t_nl "\n" 21 22 global tm_checks ulong 1 23 global tm_fail ulong 1 24 global tm_f ulong 98 25 global tm_g ulong 98 26 global tm_file_bytes uchar 4096 27 global tm_edges ulong 128 28 29 fn tm_write_str s view uchar * to void 30 _w = write 1 s 0 len s 31 end 32 33 fn tm_write_u64 v ulong to void 34 buf = new uchar 24 0 35 if eq v 0 36 put buf 0 uchar 48 37 _w = write 1 buf 0 1 38 ret 39 end 40 x = v 41 n = ulong 0 42 while gt x 0 bound 24 43 put buf n uchar add 48 rem x 10 44 x = div x 10 45 n = add n 1 46 end 47 rev = new uchar 24 0 48 for i ulong n bound 24 49 put rev i get buf sub sub n 1 i 50 end 51 _w = write 1 rev 0 n 52 end 53 54 fn tm_check ok bool to void 55 c = add get tm_checks 0 1 56 put tm_checks 0 c 57 if not ok 58 put tm_fail 0 add get tm_fail 0 1 59 _w1 = write 2 t_fail_pfx 0 len t_fail_pfx 60 tm_write_u64 c 61 _w2 = write 2 t_nl 0 1 62 end 63 end 64 65 fn tm_init_sha5 dst edit uchar 32 to void 66 put dst 0 0xdc 67 put dst 1 0x6e 68 put dst 2 0x79 69 put dst 3 0x14 70 put dst 4 0xd2 71 put dst 5 0x16 72 put dst 6 0xa2 73 put dst 7 0x1f 74 put dst 8 0x66 75 put dst 9 0x4a 76 put dst 10 0xdc 77 put dst 11 0xd4 78 put dst 12 0x84 79 put dst 13 0x3e 80 put dst 14 0x9f 81 put dst 15 0x70 82 put dst 16 0x56 83 put dst 17 0x16 84 put dst 18 0xdf 85 put dst 19 0x47 86 put dst 20 0x51 87 put dst 21 0x18 88 put dst 22 0x79 89 put dst 23 0xba 90 put dst 24 0x0b 91 put dst 25 0xbe 92 put dst 26 0xce 93 put dst 27 0xb2 94 put dst 28 0x41 95 put dst 29 0xb9 96 put dst 30 0xb5 97 put dst 31 0x0a 98 end 99 100 fn tm_init_sha50 dst edit uchar 32 to void 101 put dst 0 0xff 102 put dst 1 0x4c 103 put dst 2 0x9d 104 put dst 3 0x14 105 put dst 4 0xab 106 put dst 5 0xb6 107 put dst 6 0xf6 108 put dst 7 0x4b 109 put dst 8 0x1a 110 put dst 9 0xb9 111 put dst 10 0xf3 112 put dst 11 0x01 113 put dst 12 0x07 114 put dst 13 0x2d 115 put dst 14 0xc6 116 put dst 15 0x73 117 put dst 16 0x16 118 put dst 17 0xb7 119 put dst 18 0xfd 120 put dst 19 0x59 121 put dst 20 0xfe 122 put dst 21 0x61 123 put dst 22 0xd0 124 put dst 23 0xb7 125 put dst 24 0x63 126 put dst 25 0x2e 127 put dst 26 0xe4 128 put dst 27 0x67 129 put dst 28 0xa8 130 put dst 29 0xc2 131 put dst 30 0xaa 132 put dst 31 0xe3 133 end 134 135 fn tm_inf_out_eq_wiki to bool 136 if ne get inf_out_len 0 9 137 ret false 138 end 139 for i ulong 9 bound 9 140 if ne get inf_out i get t_wiki i 141 ret false 142 end 143 end 144 ret true 145 end 146 147 fn tm_test_inflate_basic to void 148 tm_check eq res_adler32 t_wiki 0 9 0x11e60398 149 tm_check eq res_adler32 t_wiki 0 0 1 150 st = new uchar 20 0 151 put st 0 0x78 152 put st 1 0x01 153 put st 2 0x01 154 put st 3 0x09 155 put st 4 0x00 156 put st 5 0xf6 157 put st 6 0xff 158 for i ulong 9 bound 9 159 put st add 7 i get t_wiki i 160 end 161 put st 16 0x11 162 put st 17 0xe6 163 put st 18 0x03 164 put st 19 0x98 165 tm_check eq res_zlib_inflate view st 0 20 RES_INF_OK 166 tm_check and tm_inf_out_eq_wiki eq get inf_consumed 0 20 167 put st 5 xor get st 5 1 168 tm_check eq res_zlib_inflate view st 0 20 RES_INF_ERR_BLOCK 169 end 170 171 fn tm_test_inflate_fixed to void 172 fx = new uchar 17 0 173 put fx 0 0x78 174 put fx 1 0x9c 175 put fx 2 0x0b 176 put fx 3 0xcf 177 put fx 4 0xcc 178 put fx 5 0xce 179 put fx 6 0x2c 180 put fx 7 0x48 181 put fx 8 0x4d 182 put fx 9 0xc9 183 put fx 10 0x4c 184 put fx 11 0x04 185 put fx 12 0x00 186 put fx 13 0x11 187 put fx 14 0xe6 188 put fx 15 0x03 189 put fx 16 0x98 190 tm_check eq res_zlib_inflate view fx 0 17 RES_INF_OK 191 tm_check and tm_inf_out_eq_wiki eq get inf_consumed 0 17 192 for cut ulong 17 bound 17 193 tm_check ne res_zlib_inflate view fx 0 cut RES_INF_OK 194 end 195 put fx 16 xor get fx 16 1 196 tm_check eq res_zlib_inflate view fx 0 17 RES_INF_ERR_ADLER 197 end 198 199 fn tm_test_inflate_refusals to void 200 hc = new uchar 11 0 201 put hc 0 0x78 202 put hc 1 0x00 203 put hc 2 0x01 204 put hc 5 0xff 205 put hc 6 0xff 206 put hc 10 0x01 207 tm_check eq res_zlib_inflate view hc 0 11 RES_INF_ERR_HEADER 208 dc = new uchar 15 0 209 put dc 0 0x78 210 put dc 1 0xbb 211 put dc 5 0x01 212 put dc 6 0x01 213 put dc 9 0xff 214 put dc 10 0xff 215 put dc 14 0x01 216 tm_check eq res_zlib_inflate view dc 0 15 RES_INF_ERR_HEADER 217 rs = new uchar 7 0 218 put rs 0 0x78 219 put rs 1 0x01 220 put rs 2 0x07 221 put rs 6 0x01 222 tm_check eq res_zlib_inflate view rs 0 7 RES_INF_ERR_BLOCK 223 end 224 225 fn tm_chain_edges roff ulong l ulong to long 226 m = ulong 0 227 for j ulong l bound 64 228 for i ulong l bound 64 229 v1 = get mat_re add roff add i mul l j 230 v2 = get mat_re add roff add j mul l i 231 if ne v1 v2 232 ret -1 233 end 234 if and lt i j ne v1 0.0f64 235 if or ne v1 1.0f64 ge m 64 236 ret -1 237 end 238 put tm_edges mul m 2 add i 1 239 put tm_edges add mul m 2 1 add j 1 240 m = add m 1 241 end 242 end 243 end 244 ret long m 245 end 246 247 fn tm_chain50_edge k ulong a_out edit ulong 1 b_out edit ulong 1 to void 248 e0 = new ulong 49 0 249 e1 = new ulong 49 0 250 put e0 0 1 251 put e1 0 4 252 put e0 1 2 253 put e1 1 5 254 put e0 2 3 255 put e1 2 6 256 put e0 3 3 257 put e1 3 7 258 put e0 4 5 259 put e1 4 8 260 put e0 5 6 261 put e1 5 9 262 put e0 6 7 263 put e1 6 10 264 put e0 7 4 265 put e1 7 11 266 put e0 8 8 267 put e1 8 12 268 put e0 9 9 269 put e1 9 12 270 put e0 10 10 271 put e1 10 13 272 put e0 11 13 273 put e1 11 14 274 put e0 12 11 275 put e1 12 15 276 put e0 13 14 277 put e1 13 16 278 put e0 14 15 279 put e1 14 17 280 put e0 15 16 281 put e1 15 18 282 put e0 16 17 283 put e1 16 19 284 put e0 17 18 285 put e1 17 20 286 put e0 18 20 287 put e1 18 25 288 put e0 19 19 289 put e1 19 26 290 put e0 20 21 291 put e1 20 27 292 put e0 21 21 293 put e1 21 28 294 put e0 22 22 295 put e1 22 28 296 put e0 23 22 297 put e1 23 29 298 put e0 24 23 299 put e1 24 29 300 put e0 25 23 301 put e1 25 30 302 put e0 26 24 303 put e1 26 30 304 put e0 27 24 305 put e1 27 31 306 put e0 28 25 307 put e1 28 31 308 put e0 29 27 309 put e1 29 32 310 put e0 30 26 311 put e1 30 33 312 put e0 31 32 313 put e1 31 34 314 put e0 32 33 315 put e1 32 35 316 put e0 33 35 317 put e1 33 36 318 put e0 34 34 319 put e1 34 37 320 put e0 35 36 321 put e1 35 38 322 put e0 36 37 323 put e1 36 39 324 put e0 37 39 325 put e1 37 40 326 put e0 38 38 327 put e1 38 41 328 put e0 39 40 329 put e1 39 42 330 put e0 40 41 331 put e1 40 43 332 put e0 41 42 333 put e1 41 44 334 put e0 42 43 335 put e1 42 47 336 put e0 43 44 337 put e1 43 48 338 put e0 44 45 339 put e1 44 48 340 put e0 45 45 341 put e1 45 49 342 put e0 46 46 343 put e1 46 49 344 put e0 47 46 345 put e1 47 50 346 put e0 48 47 347 put e1 48 50 348 put a_out 0 get e0 k 349 put b_out 0 get e1 k 350 end 351 352 fn tm_test_mat_5 to void 353 sha5 = new uchar 32 0 354 sha50 = new uchar 32 0 355 tm_init_sha5 sha5 356 tm_init_sha50 sha50 357 mf = new ulong 98 0 358 off = new ulong 1 0 359 res_mat_reset_pool 360 tm_check eq res_mat_load t_fix5 view sha5 true mf RES_MAT_OK 361 tm_check eq res_mat_values res_mat_find view mf t_conmat 25 off RES_MAT_OK 362 cm_off = get off 0 363 tm_check eq res_mat_values res_mat_find view mf t_ground 1 off RES_MAT_OK 364 tm_check eq get mat_re get off 0 5.0f64 365 tm_check eq res_mat_values res_mat_find view mf t_inex 25 off RES_MAT_OK 366 ix_off = get off 0 367 all1 = true 368 for k ulong 25 bound 25 369 if ne get mat_re add ix_off k 1.0f64 370 all1 = false 371 end 372 end 373 tm_check all1 374 tm_check eq tm_chain_edges cm_off 5 4 375 for k ulong 4 bound 4 376 e0 = get tm_edges mul k 2 377 e1 = get tm_edges add mul k 2 1 378 tm_check and eq e0 add k 1 eq e1 add k 2 379 end 380 tm_check eq res_mat_find view mf t_nosuch -1 381 res_mat_reset_pool 382 tm_check eq res_mat_load t_fix5 view sha50 true mf RES_MAT_ERR_DIGEST 383 tm_check eq res_mat_load t_absent view sha5 false mf RES_MAT_ERR_IO 384 end 385 386 fn tm_check_chain50_edges to bool 387 ea = new ulong 1 0 388 eb = new ulong 1 0 389 for k ulong 49 bound 49 390 tm_chain50_edge k ea eb 391 ga = get tm_edges mul k 2 392 gb = get tm_edges add mul k 2 1 393 ok = false 394 if and eq ga get ea 0 eq gb get eb 0 395 ok = true 396 end 397 if and eq ga get eb 0 eq gb get ea 0 398 ok = true 399 end 400 if not ok 401 ret false 402 end 403 end 404 ret true 405 end 406 407 fn tm_test_mat_50 to void 408 sha50 = new uchar 32 0 409 tm_init_sha50 sha50 410 mf = new ulong 98 0 411 off = new ulong 1 0 412 res_mat_reset_pool 413 tm_check eq res_mat_load t_fix50 view sha50 true mf RES_MAT_OK 414 tm_check eq res_mat_values res_mat_find view mf t_conmat 2500 off RES_MAT_OK 415 cm_off = get off 0 416 tm_check eq res_mat_values res_mat_find view mf t_ground 1 off RES_MAT_OK 417 tm_check eq get mat_re get off 0 50.0f64 418 m = tm_chain_edges cm_off 50 419 tm_check eq m 49 420 tm_check tm_check_chain50_edges 421 end 422 423 fn tm_test_mat to void 424 tm_test_mat_5 425 tm_test_mat_50 426 end 427 428 fn tm_same_re mba ulong mbb ulong to bool 429 oa = get mat_meta add mba 6 430 ob = get mat_meta add mbb 6 431 n = get mat_meta add mba 5 432 for i ulong n bound 10000 433 va = bitcast ulong get mat_re add oa i 434 vb = bitcast ulong get mat_re add ob i 435 if ne va vb 436 ret false 437 end 438 end 439 ret true 440 end 441 442 fn tm_same_vals mf_a view ulong 98 mf_b view ulong 98 name view uchar * to bool 443 ax = res_mat_find mf_a name 444 ay = res_mat_find mf_b name 445 if or lt ax 0 lt ay 0 446 ret eq ax ay 447 end 448 mba = mul ulong ax RES_MAT_META_STRIDE 449 mbb = mul ulong ay RES_MAT_META_STRIDE 450 if ne get mat_meta add mba 5 get mat_meta add mbb 5 451 ret false 452 end 453 if ne get mat_meta mba get mat_meta mbb 454 ret false 455 end 456 ret tm_same_re mba mbb 457 end 458 459 fn tm_check_one_flip buf edit uchar 4096 off ulong bit ulong mf view ulong 98 marks view ulong 2 to int 460 orig = get buf off 461 put buf off xor orig shl uchar 1 uchar bit 462 put mat_re_used 0 get marks 0 463 put mat_meta_used 0 get marks 1 464 mg = new ulong 98 0 465 s = res_mat_parse view buf 2130 mg 466 put buf off orig 467 if ne s RES_MAT_OK 468 ret 1 469 end 470 ok1 = eq get mg 1 get mf 1 471 ok2 = tm_same_vals mf view mg t_conmat 472 ok3 = tm_same_vals mf view mg t_ground 473 ok4 = tm_same_vals mf view mg t_inex 474 if not and and ok1 ok2 and ok3 ok4 475 ret -1 476 end 477 ret 0 478 end 479 480 fn tm_corrupt_flips buf edit uchar 4096 n ulong mf view ulong 98 marks view ulong 2 to void 481 silent = ulong 0 482 refused = ulong 0 483 for off ulong n bound 2130 484 r0 = tm_check_one_flip buf off 0 mf marks 485 if eq r0 1 486 refused = add refused 1 487 end 488 if eq r0 -1 489 silent = add silent 1 490 end 491 r3 = tm_check_one_flip buf off 3 mf marks 492 if eq r3 1 493 refused = add refused 1 494 end 495 if eq r3 -1 496 silent = add silent 1 497 end 498 r6 = tm_check_one_flip buf off 6 mf marks 499 if eq r6 1 500 refused = add refused 1 501 end 502 if eq r6 -1 503 silent = add silent 1 504 end 505 end 506 tm_check eq silent 0 507 tm_check gt refused 0 508 end 509 510 fn tm_corrupt_cuts buf view uchar 4096 n ulong mf view ulong 98 marks view ulong 2 to void 511 mg = new ulong 98 0 512 full = get mf 1 513 cut_bad = ulong 0 514 for cut ulong n bound 2130 515 put mat_re_used 0 get marks 0 516 put mat_meta_used 0 get marks 1 517 s = res_mat_parse buf cut mg 518 if eq s RES_MAT_OK 519 if ge get mg 1 full 520 cut_bad = add cut_bad 1 521 end 522 if ge res_mat_find view mg t_conmat 0 523 if not tm_same_vals mf view mg t_conmat 524 cut_bad = add cut_bad 1 525 end 526 end 527 end 528 end 529 tm_check eq cut_bad 0 530 end 531 532 fn tm_test_corruption to void 533 fd = fopen t_fix5 0 len t_fix5 0 0 534 tm_check ge fd 0 535 if lt fd 0 536 ret 537 end 538 buf = new uchar 4096 0 539 nr = read int fd buf 0 4096 540 _fc = fclose int fd 541 tm_check eq nr 2130 542 if ne nr 2130 543 ret 544 end 545 n = ulong 2130 546 res_mat_reset_pool 547 mf = new ulong 98 0 548 tm_check eq res_mat_parse view buf n mf RES_MAT_OK 549 marks = new ulong 2 0 550 put marks 0 get mat_re_used 0 551 put marks 1 get mat_meta_used 0 552 tm_corrupt_flips buf n view mf view marks 553 tm_corrupt_cuts view buf n view mf view marks 554 end 555 556 fn main to int 557 tm_test_inflate_basic 558 tm_test_inflate_fixed 559 tm_test_inflate_refusals 560 tm_test_mat 561 tm_test_corruption 562 tm_write_str t_hdr 563 tm_write_u64 get tm_checks 0 564 tm_write_str t_chks 565 tm_write_u64 get tm_fail 0 566 tm_write_str t_fld 567 if ne get tm_fail 0 0 568 ret 1 569 end 570 ret 0 571 end