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 / gpu / nvidia / checks / leftovers.om

94 lines · 2541 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/nvidia/checks/leftovers.om: the Omega port of CUDApp tests/leftovers_test.c. Composed after
3note gpu/nvidia/om/components/pathcopy.om, gpu/nvidia/om/components/leftovers.om and gpu/nvidia/checks/lib.om;
4note run with gpu/nvidia/checks/leftovers.tsv, whose expected values the C oracle wrote (see that file's header).
5note byte C EXPECT leftovers 0 C 0 0 0 is EXPECT (256: not a path byte)
6note path HEX CAP R OUT the path copy the C binding of src/omega_path_check.h makes from the Omega units:
7note cap 0 refuses; else n = pathlen (the source within cap); n = cap refuses; else pathcopy of the
8note n + 1 bytes into cap bytes must return 1. R is 1 for a refusal; on acceptance the copied string
9note (to its 0) is OUT. A NULL source or destination is the C binding's own refusal, not Omega's,
10note and is not a case here.
11note op OP A B C D E leftovers OP A B C D is E
12text t_name "LEFTOVERS"
13text t_kbyte "byte"
14text t_kpath "path"
15text t_kop "op"
16fn cname to void
17for i ulong len t_name bound 64
18ckoc ulong get t_name i
19end
20end
21note the same copy decided by the scalar stepper leftovers op 1 (src/cudapp_freest_leftovers.c's half of the
22note path check): 1 when it refuses, 0 when it reaches the terminator
23fn lwalk a view uchar * cap ulong to ulong
24state = ulong 0
25for i ulong len a bound 4096
26next = leftovers 1 state ulong get a i i cap
27if eq next 4
28ret 1
29end
30if eq next 5
31ret 0
32end
33state = next
34end
35ret 1
36end
37fn lpath to bool
38if ne ckcnt 5
39ret false
40end
41note a path case is at most 4095 bytes and its cap at most 4096 (Linux PATH_MAX); a longer case is ckbad (exit 2)
42src = new uchar 4096 0
43dst = new uchar 4096 85
44l = ckhexn 1
45cap = cknum 2
46if or ge l 4096 gt cap 4096
47ckbad
48end
49for j ulong l bound 4096
50put src j uchar ckhex 1 j
51end
52refused = ulong 1
53walked = ulong 1
54if gt cap 0
55n = pathlen part src 0 cap
56if ne n cap
57w = pathcopy part src 0 add n 1 part dst 0 cap
58if eq w 1
59refused = 0
60end
61walked = lwalk part src 0 add n 1 cap
62end
63end
64if or ne refused cknum 3 ne walked refused
65ret false
66end
67if eq refused 1
68ret true
69end
70m = ckhexn 4
71if ge m cap
72ret false
73end
74for j ulong m bound 4096
75if ne ulong get dst j ckhex 4 j
76ret false
77end
78end
79ret eq get dst m 0
80end
81fn crow to bool
82if and ckis 0 t_kbyte eq ckcnt 3
83ret eq leftovers 0 cknum 1 0 0 0 cknum 2
84end
85if ckis 0 t_kpath
86ret lpath
87end
88if and ckis 0 t_kop eq ckcnt 7
89r = leftovers cknum 1 cknum 2 cknum 3 cknum 4 cknum 5
90ret eq r cknum 6
91end
92ckbad
93ret false
94end