interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / aienux / store / store_test.om

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