interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / tests / gate.om

1972 lines · 34930 bytes Raw Blame History
1note mailhand scenario gate. Structure adapted from omega-zip 74e9e36d tests/gate.om.
2note Stores replace whole-file arrays; explicit disk-backed stacks replace recursive tree walks.
3note execprog forces 65536 packet bytes/1024 args; PATH_MAX 4096. No input-size/depth caps.
4note Every child has 120 seconds; compilation has 300 seconds; expiration fails, never passes.
5const GA_CASE ulong 0
6const GA_FIELDS ulong 1
7const GA_EXP ulong 2
8const GA_NAMES ulong 3
9const GA_STACK ulong 4
10const GA_FILE ulong 5
11const GA_MUT ulong 7
12const GA_UNITS ulong 8
13const GA_SRC ulong 9
14const GA_ROOT ulong 10
15const GA_SCEN ulong 11
16const GA_OMC ulong 12
17const GA_SPEC ulong 13
18const GA_BIN ulong 14
19const GA_OLD ulong 15
20const GA_NEW ulong 16
21const GA_PATH ulong 17
22const GA_LAST ulong 18
23const GA_TMP ulong 19
24note GA_ROB: the input of the running rob step (store 6, unused elsewhere in the gate).
25const GA_ROB ulong 6
26global ga_v ulong 32
27global ga_packet uchar 65536
28global ga_pn ulong 2
29global ga_in uchar 4096
30global ga_out uchar 4096
31global ga_err uchar 4096
32global ga_io ulong 3
33global ga_pinv uchar 104
34text ga_pinf "PIN"
35text ga_pinmv "omega-mv "
36text ga_pinomc "omc-sha256 "
37text ga_badpin "MHGATE NOT_RUN PIN is not \"omega-mv <40 hex>\\nomc-sha256 <64 hex>\\n\"\n"
38text ga_gitbin "/usr/bin/git"
39text ga_lsfiles "ls-files"
40text ga_pinlsfail "MHGATE pincheck: git ls-files failed\n"
41text ga_pinsum "MHGATE pincheck files="
42text ga_pinbad " restated="
43text ga_pinhit "PINCHECK restates the pin: "
44text ga_nl "\n"
45text ga_slash "/"
46text ga_empty ""
47text ga_null "/dev/null"
48text ga_build "build"
49text ga_dir "build/gate"
50text ga_sdir "build/gate/s"
51text ga_stail "/s/"
52text ga_cases "tests/scenarios"
53text ga_muts "tests/mutants.txt"
54text ga_srcunits "build/gen/src/UNITS"
55text ga_sinkunits "src/SINK_UNITS"
56text ga_mh "build/gate/mailhand"
57text ga_sink "build/gate/mailhand-sink"
58text ga_mutbin "build/gate/mutant"
59text ga_unitfile "build/gate/source.om"
60text ga_stdout "build/gate/out"
61text ga_stderr "build/gate/err"
62text ga_bgout "build/gate/sink.out"
63text ga_bgerr "build/gate/sink.err"
64text ga_txt ".txt"
65text ga_om2 "om2"
66text ga_export "export fn "
67text ga_fn "fn "
68text ga_header "om2\n"
69text ga_run "run"
70text ga_bg "bg"
71text ga_wait "wait"
72text ga_mkdir "mkdir"
73text ga_copy "copy"
74text ga_write "write"
75text ga_append "append"
76text ga_symlink "symlink"
77text ga_flip "flip"
78text ga_gen "gen"
79text ga_outeq "out-eq"
80text ga_outhas "out-has"
81text ga_outnot "out-not"
82text ga_outlines "out-lines"
83text ga_errhas "err-has"
84text ga_fileeq "file-eq"
85text ga_filehas "file-has"
86text ga_filenot "file-not"
87text ga_exists "exists"
88text ga_absent "absent"
89text ga_robw "rob"
90text ga_parse "parse"
91text ga_robin "/rob.in"
92text ga_krefused "\"refused\""
93text ga_robfailt "ROB FAIL "
94text ga_cutw " cut "
95text ga_xorw " xor "
96text ga_zerow " zero "
97text ga_exitw " exit "
98text ga_robrep "rob "
99text ga_runsw " runs="
100text ga_okw " ok="
101text ga_refw " refused="
102text ga_robtot "MHGATE rob runs="
103text ga_outsha "out-sha256"
104text ga_maxns "max-ns"
105text ga_slow "slow: actual="
106text ga_ns " ns threshold="
107text ga_dash "-"
108text ga_sep "--"
109text ga_mhw "mh"
110text ga_sinkw "sink"
111text ga_fail "FAIL "
112text ga_pass "PASS "
113text ga_step " step "
114text ga_reason ": "
115text ga_ioerr "I/O or path failure"
116text ga_badline "unknown or malformed step"
117text ga_mismatch "check mismatch"
118text ga_badexit "process exit mismatch (actual="
119text ga_want " expected="
120text ga_close ")"
121text ga_mutfail "MUTANT FAIL "
122text ga_mutkill "MUTANT killed "
123text ga_mutsurv "MUTANT SURVIVED "
124text ga_finalpass "MHGATE PASS scenarios="
125text ga_finalfail "MHGATE FAIL scenarios="
126text ga_steps " steps="
127text ga_mutcount " mutants-killed="
128text ga_notrun "MHGATE NOT_RUN compiler sha256 is not the omc-sha256 of PIN\n"
129text ga_usage "usage: gate OMC [SCENARIO-DIRECTORY [MUTANTS-FILE]]\n"
130text ga_buildfail "MHGATE FAIL build\n"
131text ga_sinknote "MHGATE sink NOT_RUN: src/SINK_UNITS absent\n"
132text ga_srvunits "build/gen/tests/srv/UNITS"
133text ga_srvbin "build/gate/srv"
134text ga_srvw "srv"
135text ga_srvnote "MHGATE srv NOT_RUN: tests/srv/UNITS absent\n"
136text ga_errnot "err-not"
137text ga_treenot "tree-not"
138text ga_genpre "tests/units/"
139text ga_genout "build/gate/gen-"
140text ga_lockf "build/gate/lock"
141text ga_lockwait "MHGATE waiting for build/gate/lock (another gate run holds it)\n"
142text ga_timeout "MHGATE limits: run=120s compile=300s\n"
143
144fn ga_say t view uchar * to void
145o_raw t
146o_flush
147end
148fn ga_num n ulong to void
149o_digits n
150o_flush
151end
152fn ga_print s ulong to void
153r = s_wfd s 1
154end
155fn ga_die t view uchar * to void
156ga_say t
157ga_say ga_nl
158exit 1
159end
160note ga_new: a fresh memfd store; a store loaded read-only by s_file cannot be reset in place.
161fn ga_new s ulong to void
162if not s_mem s
163ga_die ga_ioerr
164end
165end
166fn ga_uput s ulong v ulong to void
167for i ulong 8
168if not s_add s uchar and shr v mul i 8 255
169ga_die ga_ioerr
170end
171end
172end
173fn ga_uget s ulong p ulong to ulong
174v = ulong 0
175for i ulong 8
176v = or v shl ulong s_get s add p i mul i 8
177end
178ret v
179end
180fn ga_eol s ulong p ulong to ulong
181q = p
182while lt q s_len s bound 9223372036854775807
183if eq s_get s q 10
184break
185end
186q = add q 1
187end
188ret q
189end
190fn ga_equal a ulong ao ulong b ulong bo ulong n ulong to bool
191for i ulong n bound 9223372036854775807
192if ne s_get a add ao i s_get b add bo i
193ret false
194end
195end
196ret true
197end
198fn ga_path s ulong to void
199p_reset
200p_s s 0 s_len s
201end
202fn ga_pt t view uchar * to void
203p_reset
204p_t t
205end
206fn ga_savepath s ulong to void
207ga_new s
208for i ulong get gv VPL bound 4096
209z = s_add s get gp i
210end
211end
212fn ga_load s ulong to bool
213ret eq s_file s 0
214end
215fn ga_numrange s ulong p ulong n ulong to ulong
216v = ulong 0
217if eq n 0
218ga_die ga_badline
219end
220for i ulong n bound 9223372036854775807
221c = s_get s add p i
222if or lt c 48 gt c 57
223ga_die ga_badline
224end
225if gt v div sub ulong 18446744073709551615 ulong sub c 48 10
226ga_die ga_badline
227end
228v = add mul v 10 ulong sub c 48
229end
230ret v
231end
232note Fields retain offsets into the scenario, no fixed field-count array.
233fn ga_fields a ulong b ulong to void
234ga_new GA_FIELDS
235p = a
236while lt p b bound 9223372036854775807
237if or eq s_get GA_CASE p 32 eq s_get GA_CASE p 9
238p = add p 1
239continue
240end
241q = p
242while lt q b bound 9223372036854775807
243c = s_get GA_CASE q
244if or eq c 32 eq c 9
245break
246end
247q = add q 1
248end
249ga_uput GA_FIELDS p
250ga_uput GA_FIELDS sub q p
251p = q
252end
253put ga_v 0 div s_len GA_FIELDS 16
254put ga_v 1 b
255end
256fn ga_fo i ulong to ulong
257ret ga_uget GA_FIELDS mul i 16
258end
259fn ga_fnlen i ulong to ulong
260ret ga_uget GA_FIELDS add mul i 16 8
261end
262fn ga_is i ulong t view uchar * to bool
263if ge i get ga_v 0
264ret false
265end
266ret s_eqt GA_CASE ga_fo i ga_fnlen i t
267end
268fn ga_fnum i ulong to ulong
269ret ga_numrange GA_CASE ga_fo i ga_fnlen i
270end
271note Expand @S scenario, @B absolute build/gate, @R repo; decode \n, \t, \r, \\.
272fn ga_expand p0 ulong n ulong to void
273ga_new GA_EXP
274p = p0
275e = add p n
276while lt p e bound 9223372036854775807
277c = s_get GA_CASE p
278if lt add p 1 e
279if eq c 64
280k = s_get GA_CASE add p 1
281if or or eq k 83 eq k 66 eq k 82
282s_adds GA_EXP GA_ROOT 0 s_len GA_ROOT
283if ne k 82
284s_addt GA_EXP ga_slash
285s_addt GA_EXP ga_dir
286end
287if eq k 83
288s_addt GA_EXP ga_stail
289s_adds GA_EXP GA_SCEN 0 s_len GA_SCEN
290end
291p = add p 2
292continue
293end
294end
295if and eq c 92 eq get ga_v 31 1
296k = s_get GA_CASE add p 1
297if eq k 110
298c = 10
299end
300if eq k 116
301c = 9
302end
303if eq k 114
304c = 13
305end
306if eq k 92
307c = 92
308end
309if or or eq k 110 eq k 116 or eq k 114 eq k 92
310p = add p 1
311end
312end
313end
314if not s_add GA_EXP c
315ga_die ga_ioerr
316end
317p = add p 1
318end
319end
320fn ga_field i ulong to void
321ga_expand ga_fo i ga_fnlen i
322end
323fn ga_rest i ulong to void
324p = ga_fo i
325ga_expand p sub get ga_v 1 p
326end
327fn ga_fpath i ulong to void
328ga_field i
329ga_path GA_EXP
330end
331note mkdir -p walks path components; kernel PATH_MAX is checked by core.
332fn ga_mkp to bool
333if not p_ok
334ret false
335end
336n = get gv VPL
337for i ulong n bound 4096
338if eq get gp i 47
339if gt i 0
340r = makedir gp 0 i 448
341if and lt r 0 ne r -17
342ret false
343end
344end
345end
346end
347r = makedir gp 0 n 448
348ret or eq r 0 eq r -17
349end
350note Stack entries: path bytes, u64 path length, u64 post marker.
351fn ga_push post ulong to void
352n = get gv VPL
353for i ulong n bound 4096
354z = s_add GA_STACK get gp i
355end
356ga_uput GA_STACK n
357ga_uput GA_STACK post
358end
359fn ga_pop to ulong
360n = s_len GA_STACK
361post = ga_uget GA_STACK sub n 8
362m = ga_uget GA_STACK sub n 16
363p_reset
364p_s GA_STACK sub sub n 16 m m
365s_trunc GA_STACK sub sub n 16 m
366ret post
367end
368fn ga_wipe to bool
369ga_new GA_STACK
370ga_push 0
371while gt s_len GA_STACK 0 bound 9223372036854775807
372post = ga_pop
373if eq post 1
374r = rmdir gp 0 get gv VPL
375if lt r 0
376ret false
377end
378continue
379end
380k = p_kind
381if eq k 0
382continue
383end
384if ne k 1
385if lt p_unlink 0
386ret false
387end
388continue
389end
390ga_push 1
391if not d_open 0
392ret false
393end
394p_save
395while d_next 0 bound 9223372036854775807
396p_restore
397p_c 47
398p_dn
399if not p_ok
400d_close 0
401ret false
402end
403ga_push 0
404end
405d_close 0
406end
407ret true
408end
409note Copy tree using explicit source stack and root-prefix replacement; symlinks copied as links.
410fn ga_copyone prefix ulong to bool
411ga_savepath GA_PATH
412k = p_kind
413ga_new GA_TMP
414s_adds GA_TMP GA_NEW 0 s_len GA_NEW
415s_adds GA_TMP GA_PATH prefix sub s_len GA_PATH prefix
416if eq k 1
417if not d_open 0
418ret false
419end
420p_save
421while d_next 0 bound 9223372036854775807
422p_restore
423p_c 47
424p_dn
425if not p_ok
426d_close 0
427ret false
428end
429ga_push 0
430end
431d_close 0
432ga_path GA_TMP
433ret ga_mkp
434end
435if eq k 2
436ga_path GA_PATH
437if not ga_load GA_FILE
438ret false
439end
440ga_path GA_TMP
441fd = fopen gp 0 get gv VPL 577 384
442if lt fd 0
443ret false
444end
445r = s_wfd GA_FILE int fd
446z = fclose int fd
447ret and eq r 0 eq z 0
448end
449if eq k 3
450ret ga_copylink
451end
452ret false
453end
454fn ga_copytree to bool
455ga_new GA_STACK
456ga_path GA_OLD
457n = get gv VPL
458ga_push 0
459while gt s_len GA_STACK 0 bound 9223372036854775807
460z = ga_pop
461if not ga_copyone n
462ret false
463end
464end
465ret true
466end
467note Two-path packets use compiler's 4096-byte packed-list boundary.
468fn ga_linkstores a ulong b ulong to bool
469buf = new uchar 4096 0
470na = s_len a
471nb = s_len b
472n = add add na nb 6
473if gt n 4096
474ret false
475end
476put buf 0 2
477put buf 2 uchar and na 255
478put buf 3 uchar shr na 8
479for i ulong na bound 4096
480put buf add 4 i s_get a i
481end
482q = add na 4
483put buf q uchar and nb 255
484put buf add q 1 uchar shr nb 8
485for i ulong nb bound 4096
486put buf add add q 2 i s_get b i
487end
488ret eq symlnk buf 0 n 0
489end
490fn ga_copylink to bool
491b = new uchar 4096 0
492ga_path GA_PATH
493r = readlnk gp 0 get gv VPL b 0 4096
494if or lt r 0 eq r 4096
495ret false
496end
497ga_new GA_FILE
498s_addt GA_FILE part b 0 ulong r
499ret ga_linkstores GA_FILE GA_TMP
500end
501note Process packet: fail before any host trap if its fixed wire representation is too large.
502fn ga_pkreset to void
503put ga_pn 0 2
504put ga_pn 1 0
505end
506fn ga_pk s ulong to void
507n = s_len s
508p = get ga_pn 0
509c = add get ga_pn 1 1
510if or gt c 1024 gt add add p n 2 65536
511ga_die ga_badline
512end
513put ga_packet p uchar and n 255
514put ga_packet add p 1 uchar and shr n 8 255
515for i ulong n bound 65536
516b = s_get s i
517if eq b 0
518ga_die ga_badline
519end
520put ga_packet add add p 2 i b
521end
522put ga_pn 0 add add p n 2
523put ga_pn 1 c
524put ga_packet 0 uchar and c 255
525put ga_packet 1 uchar shr c 8
526end
527fn ga_pkt t view uchar * to void
528ga_new GA_TMP
529s_addt GA_TMP t
530ga_pk GA_TMP
531end
532fn ga_stream which ulong s ulong to void
533n = s_len s
534if or eq n 0 ge n 4096
535ga_die ga_ioerr
536end
537for i ulong n bound 4096
538c = s_get s i
539if eq which 0
540put ga_in i c
541end
542if eq which 1
543put ga_out i c
544end
545if eq which 2
546put ga_err i c
547end
548end
549put ga_io which n
550end
551fn ga_streamt which ulong t view uchar * to void
552ga_new GA_TMP
553s_addt GA_TMP t
554ga_stream which GA_TMP
555end
556fn ga_reap pid long lim long to ulong
557b = new uchar 4 0
558t0 = monons
559while true bound 9223372036854775807
560w = waitpid int pid b 0 4 1
561if eq w pid
562st = le32b b 0
563if eq and st 127 0
564ret and shr st 8 255
565end
566ret add 1000 and st 127
567end
568if lt w 0
569if ne w -4
570ret 3000
571end
572end
573if gt sub monons t0 lim
574r = killpid int pid 9
575w = waitpid int pid b 0 4 0
576ret 2000
577end
578r = sleepns 50000
579end
580ret 2000
581end
582fn ga_spawn background bool lim long to ulong
583put ga_v 12 ulong monons
584fi = fopen ga_in 0 get ga_io 0 0 0
585fo = fopen ga_out 0 get ga_io 1 577 384
586fe = fopen ga_err 0 get ga_io 2 577 384
587if or or lt fi 0 lt fo 0 lt fe 0
588ga_die ga_ioerr
589end
590pid = fork
591if lt pid 0
592ga_die ga_ioerr
593end
594if eq pid 0
595if lt dupfd int fi 0 0 0
596exit 126
597end
598if lt dupfd int fo 1 0 0
599exit 126
600end
601if lt dupfd int fe 2 0 0
602exit 126
603end
604r = execprog ga_packet 0 get ga_pn 0
605exit 127
606end
607z = fclose int fi
608z = fclose int fo
609z = fclose int fe
610if background
611put ga_v 8 ulong pid
612put ga_v 14 get ga_v 12
613ret 0
614end
615st = ga_reap pid lim
616put ga_v 13 sub ulong monons get ga_v 12
617ret st
618end
619fn ga_normalio to void
620ga_streamt 0 ga_null
621ga_streamt 1 ga_stdout
622ga_streamt 2 ga_stderr
623end
624fn ga_badstatus st ulong to bool
625if ge st 1000
626ret true
627end
628ret and ge st 101 le st 114
629end
630note Build the exact listed units, removing om2 lines and normalizing export fn like build.sh.
631fn ga_unit s ulong e ulong mutated bool to ulong
632ga_pt ga_empty
633p_s GA_UNITS s sub e s
634if not ga_load GA_FILE
635ga_die ga_ioerr
636end
637rep = false
638if mutated
639rep = ga_equal GA_UNITS s GA_SPEC 0 sub e s
640if ne sub e s s_len GA_SPEC
641rep = false
642end
643end
644hits = ulong 0
645p = ulong 0
646while lt p s_len GA_FILE bound 9223372036854775807
647q = ga_eol GA_FILE p
648n = sub q p
649if not s_eqt GA_FILE p n ga_om2
650match = false
651if rep
652if eq n s_len GA_OLD
653match = ga_equal GA_FILE p GA_OLD 0 n
654end
655end
656if match
657hits = add hits 1
658k = get ga_v 20
659if and ne k 0 ne hits k
660match = false
661end
662end
663if match
664s_adds GA_SRC GA_NEW 0 s_len GA_NEW
665else
666if ge n len ga_export
667if s_eqt GA_FILE p len ga_export ga_export
668s_addt GA_SRC ga_fn
669p = add p len ga_export
670end
671end
672s_adds GA_SRC GA_FILE p sub q p
673end
674s_addt GA_SRC ga_nl
675end
676p = add q 1
677end
678ret hits
679end
680fn ga_compile units view uchar * binary view uchar * mutated bool to bool
681ga_pt units
682if not ga_load GA_UNITS
683ret false
684end
685ga_new GA_SRC
686s_addt GA_SRC ga_header
687p = ulong 0
688hits = ulong 0
689while lt p s_len GA_UNITS bound 9223372036854775807
690q = ga_eol GA_UNITS p
691if gt q p
692if ne s_get GA_UNITS p 35
693hits = add hits ga_unit p q mutated
694end
695end
696p = add q 1
697end
698if mutated
699if eq hits 0
700ret false
701end
702if ne get ga_v 20 0
703if ne hits get ga_v 21
704ret false
705end
706end
707end
708ga_pt ga_unitfile
709fd = fopen gp 0 get gv VPL 577 384
710if lt fd 0
711ret false
712end
713r = s_wfd GA_SRC int fd
714z = fclose int fd
715if ne r 0
716ret false
717end
718ga_pkreset
719ga_pk GA_OMC
720ga_streamt 0 ga_unitfile
721ga_streamt 1 binary
722ga_streamt 2 ga_stderr
723st = ga_spawn false 300000000000
724if ne st 0
725ga_pt ga_stderr
726if ga_load GA_FILE
727ga_print GA_FILE
728end
729ret false
730end
731ga_pt binary
732ret eq chmod gp 0 get gv VPL 493 0
733end
734fn ga_pinok to bool
735d = new uchar 32 0
736if not ga_pinread
737ga_say ga_badpin
738ret false
739end
740ga_path GA_OMC
741if not ga_load GA_FILE
742ret false
743end
744sha_s GA_FILE 0 s_len GA_FILE d
745ga_new GA_TMP
746s_addhex GA_TMP d
747for i ulong 64
748if ne s_get GA_TMP i get ga_pinv add 40 i
749ret false
750end
751end
752ret true
753end
754
755note ga_pinread: PIN is exactly "omega-mv <40 hex>\nomc-sha256 <64 hex>\n"; the values go to ga_pinv
756note (0..39 the omega-mv revision, 40..103 the omc sha256)
757fn ga_pinread to bool
758ga_pt ga_pinf
759if not ga_load GA_FILE
760ret false
761end
762if ne s_len GA_FILE 126
763ret false
764end
765if not s_eqt GA_FILE 0 9 ga_pinmv
766ret false
767end
768if not s_eqt GA_FILE 50 11 ga_pinomc
769ret false
770end
771if or ne s_get GA_FILE 49 10 ne s_get GA_FILE 125 10
772ret false
773end
774for i ulong 40
775c = s_get GA_FILE add 9 i
776if not ga_ishex c
777ret false
778end
779put ga_pinv i c
780end
781for i ulong 64
782c = s_get GA_FILE add 61 i
783if not ga_ishex c
784ret false
785end
786put ga_pinv add 40 i c
787end
788ret true
789end
790
791fn ga_ishex c uchar to bool
792ret or and ge c 48 le c 57 and ge c 97 le c 102
793end
794
795fn ga_isword c uchar to bool
796if or and ge c 48 le c 57 and ge c 97 le c 122
797ret true
798end
799ret or and ge c 65 le c 90 eq c 95
800end
801
802note ---- pincheck: no tracked file (git ls-files) other than PIN restates the pin: a whole hex word of
803note at least 7 digits that is a prefix of the omega-mv revision or of the omc sha256 is a finding ----
804fn ga_pincheck to ulong
805ga_pkreset
806ga_pkt ga_gitbin
807ga_pkt ga_lsfiles
808ga_normalio
809st = ga_spawn false 120000000000
810if ne st 0
811ga_say ga_pinlsfail
812ret 1
813end
814ga_pt ga_stdout
815if not ga_load GA_SRC
816ret 1
817end
818files = ulong 0
819bad = ulong 0
820n = s_len GA_SRC
821p = ulong 0
822while lt p n bound 9223372036854775807
823q = ga_eol GA_SRC p
824if gt q p
825files = add files 1
826bad = add bad ga_scanpin p q
827end
828p = add q 1
829end
830ga_say ga_pinsum
831ga_num files
832ga_say ga_pinbad
833ga_num bad
834ga_say ga_nl
835ret bad
836end
837
838fn ga_scanpin p ulong q ulong to ulong
839if s_eqt GA_SRC p sub q p ga_pinf
840ret 0
841end
842p_reset
843p_s GA_SRC p sub q p
844if ne p_kind 2
845ret 0
846end
847if not ga_load GA_FILE
848ret 0
849end
850n = s_len GA_FILE
851bad = ulong 0
852i = ulong 0
853prev = uchar 32
854while lt i n bound 9223372036854775807
855c = s_get GA_FILE i
856if and ga_ishex c not ga_isword prev
857e = i
858while lt e n bound 9223372036854775807
859if not ga_ishex s_get GA_FILE e
860break
861end
862e = add e 1
863end
864if ga_restates i e n
865bad = add bad 1
866end
867i = e
868prev = s_get GA_FILE sub e 1
869continue
870end
871prev = c
872i = add i 1
873end
874if gt bad 0
875ga_say ga_pinhit
876ga_new GA_TMP
877s_adds GA_TMP GA_SRC p sub q p
878ga_print GA_TMP
879ga_say ga_nl
880end
881ret bad
882end
883
884fn ga_restates s ulong e ulong n ulong to bool
885l = sub e s
886if lt l 7
887ret false
888end
889if lt e n
890if ga_isword s_get GA_FILE e
891ret false
892end
893end
894ret or ga_pinpfx s l 0 40 ga_pinpfx s l 40 64
895end
896
897fn ga_pinpfx s ulong l ulong o ulong m ulong to bool
898if gt l m
899ret false
900end
901for i ulong l bound 64
902if ne s_get GA_FILE add s i get ga_pinv add o i
903ret false
904end
905end
906ret true
907end
908
909note Scenario actions and checks.
910fn ga_process background bool to bool
911start = ulong 4
912want = ulong 0
913if background
914if ne get ga_v 8 0
915ret false
916end
917start = 1
918else
919if lt get ga_v 0 5
920ret false
921end
922if not ga_is 3 ga_sep
923ret false
924end
925want = ga_fnum 1
926end
927ga_pkreset
928if ga_is start ga_mhw
929ga_pk GA_BIN
930else
931if ga_is start ga_srvw
932ga_pkt ga_srvbin
933else
934if ga_is start ga_sinkw
935ga_pkt ga_sink
936else
937ga_field start
938ga_pk GA_EXP
939end
940end
941end
942i = add start 1
943while lt i get ga_v 0 bound 9223372036854775807
944ga_field i
945ga_pk GA_EXP
946i = add i 1
947end
948ga_normalio
949if background
950ga_streamt 1 ga_bgout
951ga_streamt 2 ga_bgerr
952else
953if not ga_is 2 ga_dash
954ga_field 2
955ga_stream 0 GA_EXP
956end
957end
958st = ga_spawn background 120000000000
959put ga_v 9 st
960put ga_v 10 want
961if ga_badstatus st
962ret false
963end
964ret eq st want
965end
966fn ga_waitstep to bool
967if eq get ga_v 8 0
968ret false
969end
970st = ga_reap long get ga_v 8 120000000000
971put ga_v 13 sub ulong monons get ga_v 14
972put ga_v 8 0
973put ga_v 9 st
974want = ulong 0
975if gt get ga_v 0 1
976want = ga_fnum 1
977end
978put ga_v 10 want
979if ga_badstatus st
980ret false
981end
982note wait changes last stdout/stderr to the sink's files by copying streaming.
983ga_pt ga_bgout
984if not ga_load GA_FILE
985ret false
986end
987ga_pt ga_stdout
988if not ga_savefile false
989ret false
990end
991ga_pt ga_bgerr
992if not ga_load GA_FILE
993ret false
994end
995ga_pt ga_stderr
996if not ga_savefile false
997ret false
998end
999ret eq st want
1000end
1001fn ga_savefile append bool to bool
1002fl = int 577
1003if append
1004fl = 1089
1005end
1006if not p_ok
1007ret false
1008end
1009fd = fopen gp 0 get gv VPL fl 384
1010if lt fd 0
1011ret false
1012end
1013r = s_wfd GA_FILE int fd
1014z = fclose int fd
1015ret and eq r 0 eq z 0
1016end
1017fn ga_writefile append bool to bool
1018put ga_v 31 1
1019if gt get ga_v 0 2
1020ga_rest 2
1021else
1022ga_new GA_EXP
1023end
1024put ga_v 31 0
1025ga_new GA_FILE
1026s_adds GA_FILE GA_EXP 0 s_len GA_EXP
1027ga_fpath 1
1028ret ga_savefile append
1029end
1030fn ga_flipfile to bool
1031b = new uchar 1 0
1032ga_fpath 1
1033fd = fopen gp 0 get gv VPL 32770 0
1034if lt fd 0
1035ret false
1036end
1037p = ga_fnum 2
1038r = pread int fd b 0 1 long p
1039if ne r 1
1040z = fclose int fd
1041ret false
1042end
1043put b 0 xor get b 0 1
1044r = pwrite int fd b 0 1 long p
1045z = fclose int fd
1046ret and eq r 1 eq z 0
1047end
1048fn ga_copyaction to bool
1049ga_field 1
1050ga_new GA_OLD
1051s_adds GA_OLD GA_EXP 0 s_len GA_EXP
1052ga_field 2
1053ga_new GA_NEW
1054s_adds GA_NEW GA_EXP 0 s_len GA_EXP
1055ret ga_copytree
1056end
1057fn ga_linkaction to bool
1058ga_field 1
1059ga_new GA_OLD
1060s_adds GA_OLD GA_EXP 0 s_len GA_EXP
1061ga_field 2
1062ret ga_linkstores GA_OLD GA_EXP
1063end
1064fn ga_fileequal a ulong b ulong to bool
1065if ne s_len a s_len b
1066ret false
1067end
1068ret ga_equal a 0 b 0 s_len a
1069end
1070note Contains works on stores, including patterns and files larger than a cache window.
1071fn ga_contains a ulong b ulong to bool
1072n = s_len a
1073m = s_len b
1074if gt m n
1075ret false
1076end
1077p = ulong 0
1078while le p sub n m bound 9223372036854775807
1079if ga_equal a p b 0 m
1080ret true
1081end
1082p = add p 1
1083end
1084ret false
1085end
1086fn ga_check to bool
1087isfile = or or ga_is 0 ga_fileeq ga_is 0 ga_filehas ga_is 0 ga_filenot
1088if isfile
1089ga_fpath 1
1090else
1091ga_pt ga_stdout
1092if or ga_is 0 ga_errhas ga_is 0 ga_errnot
1093ga_pt ga_stderr
1094end
1095end
1096if not ga_load GA_FILE
1097ret false
1098end
1099if ga_is 0 ga_outlines
1100n = ulong 0
1101for i ulong s_len GA_FILE bound 9223372036854775807
1102if eq s_get GA_FILE i 10
1103n = add n 1
1104end
1105end
1106ret eq n ga_fnum 1
1107end
1108arg = ulong 1
1109if isfile
1110arg = 2
1111end
1112if or ga_is 0 ga_outeq ga_is 0 ga_fileeq
1113ga_fpath arg
1114if not ga_load GA_TMP
1115ret false
1116end
1117ret ga_fileequal GA_FILE GA_TMP
1118end
1119ga_rest arg
1120ok = ga_contains GA_FILE GA_EXP
1121if or or ga_is 0 ga_outnot ga_is 0 ga_filenot ga_is 0 ga_errnot
1122ret not ok
1123end
1124ret ok
1125end
1126note gen KIND PATH ARGS: build tests/units/KIND.txt -> build/gate/gen-KIND then run ARGS PATH.
1127note mkbig interface is KIND OUTFILE: gen mkbig OUTFILE KIND.
1128fn ga_genstep to bool
1129ub = new uchar 4096 0
1130bb = new uchar 4096 0
1131ga_field 1
1132ga_pt ga_genpre
1133p_s GA_EXP 0 s_len GA_EXP
1134p_t ga_txt
1135un = get gv VPL
1136for i ulong un bound 4096
1137put ub i get gp i
1138end
1139ga_pt ga_genout
1140p_s GA_EXP 0 s_len GA_EXP
1141bn = get gv VPL
1142for i ulong bn bound 4096
1143put bb i get gp i
1144end
1145if not ga_compile part ub 0 un part bb 0 bn false
1146ret false
1147end
1148ga_pkreset
1149ga_pkt part bb 0 bn
1150i = ulong 3
1151while lt i get ga_v 0 bound 9223372036854775807
1152ga_field i
1153ga_pk GA_EXP
1154i = add i 1
1155end
1156ga_field 2
1157ga_pk GA_EXP
1158ga_normalio
1159st = ga_spawn false 120000000000
1160put ga_v 9 st
1161put ga_v 10 0
1162ret eq st 0
1163end
1164fn ga_shaout to bool
1165d = new uchar 32 0
1166ga_pt ga_stdout
1167if not ga_load GA_FILE
1168ret false
1169end
1170sha_s GA_FILE 0 s_len GA_FILE d
1171ga_new GA_TMP
1172s_addhex GA_TMP d
1173ga_field 1
1174ret ga_fileequal GA_TMP GA_EXP
1175end
1176note ---- rob FILE: robustness of "mh parse" (adapted from omega-zip 74e9e36d robline) ----
1177note FILE cut at 64 evenly spaced lengths k*(n-1)/63 (0 and n-1 included), and changed at 256 evenly
1178note spaced bytes k*n/256 (xor 255; every 4th position, k rem 4 = 3, also set to 0). Each input is
1179note written fresh to @S/rob.in and fed to "mh parse" on stdin. A run passes with exit 0, or exit 4
1180note with exactly one JSONL line containing "refused"; a trap (101..114), a signal, the time limit or
1181note any other exit fails. ga_v: 22 quiet, 23..26 runs/ok/refused/failed of the step, 27..29 totals.
1182fn ga_wrbuf fd int b view uchar * k ulong to bool
1183w = ulong 0
1184while lt w k bound 9223372036854775807
1185r = write fd b w sub k w
1186if le r 0
1187ret false
1188end
1189w = add w ulong r
1190end
1191ret true
1192end
1193fn ga_robcopy fd int n ulong to bool
1194b = new uchar 65536 0
1195o = ulong 0
1196while lt o n bound 9223372036854775807
1197m = sub n o
1198if gt m 65536
1199m = 65536
1200end
1201k = s_read GA_ROB o part b 0 m
1202if eq k 0
1203ret false
1204end
1205if not ga_wrbuf fd b k
1206ret false
1207end
1208o = add o k
1209end
1210ret true
1211end
1212note ga_robwrite: @S/rob.in = the first n bytes of GA_ROB; mode 1 xors byte p with 255, mode 2 zeroes it.
1213fn ga_robwrite n ulong p ulong mode ulong to bool
1214b = new uchar 1 0
1215ga_scenariopath
1216p_t ga_robin
1217fd = fopen gp 0 get gv VPL 577 384
1218if lt fd 0
1219ret false
1220end
1221ok = ga_robcopy int fd n
1222if ok
1223if ne mode 0
1224if eq mode 1
1225put b 0 xor s_get GA_ROB p 255
1226end
1227r = pwrite int fd b 0 1 long p
1228ok = eq r 1
1229end
1230end
1231z = fclose int fd
1232ret and ok eq z 0
1233end
1234note ga_onerefusal: stdout is exactly one LF-terminated line that contains "refused".
1235fn ga_onerefusal to bool
1236ga_pt ga_stdout
1237if not ga_load GA_FILE
1238ret false
1239end
1240n = s_len GA_FILE
1241if eq n 0
1242ret false
1243end
1244if ne s_get GA_FILE sub n 1 10
1245ret false
1246end
1247c = ulong 0
1248for i ulong n bound 9223372036854775807
1249if eq s_get GA_FILE i 10
1250c = add c 1
1251end
1252end
1253if ne c 1
1254ret false
1255end
1256ga_new GA_EXP
1257s_addt GA_EXP ga_krefused
1258ret ga_contains GA_FILE GA_EXP
1259end
1260note ga_robrun: "mh parse" < @S/rob.in; 0 ok, 1 a defined refusal, 2 a failure (status in ga_v 9).
1261fn ga_robrun to ulong
1262ga_pkreset
1263ga_pk GA_BIN
1264ga_pkt ga_parse
1265ga_normalio
1266ga_scenariopath
1267p_t ga_robin
1268ga_savepath GA_TMP
1269ga_stream 0 GA_TMP
1270st = ga_spawn false 120000000000
1271put ga_v 9 st
1272if eq st 0
1273ret 0
1274end
1275if ne st 4
1276ret 2
1277end
1278if ga_onerefusal
1279ret 1
1280end
1281ret 2
1282end
1283fn ga_rawfield i ulong to void
1284p = ga_fo i
1285for j ulong ga_fnlen i bound 9223372036854775807
1286o_b s_get GA_CASE add p j
1287end
1288o_flush
1289end
1290fn ga_robfail mode ulong pos ulong to void
1291if eq get ga_v 22 1
1292ret
1293end
1294ga_say ga_robfailt
1295ga_rawfield 1
1296if eq mode 0
1297ga_say ga_cutw
1298end
1299if eq mode 1
1300ga_say ga_xorw
1301end
1302if eq mode 2
1303ga_say ga_zerow
1304end
1305ga_num pos
1306ga_say ga_exitw
1307ga_num get ga_v 9
1308ga_say ga_nl
1309end
1310fn ga_robinc k ulong to void
1311put ga_v k add get ga_v k 1
1312end
1313note ga_robone: one changed input (length n; byte p changed by mode, see ga_robwrite).
1314fn ga_robone n ulong p ulong mode ulong to bool
1315if not ga_robwrite n p mode
1316ga_die ga_ioerr
1317end
1318r = ga_robrun
1319ga_robinc 23
1320if eq r 0
1321ga_robinc 24
1322ret true
1323end
1324if eq r 1
1325ga_robinc 25
1326ret true
1327end
1328ga_robinc 26
1329if eq mode 0
1330ga_robfail mode n
1331else
1332ga_robfail mode p
1333end
1334ret false
1335end
1336fn ga_robsum to void
1337if eq get ga_v 22 1
1338ret
1339end
1340for i ulong 3
1341put ga_v add 27 i add get ga_v add 27 i get ga_v add 23 i
1342end
1343ga_say ga_robrep
1344ga_rawfield 1
1345ga_say ga_runsw
1346ga_num get ga_v 23
1347ga_say ga_okw
1348ga_num get ga_v 24
1349ga_say ga_refw
1350ga_num get ga_v 25
1351ga_say ga_nl
1352end
1353note ga_robcuts / ga_robbytes: the two families; quiet (mutant) runs stop at the first failure.
1354fn ga_robcuts n ulong to bool
1355m = ulong 0
1356if gt n 0
1357m = sub n 1
1358end
1359q = div m 63
1360r = rem m 63
1361ok = true
1362for k ulong 64
1363c = add mul q k div mul r k 63
1364if not ga_robone c c 0
1365ok = false
1366if eq get ga_v 22 1
1367ret false
1368end
1369end
1370end
1371ret ok
1372end
1373fn ga_robbytes n ulong to bool
1374q = div n 256
1375r = rem n 256
1376ok = true
1377for k ulong 256
1378p = add mul q k div mul r k 256
1379if lt p n
1380if not ga_robone n p 1
1381ok = false
1382end
1383if eq rem k 4 3
1384if not ga_robone n p 2
1385ok = false
1386end
1387end
1388if not ok
1389if eq get ga_v 22 1
1390ret false
1391end
1392end
1393end
1394end
1395ret ok
1396end
1397fn ga_robstep to bool
1398if ne get ga_v 0 2
1399ret false
1400end
1401for i ulong 4
1402put ga_v add 23 i 0
1403end
1404ga_fpath 1
1405if not ga_load GA_ROB
1406ret false
1407end
1408n = s_len GA_ROB
1409ok = ga_robcuts n
1410if ok
1411ok = ga_robbytes n
1412else
1413if ne get ga_v 22 1
1414z = ga_robbytes n
1415end
1416end
1417ga_robsum
1418s_close GA_ROB
1419ret ok
1420end
1421fn ga_action to bool
1422if ga_is 0 ga_robw
1423ret ga_robstep
1424end
1425if ga_is 0 ga_outsha
1426ret ga_shaout
1427end
1428if ga_is 0 ga_maxns
1429ret le get ga_v 13 ga_fnum 1
1430end
1431if ga_is 0 ga_run
1432ret ga_process false
1433end
1434if ga_is 0 ga_bg
1435ret ga_process true
1436end
1437if ga_is 0 ga_wait
1438ret ga_waitstep
1439end
1440if ga_is 0 ga_gen
1441ret ga_genstep
1442end
1443if ga_is 0 ga_mkdir
1444ga_fpath 1
1445ret ga_mkp
1446end
1447if ga_is 0 ga_copy
1448ret ga_copyaction
1449end
1450if ga_is 0 ga_write
1451ret ga_writefile false
1452end
1453if ga_is 0 ga_append
1454ret ga_writefile true
1455end
1456if ga_is 0 ga_flip
1457ret ga_flipfile
1458end
1459if ga_is 0 ga_symlink
1460ret ga_linkaction
1461end
1462if or ga_is 0 ga_exists ga_is 0 ga_absent
1463ga_fpath 1
1464k = p_kind
1465if ga_is 0 ga_exists
1466ret ne k 0
1467end
1468ret eq k 0
1469end
1470if or or ga_is 0 ga_outeq ga_is 0 ga_outhas ga_is 0 ga_outnot
1471ret ga_check
1472end
1473if or or ga_is 0 ga_outlines ga_is 0 ga_errhas ga_is 0 ga_fileeq
1474ret ga_check
1475end
1476if ga_is 0 ga_errnot
1477ret ga_check
1478end
1479if ga_is 0 ga_treenot
1480ret ga_treestep
1481end
1482if or ga_is 0 ga_filehas ga_is 0 ga_filenot
1483ret ga_check
1484end
1485ret false
1486end
1487fn ga_stopbg to void
1488if ne get ga_v 8 0
1489z = killpid int get ga_v 8 9
1490st = ga_reap long get ga_v 8 120000000000
1491put ga_v 8 0
1492end
1493end
1494fn ga_scenariopath to void
1495ga_pt ga_sdir
1496p_t ga_slash
1497p_s GA_SCEN 0 s_len GA_SCEN
1498end
1499note ga_line: the failing step's text, from its first field to the end of the line.
1500fn ga_line to void
1501p = ga_fo 0
1502for i ulong sub get ga_v 1 p bound 9223372036854775807
1503o_b s_get GA_CASE add p i
1504end
1505o_flush
1506end
1507fn ga_scenario quiet bool to bool
1508put ga_v 22 0
1509if quiet
1510put ga_v 22 1
1511end
1512ga_scenariopath
1513if not ga_wipe
1514ga_die ga_ioerr
1515end
1516ga_scenariopath
1517if not ga_mkp
1518ga_die ga_ioerr
1519end
1520s_close GA_CASE
1521ga_path GA_LAST
1522p_t ga_slash
1523p_s GA_SCEN 0 s_len GA_SCEN
1524if not ga_load GA_CASE
1525ga_die ga_ioerr
1526end
1527p = ulong 0
1528steps = ulong 0
1529while lt p s_len GA_CASE bound 9223372036854775807
1530q = ga_eol GA_CASE p
1531ga_fields p q
1532p = add q 1
1533if eq get ga_v 0 0
1534continue
1535end
1536if eq s_get GA_CASE ga_fo 0 35
1537continue
1538end
1539steps = add steps 1
1540if not ga_action
1541ga_stopbg
1542if not quiet
1543ga_say ga_fail
1544ga_print GA_SCEN
1545ga_say ga_step
1546ga_num steps
1547ga_say ga_reason
1548if or ga_is 0 ga_run ga_is 0 ga_wait
1549ga_say ga_badexit
1550ga_num get ga_v 9
1551ga_say ga_want
1552ga_num get ga_v 10
1553ga_say ga_close
1554else
1555if ga_is 0 ga_maxns
1556ga_say ga_slow
1557ga_num get ga_v 13
1558ga_say ga_ns
1559ga_num ga_fnum 1
1560else
1561ga_say ga_mismatch
1562ga_say ga_reason
1563ga_line
1564end
1565end
1566ga_say ga_nl
1567end
1568ret false
1569end
1570end
1571if ne get ga_v 8 0
1572ga_stopbg
1573if not quiet
1574ga_say ga_fail
1575ga_print GA_SCEN
1576ga_say ga_reason
1577ga_say ga_wait
1578ga_say ga_nl
1579end
1580ret false
1581end
1582if not quiet
1583put ga_v 2 add get ga_v 2 1
1584put ga_v 3 add get ga_v 3 steps
1585ga_say ga_pass
1586ga_print GA_SCEN
1587ga_say ga_steps
1588ga_num steps
1589ga_say ga_nl
1590end
1591ret true
1592end
1593note Directory names stored as newline records. Lexical successor search gives deterministic sorting.
1594fn ga_names to bool
1595ga_new GA_NAMES
1596ga_path GA_LAST
1597if not d_open 0
1598ret false
1599end
1600while d_next 0 bound 9223372036854775807
1601n = get gv VDNL
1602if lt n 4
1603continue
1604end
1605q = get gv VDNO
1606if ne get gde add q sub n 4 46
1607continue
1608end
1609if ne get gde add q sub n 3 116
1610continue
1611end
1612if ne get gde add q sub n 2 120
1613continue
1614end
1615if ne get gde add q sub n 1 116
1616continue
1617end
1618for i ulong n bound 256
1619z = s_add GA_NAMES get gde add q i
1620end
1621s_addt GA_NAMES ga_nl
1622end
1623d_close 0
1624ret true
1625end
1626fn ga_cmp ao ulong an ulong b ulong bo ulong bn ulong to int
1627n = an
1628if lt bn n
1629n = bn
1630end
1631for i ulong n bound 9223372036854775807
1632ac = s_get GA_NAMES add ao i
1633bc = s_get b add bo i
1634if lt ac bc
1635ret -1
1636end
1637if gt ac bc
1638ret 1
1639end
1640end
1641if lt an bn
1642ret -1
1643end
1644if gt an bn
1645ret 1
1646end
1647ret 0
1648end
1649fn ga_nextname to bool
1650best = s_len GA_NAMES
1651bestn = ulong 0
1652p = ulong 0
1653while lt p s_len GA_NAMES bound 9223372036854775807
1654q = ga_eol GA_NAMES p
1655n = sub q p
1656if gt ga_cmp p n GA_SCEN 0 s_len GA_SCEN 0
1657if eq best s_len GA_NAMES
1658best = p
1659bestn = n
1660else
1661if lt ga_cmp p n GA_NAMES best bestn 0
1662best = p
1663bestn = n
1664end
1665end
1666end
1667p = add q 1
1668end
1669if eq best s_len GA_NAMES
1670ret false
1671end
1672ga_new GA_SCEN
1673s_adds GA_SCEN GA_NAMES best bestn
1674ret true
1675end
1676fn ga_all quiet bool to ulong
1677ga_new GA_SCEN
1678bad = ulong 0
1679while ga_nextname bound 9223372036854775807
1680if not ga_scenario quiet
1681bad = add bad 1
1682if quiet
1683ret bad
1684end
1685end
1686end
1687ret bad
1688end
1689fn ga_bar p0 ulong e ulong to ulong
1690p = p0
1691while lt p e bound 9223372036854775807
1692if eq s_get GA_MUT p 124
1693ret p
1694end
1695p = add p 1
1696end
1697ret e
1698end
1699note ga_occ: the optional fifth mutant field K/T: replace only occurrence K of OLD, and refuse the
1700note mutant unless OLD occurs exactly T times in its file (so a moved line cannot hit another call).
1701fn ga_occ p ulong e ulong to void
1702q = p
1703while lt q e bound 9223372036854775807
1704if eq s_get GA_MUT q 47
1705break
1706end
1707q = add q 1
1708end
1709if ge q e
1710ga_die ga_badline
1711end
1712put ga_v 20 ga_numrange GA_MUT p sub q p
1713put ga_v 21 ga_numrange GA_MUT add q 1 sub sub e q 1
1714if or eq get ga_v 20 0 gt get ga_v 20 get ga_v 21
1715ga_die ga_badline
1716end
1717end
1718fn ga_mutant p ulong e ulong to bool
1719a = ga_bar p e
1720b = ga_bar add a 1 e
1721c = ga_bar add b 1 e
1722if ge c e
1723ret false
1724end
1725ga_new GA_SPEC
1726s_adds GA_SPEC GA_MUT add a 1 sub sub b a 1
1727ga_new GA_OLD
1728s_adds GA_OLD GA_MUT add b 1 sub sub c b 1
1729d = ga_bar add c 1 e
1730ga_new GA_NEW
1731s_adds GA_NEW GA_MUT add c 1 sub sub d c 1
1732put ga_v 20 0
1733put ga_v 21 0
1734if lt d e
1735ga_occ add d 1 e
1736end
1737put ga_v 5 add get ga_v 5 1
1738ok = false
1739if eq get ga_v 11 0
1740ok = ga_compile ga_srcunits ga_mutbin true
1741else
1742ok = false
1743end
1744if not ok
1745ga_say ga_mutfail
1746else
1747ga_new GA_BIN
1748s_addt GA_BIN ga_mutbin
1749bad = ga_all true
1750if gt bad 0
1751put ga_v 6 add get ga_v 6 1
1752ga_say ga_mutkill
1753else
1754ok = false
1755ga_say ga_mutsurv
1756end
1757end
1758for i ulong sub a p bound 9223372036854775807
1759o_b s_get GA_MUT add p i
1760end
1761o_flush
1762ga_say ga_nl
1763ret ok
1764end
1765fn ga_mutants to bool
1766ok = true
1767p = ulong 0
1768while lt p s_len GA_MUT bound 9223372036854775807
1769q = ga_eol GA_MUT p
1770if gt q p
1771if ne s_get GA_MUT p 35
1772if not ga_mutant p q
1773ok = false
1774end
1775end
1776end
1777p = add q 1
1778end
1779ret ok
1780end
1781fn ga_argstore i ulong s ulong to bool
1782b = new uchar 131072 0
1783r = argread i b 0 131072
1784if le r 0
1785ret false
1786end
1787ga_new s
1788s_addt s part b 0 ulong r
1789ret true
1790end
1791note ga_lock: one gate run at a time owns build/gate; the lock is released when the process exits.
1792fn ga_lock to void
1793ga_pt ga_lockf
1794fd = fopen gp 0 get gv VPL 577 384
1795if lt fd 0
1796ga_die ga_ioerr
1797end
1798r = flock int fd 6
1799if eq r -11
1800ga_say ga_lockwait
1801r = flock int fd 2
1802end
1803if ne r 0
1804ga_die ga_ioerr
1805end
1806end
1807fn main to int
1808b = new uchar 4096 0
1809if lt argcnt 2
1810ga_say ga_usage
1811ret 3
1812end
1813if not ga_argstore 1 GA_OMC
1814ga_say ga_usage
1815ret 3
1816end
1817if not ga_pinok
1818ga_say ga_notrun
1819ret 3
1820end
1821r = cwd b 0 4096
1822if le r 0
1823ga_die ga_ioerr
1824end
1825ga_new GA_ROOT
1826s_addt GA_ROOT part b 0 sub ulong r 1
1827ga_new GA_LAST
1828s_addt GA_LAST ga_cases
1829if gt argcnt 2
1830if not ga_argstore 2 GA_LAST
1831ga_die ga_badline
1832end
1833end
1834ga_pt ga_build
1835if not ga_mkp
1836ga_die ga_ioerr
1837end
1838ga_pt ga_dir
1839if not ga_mkp
1840ga_die ga_ioerr
1841end
1842ga_lock
1843ga_say ga_timeout
1844if not ga_compile ga_srcunits ga_mh false
1845ga_say ga_buildfail
1846ret 1
1847end
1848ga_pt ga_sinkunits
1849if eq p_kind 0
1850ga_say ga_sinknote
1851else
1852if not ga_compile ga_sinkunits ga_sink false
1853ga_say ga_buildfail
1854ret 1
1855end
1856end
1857ga_pt ga_srvunits
1858if eq p_kind 0
1859ga_say ga_srvnote
1860else
1861if not ga_compile ga_srvunits ga_srvbin false
1862ga_say ga_buildfail
1863ret 1
1864end
1865end
1866if not ga_names
1867ga_die ga_ioerr
1868end
1869if eq s_len GA_NAMES 0
1870ga_die ga_badline
1871end
1872ga_new GA_BIN
1873s_addt GA_BIN ga_mh
1874bad = ga_pincheck
1875bad = add bad ga_all false
1876if eq bad 0
1877if gt argcnt 3
1878if not ga_argstore 3 GA_TMP
1879ga_die ga_badline
1880end
1881ga_path GA_TMP
1882else
1883ga_pt ga_muts
1884end
1885if not ga_load GA_MUT
1886ga_die ga_ioerr
1887end
1888if not ga_mutants
1889bad = add bad 1
1890end
1891end
1892if gt get ga_v 27 0
1893ga_say ga_robtot
1894ga_num get ga_v 27
1895ga_say ga_okw
1896ga_num get ga_v 28
1897ga_say ga_refw
1898ga_num get ga_v 29
1899ga_say ga_nl
1900end
1901if eq bad 0
1902ga_say ga_finalpass
1903else
1904ga_say ga_finalfail
1905end
1906ga_num get ga_v 2
1907ga_say ga_steps
1908ga_num get ga_v 3
1909ga_say ga_mutcount
1910ga_num get ga_v 6
1911ga_say ga_slash
1912ga_num get ga_v 5
1913ga_say ga_nl
1914if ne bad 0
1915ret 1
1916end
1917ret 0
1918end
1919note ga_treestep: "tree-not DIR TEXT": no regular file under DIR (symlinks are not followed) contains
1920note TEXT; used for the credential leak scan. A hit prints "tree-not hit: PATH" and fails the step.
1921text ga_treehit "tree-not hit: "
1922fn ga_treestep to bool
1923ga_rest 2
1924ga_new GA_TMP
1925s_adds GA_TMP GA_EXP 0 s_len GA_EXP
1926if eq s_len GA_TMP 0
1927ret false
1928end
1929ga_fpath 1
1930if ne p_kind 1
1931ret false
1932end
1933ga_new GA_STACK
1934ga_push 0
1935while gt s_len GA_STACK 0 bound 9223372036854775807
1936z = ga_pop
1937k = p_kind
1938if eq k 2
1939if not ga_load GA_FILE
1940ret false
1941end
1942if ga_contains GA_FILE GA_TMP
1943ga_say ga_treehit
1944ga_new GA_FILE
1945for i ulong get gv VPL bound 4096
1946zb = s_add GA_FILE get gp i
1947end
1948ga_print GA_FILE
1949ga_say ga_nl
1950ret false
1951end
1952end
1953if eq k 1
1954if not d_open 0
1955ret false
1956end
1957p_save
1958while d_next 0 bound 9223372036854775807
1959p_restore
1960p_c 47
1961p_dn
1962if not p_ok
1963d_close 0
1964ret false
1965end
1966ga_push 0
1967end
1968d_close 0
1969end
1970end
1971ret true
1972end