-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
1505 lines (1402 loc) · 69.3 KB
/
Copy pathMakefile
File metadata and controls
1505 lines (1402 loc) · 69.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.PHONY: build self-host self-host-ir-driver bootstrap bootstrap-verify bootstrap-ir-checks bootstrap-ir-checks-only bootstrap-ir-fixed-point bootstrap-ir-fixed-point-only bootstrap-ir-invariants bootstrap-ir-invariants-only run-examples run-examples-self run-examples-self-only run-regressions run-regressions-only run-regressions-self run-regressions-self-only run-live-websocket-tests run-live-websocket-tests-self-only db-live-tests parity-examples parity-examples-only check-parse-invalid check-parse-invalid-only check-parse-invalid-self-host check-parse-invalid-self-host-only check-invalid check-invalid-only check-invalid-self-host check-invalid-self-host-only cli-regressions cli-regressions-only cli-regressions-self cli-regressions-self-only ir-contract-regressions ir-contract-regressions-only test-std-self test-std-self-only test-self-host-only test-fast-self status-audit check-no-panics safety-check fuzz-check fuzz green-smoke green-threadlocal green-pingpong green-producer-consumer green-waitgroup green-mutex green-semaphore green-barrier green-await-fanin green-echo green-starvation green-pinned-fairness green-tests verify-green-corpus verify-green-corpus-only verify-osthread-corpus verify-osthread-corpus-only docsite docsite-check zstd-pure-bench zstd-encode-check memcheck leak-check leak-check-only test clean
NONDETERMINISTIC_EXAMPLES := net_basics net_echo redis_client
EXPECTED_EXAMPLES := $(filter-out $(addprefix examples/expected/,$(addsuffix .txt,$(NONDETERMINISTIC_EXAMPLES))),$(wildcard examples/expected/*.txt))
SLOW_NATIVE_EXAMPLES := csv_ops http_api http_apps http_websocket_app websocket_chat websocket_echo
REGRESSION_EXPECTED := $(wildcard tests/expected/*.txt)
SLOW_NATIVE_REGRESSIONS := \
test_http_app_helpers \
test_http_websocket_app \
test_websocket_accept_buffered \
test_websocket_bytes \
test_websocket_fragmentation \
test_websocket_frames \
test_websocket_handshake \
test_websocket_session \
test_websocket_wire
FAST_REGRESSION_EXPECTED := $(filter-out $(addprefix tests/expected/,$(addsuffix .txt,$(SLOW_NATIVE_REGRESSIONS))),$(REGRESSION_EXPECTED))
LIVE_EXPECTED := $(wildcard tests/live/expected/*.txt)
LIVE_CASES := $(basename $(notdir $(LIVE_EXPECTED)))
LIVE_WEBSOCKET_EXPECTED := $(LIVE_EXPECTED)
LIVE_WEBSOCKET_CASES := $(LIVE_CASES)
DB_LIVE_CASES := db_postgres_live db_mysql_live db_redis_live db_postgres_pool_live db_mysql_pool_live db_postgres_tx_live db_mysql_tx_live
PARSE_INVALID_EXAMPLES := $(wildcard tests/invalid_parse/*.pith)
INVALID_EXAMPLES := $(wildcard tests/invalid/*.pith)
PARITY_EXAMPLES := \
hello \
control_flow \
structs \
collection_methods \
generics \
lambdas \
error_handling \
json_ops \
toml_ops \
yaml_ops \
http_parsing \
uuid_ops \
matrix_math \
self_host_patterns \
wildcard_import
IR_FIXED_POINT_SOURCES := \
examples/hello.pith \
examples/concurrency.pith \
tests/cases/test_suite.pith \
tests/cases/test_imported_globals_init.pith \
tests/cases/test_module_alias_calls.pith \
tests/cases/test_imported_io_methods.pith \
tests/cases/test_io_file_streams.pith \
tests/cases/test_http_request_bytes.pith \
tests/cases/test_http_websocket_app.pith \
tests/cases/test_websocket_wire.pith
BOOTSTRAP_IR_REBUILD_TARGETS := \
self-host/pith_main.pith \
self-host/ir_driver.pith
# --- primary build (Cranelift native backend) ---
build:
cargo build --release
check-no-panics:
bash tooling/check_no_panics.sh
safety-check: build check-no-panics
cargo test --manifest-path cranelift/Cargo.toml --workspace --locked
./target/release/pith run tests/cases/test_channel_runtime.pith
./target/release/pith run tests/cases/test_concurrent_runtime.pith
./target/release/pith run tests/cases/test_select_runtime.pith
./target/release/pith run tests/cases/test_mutex_runtime.pith
# build the self-hosted compiler using the Cranelift backend
self-host: build
./target/release/pith build self-host/pith_main.pith
self-host-ir-driver: build
./target/release/pith build self-host/ir_driver.pith
# regenerate the tracked ir seed that lets a fresh clone build ir_driver.
# run this after changes to the ir contract or the emitter so the seed
# keeps working without an existing ir_driver binary.
refresh-bootstrap-seed: self-host-ir-driver
PITH_DUMP_IR=self-host/bootstrap/ir_driver.ir ./target/release/pith build self-host/ir_driver.pith
# rebuild the self-hosted compiler using the Cranelift-compiled version of itself
bootstrap: self-host
@echo "--- stage 1: compile with current Cranelift binary ---"
./target/release/pith build self-host/pith_main.pith
@echo "--- stage 1 binary test ---"
./self-host/pith_main version
# verify that the Cranelift-compiled compiler produces identical output
bootstrap-verify: self-host
@echo "--- verifying self-hosted compiler on deterministic examples ---"
@$(MAKE) --no-print-directory run-examples-self-only
@$(MAKE) --no-print-directory self-host-ir-driver
@echo "--- verifying colocated std tests ---"
@$(MAKE) --no-print-directory test-std-self-only
@echo "--- verifying self-hosted compiler on regression cases ---"
@$(MAKE) --no-print-directory run-regressions-self-only
@$(MAKE) --no-print-directory bootstrap-ir-checks-only
echo "bootstrap verified"
# keep the ir hardening checks grouped so bootstrap drift is easy to spot
bootstrap-ir-checks: self-host bootstrap-ir-checks-only
bootstrap-ir-checks-only:
@echo "--- verifying combined ir contract ---"
@$(MAKE) --no-print-directory ir-contract-regressions-only
@echo "--- verifying combined ir invariants ---"
@$(MAKE) --no-print-directory bootstrap-ir-invariants-only
@echo "--- verifying ir fixed point on deterministic corpus ---"
@$(MAKE) --no-print-directory bootstrap-ir-fixed-point-only
bootstrap-ir-invariants: self-host bootstrap-ir-invariants-only
bootstrap-ir-invariants-only:
@echo "--- combined ir invariant checks ---"
@pass=0; fail=0; \
if timeout 15 ./self-host/ir_driver --combined tests/cases/test_imported_globals_init.pith | awk 'BEGIN { init=0; call=0 } /^func [A-Za-z0-9_]+___init_globals_[0-9]+(_[0-9]+)? / { init=1 } /^call 900000 [A-Za-z0-9_]+___init_globals_[0-9]+(_[0-9]+)? int 0/ { call=1 } END { if (init && call) exit 0; exit 1 }'; then \
pass=$$((pass+1)); echo "ok imported init globals wiring"; \
else \
echo "FAIL imported init globals wiring"; fail=$$((fail+1)); \
fi; \
if timeout 15 ./self-host/ir_driver --combined examples/concurrency.pith | awk 'BEGIN { m=0; w=0; s=0 } /^call / && $$3=="Mutex" && $$4=="opaque:Mutex" { m=1 } /^call / && $$3=="WaitGroup" && $$4=="opaque:WaitGroup" { w=1 } /^call / && $$3=="Semaphore" && $$4=="opaque:Semaphore" { s=1 } END { if (m && w && s) exit 0; exit 1 }'; then \
pass=$$((pass+1)); echo "ok sync primitive retkind invariants"; \
else \
echo "FAIL sync primitive retkind invariants"; fail=$$((fail+1)); \
fi; \
if timeout 15 ./self-host/ir_driver --combined examples/generic_interfaces.pith | awk 'BEGIN { value=0; x=0; bad=0 } /^field / && NF==4 { bad=1 } /^field / && ($$5=="T" || $$5=="Point") && $$6=="value" { value=1 } /^field / && $$5=="int" && $$6=="x" { x=1 } END { if (value && x && !bad) exit 0; exit 1 }'; then \
pass=$$((pass+1)); echo "ok imported struct field metadata"; \
else \
echo "FAIL imported struct field metadata"; fail=$$((fail+1)); \
fi; \
if timeout 60 ./self-host/ir_driver --combined tests/cases/test_websocket_session.pith | awk 'BEGIN { ok=0 } /^call / && $$4 ~ /^struct:/ { ok=1 } /^call / && $$4 ~ /^[A-Z]/ { bad=1 } END { if (ok && !bad) exit 0; exit 1 }'; then \
pass=$$((pass+1)); echo "ok explicit struct call retkinds"; \
else \
echo "FAIL explicit struct call retkinds"; fail=$$((fail+1)); \
fi; \
if timeout 15 ./self-host/ir_driver --combined tests/cases/test_byte_compare_scan.pith | awk 'BEGIN { b=0 } /^call [0-9]+ pith_cstring_byte_at / { b=1 } END { if (b) exit 0; exit 1 }'; then \
pass=$$((pass+1)); echo "ok single-char comparison lowers to the byte read"; \
else \
echo "FAIL single-char comparison lowers to the byte read"; fail=$$((fail+1)); \
fi; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all combined ir invariant checks passed"
bootstrap-ir-fixed-point: self-host bootstrap-ir-fixed-point-only
bootstrap-ir-fixed-point-only:
@echo "--- bootstrap ir fixed point ---"
@tmpdir=$$(mktemp -d /tmp/pith-ir-fixed-point-XXXXXX); \
pass=0; fail=0; \
trap 'rm -rf "$$tmpdir"' EXIT; \
if [ ! -x ./self-host/ir_driver ]; then \
timeout 120 ./target/release/pith build self-host/ir_driver.pith >/dev/null; \
fi; \
for target in $(BOOTSTRAP_IR_REBUILD_TARGETS); do \
timeout 120 ./self-host/pith_main build "$$target" >/dev/null; \
done; \
cp ./self-host/pith_main "$$tmpdir/pith_main_stage1"; \
cp ./self-host/ir_driver "$$tmpdir/ir_driver_stage1"; \
for target in $(BOOTSTRAP_IR_REBUILD_TARGETS); do \
timeout 120 ./self-host/pith_main build "$$target" >/dev/null; \
done; \
for src in $(IR_FIXED_POINT_SOURCES); do \
stage1=$$(timeout 60 "$$tmpdir/ir_driver_stage1" --combined "$$src" 2>/dev/null); \
stage1_status=$$?; \
stage2=$$(timeout 60 ./self-host/ir_driver --combined "$$src" 2>/dev/null); \
stage2_status=$$?; \
if [ $$stage1_status -eq 0 ] && [ $$stage2_status -eq 0 ] && [ "$$stage1" = "$$stage2" ]; then \
pass=$$((pass+1)); \
echo "ok $$src"; \
else \
echo "FAIL $$src"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "bootstrap ir fixed point verified"
# --- example validation ---
run-examples: build
@echo "--- deterministic examples (Cranelift backend) ---"
@tmpdir=$$(mktemp -d /tmp/pith-native-examples-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
pass=0; fail=0; \
for f in $(EXPECTED_EXAMPLES); do \
name=$$(basename "$$f" .txt); \
case " $(SLOW_NATIVE_EXAMPLES) " in \
*" $$name "*) \
if timeout 120 ./target/release/pith build "examples/$$name.pith" >/dev/null 2>/dev/null; then \
actual=$$(timeout 15 "./examples/$$name" 2>/dev/null); \
expected=$$(cat "$$f"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi ;; \
*) \
actual=$$(timeout 60 ./target/release/pith run "examples/$$name.pith" 2>/dev/null); \
expected=$$(cat "$$f"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi ;; \
esac; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all examples passed"
run-examples-self: self-host run-examples-self-only
run-examples-self-only:
@echo "--- deterministic examples (self-hosted compiler) ---"
@pass=0; fail=0; \
for f in $(EXPECTED_EXAMPLES); do \
name=$$(basename "$$f" .txt); \
actual=$$(timeout 60 ./self-host/pith_main run "examples/$$name.pith" 2>/dev/null); \
expected=$$(cat "$$f"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all self-hosted examples passed"
run-regressions: build run-regressions-only
run-regressions-only:
@echo "--- regression cases (Cranelift backend) ---"
@pass=0; fail=0; \
for f in $(FAST_REGRESSION_EXPECTED); do \
name=$$(basename "$$f" .txt); \
actual=$$(timeout 60 ./target/release/pith run "tests/cases/$$name.pith" 2>/dev/null); \
expected=$$(cat "$$f"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
for name in $(SLOW_NATIVE_REGRESSIONS); do \
expected_file="tests/expected/$$name.txt"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
if timeout 120 ./target/release/pith build "tests/cases/$$name.pith" >/dev/null 2>/dev/null; then \
actual=$$(timeout 15 "./tests/cases/$$name" 2>/dev/null); \
expected=$$(cat "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all regression cases passed"
run-regressions-self: self-host run-regressions-self-only
run-regressions-self-only:
@echo "--- regression cases (self-hosted compiler) ---"
@pass=0; fail=0; \
for f in $(REGRESSION_EXPECTED); do \
name=$$(basename "$$f" .txt); \
actual=$$(timeout 60 ./self-host/pith_main run "tests/cases/$$name.pith" 2>/dev/null); \
expected=$$(cat "$$f"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all self-hosted regression cases passed"
test-std-self: self-host self-host-ir-driver test-std-self-only
test-std-self-only:
@echo "--- colocated std tests (self-hosted compiler) ---"
@pass=0; fail=0; \
files=$$(find std -name '*.pith' -print | sort); \
for f in $$files; do \
if ! grep -q '^[[:space:]]*test "' "$$f"; then \
continue; \
fi; \
if timeout 60 ./self-host/pith_main test "$$f" >/tmp/pith-test-out 2>&1; then \
pass=$$((pass+1)); \
echo "ok $$f"; \
else \
echo "FAIL $$f"; \
cat /tmp/pith-test-out; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi
test-self-host-only:
@echo "--- colocated self-host tests ---"
@pass=0; fail=0; \
files=$$(find self-host -name '*.pith' -print | sort); \
for f in $$files; do \
if ! grep -q '^[[:space:]]*test "' "$$f"; then \
continue; \
fi; \
if timeout 60 ./self-host/pith_main test "$$f" >/tmp/pith-test-out 2>&1; then \
pass=$$((pass+1)); \
echo "ok $$f"; \
else \
echo "FAIL $$f"; \
cat /tmp/pith-test-out; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi
test-fast-self: self-host self-host-ir-driver
@$(MAKE) --no-print-directory test-std-self-only
@$(MAKE) --no-print-directory test-self-host-only
@$(MAKE) --no-print-directory run-regressions-self-only
# colocated live database tests, run through the test harness. each test skips
# when its server is unreachable, so this target stays green with or without a
# running postgres/mysql/redis — it verifies behavior where the servers exist.
db-live-tests: build
@echo "--- live database tests (test harness) ---"
@fail=0; \
for name in $(DB_LIVE_CASES); do \
if ! ./target/release/pith test "tests/live/$$name.pith"; then \
fail=1; \
fi; \
done; \
if [ $$fail -ne 0 ]; then exit 1; fi; \
echo "all live database tests passed"
run-live-websocket-tests: build
@echo "--- live smoke tests (Cranelift backend) ---"
@pass=0; fail=0; \
for name in $(LIVE_WEBSOCKET_CASES); do \
expected_file="tests/live/expected/$$name.txt"; \
if timeout 120 ./target/release/pith build "tests/live/$$name.pith" >/dev/null 2>/dev/null; then \
actual=$$(timeout 15 "./tests/live/$$name" 2>/dev/null); \
expected=$$(cat "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all live smoke tests passed"
run-live-websocket-tests-self-only:
@echo "--- live smoke tests (self-hosted compiler) ---"
@pass=0; fail=0; \
for name in $(LIVE_WEBSOCKET_CASES); do \
expected_file="tests/live/expected/$$name.txt"; \
if timeout 120 ./self-host/pith_main build "tests/live/$$name.pith" >/dev/null 2>/dev/null; then \
actual=$$(timeout 15 "./tests/live/$$name" 2>/dev/null); \
expected=$$(cat "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
else \
echo "FAIL $$name"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all self-hosted live smoke tests passed"
parity-examples: self-host parity-examples-only
parity-examples-only:
@echo "--- native vs self-host parity examples ---"
@pass=0; fail=0; \
for name in $(PARITY_EXAMPLES); do \
expected_file="examples/expected/$$name.txt"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
native=$$(timeout 15 ./target/release/pith run "examples/$$name.pith" 2>/dev/null); \
self_host=$$(timeout 15 ./self-host/pith_main run "examples/$$name.pith" 2>/dev/null); \
expected=$$(cat "$$expected_file"); \
if [ "$$native" = "$$self_host" ] && [ "$$native" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
if [ "$$native" != "$$self_host" ]; then \
echo "native/self-host mismatch"; \
else \
echo "output mismatch vs expected"; \
fi; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all parity examples passed"
status-audit:
@echo "examples: $$(find examples -maxdepth 1 -name '*.pith' | wc -l)"
@echo "deterministic snapshots: $$(find examples/expected -name '*.txt' | wc -l)"
@echo "regression snapshots: $$(find tests/expected -name '*.txt' | wc -l)"
@echo "std modules: $$(find std -name '*.pith' | wc -l)"
@echo "self-host pith lines: $$(git ls-files 'self-host/*.pith' | xargs wc -l | tail -1 | awk '{print $$1}')"
@echo "std pith lines: $$(git ls-files 'std/**/*.pith' 'std/*.pith' | xargs wc -l | tail -1 | awk '{print $$1}')"
@echo "tracked cranelift rust lines: $$(git ls-files 'cranelift/**/*.rs' | xargs wc -l | tail -1 | awk '{print $$1}')"
@echo "example .to_string() sites: $$(rg -o '\.to_string\(' examples -g '*.pith' | wc -l)"
@echo "example manual length loops: $$(rg 'while .*< .*\.len\(\)' examples -g '*.pith' | wc -l)"
check-parse-invalid: build check-parse-invalid-only
check-parse-invalid-only:
@echo "--- invalid parse examples (parser diagnostics) ---"
@pass=0; fail=0; \
for f in $(PARSE_INVALID_EXAMPLES); do \
name=$$(basename "$$f" .pith); \
expected_file="tests/invalid_parse/expected/$$name.codes"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
set +e; \
output=$$(timeout 15 ./target/release/pith parse "$$f" 2>&1); \
status=$$?; \
set -e; \
if [ $$status -eq 0 ]; then \
echo "FAIL $$name (unexpected success)"; \
fail=$$((fail+1)); \
continue; \
fi; \
actual=$$(printf "%s\n" "$$output" | grep -o 'E[0-9][0-9][0-9]' | sort -u || true); \
expected=$$(sort "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
echo "expected:"; \
printf "%s\n" "$$expected"; \
echo "actual:"; \
printf "%s\n" "$$actual"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all invalid parse examples passed"
check-parse-invalid-self-host: self-host check-parse-invalid-self-host-only
check-parse-invalid-self-host-only:
@echo "--- invalid parse examples (self-hosted parser diagnostics) ---"
@pass=0; fail=0; \
for f in $(PARSE_INVALID_EXAMPLES); do \
name=$$(basename "$$f" .pith); \
expected_file="tests/invalid_parse/expected/$$name.codes"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
set +e; \
output=$$(timeout 15 ./self-host/pith_main parse "$$f" 2>&1); \
status=$$?; \
set -e; \
if [ $$status -eq 0 ]; then \
echo "FAIL $$name (unexpected success)"; \
fail=$$((fail+1)); \
continue; \
fi; \
actual=$$(printf "%s\n" "$$output" | grep -o 'E[0-9][0-9][0-9]' | sort -u || true); \
expected=$$(sort "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
echo "expected:"; \
printf "%s\n" "$$expected"; \
echo "actual:"; \
printf "%s\n" "$$actual"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all self-host invalid parse examples passed"
check-invalid: build check-invalid-only
check-invalid-only:
@echo "--- invalid examples (checker diagnostics) ---"
@pass=0; fail=0; \
for f in $(INVALID_EXAMPLES); do \
name=$$(basename "$$f" .pith); \
expected_file="tests/invalid/expected/$$name.codes"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
set +e; \
output=$$(timeout 15 ./target/release/pith check "$$f" 2>&1); \
status=$$?; \
set -e; \
if [ $$status -eq 0 ]; then \
echo "FAIL $$name (unexpected success)"; \
fail=$$((fail+1)); \
continue; \
fi; \
actual=$$(printf "%s\n" "$$output" | grep -o 'E[0-9][0-9][0-9]' | sort -u || true); \
expected=$$(sort "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
echo "expected:"; \
printf "%s\n" "$$expected"; \
echo "actual:"; \
printf "%s\n" "$$actual"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all invalid examples passed"
check-invalid-self-host: self-host check-invalid-self-host-only
check-invalid-self-host-only:
@echo "--- invalid examples (self-hosted checker diagnostics) ---"
@pass=0; fail=0; \
for f in $(INVALID_EXAMPLES); do \
name=$$(basename "$$f" .pith); \
expected_file="tests/invalid/expected/$$name.codes"; \
if [ ! -f "$$expected_file" ]; then \
echo "FAIL $$name (missing $$expected_file)"; \
fail=$$((fail+1)); \
continue; \
fi; \
set +e; \
output=$$(timeout 15 ./self-host/pith_main check "$$f" 2>&1); \
status=$$?; \
set -e; \
if [ $$status -eq 0 ]; then \
echo "FAIL $$name (unexpected success)"; \
fail=$$((fail+1)); \
continue; \
fi; \
actual=$$(printf "%s\n" "$$output" | grep -o 'E[0-9][0-9][0-9]' | sort -u || true); \
expected=$$(sort "$$expected_file"); \
if [ "$$actual" = "$$expected" ]; then \
pass=$$((pass+1)); \
echo "ok $$name"; \
else \
echo "FAIL $$name"; \
echo "expected:"; \
printf "%s\n" "$$expected"; \
echo "actual:"; \
printf "%s\n" "$$actual"; \
fail=$$((fail+1)); \
fi; \
done; \
echo "$$pass passed, $$fail failed"; \
if [ $$fail -gt 0 ]; then exit 1; fi; \
echo "all self-host invalid examples passed"
# --- stdlib reference site ---
# builds the doc extractor and renders docs/site/index.html from the
# comments in std/. regenerate whenever a pub item's docs change.
docsite:
@./target/release/pith build tools/docsite/docsite.pith > /dev/null
@./tools/docsite/docsite . docs/site
# --- docsite golden check ---
# runs the extractor over a fixture stdlib and diffs the markup. the fixture
# ships its own minimal assets so the golden pins generated html rather than
# the real stylesheet, which would churn on every design change.
docsite-check:
@echo "--- docsite golden check ---"
@./target/release/pith build tools/docsite/docsite.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-docsite-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/docsite/docsite tools/docsite/sample "$$tmpdir" tools/docsite/sample/assets > /dev/null; \
diff -u tools/docsite/expected/index.html "$$tmpdir/index.html" && \
echo "docsite output matches golden files"
# --- sitegen golden check ---
# builds the dogfood site generator, runs it over the sample site, and
# diffs the outputs that pin the whole pipeline
sitegen-check:
@echo "--- sitegen golden check ---"
@./target/release/pith build tools/sitegen/sitegen.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-sitegen-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/sitegen/sitegen tools/sitegen/sample "$$tmpdir" > /dev/null; \
diff -u tools/sitegen/expected/index.html "$$tmpdir/index.html" && \
diff -u tools/sitegen/expected/feed.json "$$tmpdir/feed.json" && \
diff -u tools/sitegen/expected/post-hello-world.html "$$tmpdir/posts/hello-world.html" && \
diff -u tools/sitegen/expected/post-on-ownership.html "$$tmpdir/posts/on-ownership.html" && \
diff -u tools/sitegen/expected/tag-memory.html "$$tmpdir/tags/memory.html" && \
echo "sitegen output matches golden files"
# --- logscan golden check ---
# builds the log analyzer, runs it over the sample log both plain and
# gzipped, and diffs the report and csv export
logscan-check:
@echo "--- logscan golden check ---"
@./target/release/pith build tools/logscan/logscan.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-logscan-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/logscan/logscan tools/logscan/sample/access.log "$$tmpdir/paths.csv" | grep -v "^csv written" > "$$tmpdir/report.txt"; \
diff -u tools/logscan/expected/report.txt "$$tmpdir/report.txt" && \
diff -u tools/logscan/expected/paths.csv "$$tmpdir/paths.csv" && \
gzip -c tools/logscan/sample/access.log > "$$tmpdir/sys.gz" && \
./tools/logscan/logscan "$$tmpdir/sys.gz" | grep -v "^csv written" > "$$tmpdir/report_gz.txt" && \
diff -u tools/logscan/expected/report.txt "$$tmpdir/report_gz.txt" && \
echo "logscan output matches golden files"
# --- apic golden check ---
# builds the json api client and its fixture server, runs the client
# against the live server, and diffs the outputs
apic-check:
@echo "--- apic golden check ---"
@./target/release/pith build tools/apic/apic.pith > /dev/null
@./target/release/pith build tools/apic/fixture_server.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-apic-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/apic/fixture_server 8047 3 & \
server_pid=$$!; \
sleep 1; \
./tools/apic/apic localhost:8047/item?id=7 --extract name > "$$tmpdir/extract.txt"; \
./tools/apic/apic localhost:8047/item?id=7 --pretty > "$$tmpdir/pretty.txt"; \
./tools/apic/apic localhost:8047/echo --post '{"ping":1}' --extract received.ping > "$$tmpdir/post.txt"; \
wait $$server_pid; \
diff -u tools/apic/expected/extract.txt "$$tmpdir/extract.txt" && \
diff -u tools/apic/expected/pretty.txt "$$tmpdir/pretty.txt" && \
diff -u tools/apic/expected/post.txt "$$tmpdir/post.txt" && \
echo "apic output matches golden files"
# --- parq golden check ---
# builds the parallel task runner and diffs its report; the
# workers-used line depends on scheduling and is excluded
parq-check:
@echo "--- parq golden check ---"
@./target/release/pith build tools/parq/parq.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-parq-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/parq/parq tools/parq/sample/jobs.txt 4 | grep -v "^workers used" > "$$tmpdir/report.txt"; \
diff -u tools/parq/expected/report.txt "$$tmpdir/report.txt" && \
./tools/parq/parq tools/parq/sample/jobs.txt 1 | grep -v "^workers used" > "$$tmpdir/report1.txt"; \
diff -u tools/parq/expected/report.txt "$$tmpdir/report1.txt" && \
echo "parq output matches golden files"
# --- protogen golden check ---
# builds the proto3 code generator, regenerates the sample module and checks it
# is byte-for-byte the committed one (determinism), runs the generated code's
# round-trip and wire-vector tests, and valgrinds a driver over encode/decode
protogen-check:
@echo "--- protogen golden check ---"
@./target/release/pith build tools/protogen/protogen.pith > /dev/null
@tmpdir=$$(mktemp -d /tmp/pith-protogen-XXXXXX); \
trap 'rm -rf "$$tmpdir"' EXIT; \
./tools/protogen/protogen tools/protogen/sample.proto "$$tmpdir/sample_gen.pith" > /dev/null; \
diff -u tools/protogen/sample_gen.pith "$$tmpdir/sample_gen.pith" && \
./target/release/pith test tools/protogen/protogen_test.pith && \
if command -v valgrind > /dev/null; then \
./target/release/pith build tools/protogen/protogen_memcheck.pith > /dev/null; \
PITH_STRUCT_FREELIST=0 valgrind --error-exitcode=99 --leak-check=no --errors-for-leak-kinds=none -q ./tools/protogen/protogen_memcheck > /dev/null && \
echo "protogen output matches golden, tests pass, valgrind clean"; \
else \
echo "protogen output matches golden and tests pass (valgrind absent)"; \
fi
# the ci gate: a fixed seed over both generated programs and mutated
# corpus cases, deterministic and green. it asserts the frontend never
# crashes, exits silent, or drops a valid program. the two silent-input
# gaps the mutation half first surfaced are now fixed (E243 for stray
# characters, E247 for missing modules), so the mutation half joins the
# gate. use `make fuzz` for a wider, longer search.
fuzz-check: build
@echo "--- fuzz check (generated + mutated corpus, deterministic) ---"
@./target/release/pith build tools/fuzz/fuzz.pith > /dev/null
@./tools/fuzz/fuzz --count 120 --build-every 8
# open-ended fuzzing: generated + corpus mutation. pass --count / --seed
# to explore. known findings live in the bulletproof plan; use this to
# hunt for new silent seams.
fuzz: build
@./target/release/pith build tools/fuzz/fuzz.pith > /dev/null
@./tools/fuzz/fuzz --count 300 --build-every 5
# --- green-thread smoke test ---
# the green backend (PITH_GREEN=1) must produce byte-identical output to the
# os-thread backend (PITH_GREEN=0) on independent, non-coordinating tasks. this
# builds the fan-out/join smoke program once and compares the two runs.
#
# every green-* target below pins BOTH sides of the comparison explicitly. green
# is the default on linux, so a run that just says `pith run` is now the green
# side, and a differential that relied on the default for its reference would be
# comparing green against green and passing for free.
green-smoke: build
@echo "--- green-thread smoke (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/smoke.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 ./target/release/pith run tests/green/smoke.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
# --- green-thread threadlocal isolation test ---
# `threadlocal` module globals must be per-task under the green backend: one
# worker OS thread runs many tasks, so they must not share the worker's storage.
# each task reads a threadlocal (fresh 0), adds its id, and returns it — correct
# storage yields "bad 0" and output byte-identical to the os-thread backend.
# before P1b this failed green (tasks saw a sibling's leftover value).
green-threadlocal: build
@echo "--- green-thread threadlocal isolation (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/threadlocal.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 ./target/release/pith run tests/green/threadlocal.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
# --- green-thread channel coordination tests (P2) ---
# these two tasks are NOT independent: they coordinate through channels, so each
# blocks waiting on the other. we force a single worker (PITH_GREEN_WORKERS=1) so
# the pre-P2 "block the worker" behavior would deadlock outright — the first task
# to block parks the only worker and nothing else can run. P2 makes a would-block
# channel op yield the coroutine instead, so one worker cooperatively runs both
# tasks to completion. output must stay byte-identical to the os-thread backend.
green-pingpong: build
@echo "--- green-thread channel ping-pong (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/pingpong.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/pingpong.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
green-producer-consumer: build
@echo "--- green-thread producer/consumer (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/producer_consumer.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/producer_consumer.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
# --- green-thread blocking-primitive coordination tests (P2b) ---
# P2 made channel ops yield the green worker instead of parking it; P2b extends
# that to waitgroup, semaphore, and mutex. each of these programs coordinates
# green tasks through one of those primitives such that a would-block op must
# yield or the run deadlocks.
#
# waitgroup and mutex are pinned to a single worker (PITH_GREEN_WORKERS=1): a
# green task blocks on the primitive while it is the only worker, so the pre-P2b
# "park the worker" behavior would hang outright. P2b yields instead and the
# program completes with output byte-identical to the os-thread backend.
green-waitgroup: build
@echo "--- green-thread waitgroup fan-out (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/waitgroup.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/waitgroup.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
green-mutex: build
@echo "--- green-thread mutex shared-counter (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/mutex.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/mutex.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
# the semaphore contention only materializes with more than one worker (a single
# worker runs the tasks serially and never overlaps in the critical section), so
# this one runs at the default worker count. with permits < tasks the workers
# repeatedly block acquiring the permit, exercising the green acquire/release
# yield-and-wake path; the completion total must match the os-thread backend.
green-semaphore: build
@echo "--- green-thread semaphore contention (byte-identical off vs on) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/semaphore.pith 2>/dev/null); \
on=$$(PITH_GREEN=1 ./target/release/pith run tests/green/semaphore.pith 2>/dev/null); \
if [ "$$off" = "$$on" ]; then \
echo "ok identical output: $$on"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green: $$on"; \
exit 1; \
fi
# --- green-thread barrier drain/release test ---
# several workers park on one channel while a coordinator drains their arrivals
# and then releases them. this is the shape that live-locked the single worker:
# a channel op woke every parked green task, not just the opposite role, so two
# workers parked on the release channel woke each other forever and starved the
# coordinator. it completed at two+ workers and on the os-thread backend, so we
# run it at BOTH a single worker and the default count — a regression here can
# only be caught at one worker.
green-barrier: build
@echo "--- green-thread barrier drain/release (byte-identical off vs on, 1 and default workers) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/barrier.pith 2>/dev/null); \
on1=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/barrier.pith 2>/dev/null); \
onN=$$(PITH_GREEN=1 ./target/release/pith run tests/green/barrier.pith 2>/dev/null); \
if [ "$$off" = "$$on1" ] && [ "$$off" = "$$onN" ]; then \
echo "ok identical output at 1 and default workers: $$on1"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green 1 worker: $$on1"; \
echo " green default: $$onN"; \
exit 1; \
fi
# --- green-thread await fan-in test (P2c) ---
# a green coordinator task spawns K green children and awaits each. this is the
# case the P2/P2b work left as a follow-up: awaiting from inside a green task
# hard-parked the worker, so at a single worker the coordinator parks the only
# worker awaiting its first child and the child can never run — a deadlock. P2c
# makes await yield the coroutine instead, so one worker cooperatively runs the
# coordinator and its children to completion. we run at BOTH a single worker and
# the default count — the one-worker hang can only be caught at one worker.
green-await-fanin: build
@echo "--- green-thread await fan-in (byte-identical off vs on, 1 and default workers) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/await_fanin.pith 2>/dev/null); \
on1=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/await_fanin.pith 2>/dev/null); \
onN=$$(PITH_GREEN=1 ./target/release/pith run tests/green/await_fanin.pith 2>/dev/null); \
if [ "$$off" = "$$on1" ] && [ "$$off" = "$$onN" ]; then \
echo "ok identical output at 1 and default workers: $$on1"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green 1 worker: $$on1"; \
echo " green default: $$onN"; \
exit 1; \
fi
# --- green-thread tcp echo (P3a: the epoll reactor) ---
# a green echo server and a green client run as spawned tasks over a real tcp
# socket. every socket op that would block — accept, connect, read, write —
# yields the green task to the epoll reactor instead of parking its worker OS
# thread. at a single worker the server and client share one worker, so the
# reactor must hand it back and forth between them; before P3a a would-block
# socket op parked the only worker and this deadlocked. we run it at BOTH one
# and the default worker count, since a reactor handoff regression only shows at
# one worker. the summary is input-determined, so it is byte-identical to the
# os-thread backend.
green-echo: build
@echo "--- green-thread tcp echo (byte-identical off vs on, 1 and default workers) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/echo.pith 2>/dev/null); \
on1=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/echo.pith 2>/dev/null); \
onN=$$(PITH_GREEN=1 ./target/release/pith run tests/green/echo.pith 2>/dev/null); \
if [ "$$off" = "$$on1" ] && [ "$$off" = "$$onN" ]; then \
echo "ok identical output at 1 and default workers: $$on1"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green 1 worker: $$on1"; \
echo " green default: $$onN"; \
exit 1; \
fi
# --- green-thread cooperative preemption (P5: the safe-point + monitor) ---
# a compute-only task spins in a tight loop with no yield point while N reporter
# tasks must each bump a shared counter. WITHOUT preemption the spinner holds its
# worker forever and the reporters never run, so at a single worker
# (PITH_GREEN_WORKERS=1) the program hangs. the green runs here compile with
# PITH_GREEN_PREEMPT=1 so the backend inserts safe-points at loop back-edges; the
# monitor then deschedules the overrunning spinner onto its worker's lowest-
# priority queue and the reporters run. the os-thread run needs no safe-points, so
# `off` compiles at the default (zero-overhead) setting. the printed total is the
# fixed counter value, so all three runs are byte-identical. we run the green side
# at BOTH one and the default worker count — the single-worker hang can only be
# caught at one worker.
green-starvation: build
@echo "--- green-thread cooperative preemption (byte-identical off vs on, 1 and default workers) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/starvation.pith 2>/dev/null); \
on1=$$(PITH_GREEN_PREEMPT=1 PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/starvation.pith 2>/dev/null); \
onN=$$(PITH_GREEN_PREEMPT=1 PITH_GREEN=1 ./target/release/pith run tests/green/starvation.pith 2>/dev/null); \
if [ "$$off" = "$$on1" ] && [ "$$off" = "$$onN" ]; then \
echo "ok identical output at 1 and default workers: $$on1"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green 1 worker: $$on1"; \
echo " green default: $$onN"; \
exit 1; \
fi
# --- green-thread wake affinity fairness ---
# waking a task onto the worker that woke it is a big win for a ping-pong pair,
# but the affinity slot holds exactly one task: a second same-worker wake
# displaces the first to the back of the fifo. without that displacement a hot
# pair keeps re-claiming the slot and any task queued behind it never runs, so at
# a single worker this hangs instead of printing. preemption cannot rescue it —
# each half of the pair re-parks long before it overruns its quantum.
green-pinned-fairness: build
@echo "--- green-thread wake affinity fairness (byte-identical off vs on, 1 and default workers) ---"
@off=$$(PITH_GREEN=0 ./target/release/pith run tests/green/pinned_fairness.pith 2>/dev/null); \
on1=$$(PITH_GREEN=1 PITH_GREEN_WORKERS=1 ./target/release/pith run tests/green/pinned_fairness.pith 2>/dev/null); \
onN=$$(PITH_GREEN=1 ./target/release/pith run tests/green/pinned_fairness.pith 2>/dev/null); \
if [ "$$off" = "$$on1" ] && [ "$$off" = "$$onN" ]; then \
echo "ok identical output at 1 and default workers: $$(echo $$on1)"; \
else \
echo "FAIL output differs"; \
echo " os-thread: $$off"; \
echo " green 1 worker: $$on1"; \
echo " green default: $$onN"; \
exit 1; \