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 / ng / tests / ir / host-oracle.om

432 lines · 10686 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Build with src/ir.om. host-oracle UNIT.ir NEW-NATIVE-DIR emits IR and executes equivalent native host operations.
3note The gate passes the same two program arguments and a controlled environment to ngrun.
4note Every native expected success is checked before an expected IR value is recorded.
5global hc_s uint 16
6global hc_a uint 16
7global hc_seen uchar 256
8global hc_count ulong 2
9global hc_dig uchar 24
10text hc_st0 "HC_NATIVE operations="
11text hc_st1 " words="
12text hc_st2 "\n"
13text hc_bad0 "HC_FAIL operation="
14text hc_bad1 " actual-bits="
15text hc_bad2 " expected-bits="
16global hc_buf uchar 512
17global hc_out uchar 8192
18global hc_root uchar 4096
19global hc_arg uchar 4096
20global hc_pkt uchar 64
21text hc_name "probe"
22text hc_new "renamed"
23text hc_link "linked"
24text hc_dir "child"
25text hc_empty "empty"
26text hc_data "hello"
27text hc_one "X"
28text hc_env "NG_ORACLE=present"
29text hc_msg "HOSTORACLE\n"
30fn hc_c t uint v ulong to uint
31ret ir_res ir_op get hc_s 0 1 t v 0
32end
33
34fn hc_true c uint to void
35o = ir_op get hc_s 0 82 0 14 2
36ir_set o 0 get hc_s 1
37ir_set o 1 c
38put hc_s 1 ir_otok o
39end
40fn hc_cmp op uint a uint b uint to uint
41o = ir_op get hc_s 0 op 1 0 2
42ir_set o 0 a
43ir_set o 1 b
44ret ir_res o
45end
46fn hc_ok v uint actual long expected long to void
47if ne actual expected
48hc_diag actual expected
49exit 2
50end
51hc_true hc_cmp 30 v hc_c 9 bitcast ulong actual
52end
53fn hc_pos v uint actual long to void
54if le actual 0
55hc_diag actual 1
56exit 2
57end
58hc_true hc_cmp 34 v hc_c 9 0
59end
60fn hc_host w ulong ty uint n uint to uint
61put hc_count 0 add get hc_count 0 1
62if eq get hc_seen w 0
63put hc_count 1 add get hc_count 1 1
64put hc_seen w 1
65end
66o = ir_op get hc_s 0 110 ty w add n 1
67ir_set o 0 get hc_s 1
68for j uint n bound 16
69ir_set o add j 1 get hc_a j
70end
71put hc_s 1 ir_otok o
72ret ir_res o
73end
74fn hc_slice slot ulong ref uint off ulong n ulong to void
75z = hc_c 5 off
76sz = hc_c 5 n
77o = ir_op get hc_s 0 80 0 3 4
78ir_set o 0 get hc_s 1
79ir_set o 1 ref
80ir_set o 2 z
81ir_set o 3 sz
82put hc_s 1 ir_otok o
83put hc_a slot ref
84put hc_a add slot 1 z
85put hc_a add slot 2 sz
86end
87fn hc_text txt view uchar * to uint
88t = ir_tarr 2 uint len txt
89r = ir_tref t 0 0
90g = ir_glob t 1
91for j ulong len txt bound 4096
92ir_gbyt g uint get txt j
93end
94ret ir_res ir_op get hc_s 0 52 r ulong g 0
95end
96fn hc_memory to uint
97t = ir_tarr 2 512
98r = ir_tref t 1 0
99g = ir_glob t 0
100ret ir_res ir_op get hc_s 0 52 r ulong g 0
101end
102fn hc_byte idx ulong actual uchar expected uchar to void
103if ne actual expected
104hc_diag long actual long expected
105exit 2
106end
107r = get hc_s 2
108i = hc_c 5 idx
109e = hc_c 5 1
110o = ir_op get hc_s 0 79 0 3 4
111ir_set o 0 get hc_s 1
112ir_set o 1 r
113ir_set o 2 i
114ir_set o 3 e
115put hc_s 1 ir_otok o
116o = ir_op get hc_s 0 42 2 0 3
117ir_set o 0 get hc_s 1
118ir_set o 1 r
119ir_set o 2 i
120v = ir_res o
121hc_true hc_cmp 30 v hc_c 2 ulong actual
122end
123
124fn hc_fdword w ulong actual long expected long to void
125put hc_a 0 hc_c 8 3
126hc_ok hc_host w 9 1 actual expected
127end
128fn hc_args to void
129hc_ok hc_host 121 9 0 argcnt 3
130put hc_a 0 hc_c 5 1
131hc_slice 1 get hc_s 2 0 1
132hc_ok hc_host 122 9 4 argread 1 hc_buf 0 1 -105
133hc_byte 0 get hc_buf 0 0
134put hc_a 0 hc_c 5 1
135hc_slice 1 get hc_s 2 0 len hc_buf
136n = argread 1 hc_buf 0 len hc_buf
137hc_pos hc_host 122 9 4 n
138hc_ok hc_host 136 9 0 envcnt 1
139put hc_a 0 hc_c 5 0
140hc_slice 1 get hc_s 2 0 0
141hc_ok hc_host 137 9 4 envread 0 hc_buf 0 0 -105
142put hc_a 0 hc_c 5 0
143hc_slice 1 get hc_s 2 0 len hc_buf
144hc_ok hc_host 137 9 4 envread 0 hc_buf 0 len hc_buf long len hc_env
145hc_byte 0 get hc_buf 0 78
146hc_pos hc_host 109 9 0 monons
147hc_pos hc_host 130 9 0 realns
148put hc_a 0 hc_c 9 0
149hc_ok hc_host 120 9 1 sleepns 0 0
150uid = getuid
151hc_ok hc_host 145 9 0 uid uid
152gid = getgid
153hc_ok hc_host 147 9 0 gid gid
154hc_ok hc_host 146 9 0 geteuid uid
155hc_ok hc_host 148 9 0 getegid gid
156v = hc_host 199 0 0
157cpufence
158v = hc_host 200 0 0
159cpurelax
160end
161fn hc_files1 to void
162hc_slice 0 get hc_s 3 0 len hc_name
163put hc_a 3 hc_c 8 194
164put hc_a 4 hc_c 8 384
165fd = fopen hc_name 0 len hc_name 194 384
166hc_ok hc_host 110 9 5 fd 3
167put hc_a 0 hc_c 8 3
168hc_slice 1 get hc_s 4 0 len hc_data
169hc_ok hc_host 54 9 4 write int fd hc_data 0 len hc_data long len hc_data
170put hc_a 0 hc_c 8 3
171hc_slice 1 get hc_s 5 0 len hc_one
172put hc_a 4 hc_c 9 2
173hc_ok hc_host 162 9 5 pwrite int fd hc_one 0 len hc_one 2 1
174put hc_a 0 hc_c 8 3
175put hc_a 1 hc_c 9 0
176put hc_a 2 hc_c 8 0
177hc_ok hc_host 103 9 3 fseek int fd 0 0 0
178put hc_a 0 hc_c 8 3
179hc_slice 1 get hc_s 2 0 5
180hc_ok hc_host 53 9 4 read int fd hc_buf 0 5 5
181hc_byte 0 get hc_buf 0 104
182hc_byte 1 get hc_buf 1 101
183hc_byte 2 get hc_buf 2 88
184hc_byte 3 get hc_buf 3 108
185hc_byte 4 get hc_buf 4 111
186put hc_a 0 hc_c 8 3
187hc_slice 1 get hc_s 2 0 3
188put hc_a 4 hc_c 9 1
189hc_ok hc_host 161 9 5 pread int fd hc_buf 0 3 1 3
190hc_byte 0 get hc_buf 0 101
191hc_byte 1 get hc_buf 1 88
192hc_byte 2 get hc_buf 2 108
193put hc_a 0 hc_c 8 3
194hc_slice 1 get hc_s 2 0 128
195hc_ok hc_host 117 9 4 fstat int fd hc_buf 0 128 0
196hc_byte 48 get hc_buf 48 5
197put hc_a 0 hc_c 8 3
198put hc_a 1 hc_c 9 4
199hc_ok hc_host 139 9 2 ftrunc int fd 4 0
200hc_fdword 101 fsync int fd 0
201hc_fdword 156 fdsync int fd 0
202put hc_a 0 hc_c 8 3
203put hc_a 1 hc_c 8 384
204hc_ok hc_host 102 9 2 fchmod int fd 384 0
205put hc_a 0 hc_c 8 3
206put hc_a 1 hc_c 8 6
207hc_ok hc_host 197 9 2 flock int fd 6 0
208put hc_a 0 hc_c 8 3
209put hc_a 1 hc_c 8 8
210hc_ok hc_host 197 9 2 flock int fd 8 0
211hc_fdword 100 fclose int fd 0
212end
213fn hc_files2 to void
214hc_slice 0 get hc_s 3 0 len hc_name
215put hc_a 3 hc_c 8 0
216hc_ok hc_host 144 9 4 faccess hc_name 0 len hc_name 0 0
217hc_slice 0 get hc_s 3 0 len hc_name
218put hc_a 3 hc_c 8 384
219hc_ok hc_host 143 9 4 chmod hc_name 0 len hc_name 384 0
220hc_slice 0 get hc_s 3 0 len hc_name
221put hc_a 3 hc_c 8 bitcast ulong getuid
222put hc_a 4 hc_c 8 bitcast ulong getgid
223hc_ok hc_host 151 9 5 chown hc_name 0 len hc_name int getuid int getgid 0
224hc_slice 0 get hc_s 3 0 len hc_name
225hc_slice 3 get hc_s 2 0 128
226hc_ok hc_host 140 9 6 stat hc_name 0 len hc_name hc_buf 0 128 0
227hc_byte 48 get hc_buf 48 4
228hc_slice 0 get hc_s 3 0 len hc_name
229hc_slice 3 get hc_s 2 0 128
230hc_ok hc_host 149 9 6 lstat hc_name 0 len hc_name hc_buf 0 128 0
231hc_slice 0 get hc_s 3 0 len hc_name
232hc_slice 3 get hc_s 2 0 128
233hc_ok hc_host 133 9 6 readlnk hc_name 0 len hc_name hc_buf 0 128 -22
234hc_slice 0 get hc_s 3 0 len hc_name
235put hc_a 3 hc_c 9 3
236hc_ok hc_host 150 9 4 truncate hc_name 0 len hc_name 3 0
237hc_slice 0 get hc_s 3 0 len hc_name
238put hc_a 3 hc_c 8 0
239put hc_a 4 hc_c 8 0
240fd = fopen hc_name 0 len hc_name 0 0
241hc_ok hc_host 110 9 5 fd 3
242put hc_a 0 hc_c 8 3
243hc_slice 1 get hc_s 2 0 8
244hc_ok hc_host 53 9 4 read int fd hc_buf 0 8 3
245hc_byte 2 get hc_buf 2 88
246hc_fdword 100 fclose int fd 0
247end
248fn hc_packet a view uchar * b view uchar * to uint
249put hc_pkt 0 2
250put hc_pkt 1 0
251put hc_pkt 2 uchar len a
252put hc_pkt 3 0
253for j ulong len a bound 32
254put hc_pkt add 4 j get a j
255end
256p = add 4 len a
257put hc_pkt p uchar len b
258put hc_pkt add p 1 0
259for j ulong len b bound 32
260put hc_pkt add add p 2 j get b j
261end
262n = add add p 2 len b
263t = ir_tarr 2 uint n
264r = ir_tref t 0 0
265g = ir_glob t 1
266for j ulong n bound 64
267ir_gbyt g uint get hc_pkt j
268end
269put hc_s 15 uint n
270ret ir_res ir_op get hc_s 0 52 r ulong g 0
271end
272fn hc_files3 to void
273r = hc_packet hc_name hc_new
274hc_slice 0 r 0 ulong get hc_s 15
275put hc_a 3 hc_c 8 1
276hc_ok hc_host 125 9 4 renames hc_pkt 0 ulong get hc_s 15 1 0
277r = hc_packet hc_new hc_link
278hc_slice 0 r 0 ulong get hc_s 15
279hc_ok hc_host 141 9 3 link hc_pkt 0 ulong get hc_s 15 0
280r = hc_text hc_link
281hc_slice 0 r 0 len hc_link
282hc_ok hc_host 111 9 3 unlink hc_link 0 len hc_link 0
283r = hc_text hc_new
284hc_slice 0 r 0 len hc_new
285hc_ok hc_host 111 9 3 unlink hc_new 0 len hc_new 0
286r = hc_text hc_empty
287hc_slice 0 r 0 len hc_empty
288put hc_a 3 hc_c 8 448
289hc_ok hc_host 112 9 4 makedir hc_empty 0 len hc_empty 448 0
290hc_slice 0 r 0 len hc_empty
291hc_ok hc_host 126 9 3 rmdir hc_empty 0 len hc_empty 0
292hc_slice 0 get hc_s 3 0 len hc_name
293put hc_a 3 hc_c 8 0
294fd = memfd hc_name 0 len hc_name 0
295hc_ok hc_host 157 9 4 fd 3
296put hc_a 0 hc_c 8 3
297hc_slice 1 get hc_s 4 0 len hc_data
298hc_ok hc_host 54 9 4 write int fd hc_data 0 len hc_data long len hc_data
299hc_fdword 100 fclose int fd 0
300end
301fn hc_dirs to void
302r = hc_text hc_dir
303hc_slice 0 r 0 len hc_dir
304put hc_a 3 hc_c 8 448
305hc_ok hc_host 112 9 4 makedir hc_dir 0 len hc_dir 448 0
306hc_slice 0 r 0 len hc_dir
307put hc_a 3 hc_c 8 16384
308put hc_a 4 hc_c 8 0
309fd = fopen hc_dir 0 len hc_dir 16384 0
310hc_ok hc_host 110 9 5 fd 3
311put hc_a 0 hc_c 8 3
312hc_slice 1 get hc_s 2 0 len hc_buf
313hc_pos hc_host 113 9 4 getdnts int fd hc_buf 0 len hc_buf
314hc_slice 0 r 0 len hc_dir
315hc_ok hc_host 138 9 3 chdir hc_dir 0 len hc_dir 0
316put hc_a 0 hc_c 8 3
317hc_ok hc_host 153 9 1 fchdir int fd 0
318hc_fdword 100 fclose int fd 0
319hc_slice 0 get hc_s 2 0 len hc_buf
320hc_pos hc_host 132 9 3 cwd hc_buf 0 len hc_buf
321hc_byte 0 get hc_buf 0 47
322end
323fn hc_paths to void
324n = argread 1 hc_arg 0 len hc_arg
325if or le n 0 ge n 4096
326exit 2
327end
328base = ulong 0
329if ne get hc_arg 0 47
330k = cwd hc_out 0 len hc_out
331if le k 0
332exit 2
333end
334base = sub ulong k 1
335put hc_out base 47
336base = add base 1
337end
338if gt add base ulong n 4095
339exit 2
340end
341for j ulong ulong n bound 4096
342put hc_out add base j get hc_arg j
343end
344put hc_s 14 uint add base ulong n
345n = argread 2 hc_root 0 len hc_root
346if or le n 0 ge n 4096
347exit 2
348end
349k = makedir hc_root 0 ulong n 448
350if ne k 0
351exit 2
352end
353k = chdir hc_root 0 ulong n
354if ne k 0
355exit 2
356end
357end
358fn hc_print v ulong to void
359x = v
360i = ulong 24
361while true bound 24
362i = sub i 1
363put hc_dig i uchar add 48 rem x 10
364x = div x 10
365if eq x 0
366k = write 2 hc_dig i sub 24 i
367ret
368end
369end
370end
371fn hc_diag actual long expected long to void
372k = write 2 hc_bad0 0 len hc_bad0
373hc_print get hc_count 0
374k = write 2 hc_bad1 0 len hc_bad1
375hc_print bitcast ulong actual
376k = write 2 hc_bad2 0 len hc_bad2
377hc_print bitcast ulong expected
378k = write 2 hc_st2 0 len hc_st2
379end
380fn main to int
381if ne argcnt 3
382ret 2
383end
384ir_init
385f = ir_fnew 2 0 8
386put hc_s 0 ir_blk f
387put hc_s 1 ir_ftok f
388put hc_s 2 hc_memory
389put hc_s 3 hc_text hc_name
390put hc_s 4 hc_text hc_data
391put hc_s 5 hc_text hc_one
392hc_paths
393mask = umask 0
394put hc_a 0 hc_c 8 0
395hc_ok hc_host 155 9 1 mask mask
396hc_args
397hc_files1
398hc_files2
399hc_files3
400hc_dirs
401r = hc_text hc_msg
402put hc_a 0 hc_c 8 1
403hc_slice 1 r 0 len hc_msg
404v = hc_host 54 9 4
405hc_true hc_cmp 30 v hc_c 9 len hc_msg
406status = hc_c 8 7
407o = ir_op get hc_s 0 66 0 0 2
408ir_set o 0 get hc_s 1
409ir_set o 1 status
410n = ir_wr
411fd = fopen hc_out 0 ulong get hc_s 14 577 384
412if lt fd 0
413hc_diag fd 0
414ret 2
415end
416written = ar_out ulong fd 1 0 n
417cl = fclose int fd
418if eq written 0
419hc_diag 0 long n
420ret 2
421end
422k = write 2 hc_st0 0 len hc_st0
423hc_print get hc_count 0
424k = write 2 hc_st1 0 len hc_st1
425hc_print get hc_count 1
426k = write 2 hc_st2 0 len hc_st2
427k = write 1 hc_msg 0 len hc_msg
428if ne k long len hc_msg
429ret 2
430end
431exit 7
432end