interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / golden / fake.om

329 lines · 5584 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note om/golden/fake.om: TEST ONLY fake HTTP responder for om/golden/check.sh. It is not an engine and
3note never produces a REAL record: check.sh records against it with label FAKE.
4note fake PORTFILE CANNED CAPTURE N
5note Binds 127.0.0.1 on a kernel-chosen port, writes "PORT\n" to PORTFILE (created, never overwritten),
6note then serves exactly N connections in order: connection k reads one HTTP/1.1 request (headers up to
7note 65536 bytes, body by Content-Length), stores the raw request bytes as CAPTURE/k.http and answers
8note with the bytes of CANNED/k.http verbatim. Exit 0 after N connections; 10 usage, 11 socket,
9note 12 file, 13 malformed request.
10
11const FQCAP ulong 1048576
12const FHCAP ulong 65536
13
14global fa uchar 8192
15global fas ulong 8
16global fal ulong 8
17global fp uchar 4200
18global fq uchar 1048576
19global fr uchar 1048576
20global fb uchar 64
21global fst uchar 128
22
23text tfpre "fake: exit "
24text tfsuf ".http"
25text tfcl "content-length:"
26
27fn fx code int to void
28d = new uchar 3 0
29w = write 2 tfpre 0 len tfpre
30put d 0 uchar add 48 div code 10
31put d 1 uchar add 48 rem code 10
32put d 2 10
33w = write 2 d 0 3
34exit code
35end
36
37note fpath: fp = argument a, a slash, decimal k, .http; returns the length
38fn fpath a ulong k ulong to ulong
39n = get fal a
40if or eq n 0 gt n 4096
41fx 10
42end
43o = get fas a
44for i ulong n
45put fp i get fa add o i
46end
47put fp n 47
48n = add n 1
49if ge k 100
50put fp n uchar add 48 div k 100
51n = add n 1
52end
53if ge k 10
54put fp n uchar add 48 rem div k 10 10
55n = add n 1
56end
57put fp n uchar add 48 rem k 10
58n = add n 1
59for j ulong len tfsuf
60put fp add n j get tfsuf j
61end
62ret add n len tfsuf
63end
64
65note fcreate: write fq[0..n) to the new file fp[0..pn) (O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600)
66fn fcreate pn ulong n ulong to void
67fd = int fopen fp 0 pn 557249 384
68if lt fd 0
69fx 12
70end
71o = ulong 0
72while lt o n bound 999999
73r = write fd fq o sub n o
74if le r 0
75fx 12
76end
77o = add o ulong r
78end
79if ne fclose fd 0
80fx 12
81end
82end
83
84fn fle64 o ulong to ulong
85v = ulong 0
86for i ulong 8
87v = or v shl ulong get fst add o i mul 8 i
88end
89ret v
90end
91
92note fload: read the regular file fp[0..pn) into fr (O_RDONLY|O_CLOEXEC|O_NOFOLLOW); returns its size
93fn fload pn ulong to ulong
94fd = int fopen fp 0 pn 557056 0
95if lt fd 0
96fx 12
97end
98if ne fstat fd fst 0 128 0
99fx 12
100end
101sz = fle64 48
102if gt sz FQCAP
103fx 12
104end
105o = ulong 0
106while lt o sz bound 999999
107q = pread fd fr o sub sz o long o
108if le q 0
109fx 12
110end
111o = add o ulong q
112end
113if ne fclose fd 0
114fx 12
115end
116ret sz
117end
118
119fn fcrlf i ulong to bool
120ret and eq get fq i 13 eq get fq add i 1 10
121end
122
123note fhend: the offset just past the first CR LF CR LF in fq[0..n), or 0
124fn fhend n ulong to ulong
125if lt n 4
126ret 0
127end
128for i ulong sub n 3
129if and fcrlf i fcrlf add i 2
130ret add i 4
131end
132end
133ret 0
134end
135
136fn flow c uchar to uchar
137if and ge c 65 le c 90
138ret uchar add c 32
139end
140ret c
141end
142
143fn fiscl p ulong h ulong to bool
144if gt add p len tfcl h
145ret false
146end
147for i ulong len tfcl
148if ne flow get fq add p i get tfcl i
149ret false
150end
151end
152ret true
153end
154
155fn fblank q ulong to bool
156ret or eq get fq q 32 eq get fq q 9
157end
158
159fn fdig q ulong to bool
160ret and ge get fq q 48 le get fq q 57
161end
162
163note fcval: the decimal after optional blanks at p; 13 on a missing or oversized value
164fn fcval p ulong h ulong to ulong
165q = p
166while and lt q h fblank q bound 65536
167q = add q 1
168end
169v = ulong 0
170d = ulong 0
171while and lt q h fdig q bound 65536
172v = add mul v 10 ulong sub get fq q 48
173if gt v FQCAP
174fx 13
175end
176d = add d 1
177q = add q 1
178end
179if eq d 0
180fx 13
181end
182ret v
183end
184
185note fclen: Content-Length of the header block fq[0..h), 0 when absent
186fn fclen h ulong to ulong
187p = ulong 0
188while lt p h bound 65536
189if fiscl p h
190ret fcval add p len tfcl h
191end
192while and lt p h ne get fq p 10 bound 65536
193p = add p 1
194end
195p = add p 1
196end
197ret 0
198end
199
200note frdreq: read one request from connection a into fq; returns its byte count
201fn frdreq a int to ulong
202n = ulong 0
203h = ulong 0
204while eq h 0 bound 65536
205if ge n FHCAP
206fx 13
207end
208r = recv a fq n sub FHCAP n 0
209if le r 0
210fx 13
211end
212n = add n ulong r
213h = fhend n
214end
215t = add h fclen h
216if gt t FQCAP
217fx 13
218end
219while lt n t bound 999999
220r = recv a fq n sub t n 0
221if le r 0
222fx 13
223end
224n = add n ulong r
225end
226if ne n t
227fx 13
228end
229ret t
230end
231
232fn fsendall a int n ulong to void
233o = ulong 0
234while lt o n bound 999999
235r = send a fr o sub n o 0
236if le r 0
237fx 11
238end
239o = add o ulong r
240end
241end
242
243fn fserve s int k ulong to void
244a = int accept s 0
245if lt a 0
246fx 11
247end
248t = frdreq a
249fcreate fpath 3 k t
250fsendall a fload fpath 2 k
251if ne fclose a 0
252fx 11
253end
254end
255
256note fport: bind 127.0.0.1:0, listen, write the chosen port to argument 1; returns the socket
257fn fport to int
258s = int socknew 2 1 0
259if lt s 0
260fx 11
261end
262put fb 0 2
263put fb 4 127
264put fb 7 1
265if ne bind s fb 0 16 0
266fx 11
267end
268if ne listen s 16 0
269fx 11
270end
271if ne sockname s fb 0 64 16
272fx 11
273end
274v = add mul ulong get fb 2 256 ulong get fb 3
275note the port digits go through fq, which holds no request yet
276k = ulong 0
277x = v
278while gt x 0 bound 6
279x = div x 10
280k = add k 1
281end
282x = v
283for i ulong k
284put fq sub sub k 1 i uchar add 48 rem x 10
285x = div x 10
286end
287put fq k 10
288n = get fal 1
289o = get fas 1
290for i ulong n
291put fp i get fa add o i
292end
293fcreate n add k 1
294ret s
295end
296
297fn main to int
298c = argcnt
299if ne c 5
300fx 10
301end
302o = ulong 0
303for i ulong ulong c
304r = argread i fa o sub len fa o
305if lt r 0
306fx 10
307end
308put fas i o
309put fal i ulong r
310o = add o ulong r
311end
312nn = ulong 0
313o = get fas 4
314for i ulong get fal 4
315x = get fa add o i
316if or lt x 48 gt x 57
317fx 10
318end
319nn = add mul nn 10 ulong sub x 48
320if gt nn 999
321fx 10
322end
323end
324s = fport
325for k ulong nn
326fserve s k
327end
328ret 0
329end