interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / zero-legacy / expect.om

175 lines · 2880 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note expect: judge a closure report against an expected row file (#316 gate).
3note usage: expect OUTPUT EXPECTED
4note Every line of EXPECTED must occur as a whole line of OUTPUT (order free,
5note because directory enumeration order is filesystem dependent), and the two
6note files must hold the same number of row lines (lines not starting with #).
7note Exit 0 when both hold; 1 and the missing line on stderr otherwise; 2 when
8note the row counts differ; 64 for usage; 65 when a file cannot be read.
9
10text tuse "usage: expect OUTPUT EXPECTED\n"
11text terr "expect: cannot read a file\n"
12text tmiss "expect: missing line: "
13text tcnt "expect: row count differs\n"
14text tnl "\n"
15
16global out uchar 65536
17global outn ulong 1
18global exp uchar 65536
19global expn ulong 1
20global name uchar 256
21
22fn load1 to bool
23n = argread 1 name 0 255
24if lt n 1
25ret false
26end
27fd = fopen name 0 ulong n 0 0
28if lt fd 0
29ret false
30end
31r = read int fd out 0 65535
32if gt r 0
33put outn 0 ulong r
34end
35r = fclose int fd
36ret true
37end
38
39fn load2 to bool
40n = argread 2 name 0 255
41if lt n 1
42ret false
43end
44fd = fopen name 0 ulong n 0 0
45if lt fd 0
46ret false
47end
48r = read int fd exp 0 65535
49if gt r 0
50put expn 0 ulong r
51end
52r = fclose int fd
53ret true
54end
55
56note end of the line that starts at s in out
57fn oend s ulong to ulong
58e = s
59n = get outn 0
60while lt e n bound 65536
61if eq get out e 10
62ret e
63end
64e = add e 1
65end
66ret e
67end
68
69fn eend s ulong to ulong
70e = s
71n = get expn 0
72while lt e n bound 65536
73if eq get exp e 10
74ret e
75end
76e = add e 1
77end
78ret e
79end
80
81note does exp[s..s+m) equal out[t..t+m)
82fn same s ulong t ulong m ulong to bool
83for i ulong m
84if ne get exp add s i get out add t i
85ret false
86end
87end
88ret true
89end
90
91note is the expected line exp[s..s+m) a whole, not yet used line of out; the match is consumed
92note (its first byte becomes 1, which no text line starts with) so repeated rows must each occur
93fn has s ulong m ulong to bool
94n = get outn 0
95t = ulong 0
96while lt t n bound 65536
97e = oend t
98if eq sub e t m
99if same s t m
100put out t 1
101ret true
102end
103end
104t = add e 1
105end
106ret false
107end
108
109fn rows1 to ulong
110n = get outn 0
111c = ulong 0
112t = ulong 0
113while lt t n bound 65536
114e = oend t
115if gt e t
116if ne get out t 35
117c = add c 1
118end
119end
120t = add e 1
121end
122ret c
123end
124
125fn rows2 to ulong
126n = get expn 0
127c = ulong 0
128t = ulong 0
129while lt t n bound 65536
130e = eend t
131if gt e t
132if ne get exp t 35
133c = add c 1
134end
135end
136t = add e 1
137end
138ret c
139end
140
141fn main to int
142if lt argcnt 3
143r = write 2 tuse 0 len tuse
144ret 64
145end
146if not load1
147r = write 2 terr 0 len terr
148ret 65
149end
150if not load2
151r = write 2 terr 0 len terr
152ret 65
153end
154c1 = rows1
155n = get expn 0
156s = ulong 0
157while lt s n bound 65536
158e = eend s
159m = sub e s
160if gt m 0
161if not has s m
162r = write 2 tmiss 0 len tmiss
163r = write 2 exp s m
164r = write 2 tnl 0 1
165ret 1
166end
167end
168s = add e 1
169end
170if ne c1 rows2
171r = write 2 tcnt 0 len tcnt
172ret 2
173end
174ret 0
175end