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 / aienux / store / store_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/store/store_test.om: Behavioral self-test for Store v1 format, engine, and geometry adapter. |
| 3 | note Compose with: si/directives/om2.om aienux/store/store_v1.om aienux/store/store_engine.om aienux/store/store_test.om om/tls/sha2.om |
| 4 | |
| 5 | text st_pass "PASS " |
| 6 | text st_fail "FAIL " |
| 7 | text st_nl "\n" |
| 8 | text st_t01 "crc32c_and_geometry_adapter" |
| 9 | text st_t02 "format_open_genesis_and_unformatted" |
| 10 | text st_t03 "transact_read_and_dedup" |
| 11 | text st_t04 "multi_generation_reopen_and_slot_alternation" |
| 12 | text st_t05 "degraded_recovery_is_read_only" |
| 13 | text st_t06 "corrupt_object_padding_and_poison_reopen" |
| 14 | text st_sum "STORE_TEST_PASS total=6 failed=0\n" |
| 15 | text st_fsum "STORE_TEST_FAIL\n" |
| 16 | text st_crc_vec "123456789" |
| 17 | text st_payload1 "alpha-object-payload-v1" |
| 18 | text st_payload2 "beta-second-object-payload" |
| 19 | |
| 20 | fn st_write_all fd int buf view uchar * to bool |
| 21 | total = len buf |
| 22 | off = ulong 0 |
| 23 | while lt off total bound 4096 |
| 24 | n = write fd buf off sub total off |
| 25 | if le n 0 |
| 26 | ret false |
| 27 | end |
| 28 | off = add off ulong n |
| 29 | end |
| 30 | ret true |
| 31 | end |
| 32 | |
| 33 | fn st_report name view uchar * ok bool to uint |
| 34 | if ok |
| 35 | w1 = st_write_all 1 st_pass |
| 36 | w2 = st_write_all 1 name |
| 37 | w3 = st_write_all 1 st_nl |
| 38 | if and w1 and w2 w3 |
| 39 | ret 0 |
| 40 | end |
| 41 | ret 1 |
| 42 | end |
| 43 | w1 = st_write_all 1 st_fail |
| 44 | w2 = st_write_all 1 name |
| 45 | w3 = st_write_all 1 st_nl |
| 46 | if and w1 and w2 w3 |
| 47 | ret 1 |
| 48 | end |
| 49 | ret 1 |
| 50 | end |
| 51 | |
| 52 | fn make_uuid dst edit uchar 16 to void |
| 53 | for i ulong 16 |
| 54 | put dst i add uchar 0x10 uchar i |
| 55 | end |
| 56 | end |
| 57 | |
| 58 | fn stt_01_crc_and_geometry to bool |
| 59 | note Standard CRC-32C check value for "123456789" is 0xe3069283 |
| 60 | crc = sv1_crc32c st_crc_vec 0 9 |
| 61 | if ne crc 0xe3069283 |
| 62 | ret false |
| 63 | end |
| 64 | st_media_zero |
| 65 | note Unsupported block size 1024 refused |
| 66 | if ne st_disk_bind 1024 128 0 16 ST_E_GEOMETRY |
| 67 | ret false |
| 68 | end |
| 69 | note Unaligned base_lba for 512-byte blocks refused |
| 70 | if ne st_disk_bind 512 256 3 16 ST_E_GEOMETRY |
| 71 | ret false |
| 72 | end |
| 73 | note Region past device end refused |
| 74 | if ne st_disk_bind 4096 16 0 17 ST_E_GEOMETRY |
| 75 | ret false |
| 76 | end |
| 77 | note Valid 512-byte geometry (aligned base_lba=8, 32 units) |
| 78 | if ne st_disk_bind 512 512 8 32 SV1_OK |
| 79 | ret false |
| 80 | end |
| 81 | ret true |
| 82 | end |
| 83 | |
| 84 | fn stt_02_format_and_open to bool |
| 85 | st_media_zero |
| 86 | if ne st_disk_bind 4096 64 0 64 SV1_OK |
| 87 | ret false |
| 88 | end |
| 89 | note Blank media mounts as ST_M_UNFORMATTED |
| 90 | if ne st_open ST_M_UNFORMATTED |
| 91 | ret false |
| 92 | end |
| 93 | uuid = new uchar 16 0 |
| 94 | make_uuid uuid |
| 95 | if ne st_format uuid SV1_OK |
| 96 | ret false |
| 97 | end |
| 98 | if ne st_open SV1_OK |
| 99 | ret false |
| 100 | end |
| 101 | if or ne st_generation 1 or ne st_high_water 4 or ne st_active_slot 0 or ne st_state ST_VALID ne st_peer ST_PEER_ZERO |
| 102 | ret false |
| 103 | end |
| 104 | ret true |
| 105 | end |
| 106 | |
| 107 | fn stt_03_transact_read_dedup to bool |
| 108 | st_media_zero |
| 109 | if ne st_disk_bind 4096 64 0 64 SV1_OK |
| 110 | ret false |
| 111 | end |
| 112 | uuid = new uchar 16 0 |
| 113 | make_uuid uuid |
| 114 | if ne st_format uuid SV1_OK |
| 115 | ret false |
| 116 | end |
| 117 | if ne st_open SV1_OK |
| 118 | ret false |
| 119 | end |
| 120 | note Compute expected ObjectId for st_payload1 (kind=16, ver=1) |
| 121 | id1 = new uchar 32 0 |
| 122 | if ne sv1_object_id 16 1 st_payload1 id1 SV1_OK |
| 123 | ret false |
| 124 | end |
| 125 | st_tx_begin |
| 126 | if ne st_tx_add 16 1 st_payload1 SV1_OK |
| 127 | ret false |
| 128 | end |
| 129 | if ne st_tx_commit SV1_OK |
| 130 | ret false |
| 131 | end |
| 132 | if or ne st_generation 2 or ne st_active_slot 1 ne st_catalog_count 1 |
| 133 | ret false |
| 134 | end |
| 135 | note Read back and verify exact bytes |
| 136 | buf = new uchar 64 0 |
| 137 | rlen = new ulong 1 0 |
| 138 | if ne st_read_object id1 buf rlen SV1_OK |
| 139 | ret false |
| 140 | end |
| 141 | if ne get rlen 0 len st_payload1 |
| 142 | ret false |
| 143 | end |
| 144 | if not sv1_equal part buf 0 len st_payload1 st_payload1 |
| 145 | ret false |
| 146 | end |
| 147 | note Re-submitting identical object deduplicates (catalog stays at 1) |
| 148 | hw_before = st_high_water |
| 149 | st_tx_begin |
| 150 | if ne st_tx_add 16 1 st_payload1 SV1_OK |
| 151 | ret false |
| 152 | end |
| 153 | if ne st_tx_commit SV1_OK |
| 154 | ret false |
| 155 | end |
| 156 | if or ne st_generation 3 or ne st_catalog_count 1 ne st_high_water add hw_before 2 |
| 157 | ret false |
| 158 | end |
| 159 | ret true |
| 160 | end |
| 161 | |
| 162 | fn stt_04_multi_gen_reopen to bool |
| 163 | st_media_zero |
| 164 | if ne st_disk_bind 512 512 0 64 SV1_OK |
| 165 | ret false |
| 166 | end |
| 167 | uuid = new uchar 16 0 |
| 168 | make_uuid uuid |
| 169 | if ne st_format uuid SV1_OK |
| 170 | ret false |
| 171 | end |
| 172 | if ne st_open SV1_OK |
| 173 | ret false |
| 174 | end |
| 175 | id1 = new uchar 32 0 |
| 176 | id2 = new uchar 32 0 |
| 177 | if ne sv1_object_id 16 1 st_payload1 id1 SV1_OK |
| 178 | ret false |
| 179 | end |
| 180 | if ne sv1_object_id 17 1 st_payload2 id2 SV1_OK |
| 181 | ret false |
| 182 | end |
| 183 | st_tx_begin |
| 184 | if ne st_tx_add 16 1 st_payload1 SV1_OK |
| 185 | ret false |
| 186 | end |
| 187 | if ne st_tx_commit SV1_OK |
| 188 | ret false |
| 189 | end |
| 190 | st_tx_begin |
| 191 | if ne st_tx_add 17 1 st_payload2 SV1_OK |
| 192 | ret false |
| 193 | end |
| 194 | if ne st_tx_commit SV1_OK |
| 195 | ret false |
| 196 | end |
| 197 | note Fresh reopen must select generation 3 (slot 0) with ST_PEER_VALID |
| 198 | if ne st_open SV1_OK |
| 199 | ret false |
| 200 | end |
| 201 | if or ne st_generation 3 or ne st_active_slot 0 or ne st_peer ST_PEER_VALID ne st_catalog_count 2 |
| 202 | ret false |
| 203 | end |
| 204 | buf = new uchar 64 0 |
| 205 | rlen = new ulong 1 0 |
| 206 | if ne st_read_object id2 buf rlen SV1_OK |
| 207 | ret false |
| 208 | end |
| 209 | if not sv1_equal part buf 0 len st_payload2 st_payload2 |
| 210 | ret false |
| 211 | end |
| 212 | ret true |
| 213 | end |
| 214 | |
| 215 | fn stt_05_degraded_read_only to bool |
| 216 | st_media_zero |
| 217 | if ne st_disk_bind 4096 64 0 64 SV1_OK |
| 218 | ret false |
| 219 | end |
| 220 | uuid = new uchar 16 0 |
| 221 | make_uuid uuid |
| 222 | if ne st_format uuid SV1_OK |
| 223 | ret false |
| 224 | end |
| 225 | if ne st_open SV1_OK |
| 226 | ret false |
| 227 | end |
| 228 | note Corrupt inactive superblock slot 1 -> mounts ST_DEGRADED_RECOVERY |
| 229 | st_media_poke 1 0 0xde |
| 230 | if ne st_open SV1_OK |
| 231 | ret false |
| 232 | end |
| 233 | if or ne st_state ST_DEGRADED_RECOVERY ne st_peer ST_PEER_MALFORMED |
| 234 | ret false |
| 235 | end |
| 236 | note Transactions refused on degraded mount |
| 237 | st_tx_begin |
| 238 | if ne st_tx_add 16 1 st_payload1 SV1_OK |
| 239 | ret false |
| 240 | end |
| 241 | if ne st_tx_commit ST_E_READ_ONLY_DEGRADED |
| 242 | ret false |
| 243 | end |
| 244 | ret true |
| 245 | end |
| 246 | |
| 247 | fn stt_06_corrupt_padding_and_poison to bool |
| 248 | st_media_zero |
| 249 | if ne st_disk_bind 4096 64 0 64 SV1_OK |
| 250 | ret false |
| 251 | end |
| 252 | uuid = new uchar 16 0 |
| 253 | make_uuid uuid |
| 254 | if ne st_format uuid SV1_OK |
| 255 | ret false |
| 256 | end |
| 257 | if ne st_open SV1_OK |
| 258 | ret false |
| 259 | end |
| 260 | id1 = new uchar 32 0 |
| 261 | if ne sv1_object_id 16 1 st_payload1 id1 SV1_OK |
| 262 | ret false |
| 263 | end |
| 264 | st_tx_begin |
| 265 | if ne st_tx_add 16 1 st_payload1 SV1_OK |
| 266 | ret false |
| 267 | end |
| 268 | if ne st_tx_commit SV1_OK |
| 269 | ret false |
| 270 | end |
| 271 | note Inject I/O write fault on next transaction -> poisons store (ST_E_NEEDS_REOPEN) |
| 272 | st_set_faults 1 0 |
| 273 | st_tx_begin |
| 274 | if ne st_tx_add 17 1 st_payload2 SV1_OK |
| 275 | ret false |
| 276 | end |
| 277 | if ne st_tx_commit ST_E_IO |
| 278 | ret false |
| 279 | end |
| 280 | st_set_faults 0 0 |
| 281 | if ne st_tx_commit ST_E_NEEDS_REOPEN |
| 282 | ret false |
| 283 | end |
| 284 | note Corrupt trailing zero padding of object at unit 4 -> read_object fails ST_E_CORRUPT and zeroes buffer |
| 285 | if ne st_open SV1_OK |
| 286 | ret false |
| 287 | end |
| 288 | st_media_poke 4 4095 0x01 |
| 289 | buf = new uchar 64 0xaa |
| 290 | rlen = new ulong 1 0 |
| 291 | if ne st_read_object id1 buf rlen ST_E_CORRUPT |
| 292 | ret false |
| 293 | end |
| 294 | if not sv1_all_zero buf 0 64 |
| 295 | ret false |
| 296 | end |
| 297 | ret true |
| 298 | end |
| 299 | |
| 300 | fn main to int |
| 301 | fails = uint 0 |
| 302 | fails = add fails st_report st_t01 stt_01_crc_and_geometry |
| 303 | fails = add fails st_report st_t02 stt_02_format_and_open |
| 304 | fails = add fails st_report st_t03 stt_03_transact_read_dedup |
| 305 | fails = add fails st_report st_t04 stt_04_multi_gen_reopen |
| 306 | fails = add fails st_report st_t05 stt_05_degraded_read_only |
| 307 | fails = add fails st_report st_t06 stt_06_corrupt_padding_and_poison |
| 308 | if eq fails 0 |
| 309 | w = st_write_all 1 st_sum |
| 310 | if w |
| 311 | ret 0 |
| 312 | end |
| 313 | ret 1 |
| 314 | end |
| 315 | w = st_write_all 1 st_fsum |
| 316 | if w |
| 317 | ret 1 |
| 318 | end |
| 319 | ret 1 |
| 320 | end |