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 / tests / physics0 / test_pd0_world.om

675 lines · 18415 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tests/physics0/test_pd0_world.om: PD-0 G0 harness self-test in pure seeded OM-2.
3note Prints PHYSICS0_G0: PASS|FAIL.
4
5global g0_checks ulong 1
6global g0_fails ulong 1
7global g0_buf_a uchar 65536
8global g0_buf_b uchar 65536
9global g0_buf_p uchar 65536
10global g0_pos ulong 1
11
12text G0_FAIL_PREFIX "FAIL G0 check #"
13text G0_NL "\n"
14text G0_PASS_LINE "PHYSICS0_G0: PASS\n"
15text G0_FAIL_LINE "PHYSICS0_G0: FAIL\n"
16text G0_CHECKS_PREFIX "checks="
17text G0_FAILS_PREFIX " failures="
18text G0_TAG_SCRIPT "script"
19text G0_EMPTY "x"
20text G0_W_ALWAYS "always"
21text G0_W_TRUE "true"
22text G0_W_UNIV "universally"
23
24fn g0_check cond bool id ulong to void
25b = new uchar 64 0
26put g0_checks 0 add get g0_checks 0 ulong 1
27if not cond
28put g0_fails 0 add get g0_fails 0 ulong 1
29p = pd0_buf_str edit b ulong 0 ulong 64 G0_FAIL_PREFIX
30p = pd0_buf_u64 edit b p ulong 64 id
31p = pd0_buf_ch edit b p ulong 64 uchar 10
32pd0_put_bytes 1 view b p
33end
34ret
35end
36
37fn g0_has_substr hay view uchar * hlen ulong needle view uchar * to int
38nlen = len needle
39if gt nlen hlen
40ret 0
41end
42lim = add sub hlen nlen ulong 1
43for i ulong lim bound 1024
44ok = int 1
45for j ulong nlen bound 64
46if ne get hay add i j get needle j
47ok = 0
48break
49end
50end
51if eq ok 1
52ret 1
53end
54end
55ret 0
56end
57
58fn t_wire_law to void
59p0r_clear ulong 0
60put p0r_nvars 0 uchar 2
61put p0r_nlat 0 uchar 0
62put p0r_nch 0 uchar 1
63put p0r_neq 0 uchar 2
64put p0r_eq_tgt p0r_eq_idx 0 0 uchar 0
65put p0r_eq_nt p0r_eq_idx 0 0 uchar 1
66put p0r_coef p0r_term_idx 0 0 0 long 50000
67put p0r_ex p0r_ex_idx 0 0 0 1 uchar 1
68put p0r_eq_tgt p0r_eq_idx 0 1 uchar 1
69put p0r_eq_nt p0r_eq_idx 0 1 uchar 2
70put p0r_coef p0r_term_idx 0 1 0 long -200000
71put p0r_ex p0r_ex_idx 0 1 0 0 uchar 1
72put p0r_coef p0r_term_idx 0 1 1 long 50000
73put p0r_ex p0r_ex_idx 0 1 1 PD0_MAX_VARS uchar 1
74m = new Pd0LawMeta 0 0 0 0 0 0 0 0 0 0 0 0 0
75m2 = new Pd0LawMeta 0 0 0 0 0 0 0 0 0 0 0 0 0
76put m state PD0_LAW_PROVISIONAL
77put m n_obs_dom ulong 2400
78put m n_ep_dom uint 60
79put m reset_min long -2000000
80put m reset_max long 2000000
81put m ep_len uint 100
82put m confidence_ppm pd0_confidence_ppm uint 34 uint 0
83put m n_exp ushort 1
84put p0l_exp_kind 0 uchar 1
85put m n_refutations ushort 1
86put m eps_micro uint 20000
87lb = new uchar 4096 0
88ln = pd0_law_encode ulong 0 view m edit lb
89g0_check gt ln ulong 0 ulong 111
90g0_check eq pd0_confidence_ppm uint 34 uint 0 uint 972222 ulong 112
91g0_check eq pd0_relation_description_bits ulong 0 uint 144 ulong 113
92g0_check eq pd0_law_decode part lb 0 ln ulong 1 edit m2 0 ulong 114
93g0_check and eq get m2 n_refutations ushort 1 eq get m2 confidence_ppm uint 972222 ulong 115
94put lb 46 xor get lb 46 uchar 1
95g0_check ne pd0_law_decode part lb 0 ln ulong 1 edit m2 0 ulong 116
96put lb 46 xor get lb 46 uchar 1
97put lb 8 uchar 2
98g0_check ne pd0_law_decode part lb 0 ln ulong 1 edit m2 0 ulong 117
99put lb 8 uchar 1
100put lb sub ln 3 xor get lb sub ln 3 uchar 1
101g0_check ne pd0_law_decode part lb 0 ln ulong 1 edit m2 0 ulong 118
102claim = new uchar 512 0
103cl = pd0_claim_text ulong 0 view m edit claim
104g0_check and eq g0_has_substr view claim cl G0_W_ALWAYS 0 and eq g0_has_substr view claim cl G0_W_TRUE 0 eq g0_has_substr view claim cl G0_W_UNIV 0 ulong 119
105ret
106end
107
108fn t_wire_rec to void
109r = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
110r2 = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
111put r n_obs uchar 2
112put r kind PD0_KIND_STEP
113put r channel uchar 0
114put r seq ulong 7
115put r episode uint 1
116put r step_in_episode uint 3
117put r time_micro long 150000
118put r requested long -123456
119put r applied long -123456
120put r before 0 long 1
121put r before 1 long -2
122put r after 0 long 3
123put r after 1 long -4
124for i ulong 8
125put r prev_hash i uint 0xabababab
126end
127rb = new uchar 256 0
128rn = pd0_rec_encode edit r edit rb
129g0_check eq rn ulong 152 ulong 105
130g0_check eq pd0_rec_decode part rb 0 rn edit r2 0 ulong 106
131g0_check eq get r2 seq ulong 7 ulong 107
132g0_check eq get r2 after 1 long -4 ulong 107
133put rb 9 uchar 2
134g0_check ne pd0_rec_decode part rb 0 rn edit r2 0 ulong 108
135put rb 9 uchar 0
136put rb 60 xor get rb 60 uchar 1
137g0_check ne pd0_rec_decode part rb 0 rn edit r2 0 ulong 109
138put rb 60 xor get rb 60 uchar 1
139g0_check eq pd0_rec_decode part rb 0 rn edit r2 0 ulong 110
140ret
141end
142
143fn t_wire to void
144d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
145d2 = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
146rc = pd0_gen_desc PD0_L3 edit d
147g0_check eq rc 0 ulong 100
148buf = new uchar 256 0
149n = pd0_desc_encode view d edit buf
150g0_check eq n ulong 126 ulong 101
151g0_check eq pd0_eq_bytes view buf ulong 0 PD0_MAGIC_DESC2 ulong 8 1 ulong 101
152g0_check eq pd0_desc_decode part buf 0 n edit d2 0 ulong 102
153g0_check eq get d2 n_obs uchar 4 ulong 103
154g0_check eq get d2 n_channels uchar 2 ulong 103
155g0_check ne pd0_desc_decode part buf 0 sub n 1 edit d2 0 ulong 104
156t_wire_rec
157t_wire_law
158ret
159end
160
161fn t_reset_request_bounds to void
162vals = new long 4 0
163put vals 0 long 1
164put vals 1 long -2
165put vals 2 long 3
166put vals 3 long -4
167req = new uchar 34 0xa5
168g0_check eq pd0_req_reset uchar 0 view vals edit req ulong 0 ulong 200
169g0_check eq pd0_req_reset uchar 5 view vals edit req ulong 0 ulong 201
170g0_check eq pd0_req_reset uchar 116 view vals edit req ulong 0 ulong 202
171g0_check eq pd0_req_reset uchar 255 view vals edit req ulong 0 ulong 203
172g0_check eq get req 0 uchar 0xa5 ulong 204
173short_req = new uchar 33 0xa5
174g0_check eq pd0_req_reset uchar 4 view vals edit short_req ulong 0 ulong 205
175n = pd0_req_reset uchar 4 view vals edit req
176g0_check and eq n ulong 34 and eq get req 0 PD0_OP_RESET eq get req 1 uchar 4 ulong 206
177g0_check and eq bitcast long pd0_get_u64 view req ulong 2 long 1 eq bitcast long pd0_get_u64 view req ulong 26 long -4 ulong 207
178ret
179end
180
181fn t_rules_budget to void
182wb = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
183db = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
184gb = new Pd0Gen 0 0 0 0 0 0 0
185r = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
186z = new long 4 0
187rcb = pd0_world_init edit wb edit db edit gb PD0_L0 ulong 2
188exh = int 0
189for e ulong 160
190pd0_world_reset edit wb view db view gb view z uchar 2 edit r
191if eq get r status PD0_BUDGET_EXHAUSTED
192exh = add exh 1
193end
194end
195g0_check eq exh 10 ulong 314
196g0_check eq pd0_guard_in_box PD0_BOUND 1 ulong 315
197g0_check eq pd0_guard_in_box add PD0_BOUND long 1 0 ulong 315
198g0_check eq pd0_guard_in_box neg PD0_BOUND 1 ulong 315
199ret
200end
201
202fn t_rules_l0 to void
203w0 = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
204d0 = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
205g0 = new Pd0Gen 0 0 0 0 0 0 0
206r = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
207rc0 = pd0_world_init edit w0 edit d0 edit g0 PD0_L0 ulong 1
208g0_check eq rc0 0 ulong 309
209z = new long 4 0
210pd0_world_reset edit w0 view d0 view g0 view z uchar 2 edit r
211for i ulong 20
212pd0_world_step edit w0 view d0 view g0 PD0_CH_NONE long 0 edit r
213end
214g0_check eq get r status PD0_EPISODE_END ulong 310
215g0_check eq get d0 episode_max_steps uint 20 ulong 310
216g0_check eq get d0 budget_episodes uint 150 ulong 310
217fast = new long 4 0
218put fast 0 long 2000000
219put fast 1 long 200000
220pd0_world_reset edit w0 view d0 view g0 view fast uchar 2 edit r
221saw_oob = int 0
222for i ulong 20
223pd0_world_step edit w0 view d0 view g0 uchar 0 long 100000 edit r
224if eq get r status PD0_OUT_OF_BOUNDS
225saw_oob = 1
226g0_check eq get r after 0 get r before 0 ulong 311
227g0_check eq get r after 1 get r before 1 ulong 311
228pd0_world_step edit w0 view d0 view g0 uchar 0 long 0 edit r
229g0_check eq get r status PD0_BUDGET_EXHAUSTED ulong 312
230break
231end
232end
233g0_check eq saw_oob 1 ulong 313
234t_rules_budget
235ret
236end
237
238fn t_rules to void
239w = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
240d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
241g = new Pd0Gen 0 0 0 0 0 0 0
242r = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
243rv = new long 4 0
244g0_check eq pd0_world_init edit w edit d edit g PD0_L1 ulong 3 0 ulong 300
245put rv 0 long 1000000
246put rv 1 long -500000
247pd0_world_reset edit w view d view g view rv uchar 2 edit r
248g0_check eq get r status PD0_OK ulong 301
249g0_check eq get r kind PD0_KIND_RESET ulong 301
250g0_check eq get r seq ulong 0 ulong 301
251pd0_world_step edit w view d view g uchar 0 long 3000000 edit r
252g0_check eq get r status PD0_REFUSED_RANGE ulong 302
253g0_check eq get r applied long 0 ulong 302
254g0_check eq get w steps_used uint 1 ulong 302
255pd0_world_step edit w view d view g uchar 1 long 0 edit r
256g0_check eq get r status PD0_REFUSED_RANGE ulong 303
257g0_check eq get w steps_used uint 2 ulong 303
258pd0_world_step edit w view d view g PD0_CH_NONE long 0 edit r
259g0_check eq get r status PD0_OK ulong 304
260g0_check eq get r after 0 add long 1000000 pd0_mul long -500000 long 50000 ulong 304
261pd0_world_step edit w view d view g uchar 0 long 2000000 edit r
262g0_check eq get r status PD0_OK ulong 305
263g0_check eq get r applied long 2000000 ulong 305
264used = get w episodes_used
265put rv 0 long 2500000
266put rv 1 long 0
267pd0_world_reset edit w view d view g view rv uchar 2 edit r
268g0_check eq get r status PD0_REFUSED_RANGE ulong 306
269g0_check eq get w episodes_used add used uint 1 ulong 306
270pd0_world_step edit w view d view g uchar 0 long 0 edit r
271g0_check eq get r status PD0_BUDGET_EXHAUSTED ulong 307
272put rv 0 long 1000000
273put rv 1 long -500000
274pd0_world_reset edit w view d view g view rv uchar 2 edit r
275ends = int 0
276for i ulong 100
277pd0_world_step edit w view d view g PD0_CH_NONE long 0 edit r
278if eq get r status PD0_EPISODE_END
279ends = add ends 1
280end
281end
282g0_check eq ends 1 ulong 308
283g0_check eq get r status PD0_EPISODE_END ulong 308
284g0_check eq get r step_in_episode uint 99 ulong 308
285t_rules_l0
286ret
287end
288
289fn t_splitmix to void
290r = new ulong 1 0
291pd0_stream edit r ulong 0 PD0_TAG_CONST
292g0_check eq get r 0 pd0_fnv1a64 PD0_TAG_CONST ulong 400
293g0_check eq pd0_fnv1a64 part G0_EMPTY 0 0 ulong 0xcbf29ce484222325 ulong 401
294mn = long 1073741824
295mx = long -1
296for i ulong 10000
297u = pd0_uniform edit r
298if lt u mn
299mn = u
300end
301if gt u mx
302mx = u
303end
304end
305g0_check and ge mn long 0 le mx long 1000000 ulong 402
306ok_c = int 1
307for i ulong 1000
308c = pd0_const edit r long -3000000 long 7000000
309if or lt c long -3000000 gt c long 7000000
310ok_c = 0
311end
312end
313g0_check eq ok_c 1 ulong 403
314s = f64 0.0f64
315sq = f64 0.0f64
316for i ulong 50000
317e = f64 pd0_noise edit r long 20000
318s = add s e
319sq = add sq mul e e
320end
321mean = div s 50000.0f64
322sd = fsqrt sub div sq 50000.0f64 mul mean mean
323g0_check and gt mean -500.0f64 and lt mean 500.0f64 and gt sd 18500.0f64 lt sd 21500.0f64 ulong 404
324ret
325end
326
327fn g0_null_collect r0 long r1 long uval long dst edit long 100 to void
328w = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
329d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
330g = new Pd0Gen 0 0 0 0 0 0 0
331rc = pd0_world_init edit w edit d edit g PD0_LEVEL_NULL ulong 101
332rv = new long 4 0
333put rv 0 r0
334put rv 1 r1
335rec = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
336pd0_world_reset edit w view d view g view rv uchar 2 edit rec
337for i ulong 50
338pd0_world_step edit w view d view g uchar 0 uval edit rec
339put dst mul i 2 get rec after 0
340put dst add mul i 2 1 get rec after 1
341end
342g0_check eq get d budget_steps uint 3000 ulong 501
343g0_check eq get d n_obs uchar 2 ulong 501
344ret
345end
346
347fn t_null_world to void
348a = new long 100 0
349b = new long 100 0
350g0_null_collect long 0 long 0 long 2000000 edit a
351g0_null_collect long 1500000 long -1500000 long -2000000 edit b
352same = int 1
353for i ulong 100
354if ne get a i get b i
355same = 0
356end
357end
358g0_check eq same 1 ulong 500
359ret
360end
361
362fn t_rev3 to void
363g = new Pd0Gen 0 0 0 0 0 0 0
364gcap = new Pd0Gen 0 0 0 0 0 0 0
365g0_check eq pd0_gen_reset_bound PD0_L0 0 long 2000000 ulong 600
366g0_check eq pd0_gen_reset_bound PD0_L0 1 long 200000 ulong 601
367g0_check eq pd0_gen_reset_bound PD0_L4 0 long 1000000 ulong 602
368g0_check eq pd0_gen_score_bound PD0_L0 1 1 long 300000 ulong 603
369g0_check eq pd0_gen_score_bound PD0_L4 0 1 long 1500000 ulong 604
370g0_check eq pd0_gen_score_bound PD0_L1 0 1 long 3000000 ulong 605
371saw_redraw = int 0
372all_ok = int 1
373for seed ulong 200
374sd = add seed ulong 1
375if ne pd0_gen_init edit g PD0_L6 sd 0
376all_ok = 0
377end
378if ne pd0_l6_unstable view g 0
379all_ok = 0
380end
381if gt get g redraws 0
382saw_redraw = 1
383end
384end
385g0_check and eq all_ok 1 eq saw_redraw 1 ulong 606
386for seed ulong 200
387sd = add seed ulong 1
388rc = pd0_gen_init edit g PD0_L6 sd
389if gt get g redraws 0
390rc0 = pd0_gen_init_cap edit gcap PD0_L6 sd 0
391g0_check and ne rc0 0 eq get gcap invalid 1 ulong 607
392break
393end
394end
395ret
396end
397
398fn t_desc2 to void
399d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
400d2 = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
401rc = pd0_gen_desc PD0_L0 edit d
402buf = new uchar 128 0
403n = pd0_desc_encode view d edit buf
404g0_check eq n ulong 78 ulong 700
405g0_check and eq get buf 0 uchar 80 and eq get buf 7 uchar 50 eq get buf 8 uchar 2 ulong 701
406g0_check eq pd0_desc_decode part buf 0 n edit d2 0 ulong 702
407g0_check and eq get d2 reset_min 1 long -200000 eq get d2 reset_max 1 long 200000 ulong 703
408put buf 7 uchar 49
409g0_check eq pd0_desc_decode part buf 0 n edit d2 PD0_DESC_REFUSED_V1 ulong 704
410put buf 7 uchar 51
411g0_check eq pd0_desc_decode part buf 0 n edit d2 -1 ulong 705
412put buf 7 uchar 50
413g0_check ne pd0_desc_decode part buf 0 sub n 1 edit d2 0 ulong 706
414ret
415end
416
417fn g0_append_rec rec edit Pd0Rec dst_sel int to void
418rbuf = new uchar 256 0
419rn = pd0_rec_encode rec edit rbuf
420n = get g0_pos 0
421for k ulong rn bound 256
422if eq dst_sel 0
423put g0_buf_a add n k get rbuf k
424else
425if eq dst_sel 1
426put g0_buf_b add n k get rbuf k
427else
428put g0_buf_p add n k get rbuf k
429end
430end
431end
432put g0_pos 0 add n rn
433ret
434end
435
436fn g0_draw_reset level int nobs ulong rng edit ulong 1 rv edit long 4 to void
437for v ulong nobs bound 4
438b = pd0_gen_reset_bound level int v
439put rv v pd0_const rng neg b b
440end
441ret
442end
443
444fn g0_script_ep_inproc w edit Pd0World d view Pd0Desc g view Pd0Gen rng edit ulong 1 dst_sel int to void
445rv = new long 4 0
446rec = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
447g0_draw_reset get g level ulong get d n_obs rng edit rv
448pd0_world_reset w d g view rv get d n_obs edit rec
449g0_append_rec edit rec dst_sel
450for i ulong 25
451ch = uchar rem pd0_splitmix64 rng ulong get d n_channels
452val = pd0_const rng get d chan_min ulong ch get d chan_max ulong ch
453pd0_world_step w d g ch val edit rec
454g0_append_rec edit rec dst_sel
455if ne get rec status PD0_OK
456break
457end
458end
459ret
460end
461
462fn g0_script_inproc level int seed ulong dst_sel int to ulong
463w = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
464d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
465g = new Pd0Gen 0 0 0 0 0 0 0
466if ne pd0_world_init edit w edit d edit g level seed 0
467ret ulong 0
468end
469rng = new ulong 1 0
470pd0_stream edit rng ulong 77 G0_TAG_SCRIPT
471put g0_pos 0 ulong 0
472for ep ulong 3
473g0_script_ep_inproc edit w view d view g edit rng dst_sel
474end
475ret get g0_pos 0
476end
477
478fn g0_script_ep_pipe level int d view Pd0Desc in_fd int out_fd int rng edit ulong 1 to int
479rv = new long 4 0
480rec = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
481g0_draw_reset level ulong get d n_obs rng edit rv
482if ne pd0_chan_reset_fd in_fd out_fd get d n_obs view rv edit rec 0
483ret -1
484end
485g0_append_rec edit rec 2
486for i ulong 25
487ch = uchar rem pd0_splitmix64 rng ulong get d n_channels
488val = pd0_const rng get d chan_min ulong ch get d chan_max ulong ch
489if ne pd0_chan_step_fd in_fd out_fd ch val edit rec 0
490ret -1
491end
492g0_append_rec edit rec 2
493if ne get rec status PD0_OK
494break
495end
496end
497ret 0
498end
499
500fn g0_script_pipe level int in_fd int out_fd int to ulong
501d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
502if ne pd0_chan_describe_fd in_fd out_fd edit d 0
503ret ulong 0
504end
505rng = new ulong 1 0
506pd0_stream edit rng ulong 77 G0_TAG_SCRIPT
507put g0_pos 0 ulong 0
508for ep ulong 3
509if ne g0_script_ep_pipe level view d in_fd out_fd edit rng 0
510ret ulong 0
511end
512end
513ret get g0_pos 0
514end
515
516fn g0_chain_ok sel int total ulong to int
517prev = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
518cur = new Pd0Rec 0 0 0 0 0 0 0 0 0 0 0 0 0 0
519tmp = new uchar 256 0
520have = int 0
521off = ulong 0
522while lt off total bound 1000
523if lt sub total off ulong 12
524ret 0
525end
526nobs = uchar 0
527if eq sel 0
528nobs = get g0_buf_a add off 10
529else
530nobs = get g0_buf_b add off 10
531end
532sz = pd0_rec_size nobs
533if or gt sz ulong 256 gt add off sz total
534ret 0
535end
536for k ulong sz bound 256
537if eq sel 0
538put tmp k get g0_buf_a add off k
539else
540put tmp k get g0_buf_b add off k
541end
542end
543if ne pd0_rec_decode part tmp 0 sz edit cur 0
544ret 0
545end
546if ne pd0_rec_chained view cur have view prev 1
547ret 0
548end
549put prev seq get cur seq
550for j ulong 8
551put prev hash j get cur hash j
552end
553have = 1
554off = add off sz
555end
556ret 1
557end
558
559fn g0_child_serve level int to_r int fr_w int to void
560wc = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0
561dc = new Pd0Desc 0 0 0 0 0 0 0 0 0 0
562gc = new Pd0Gen 0 0 0 0 0 0 0
563ri = pd0_world_init edit wc edit dc edit gc level ulong 5
564rs = pd0_world_serve edit wc view dc view gc to_r fr_w
565if eq rs 0
566exit 0
567end
568exit 1
569end
570
571fn g0_buf_eq_ap na ulong to int
572for k ulong na bound 65536
573if ne get g0_buf_a k get g0_buf_p k
574ret 0
575end
576end
577ret 1
578end
579
580fn g0_wait pid long to void
581wst = new uchar 8 0
582rc = waitpid int pid wst 0 8 0
583if lt rc long 0
584ret
585end
586ret
587end
588
589fn g0_pipe_run lvl ulong to ulong
590p_to = new uchar 8 0
591p_fr = new uchar 8 0
592rc = pipefds p_to 0 8 0
593g0_check eq rc long 0 add ulong 802 mul lvl 10
594rc = pipefds p_fr 0 8 0
595g0_check eq rc long 0 add ulong 802 mul lvl 10
596to_r = int pd0_get_u32 view p_to ulong 0
597to_w = int pd0_get_u32 view p_to ulong 4
598fr_r = int pd0_get_u32 view p_fr ulong 0
599fr_w = int pd0_get_u32 view p_fr ulong 4
600pid = fork
601if eq pid long 0
602rc = fclose to_w
603rc = fclose fr_r
604g0_child_serve int lvl to_r fr_w
605end
606rc = fclose to_r
607rc = fclose fr_w
608np = g0_script_pipe int lvl fr_r to_w
609rc = fclose to_w
610rc = fclose fr_r
611g0_wait pid
612ret np
613end
614
615fn t_repro_pipe lvl ulong na ulong to void
616np = g0_pipe_run lvl
617if ne np na
618g0_check false add ulong 803 mul lvl 10
619else
620g0_check eq g0_buf_eq_ap na 1 add ulong 803 mul lvl 10
621end
622ret
623end
624
625fn t_repro_one lvl ulong to void
626level = int lvl
627na = g0_script_inproc level ulong 5 0
628nb = g0_script_inproc level ulong 5 1
629eq_ab = int 1
630if or eq na ulong 0 ne na nb
631eq_ab = 0
632else
633for k ulong na bound 65536
634if ne get g0_buf_a k get g0_buf_b k
635eq_ab = 0
636break
637end
638end
639end
640g0_check eq eq_ab 1 add ulong 800 mul lvl 10
641g0_check eq g0_chain_ok 0 na 1 add ulong 801 mul lvl 10
642t_repro_pipe lvl na
643ret
644end
645
646fn t_repro_and_process to void
647for lvl ulong 8
648t_repro_one lvl
649end
650ret
651end
652
653fn main to int
654t_wire
655t_reset_request_bounds
656t_rules
657t_splitmix
658t_null_world
659t_rev3
660t_desc2
661t_repro_and_process
662obuf = new uchar 128 0
663p = pd0_buf_str edit obuf ulong 0 ulong 128 G0_CHECKS_PREFIX
664p = pd0_buf_u64 edit obuf p ulong 128 get g0_checks 0
665p = pd0_buf_str edit obuf p ulong 128 G0_FAILS_PREFIX
666p = pd0_buf_u64 edit obuf p ulong 128 get g0_fails 0
667p = pd0_buf_ch edit obuf p ulong 128 uchar 10
668pd0_put_bytes 1 view obuf p
669if eq get g0_fails 0 ulong 0
670pd0_puts 1 G0_PASS_LINE
671ret 0
672end
673pd0_puts 1 G0_FAIL_LINE
674ret 1
675end