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 / src / tensor / test_tensor_store.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note test_tensor_store.om -- Pure seeded OM-2 M20 crash-safe tensor store test suite. |
| 3 | |
| 4 | global tss_c ulong 2 |
| 5 | global tss_base uchar 256 |
| 6 | global tss_blen ulong 1 |
| 7 | global tss_dn ulong 1 |
| 8 | |
| 9 | text tss_pass "M20_TENSOR_STORE_TESTS_PASS\n" |
| 10 | text tss_fail "M20_TENSOR_STORE_TESTS_FAIL\n" |
| 11 | text tss_usage "usage: test_tensor_store <scratch-dir>\n" |
| 12 | text tss_t_rt "rt" |
| 13 | text tss_t_cr "cr" |
| 14 | text tss_t_ng "ng" |
| 15 | |
| 16 | fn ts_chk cond bool to void |
| 17 | put tss_c 0 add get tss_c 0 1 |
| 18 | if not cond |
| 19 | put tss_c 1 add get tss_c 1 1 |
| 20 | end |
| 21 | end |
| 22 | |
| 23 | fn ts_newdir dst edit uchar 512 tag view uchar * to ulong |
| 24 | bl = get tss_blen 0 |
| 25 | dn = get tss_dn 0 |
| 26 | put tss_dn 0 add dn 1 |
| 27 | for i ulong bl |
| 28 | put dst i get tss_base i |
| 29 | end |
| 30 | put dst bl 47 |
| 31 | p = add bl 1 |
| 32 | put dst p uchar add 48 rem div dn 10 10 |
| 33 | put dst add p 1 uchar add 48 rem dn 10 |
| 34 | put dst add p 2 45 |
| 35 | p = add p 3 |
| 36 | tl = len tag |
| 37 | for i ulong tl |
| 38 | put dst add p i get tag i |
| 39 | end |
| 40 | ret add p tl |
| 41 | end |
| 42 | |
| 43 | fn test_roundtrip_and_lock to void |
| 44 | d = new uchar 512 0 |
| 45 | dl = ts_newdir d tss_t_rt |
| 46 | ts_chk eq ot_ctx_init 32 OT_OK |
| 47 | ts_chk eq ots_open part d 0 dl dl 8 OT_OK |
| 48 | sh = new ulong 8 0 |
| 49 | put sh 0 4 |
| 50 | dat = new f32 4 0.0f32 |
| 51 | put dat 0 1.5f32 |
| 52 | put dat 1 -0.0f32 |
| 53 | put dat 2 3.25f32 |
| 54 | put dat 3 42.0f32 |
| 55 | ht = new ulong 2 0 |
| 56 | ts_chk eq ot_from_f32 1 sh dat ht OT_OK |
| 57 | hs = new ulong 2 0 |
| 58 | ts_chk eq ots_put get ht 0 get ht 1 hs OT_OK |
| 59 | ts_chk eq ots_live_count 1 |
| 60 | note Busy lock check via child process |
| 61 | pid = fork |
| 62 | if eq pid 0 |
| 63 | if eq ots_open part d 0 dl dl 8 OTS_ERR_BUSY |
| 64 | exit 0 |
| 65 | end |
| 66 | exit 1 |
| 67 | end |
| 68 | sb = new uchar 4 0 |
| 69 | wp = waitpid int pid sb 0 4 0 |
| 70 | ws = or uint get sb 0 shl uint get sb 1 8 |
| 71 | ts_chk eq and shr ws 8 255 0 |
| 72 | ots_close |
| 73 | note Reopen and verify data + release generation stays stale |
| 74 | ts_chk eq ots_open part d 0 dl dl 8 OT_OK |
| 75 | ts_chk eq ots_live_count 1 |
| 76 | hg = new ulong 2 0 |
| 77 | ts_chk eq ots_get get hs 0 get hs 1 hg OT_OK |
| 78 | obuf = new f32 4 0.0f32 |
| 79 | ts_chk eq ot_read_f32 get hg 0 get hg 1 obuf OT_OK |
| 80 | ts_chk eq get obuf 0 1.5f32 |
| 81 | ts_chk eq bitcast uint get obuf 1 OT_NEG0_BITS |
| 82 | ts_chk eq get obuf 3 42.0f32 |
| 83 | ts_chk eq ots_release get hs 0 get hs 1 OT_OK |
| 84 | ts_chk eq ots_release get hs 0 get hs 1 OT_ERR_STALE |
| 85 | ots_close |
| 86 | ts_chk eq ots_open part d 0 dl dl 8 OT_OK |
| 87 | ts_chk eq ots_live_count 0 |
| 88 | ts_chk not ots_valid get hs 0 get hs 1 |
| 89 | ots_close |
| 90 | end |
| 91 | |
| 92 | fn test_crash_child step ulong d view uchar 512 dl ulong sh view ulong 8 dat view f32 4 to void |
| 93 | ht = new ulong 2 0 |
| 94 | hs = new ulong 2 0 |
| 95 | if ne ots_open part d 0 dl dl 4 OT_OK |
| 96 | exit 2 |
| 97 | end |
| 98 | rc = ot_from_f32 1 sh dat ht |
| 99 | rc = ots_set_crash_step step |
| 100 | rc = ots_put get ht 0 get ht 1 hs |
| 101 | exit 3 |
| 102 | end |
| 103 | |
| 104 | fn test_crash_one step ulong sh view ulong 8 dat view f32 4 to void |
| 105 | d = new uchar 512 0 |
| 106 | sb = new uchar 4 0 |
| 107 | dl = ts_newdir d tss_t_cr |
| 108 | ts_chk eq ot_ctx_init 32 OT_OK |
| 109 | ts_chk eq ots_open part d 0 dl dl 4 OT_OK |
| 110 | ots_close |
| 111 | pid = fork |
| 112 | if eq pid 0 |
| 113 | test_crash_child step d dl sh dat |
| 114 | end |
| 115 | wp = waitpid int pid sb 0 4 0 |
| 116 | ws = or uint get sb 0 shl uint get sb 1 8 |
| 117 | ts_chk eq and shr ws 8 255 uint OTS_CRASH_EXIT |
| 118 | ts_chk eq ots_open part d 0 dl dl 4 OT_OK |
| 119 | if ge step OTS_CRASH_JOURNAL_RENAMED |
| 120 | ts_chk eq ots_live_count 1 |
| 121 | else |
| 122 | ts_chk eq ots_live_count 0 |
| 123 | end |
| 124 | ots_close |
| 125 | end |
| 126 | |
| 127 | fn test_crash_matrix to void |
| 128 | sh = new ulong 8 0 |
| 129 | put sh 0 4 |
| 130 | dat = new f32 4 0.0f32 |
| 131 | put dat 0 7.0f32 |
| 132 | put dat 1 8.0f32 |
| 133 | put dat 2 9.0f32 |
| 134 | put dat 3 10.0f32 |
| 135 | for si ulong 8 |
| 136 | test_crash_one add si 1 sh dat |
| 137 | end |
| 138 | end |
| 139 | |
| 140 | fn test_corrupt_and_torn to void |
| 141 | d = new uchar 512 0 |
| 142 | dl = ts_newdir d tss_t_ng |
| 143 | ts_chk eq ot_ctx_init 32 OT_OK |
| 144 | ts_chk eq ots_open part d 0 dl dl 4 OT_OK |
| 145 | sh = new ulong 8 0 |
| 146 | put sh 0 2 |
| 147 | dat = new f32 2 1.0f32 |
| 148 | ht = new ulong 2 0 |
| 149 | hs = new ulong 2 0 |
| 150 | ts_chk eq ot_from_f32 1 sh dat ht OT_OK |
| 151 | ts_chk eq ots_put get ht 0 get ht 1 hs OT_OK |
| 152 | ots_close |
| 153 | note Wrong capacity refused |
| 154 | ts_chk eq ots_open part d 0 dl dl 8 OT_ERR_BAD_ARGS |
| 155 | note Torn journal refused |
| 156 | pl = ots_mk_path 0 ots_txt_jrn |
| 157 | tr = truncate ots_pa 0 pl 40 |
| 158 | ts_chk eq ots_open part d 0 dl dl 4 OTS_ERR_TORN |
| 159 | end |
| 160 | |
| 161 | fn main to int |
| 162 | if ne argcnt 2 |
| 163 | w = write 2 tss_usage 0 len tss_usage |
| 164 | ret 2 |
| 165 | end |
| 166 | bl = argread 1 tss_base 0 256 |
| 167 | if le bl 0 |
| 168 | ret 2 |
| 169 | end |
| 170 | put tss_blen 0 ulong bl |
| 171 | mr = makedir tss_base 0 ulong bl 493 |
| 172 | if and lt mr 0 ne mr -17 |
| 173 | ret 2 |
| 174 | end |
| 175 | test_roundtrip_and_lock |
| 176 | test_crash_matrix |
| 177 | test_corrupt_and_torn |
| 178 | if ne get tss_c 1 0 |
| 179 | w = write 1 tss_fail 0 len tss_fail |
| 180 | ret 1 |
| 181 | end |
| 182 | w = write 1 tss_pass 0 len tss_pass |
| 183 | ret 0 |
| 184 | end |