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 / node / code-test.om

602 lines · 12130 bytes Raw Blame History
1note seed/node/code-test.om -- checks of the coding workflow (DRA-290).
2note omnode-code-test unit JDIR: the creator's decisions on crafted model
3note and tool records, no child process; prints "code checks=N fail=F" and
4note exits 0, or 150 + the number of the first failing check.
5note omnode-code-test cancel MS INFER TOOL OMC ROOT WORK JDIR PORT VIEW OBJ...:
6note omnode-code with objective 0's first inference cancelled through
7note auth_cancel once it has run MS milliseconds.
8note omnode-code-test overload LIMIT INFER ... OBJ...: omnode-code admitting
9note at most LIMIT jobs (DRA-291: the view shows the refusals).
10note omnode-code-test uncertain INFER ... OBJ...: omnode-code whose first
11note granted replace has its worker killed once its START is durable
12note (DRA-291, DRA-292: an unknown effect).
13text ctunit "unit"
14text ctcanc "cancel"
15text ctover "overload"
16text ctunc "uncertain"
17text ctobj "loop,4,3,70,jobs/item76666.om,Fix the error in this file and confirm its goal."
18text ctpath "jobs/item76666.om"
19text ctbadp "jobs/item76667.om"
20text ctsrc "fn calc x int to int\ns = x\nfor i ulong 2\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\n"
21text ctfix "fn calc x int to int\ns = x\nfor i ulong 3\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\n"
22text ctold "ulong 2"
23text ctnew "ulong 3"
24text ctnone "ulong 9"
25text ctdup "int 4"
26text ctdup2 "s"
27text ctgar "ulong 3 x"
28text ctrs "Read succeeded."
29text ctfnf "File not found."
30text cttf "Test failed: calc(70) expected 82, got 78."
31text ctes "Edit saved."
32text cttp "Tests passed."
33text ctp0 "Task: Fix the error in this file and confirm its goal.\nFile: jobs/item76666.om\nGoal: calc starts with x and adds 4 exactly 3 times in a for loop. main calls calc with 70.\nState: unread\nAnswer:\n"
34text ctp2 "Task: Fix the error in this file and confirm its goal.\nFile: jobs/item76666.om\nGoal: calc starts with x and adds 4 exactly 3 times in a for loop. main calls calc with 70.\nState: failed\nSource:\nfn calc x int to int\ns = x\nfor i ulong 2\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\nTool result: Test failed: calc(70) expected 82, got 78.\nAnswer:\n"
35text ctfl "code-test check "
36text ctfl2 " FAIL\n"
37text ctsum "code checks="
38text ctsum2 " fail="
39text ctomni "OMNI1 "
40text ctomnt "OMNT1 "
41global ctcases ulong 1
42global ctn ulong 3
43global ctc ulong 1
44
45note The creator's pool handle, kept for the record helpers.
46fn ct_c to long
47ret long get ctc 0
48end
49
50fn ct_ok b bool to void
51put ctn 0 add get ctn 0 1
52if b
53ret
54end
55put ctn 1 add get ctn 1 1
56if eq get ctn 2 0
57put ctn 2 get ctn 0
58end
59o = new uchar 4096 0
60p = cw_cat o 0 ctfl
61p = cw_dec o p get ctn 0
62p = cw_cat o p ctfl2
63cw_out o p
64end
65
66note Objective 0 in state st (verified vf), its source sel (0 none, 1 the
67note broken source, 2 the fixed one), no job, running.
68note Independent scenarios each need a fresh durable objective after the previous one ended.
69fn ct_newjournal to void
70b = new uchar 4096 0
71tag = get ctcases 0
72put ctcases 0 add tag 1
73n = cw_dec b 0 ulong getpid
74put b n 45
75n = cw_dec b add n 1 tag
76r = makedir b 0 n 448
77if ne r 0
78exit 59
79end
80for i ulong n bound 100
81put cwcf add 5120 i get b i
82end
83put cwcl 5 n
84if ne cw_jopen 1 1 0
85exit 59
86end
87end
88
89fn ct_set st ulong vf ulong sel ulong to void
90if ne jn_res 0 0
91jn_close
92ct_newjournal
93end
94cw_s 0 6 st
95cw_s 0 8 vf
96cw_s 0 9 0
97cw_s 0 10 0
98cw_s 0 12 0
99cw_s 0 13 0
100cw_s 0 14 0
101put cwinf 0 0
102if eq sel 1
103cw_setsrc 0 ctsrc
104end
105if eq sel 2
106cw_setsrc 0 ctfix
107end
108end
109
110note The objective's state: result r and, when r is 0, a job of kind k in
111note flight (k 0: none).
112fn ct_is r ulong k ulong to bool
113if ne cw_g 0 12 r
114ret false
115end
116if ne r 0
117ret true
118end
119if eq k 0
120ret eq cw_g 0 10 0
121end
122id = cw_g 0 10
123ret and gt id 0 and eq rem id 10 k jn_known id
124end
125
126note Record texts by index: 0 path, 1 another path, 2 old, 3 new, 4 old
127note text not in the source, 5 old text twice in it, 6 old text many times,
128note 7 new text outside the grammar. Appended to b at p; the new length.
129fn ct_cat b edit uchar 4096 p ulong s ulong to ulong
130if eq s 0
131ret cw_cat b p ctpath
132end
133if eq s 1
134ret cw_cat b p ctbadp
135end
136if eq s 2
137ret cw_cat b p ctold
138end
139if eq s 3
140ret cw_cat b p ctnew
141end
142if eq s 4
143ret cw_cat b p ctnone
144end
145if eq s 5
146ret cw_cat b p ctdup
147end
148if eq s 6
149ret cw_cat b p ctdup2
150end
151ret cw_cat b p ctgar
152end
153
154fn ct_len s ulong to ulong
155b = new uchar 4096 0
156ret ct_cat b 0 s
157end
158
159fn ct_nums b edit uchar 4096 p ulong a ulong o ulong to ulong
160q = cw_cat b p cwsp
161q = cw_dec b q 1
162q = cw_cat b q cwsp
163q = cw_dec b q 100
164q = cw_cat b q cwsp
165q = cw_dec b q 12
166q = cw_cat b q cwsp
167q = cw_dec b q a
168q = cw_cat b q cwsp
169q = cw_dec b q o
170ret q
171end
172
173fn ct_tail b edit uchar 4096 p ulong nl ulong tl ulong to ulong
174q = cw_cat b p cwsp
175q = cw_dec b q nl
176q = cw_cat b q cwsp
177q = cw_dec b q tl
178ret cw_cat b q cwnl
179end
180
181note The model's action k on path text pa, replacing text ol by text nw
182note (indices for ct_cat); the raw text is two newlines.
183fn ct_act k ulong pa ulong ol ulong nw ulong to void
184b = new uchar 4096 0
185p = cw_cat b 0 ctomni
186p = cw_dec b p k
187p = ct_nums b p ct_len pa ct_len ol
188p = ct_tail b p ct_len nw 2
189p = ct_cat b p pa
190p = ct_cat b p ol
191p = ct_cat b p nw
192p = cw_cat b p cwnl
193p = cw_cat b p cwnl
194cw_ires ct_c 0 b
195end
196
197note A plain answer (Tests passed., File not found.) of kind k.
198fn ct_ans k ulong a view uchar * to void
199b = new uchar 4096 0
200p = cw_cat b 0 ctomni
201p = cw_dec b p k
202p = ct_nums b p 0 0
203p = ct_tail b p 0 len a
204p = cw_cat b p a
205cw_ires ct_c 0 b
206end
207
208note A tool record of job kind k: status st, observation ob, content ct.
209fn ct_tool k ulong st ulong ob view uchar * ct view uchar * to void
210b = new uchar 4096 0
211p = cw_cat b 0 ctomnt
212p = cw_dec b p st
213p = cw_cat b p cwsp
214p = cw_dec b p len ob
215p = cw_cat b p cwsp
216p = cw_dec b p len ct
217p = cw_cat b p cwnl
218p = cw_cat b p ob
219p = cw_cat b p ct
220cw_tres ct_c 0 k b
221end
222
223fn ct_prompt to void
224o = new uchar 4096 0
225ct_set 0 0 0
226n = cw_prmt o 0
227ct_ok cw_eq view part o 0 n ctp0
228ct_set 2 0 1
229cw_seto 0 cttf
230n = cw_prmt o 0
231ct_ok cw_eq view part o 0 n ctp2
232end
233
234note Model actions against the policy.
235fn ct_model to void
236ct_set 0 0 0
237ct_act 1 0 2 3
238ct_ok ct_is 0 2
239ct_set 0 0 0
240ct_act 1 1 2 3
241ct_ok ct_is 11 0
242ct_set 0 0 0
243ct_act 2 0 2 3
244ct_ok ct_is 10 0
245ct_set 0 0 0
246ct_act 9 0 2 3
247ct_ok ct_is 10 0
248ct_set 1 0 1
249ct_act 3 0 2 3
250ct_ok ct_is 10 0
251ct_set 1 0 1
252ct_act 2 0 2 3
253ct_ok ct_is 0 3
254ct_set 3 0 2
255ct_act 2 0 2 3
256ct_ok ct_is 0 3
257ct_set 4 1 2
258ct_act 2 0 2 3
259ct_ok ct_is 10 0
260ct_edits
261ct_answers
262end
263
264fn ct_edits to void
265u = new uchar 4096 0
266ct_set 2 0 1
267ct_act 3 0 4 3
268ct_ok ct_is 13 0
269ct_set 2 0 1
270ct_act 3 0 5 3
271ct_ok ct_is 13 0
272ct_set 2 0 1
273ct_act 3 0 6 3
274ct_ok ct_is 13 0
275ct_set 2 0 1
276ct_act 3 0 2 7
277ct_ok ct_is 13 0
278ct_set 2 0 1
279ct_act 3 1 2 3
280ct_ok ct_is 11 0
281ct_set 2 0 1
282ct_act 3 0 2 3
283ct_ok ct_is 0 4
284n = cw_ld u 4 0
285ct_ok cw_eq view part u 0 n ctfix
286end
287
288fn ct_answers to void
289ct_set 4 0 1
290ct_ans 4 cttp
291ct_ok ct_is 14 0
292ct_set 3 0 2
293ct_ans 4 cttp
294ct_ok ct_is 14 0
295ct_set 4 1 2
296ct_ans 4 cttp
297ct_ok ct_is 0 5
298ct_set 0 0 0
299ct_ans 5 ctfnf
300ct_ok ct_is 10 0
301ct_set 5 0 0
302ct_ans 5 ctfnf
303ct_ok ct_is 1 0
304end
305
306note Malformed model records.
307fn ct_bad to void
308b = new uchar 4096 0
309ct_set 0 0 0
310p = cw_cat b 0 ctomnt
311cw_ires ct_c 0 b
312ct_ok ct_is 18 0
313ct_set 0 0 0
314p = cw_cat b 0 ctomni
315p = cw_dec b p 4
316p = ct_nums b p 0 0
317p = ct_tail b p 0 3969
318cw_ires ct_c 0 b
319ct_ok ct_is 18 0
320ct_set 0 0 0
321p = cw_cat b 0 ctomni
322p = cw_dec b p 4
323p = cw_cat b p cwnl
324cw_ires ct_c 0 b
325ct_ok ct_is 18 0
326end
327
328note Tool records.
329fn ct_tools to void
330u = new uchar 4096 0
331ct_set 0 0 0
332ct_tool 2 0 ctrs ctsrc
333ct_ok and ct_is 0 0 eq cw_g 0 6 1
334n = cw_ld u 2 0
335ct_ok cw_eq view part u 0 n ctsrc
336ct_set 0 0 0
337ct_tool 2 1 ctfnf ctes
338ct_ok and ct_is 0 0 eq cw_g 0 6 5
339ct_set 0 0 0
340ct_tool 2 2 ctfnf ctes
341ct_ok ct_is 17 0
342ct_set 1 0 1
343ct_tool 3 6 cttf ctsrc
344ct_ok and ct_is 0 0 and eq cw_g 0 6 2 eq cw_g 0 8 0
345ct_set 1 0 1
346ct_tool 3 6 cttf ctfix
347ct_ok ct_is 15 0
348ct_set 3 0 2
349ct_tool 3 0 cttp ctfix
350ct_ok and ct_is 0 0 and eq cw_g 0 6 4 eq cw_g 0 8 1
351ct_set 3 0 2
352ct_tool 3 4 cttp ctfix
353ct_ok ct_is 17 0
354ct_saves
355end
356
357fn ct_saves to void
358ct_set 2 0 1
359ct_act 3 0 2 3
360ct_ok ct_is 0 4
361cw_s 0 10 0
362ct_tool 4 0 ctes ctfix
363ct_ok and ct_is 0 0 eq cw_g 0 6 3
364ct_set 2 0 1
365cw_s 0 15 0
366ct_tool 4 0 ctes ctfix
367ct_ok ct_is 15 0
368ct_set 2 0 1
369ct_tool 4 5 ctes ctsrc
370ct_ok ct_is 13 0
371ct_set 4 1 2
372ct_tool 5 0 cttp ctfix
373ct_ok ct_is 1 0
374ct_set 4 1 2
375ct_tool 5 6 cttf ctfix
376ct_ok ct_is 15 0
377ct_set 4 1 2
378ct_tool 5 0 cttp ctsrc
379ct_ok ct_is 15 0
380end
381
382note Job outcome words.
383fn ct_fates to void
384ct_ok eq cw_fate 2 1 0
385ct_ok eq cw_fate or ulong 2 shl ulong 1024 8 1 16
386ct_ok eq cw_fate or ulong 2 shl ulong 1280 8 1 16
387ct_ok eq cw_fate or ulong 2 shl ulong 2048 8 1 16
388ct_ok eq cw_fate or ulong 2 shl ulong 256 8 3 17
389ct_ok eq cw_fate or ulong 2 shl ulong 9 8 1 21
390ct_ok eq cw_fate or ulong 1 shl ulong 9 8 1 19
391ct_ok eq cw_fate 22 1 19
392ct_ok eq cw_fate 0 4 21
393ct_ok eq cw_fate 90 2 22
394ct_ok eq cw_fate 18 2 23
395end
396
397note Turn limit and prompt length.
398fn ct_limits c long to void
399sp = new uchar 4096 0
400ct_set 1 0 0
401cw_s 0 7 7
402cw_plan c
403ct_ok ct_is 12 0
404for j ulong 3790
405put sp j 32
406end
407ct_set 1 0 0
408cw_setsrc 0 view part sp 0 3790
409cw_s 0 7 0
410cw_plan c
411ct_ok ct_is 20 0
412ct_set 0 0 0
413cw_plan c
414ct_ok and ct_is 0 1 eq cw_g 0 7 1
415end
416
417note The cancel hook with a journal that refuses (DRA-398 review r2): a
418note job running in a free slot as objective 0's inference, the hook armed
419note and due. auth_cancel refuses (-5): nothing traps, the job keeps
420note running and the hook stays armed. Everything is restored after.
421fn ct_hook c long to void
422s = ulong 64
423for j ulong 64
424if eq get sjst j 0
425s = j
426end
427end
428ct_ok lt s 64
429if ge s 64
430ret
431end
432ct_set 1 0 0
433cw_s 0 9 1
434cw_s 0 10 4242
435put cwt0 0 0
436put sjid s 4242
437put sjst s 3
438put cwtk 0 1
439put cwtk 1 0
440put jbad 0 1
441cw_hook c
442ct_ok and eq get cwtk 0 1 eq get sjst s 3
443put jbad 0 0
444put cwtk 0 0
445put sjst s 0
446put sjid s 0
447ct_set 0 0 0
448end
449
450note A full queue: a refused inference is asked for again (the objective
451note keeps waiting for a turn); a refused tool job ends the objective with
452note 23; both refusals are counted for the view.
453fn ct_full c long to void
454for k ulong 64
455if lt jn_admit add 9001 k 0 1 0
456break
457end
458end
459r0 = vw_cget 0
460ct_set 0 0 0
461cw_plan c
462ct_ok and ct_is 0 0 eq cw_g 0 9 0
463ct_set 1 0 1
464cw_tool c 0 3
465ct_ok ct_is 23 0
466ct_ok eq vw_cget 0 add r0 2
467end
468
469fn ct_unit to int
470if lt argcnt 3
471ret 2
472end
473d = new uchar 1024 0
474n = argread 2 d 0 1000
475if lt n 1
476ret 2
477end
478for k ulong 7
479put cwcl k 1
480put cwcf mul k 1024 47
481end
482r = makedir d 0 ulong n 448
483if and lt r 0 ne r neg long 17
484ret 59
485end
486if ne chdir d 0 ulong n 0
487ret 59
488end
489put cwno 0 1
490if not cw_parse 0 ctobj
491ret 3
492end
493c = pool_new 4 2
494if le c 0
495ret 50
496end
497put ctc 0 ulong c
498if ne sup_init c 0
499ret 51
500end
501if ne sched_new c 8 8 0
502ret 52
503end
504if ne auth_new c 0
505ret 53
506end
507ct_newjournal
508ct_prompt
509ct_model
510ct_bad
511ct_tools
512ct_fates
513ct_limits c
514ct_hook c
515ct_full c
516ct_set 0 0 0
517put jbad 0 1
518cw_end 0 1
519ct_ok and ne get cwresultbad 0 0 and eq cw_g 0 12 0 eq jn_res 0 0
520put jbad 0 0
521jn_close
522ret ct_end
523end
524
525fn ct_end to int
526o = new uchar 4096 0
527p = cw_cat o 0 ctsum
528p = cw_dec o p get ctn 0
529p = cw_cat o p ctsum2
530p = cw_dec o p get ctn 1
531p = cw_cat o p cwnl
532cw_out o p
533if eq get ctn 1 0
534ret 0
535end
536ret int add 150 get ctn 2
537end
538
539fn ct_mode to ulong
540b = new uchar 16 0
541n = argread 1 b 0 16
542if lt n 1
543ret 0
544end
545if cw_eq view part b 0 ulong n ctunit
546ret 1
547end
548if cw_eq view part b 0 ulong n ctcanc
549ret 2
550end
551if cw_eq view part b 0 ulong n ctover
552ret 3
553end
554if cw_eq view part b 0 ulong n ctunc
555ret 4
556end
557ret 0
558end
559
560fn main to int
561m = ct_mode
562if eq m 1
563ret ct_unit
564end
565if eq m 2
566ms = ct_num 2
567put cwtk 0 1
568put cwtk 1 ms
569ret cw_main 3 3600
570end
571if eq m 3
572q = ct_num 2
573if eq q 0
574ret 2
575end
576put cwql 0 q
577ret cw_main 3 3600
578end
579if eq m 4
580put cwtu 0 1
581ret cw_main 2 3600
582end
583ret 2
584end
585
586note Argument i as a decimal of at most 7 digits; 0 when malformed.
587fn ct_num i ulong to ulong
588b = new uchar 16 0
589n = argread i b 0 16
590if or lt n 1 gt n 7
591ret 0
592end
593v = ulong 0
594for j ulong ulong n
595c = ulong get b j
596if or lt c 48 gt c 57
597ret 0
598end
599v = add mul v 10 sub c 48
600end
601ret v
602end