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 / seed / trace / segment-test.om

333 lines · 6767 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note seed/trace/segment-test.om: checks for segment.om (#608). Concatenate after segment.om and compile.
3note Runs in the current directory under build/trace-test/. Each check prints "<label> <observed>" and,
4note when it differs, " FAIL want=<expected>". The gate compares stdout with expected.txt byte for byte.
5note Exit 0 when every check holds, 1 otherwise, 2 when stdout cannot be written.
6global checks ulong 1
7global fails ulong 1
8global obuf uchar 256
9global on ulong 1
10global wbad ulong 1
11text labs "crc-123456789\ncrc-empty\nmissing-scan\nmissing-errno\ncreate\ncreate-again-refused\ncreate-again-errno\nappend-100-errors\nappend-last-seq\nscan\nscan-count\nscan-reason\nscan-total\nscan-lost\nappend-oversize-refused\ntruncate-last-record\ntorn-scan\ntorn-count\ntorn-reason\ntorn-lost\ntorn-append-refused\ntorn-size-unchanged\ntorn-recover\ntorn-recover-lost\nrecovered-scan\nrecovered-count\nrecovered-reason\nrecovered-total\nquarantine-size\nappend-after-recover\nappend-after-seq\nrecover-clean\nclean-count\ncrc-flip-poke\ncrc-scan\ncrc-count\ncrc-reason\ncrc-lost\ncrc-recover-bad-exists\ncrc-segment-unchanged\nunlink-bad\ncrc-recover\ncrc-recovered-scan\ncrc-recovered-count\ncrc-recovered-reason\nlen-raw-append\nlen-scan\nlen-count\nlen-reason\nlen-recover\nseq-raw-append\nseq-scan\nseq-count\nseq-reason\nseq-recover\nversion-poke\nversion-scan\nversion-append-refused\nversion-size-unchanged\nmagic-scan\ngeometry-scan\nreserved-scan\nrestored-scan\nrestored-count\nsymlink-create\nsymlink-scan\nsymlink-errno\nsymlink-append-refused\nsymlink-recover-refused\nfinal-scan\nfinal-count\n"
12text paths "build/trace-test/segment\nbuild/trace-test/link\n"
13text dbuild "build"
14text dtest "build/trace-test"
15text tgt "segment"
16text sfail " FAIL want="
17text sumt "segment-test checks="
18text sumf " fails="
19fn oflush to void
20w = write 1 obuf 0 get on 0
21if ne w long get on 0
22put wbad 0 1
23end
24put on 0 0
25end
26fn obyte b uchar to void
27put obuf get on 0 b
28put on 0 add get on 0 1
29end
30fn onum v ulong to void
31d = new uchar 20 0
32x = v
33k = ulong 0
34go = true
35while go bound 21
36put d k uchar add 48 rem x 10
37k = add k 1
38x = div x 10
39if eq x 0
40go = false
41end
42end
43while gt k 0 bound 21
44k = sub k 1
45obyte get d k
46end
47end
48note label k: emit the k-th newline-terminated line of labs (k from 1).
49fn label k ulong to void
50line = ulong 1
51for i ulong len labs
52b = get labs i
53if eq b 10
54line = add line 1
55else
56if eq line k
57obyte b
58end
59end
60end
61end
62fn check got ulong want ulong to void
63put checks 0 add get checks 0 1
64label get checks 0
65obyte 32
66onum got
67if ne got want
68put fails 0 add get fails 0 1
69for i ulong len sfail
70obyte get sfail i
71end
72onum want
73end
74obyte 10
75oflush
76end
77note setp k: the k-th line of paths (k from 1) becomes the segment path.
78fn setp k ulong to void
79line = ulong 1
80n = ulong 0
81for i ulong len paths
82b = get paths i
83if eq b 10
84line = add line 1
85else
86if eq line k
87put tpath n b
88n = add n 1
89end
90end
91end
92put tlen 0 n
93end
94fn errno to ulong
95ret ulong neg get serrno 0
96end
97fn fsize to ulong
98fd = fopen tpath 0 get tlen 0 32768 0
99if lt fd 0
100ret 0
101end
102pos = fseek int fd 0 2
103shut fd
104if lt pos 0
105ret 0
106end
107ret ulong pos
108end
109fn fsizebad to ulong
110sidepath 1
111fd = fopen opath 0 get olen 0 32768 0
112if lt fd 0
113ret 0
114end
115pos = fseek int fd 0 2
116shut fd
117if lt pos 0
118ret 0
119end
120ret ulong pos
121end
122note poke off v: overwrite one byte of the segment in place (fault injection, not a library path).
123fn poke off ulong v ulong to ulong
124fd = fopen tpath 0 get tlen 0 32769 0
125if lt fd 0
126ret 1
127end
128put trec 0 uchar v
129w = pwrite int fd trec 0 1 long off
130shut fd
131if ne w 1
132ret 1
133end
134ret 0
135end
136note rawapp: append trec as-is, bypassing segappend (fault injection for crafted records).
137fn rawapp to ulong
138fd = fopen tpath 0 get tlen 0 33793 0
139if lt fd 0
140ret 1
141end
142w = write int fd trec 0 64
143shut fd
144if ne w 64
145ret 1
146end
147ret 0
148end
149fn unlbad to ulong
150sidepath 1
151u = unlink opath 0 get olen 0
152if lt u 0
153ret 1
154end
155ret 0
156end
157fn mklink to ulong
158setp 2
159put tn 0 0
160tput16 2
161tput16 len tgt
162for i ulong len tgt
163put tpkt add get tn 0 i get tgt i
164end
165put tn 0 add get tn 0 len tgt
166pkttop
167s = symlnk tpkt 0 get tn 0
168setp 1
169if lt s 0
170ret 1
171end
172ret 0
173end
174fn cleanup to void
175setp 2
176u1 = unlink tpath 0 get tlen 0
177setp 1
178u2 = unlink tpath 0 get tlen 0
179sidepath 1
180u3 = unlink opath 0 get olen 0
181sidepath 2
182u4 = unlink opath 0 get olen 0
183end
184fn crcvec to void
185for i ulong 9
186put trec i uchar add 49 i
187end
188check segcrc 9 3421780262
189check segcrc 0 0
190end
191fn fill100 to void
192bad = ulong 0
193for i ulong 100
194put pay 0 uchar and i 255
195put pay 1 uchar and shr i 8 255
196put pay 2 0
197put pay 3 0
198if ne segappend 1 4 0
199bad = add bad 1
200end
201end
202check bad 0
203check get sseq 0 99
204end
205fn scan5 c ulong r ulong t ulong l ulong to void
206check segscan 0
207check get scount 0 c
208check get sreason 0 r
209check get stotal 0 t
210check get slost 0 l
211end
212fn phase1 to void
213check segscan 10
214check errno 2
215check segcreate 0
216check segcreate 10
217check errno 17
218fill100
219scan5 100 0 6416 0
220check segappend 1 53 20
221check ulong truncate tpath 0 get tlen 0 6382 0
222check segscan 0
223check get scount 0 99
224check get sreason 0 1
225check get slost 0 30
226check segappend 1 4 25
227check fsize 6382
228check segrecover 1
229check get slost 0 30
230check segscan 0
231check get scount 0 99
232check get sreason 0 0
233check get stotal 0 6352
234check fsizebad 6382
235check segappend 1 4 0
236check get sseq 0 99
237check segrecover 0
238e = segscan
239end
240fn phase2 to void
241check get scount 0 100
242check poke 3224 51 0
243check segscan 0
244check get scount 0 50
245check get sreason 0 3
246check get slost 0 3200
247check segrecover 32
248check fsize 6416
249check unlbad 0
250check segrecover 1
251check segscan 0
252check get scount 0 50
253check get sreason 0 0
254end
255fn phase3 to void
256segpack 1 4 50
257put trec 2 60
258segseal
259check rawapp 0
260check segscan 0
261check get scount 0 50
262check get sreason 0 2
263e = unlbad
264check segrecover 1
265segpack 1 4 7
266check rawapp 0
267check segscan 0
268check get scount 0 50
269check get sreason 0 4
270e2 = unlbad
271check segrecover 1
272end
273fn phase4 to void
274check poke 4 2 0
275check segscan 15
276check segappend 1 4 15
277check fsize 3216
278p1 = poke 4 1
279p2 = poke 0 0
280check segscan 11
281p3 = poke 0 65
282p4 = poke 6 32
283check segscan 16
284p5 = poke 6 64
285p6 = poke 12 1
286check segscan 16
287p7 = poke 12 0
288check segscan 0
289check get scount 0 50
290end
291fn phase5 to void
292check mklink 0
293setp 2
294check segscan 10
295check errno 40
296check segappend 1 4 10
297check segrecover 10
298setp 1
299check segscan 0
300check get scount 0 50
301end
302fn summary to void
303for i ulong len sumt
304obyte get sumt i
305end
306onum get checks 0
307for i ulong len sumf
308obyte get sumf i
309end
310onum get fails 0
311obyte 10
312oflush
313end
314fn main to int
315m1 = makedir dbuild 0 len dbuild 448
316m2 = makedir dtest 0 len dtest 448
317cleanup
318setp 1
319crcvec
320phase1
321phase2
322phase3
323phase4
324phase5
325summary
326if ne get wbad 0 0
327ret 2
328end
329if ne get fails 0 0
330ret 1
331end
332ret 0
333end