interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / browse / tests / stubutil.om

641 lines · 10829 bytes Raw Blame History
1note browse/tests/stubutil.om: TEST-ONLY stand-in for server/util.om (CONTRACT.md v1 names), used
2note by browse/tests/run.sh until/unless the real util.om is composed. Not part of forged.
3note Exec logic follows hive-view src/run.om (read-only reference, ~/work/hiveview).
4global fob uchar 8388608
5global fobl ulong 1
6global fobtr ulong 1
7global fmeth ulong 1
8global fpath uchar 4096
9global fpathl ulong 1
10global fqs uchar 4096
11global fqsl ulong 1
12global fbase uchar 64
13global fbasel ulong 1
14global fridx ulong 1
15global frid uchar 64
16global fridl ulong 1
17global fown uchar 64
18global fownl ulong 1
19global frepo uchar 128
20global frepol ulong 1
21global fpin uchar 40
22global frest uchar 4096
23global frestl ulong 1
24global fkind ulong 1
25global fct uchar 128
26global fctl ulong 1
27global fcd uchar 512
28global fcdl ulong 1
29global floc uchar 4096
30global flocl ulong 1
31global fti uchar 256
32global ftil ulong 1
33global fval uchar 4096
34global fpk uchar 16384
35global fpkl ulong 1
36global fpkr ulong 1
37global fxo uchar 16777216
38global fxol ulong 1
39global fxotr ulong 1
40note fincut (server/repos.om): the stub only records the call
41global ficut ulong 1
42fn fincut to void
43put ficut 0 1
44end
45global fpfd uchar 8
46global fwst uchar 4
47text tfstore "/home/drakestapleton/.radicle/storage/"
48text tfgit "/usr/bin/git"
49text tfnid "z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK"
50text tfdevn "/dev/null"
51text tfgd "--git-dir="
52text tfamp "&"
53text tflt "<"
54text tfgt ">"
55text tfquot """
56text tfapos "'"
57text tfhd1 "<h1 class=\"repo\">"
58text tfhd2 "</h1>\n"
59fn fputc c uchar to void
60n = get fobl 0
61if lt n len fob
62put fob n c
63put fobl 0 add n 1
64ret
65end
66put fobtr 0 1
67end
68fn fput s view uchar * to void
69for i ulong len s bound 16777216
70fputc get s i
71end
72end
73fn fescc c uchar to void
74if eq c 38
75fput tfamp
76ret
77end
78if eq c 60
79fput tflt
80ret
81end
82if eq c 62
83fput tfgt
84ret
85end
86if eq c 34
87fput tfquot
88ret
89end
90if eq c 39
91fput tfapos
92ret
93end
94fputc c
95end
96fn fesc s view uchar * to void
97for i ulong len s bound 16777216
98fescc get s i
99end
100end
101fn fnum v ulong to void
102d = new uchar 20 0
103i = ulong 20
104x = v
105for it ulong 20
106i = sub i 1
107put d i uchar add rem x 10 48
108x = div x 10
109if eq x 0
110break
111end
112end
113for k ulong sub 20 i
114fputc get d add i k
115end
116end
117fn fputb to void
118for i ulong get fbasel 0
119fputc get fbase i
120end
121end
122fn flink p view uchar * to void
123fputb
124fput p
125end
126fn fputrepo to void
127for i ulong get fownl 0
128fescc get fown i
129end
130fputc 47
131for i ulong get frepol 0
132fescc get frepo i
133end
134end
135fn frepohd tab ulong to void
136fput tfhd1
137fputrepo
138fput tfhd2
139end
140fn fsetct t view uchar * to void
141n = len t
142if gt n 128
143n = 128
144end
145for i ulong n
146put fct i get t i
147end
148put fctl 0 n
149end
150fn fcdc c uchar to void
151n = get fcdl 0
152if lt n 512
153put fcd n c
154put fcdl 0 add n 1
155end
156end
157fn fsetcd t view uchar * to void
158put fcdl 0 0
159for i ulong len t
160fcdc get t i
161end
162end
163fn ftic c uchar to void
164n = get ftil 0
165if lt n 256
166put fti n c
167put ftil 0 add n 1
168end
169end
170fn fsetti t view uchar * to void
171put ftil 0 0
172for i ulong len t
173ftic get t i
174end
175end
176fn flocc c uchar to void
177n = get flocl 0
178if lt n 4096
179put floc n c
180put flocl 0 add n 1
181end
182end
183fn floct t view uchar * to void
184for i ulong len t
185flocc get t i
186end
187end
188fn flocb to void
189put flocl 0 0
190for i ulong get fbasel 0
191flocc get fbase i
192end
193end
194fn fqhex c uchar to ulong
195if and ge c 48 le c 57
196ret ulong sub c 48
197end
198if and ge c 97 le c 102
199ret ulong sub c 87
200end
201if and ge c 65 le c 70
202ret ulong sub c 55
203end
204ret 99
205end
206note fqget: query param n in fqs, percent-decoded into fval; length or -1
207fn fqget n view uchar * to long
208q = get fqsl 0
209i = ulong 0
210while lt i q bound 8192
211s = i
212e = i
213while lt e q bound 8192
214if eq get fqs e 38
215break
216end
217e = add e 1
218end
219k = len n
220ok = false
221if le add s k e
222ok = true
223for j ulong k
224if ne get fqs add s j get n j
225ok = false
226end
227end
228if ok
229if lt add s k e
230ok = eq get fqs add s k 61
231else
232ok = false
233end
234end
235end
236if ok
237ret fqdec add add s k 1 e
238end
239i = add e 1
240end
241ret -1
242end
243fn fqdec a ulong e ulong to long
244o = ulong 0
245i = a
246while lt i e bound 8192
247c = get fqs i
248if eq c 43
249c = 32
250end
251if eq c 37
252if lt add i 2 e
253h = fqhex get fqs add i 1
254l = fqhex get fqs add i 2
255if and lt h 16 lt l 16
256c = uchar add mul h 16 l
257i = add i 2
258end
259end
260end
261if lt o 4096
262put fval o c
263o = add o 1
264end
265i = add i 1
266end
267ret long o
268end
269fn fkb to void
270put fpk 0 0
271put fpk 1 0
272put fpkl 0 2
273end
274fn fkopen to void
275n = get fpkl 0
276put fpkr 0 n
277put fpk n 0
278put fpk add n 1 0
279put fpkl 0 add n 2
280c = add or ulong get fpk 0 shl ulong get fpk 1 8 1
281put fpk 0 uchar and c 255
282put fpk 1 uchar shr c 8
283end
284fn fkc c uchar to void
285n = get fpkl 0
286if lt n 16383
287put fpk n c
288put fpkl 0 add n 1
289r = get fpkr 0
290k = add or ulong get fpk r shl ulong get fpk add r 1 8 1
291put fpk r uchar and k 255
292put fpk add r 1 uchar shr k 8
293end
294end
295fn fka t view uchar * to void
296fkopen
297for i ulong len t
298fkc get t i
299end
300end
301fn fksource to void
302fkgit
303end
304fn fkgit to void
305fkb
306fka tfgit
307fkopen
308for i ulong len tfgd
309fkc get tfgd i
310end
311for i ulong len tfstore
312fkc get tfstore i
313end
314for i ulong get fridl 0
315fkc get frid i
316end
317end
318fn fpfdv i ulong to int
319b = mul i 4
320v = or ulong get fpfd b shl ulong get fpfd add b 1 8
321v = or v shl ulong get fpfd add b 2 16
322v = or v shl ulong get fpfd add b 3 24
323ret int v
324end
325fn fchild wfd int to void
326nul = fopen tfdevn 0 len tfdevn 2 0
327if lt nul 0
328exit 126
329end
330x = dupfd int nul 0 0
331x = dupfd wfd 1 0
332x = dupfd int nul 2 0
333x = execprog fpk 0 get fpkl 0
334exit 127
335end
336fn fdrain fd int dl long to bool
337for it ulong 10000000 bound 10000000
338left = sub dl long monons
339if le left 0
340ret false
341end
342w = waitio fd 1 left
343if lt w 0
344if ne w -4
345ret false
346end
347continue
348end
349if eq w 0
350continue
351end
352n = get fxol 0
353if ge n len fxo
354put fxotr 0 1
355ret true
356end
357r = read fd fxo n sub len fxo n
358if eq r 0
359ret true
360end
361if lt r 0
362if and ne r -4 ne r -11
363ret false
364end
365continue
366end
367put fxol 0 add n ulong r
368end
369ret false
370end
371fn freap pid int dl long to long
372for it ulong 100000
373w = waitpid pid fwst 0 4 1
374if eq w long pid
375s = or ulong get fwst 0 shl ulong get fwst 1 8
376if eq and s 127 0
377ret long and shr s 8 255
378end
379ret -3
380end
381if lt w 0
382if ne w -4
383ret -4
384end
385continue
386end
387if gt long monons dl
388x = killpid pid 9
389w = waitpid pid fwst 0 4 0
390ret -1
391end
392x = sleepns 1000000
393end
394ret -4
395end
396fn fexec tmo long to long
397put fxol 0 0
398put fxotr 0 0
399r = pipefds fpfd 0 8 524288
400if lt r 0
401ret -2
402end
403rfd = fpfdv 0
404wfd = fpfdv 1
405dl = add long monons tmo
406pid = fork
407if lt pid 0
408x = fclose rfd
409x = fclose wfd
410ret -2
411end
412if eq pid 0
413fchild wfd
414exit 127
415end
416x = fclose wfd
417ok = fdrain rfd dl
418x = fclose rfd
419if not ok
420x = killpid int pid 9
421end
422if eq get fxotr 0 1
423x = killpid int pid 9
424end
425st = freap int pid dl
426if not ok
427ret -1
428end
429ret st
430end
431fn fxput a ulong n ulong to void
432for i ulong n bound 16777216
433fputc get fxo add a i
434end
435end
436fn fxesc a ulong n ulong to void
437for i ulong n bound 16777216
438fescc get fxo add a i
439end
440end
441note dlrch0 / dlrch1: the downloads slice's reachability argv (dl/dl.om); the renderer tests
442note never resolve a ref, so these only satisfy the linker
443fn dlrch0 to void
444fkgit
445end
446fn dlrch1 to bool
447ret false
448end
449note ---- path builder fpth and whole-file read into fxo: copy of server/util.om fpb fpc fpt frdall, for
450note nodes/head.om nshead (brdefref), which the test compose now includes as run.sh units does
451global fpth uchar 4096
452global fpthl ulong 1
453fn fpb to void
454put fpthl 0 0
455end
456fn fpc c uchar to void
457n = get fpthl 0
458if lt n 4095
459put fpth n c
460put fpthl 0 add n 1
461end
462end
463fn fpt t view uchar * to void
464for i ulong len t bound 4096
465fpc get t i
466end
467end
468fn frdall to long
469put fxol 0 0
470put fxotr 0 0
471fd = fopen fpth 0 get fpthl 0 524288 0
472if lt fd 0
473ret fd
474end
475for it ulong 100000
476n = get fxol 0
477if ge n len fxo
478put fxotr 0 1
479break
480end
481r = read int fd fxo n sub len fxo n
482if le r 0
483break
484end
485put fxol 0 add n ulong r
486end
487x = fclose int fd
488ret long get fxol 0
489end
490note copy of server/util.om for browse/a_core.om (brbest reads the ref list one line at a time):
491note streaming exec (fsopen / fsnext / fsclose): 0 read fd, 1 pid, 2 deadline, 3 state (0 open,
492note 1 end of output, 2 failed); fsp the first unread byte of fxo, fsq the first byte not yet scanned
493note for the separator, fsrs the start of the record fsnext returned last
494global fsst long 4
495global fsp ulong 1
496global fsq ulong 1
497global fsrs ulong 1
498note ---- streaming exec: a listing longer than fxo is read through it in windows, one record at a time
499note (the cut copy of fexec is never taken for the whole). fsopen starts argv fpk like fexec; fsnext C
500note returns the end e of the next record (the bytes up to the next C, or up to the end of the output),
501note which is fxo[get fsrs 0, e) until the next fsnext call. fsnext returns FSEND at the end of the output
502note and FSFAIL on a timeout, a read error, or one record longer than fxo (fxotr is set then: the
503note caller answers the whole 500 of fincut). fsclose ends the child (killed if it is still writing)
504note and returns its exit status, or -1 when the output was not read to its end.
505const FSEND ulong 16777217
506const FSFAIL ulong 16777218
507fn fsopen tmo long to bool
508put fxol 0 0
509put fxotr 0 0
510put fsp 0 0
511put fsq 0 0
512put fsrs 0 0
513put fsst 3 2
514r = pipefds fpfd 0 8 524288
515if lt r 0
516ret false
517end
518rfd = fpfdv 0
519wfd = fpfdv 1
520pid = fork
521if lt pid 0
522x = fclose rfd
523x = fclose wfd
524ret false
525end
526if eq pid 0
527fchild wfd
528exit 127
529end
530x = fclose wfd
531put fsst 0 long rfd
532put fsst 1 long pid
533put fsst 2 add long monons tmo
534put fsst 3 0
535ret true
536end
537note fsfill: move the unread bytes fxo[fsp, fxol) to the front, then read until fxo is full or the
538note output ends. false on a timeout or read error.
539fn fsfill to bool
540p = get fsp 0
541n = get fxol 0
542if gt p 0
543for i ulong sub n p bound 16777216
544put fxo i get fxo add p i
545end
546put fxol 0 sub n p
547put fsq 0 sub get fsq 0 p
548put fsrs 0 0
549put fsp 0 0
550end
551if ne get fsst 3 0
552ret eq get fsst 3 1
553end
554fd = int get fsst 0
555dl = get fsst 2
556for it ulong 100000000
557m = get fxol 0
558if ge m len fxo
559ret true
560end
561left = sub dl long monons
562if le left 0
563put fsst 3 2
564ret false
565end
566w = waitio fd 1 left
567if lt w 0
568if ne w -4
569put fsst 3 2
570ret false
571end
572continue
573end
574if eq w 0
575continue
576end
577r = read fd fxo m sub len fxo m
578if eq r 0
579put fsst 3 1
580ret true
581end
582if lt r 0
583if and ne r -4 ne r -11
584put fsst 3 2
585ret false
586end
587continue
588end
589put fxol 0 add m ulong r
590end
591put fsst 3 2
592ret false
593end
594fn fsnext c uchar to ulong
595for it ulong 100000000
596s = get fsp 0
597n = get fxol 0
598q = get fsq 0
599while lt q n bound 16777216
600if eq get fxo q c
601put fsrs 0 s
602put fsp 0 add q 1
603put fsq 0 add q 1
604ret q
605end
606q = add q 1
607end
608put fsq 0 q
609if eq get fsst 3 1
610if lt s n
611put fsrs 0 s
612put fsp 0 n
613ret n
614end
615ret FSEND
616end
617if and eq s 0 ge n len fxo
618put fxotr 0 1
619ret FSFAIL
620end
621if not fsfill
622ret FSFAIL
623end
624end
625ret FSFAIL
626end
627fn fsclose to long
628fd = int get fsst 0
629x = fclose fd
630pid = int get fsst 1
631done = eq get fsst 3 1
632if not done
633x = killpid pid 9
634end
635st = freap pid get fsst 2
636put fsst 3 2
637if not done
638ret -1
639end
640ret st
641end