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 / host / negative.sh

449 lines · 7992 bytes Raw Blame History
1#!/bin/sh
2set -eu
3cd "$(dirname "$0")/../.."
4root=$PWD
5OMC=${OMC:-"$root/seed/out/omc"}
6mkdir -p build/seed/host
7stage=$(mktemp -d "$root/build/seed/host/negative.XXXXXX")
8trap 'rm -rf "$stage"' EXIT HUP INT TERM
9count=0
10runtime() {
11 name=$1
12 cat > "$stage/$name.om"
13 "$OMC" < "$stage/$name.om" > "$stage/$name"
14 chmod +x "$stage/$name"
15 code=0
16 (cd "$stage"; "./$name") > "$stage/out" || code=$?
17 test "$code" = 103 && test ! -s "$stage/out" || {
18 echo "Wrong refusal: $name (exit $code)" >&2; exit 1;
19 }
20 count=$((count + 1))
21}
22compile_error() {
23 name=$1
24 want=$2
25 code=0
26 cat > "$stage/$name.om"
27 "$OMC" < "$stage/$name.om" > "$stage/out" 2> "$stage/err" || code=$?
28 test "$code" = "$want" && test ! -s "$stage/out" || {
29 echo "Wrong compile refusal: $name (exit $code)" >&2; exit 1;
30 }
31 count=$((count + 1))
32}
33runtime path-overflow <<'EOF'
34text path "must-not-exist"
35fn main to int
36r = fopen path 18446744073709551615 1 194 384
37ret 1
38end
39EOF
40runtime path-zero <<'EOF'
41global path uchar 3
42fn main to int
43put path 0 97
44put path 2 98
45r = fopen path 0 3 194 384
46ret 1
47end
48EOF
49runtime path-length <<'EOF'
50global path uchar 4096
51fn main to int
52r = fopen path 0 len path 194 384
53ret 1
54end
55EOF
56runtime stat-short <<'EOF'
57global buf uchar 127
58fn main to int
59r = fstat 0 buf 0 len buf
60ret 1
61end
62EOF
63runtime pipe-short <<'EOF'
64global buf uchar 7
65fn main to int
66r = pipefds buf 0 len buf 0
67ret 1
68end
69EOF
70runtime packet-empty <<'EOF'
71global buf uchar 2
72fn main to int
73r = execprog buf 0 len buf
74ret 1
75end
76EOF
77runtime packet-count <<'EOF'
78global buf uchar 4
79fn main to int
80put buf 0 65
81r = execprog buf 0 len buf
82ret 1
83end
84EOF
85runtime packet-truncated <<'EOF'
86global buf uchar 5
87fn main to int
88put buf 0 1
89put buf 2 2
90put buf 4 97
91r = execprog buf 0 len buf
92ret 1
93end
94EOF
95runtime packet-zero <<'EOF'
96global buf uchar 6
97fn main to int
98put buf 0 1
99put buf 2 2
100put buf 4 97
101r = execprog buf 0 len buf
102ret 1
103end
104EOF
105runtime packet-extra <<'EOF'
106global buf uchar 6
107fn main to int
108put buf 0 1
109put buf 2 1
110put buf 4 97
111r = execprog buf 0 len buf
112ret 1
113end
114EOF
115runtime rename-count <<'EOF'
116global buf uchar 5
117fn main to int
118put buf 0 1
119put buf 2 1
120put buf 4 97
121r = renames buf 0 len buf 0
122ret 1
123end
124EOF
125runtime arg-index <<'EOF'
126global buf uchar 4
127fn main to int
128r = argread ulong argcnt buf 0 len buf
129ret 1
130end
131EOF
132runtime negative-sleep <<'EOF'
133fn main to int
134r = sleepns neg long 1
135ret 1
136end
137EOF
138runtime poll-truncation <<'EOF'
139fn main to int
140r = waitio 0 65536 0
141ret 1
142end
143EOF
144compile_error read-only 20 <<'EOF'
145text buf "abcd"
146fn main to int
147r = recv 0 buf 0 len buf 0
148ret 0
149end
150EOF
151compile_error array-type 7 <<'EOF'
152global buf ulong 32
153fn main to int
154r = fstat 0 buf 0 128
155ret 0
156end
157EOF
158compile_error descriptor-type 7 <<'EOF'
159fn main to int
160r = fclose ulong 0
161ret 0
162end
163EOF
164compile_error function-mode 9 <<'EOF'
165fn probe to long
166ret monons
167end
168EOF
169test ! -e "$stage/must-not-exist"
170test ! -e "$stage/a"
171printf 'PASS %s bounds, packet, mutability, type and function-mode negative controls\n' "$count"
172runtime cwd-overflow <<'OM'
173global buf uchar 8
174fn main to int
175r = cwd buf 18446744073709551615 1
176ret 1
177end
178OM
179runtime cwd-capacity <<'OM'
180global buf uchar 8
181fn main to int
182r = cwd buf 1 8
183ret 1
184end
185OM
186runtime readlnk-empty <<'OM'
187text path "/proc/self/cwd"
188global buf uchar 8
189fn main to int
190r = readlnk path 0 0 buf 0 8
191ret 1
192end
193OM
194runtime readlnk-zero <<'OM'
195global path uchar 3
196global buf uchar 8
197fn main to int
198put path 0 97
199put path 2 98
200r = readlnk path 0 3 buf 0 8
201ret 1
202end
203OM
204runtime readlnk-length <<'OM'
205global path uchar 4096
206global buf uchar 8
207fn main to int
208for i ulong len path
209put path i 97
210end
211r = readlnk path 0 len path buf 0 8
212ret 1
213end
214OM
215runtime readlnk-path-bounds <<'OM'
216text path "/proc/self/cwd"
217global buf uchar 8
218fn main to int
219r = readlnk path 18446744073709551615 1 buf 0 8
220ret 1
221end
222OM
223runtime readlnk-output-bounds <<'OM'
224text path "/proc/self/cwd"
225global buf uchar 8
226fn main to int
227r = readlnk path 0 len path buf 1 8
228ret 1
229end
230OM
231runtime sockopt-bounds <<'OM'
232text buf "abcd"
233fn main to int
234r = sockopt neg int 1 1 2 buf 1 4
235ret 1
236end
237OM
238compile_error cwd-readonly 20 <<'OM'
239text buf "abcd"
240fn main to int
241r = cwd buf 0 4
242ret 0
243end
244OM
245compile_error cwd-view 20 <<'OM'
246fn probe buf view uchar 4 to long
247ret cwd buf 0 4
248end
249fn main to int
250ret 0
251end
252OM
253compile_error cwd-type 7 <<'OM'
254global buf uint 8
255fn main to int
256r = cwd buf 0 8
257ret 0
258end
259OM
260compile_error cwd-offset-type 7 <<'OM'
261global buf uchar 8
262fn main to int
263r = cwd buf int 0 8
264ret 0
265end
266OM
267compile_error readlnk-readonly 20 <<'OM'
268text path "/proc/self/cwd"
269text buf "abcd"
270fn main to int
271r = readlnk path 0 len path buf 0 4
272ret 0
273end
274OM
275compile_error readlnk-view 20 <<'OM'
276text path "/proc/self/cwd"
277fn probe buf view uchar 4 to long
278ret readlnk path 0 len path buf 0 4
279end
280fn main to int
281ret 0
282end
283OM
284compile_error readlnk-path-type 7 <<'OM'
285global path ulong 8
286global buf uchar 8
287fn main to int
288r = readlnk path 0 8 buf 0 8
289ret 0
290end
291OM
292compile_error readlnk-output-type 7 <<'OM'
293text path "/proc/self/cwd"
294global buf ulong 8
295fn main to int
296r = readlnk path 0 len path buf 0 8
297ret 0
298end
299OM
300compile_error sockopt-fd-type 7 <<'OM'
301text buf "abcd"
302fn main to int
303r = sockopt long 0 1 2 buf 0 4
304ret 0
305end
306OM
307compile_error sockopt-level-type 7 <<'OM'
308text buf "abcd"
309fn main to int
310r = sockopt 0 long 1 2 buf 0 4
311ret 0
312end
313OM
314compile_error sockopt-option-type 7 <<'OM'
315text buf "abcd"
316fn main to int
317r = sockopt 0 1 long 2 buf 0 4
318ret 0
319end
320OM
321compile_error sockopt-array-type 7 <<'OM'
322global buf uint 4
323fn main to int
324r = sockopt 0 1 2 buf 0 4
325ret 0
326end
327OM
328compile_error cwd-function-mode 9 <<'OM'
329fn probe buf edit uchar 4096 to long
330ret cwd buf 0 4096
331end
332OM
333compile_error readlnk-function-mode 9 <<'OM'
334fn probe path view uchar 4 buf edit uchar 8 to long
335ret readlnk path 0 4 buf 0 8
336end
337OM
338compile_error sockopt-function-mode 9 <<'OM'
339fn probe buf view uchar 4 to long
340ret sockopt 0 1 2 buf 0 4
341end
342OM
343compile_error flock-fd-type 7 <<'OM'
344fn main to int
345r = flock long 0 2
346ret 0
347end
348OM
349compile_error flock-op-type 7 <<'OM'
350fn main to int
351r = flock 0 ulong 2
352ret 0
353end
354OM
355compile_error flock-arity 4 <<'OM'
356fn main to int
357r = flock 0
358ret 0
359end
360OM
361compile_error flock-name 16 <<'OM'
362fn main to int
363flock = int 1
364ret 0
365end
366OM
367compile_error flock-function-mode 9 <<'OM'
368fn probe fd int to long
369ret flock fd 2
370end
371OM
372runtime pollfds-limit <<'OM'
373global buf uchar 8200
374fn main to int
375ret int pollfds buf 0 len buf 0
376end
377OM
378compile_error peercred-readonly 20 <<'OM'
379text buf "abcdefghijkl"
380fn main to int
381ret int peercred 0 buf 0 12
382end
383OM
384compile_error pollfds-readonly 20 <<'OM'
385text buf "abcdefgh"
386fn main to int
387ret int pollfds buf 0 8 0
388end
389OM
390compile_error sendmsg-array-type 7 <<'OM'
391global buf uint 4
392fn main to int
393ret int sendmsg 0 buf 0 4 0
394end
395OM
396compile_error peercred-function-mode 9 <<'OM'
397fn probe buf edit uchar 16 to long
398ret peercred 0 buf 0 12
399end
400OM
401compile_error pollfds-function-mode 9 <<'OM'
402fn probe buf edit uchar 16 to long
403ret pollfds buf 0 8 0
404end
405OM
406compile_error sendmsg-function-mode 9 <<'OM'
407fn probe buf view uchar 16 to long
408ret sendmsg 0 buf 0 8 0
409end
410OM
411compile_error peername-readonly 20 <<'OM'
412text buf "abcdefghijklmnop"
413fn main to int
414ret int peername 0 buf 0 16
415end
416OM
417compile_error peername-array-type 7 <<'OM'
418global buf uint 4
419fn main to int
420ret int peername 0 buf 0 4
421end
422OM
423compile_error peername-descriptor-type 7 <<'OM'
424global buf uchar 16
425fn main to int
426ret int peername ulong 0 buf 0 16
427end
428OM
429compile_error peername-offset-type 7 <<'OM'
430global buf uchar 16
431fn main to int
432ret int peername 0 buf int 0 16
433end
434OM
435compile_error peername-view 20 <<'OM'
436fn probe buf view uchar 16 to long
437ret peername 0 buf 0 16
438end
439fn main to int
440buf = new uchar 16 0
441ret int probe buf
442end
443OM
444compile_error peername-function-mode 9 <<'OM'
445fn probe buf edit uchar 16 to long
446ret peername 0 buf 0 16
447end
448OM
449printf 'PASS %s total host negative controls, including cwd, readlnk, sockopt, flock and network\n' "$count"