Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1444 lines (1250 loc) · 92.9 KB
/
Copy pathMakefile
File metadata and controls
1444 lines (1250 loc) · 92.9 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
CC ?= cc
# The wall-clock floor (runtime/vm/host.h): the time of this make run.
BUILD_UNIX_MS := $(shell date +%s)000
CFLAGS_BASE = -Iruntime/input -std=c99 -Wall -Wextra -Werror -O2 -g
CFLAGS = $(CFLAGS_BASE) -DGOGO_BUILD_UNIX_MS=$(BUILD_UNIX_MS)LL $(EXTRA_CFLAGS)
BUILD = build
# $(BUILD)/.cflags holds the compiler and flags the build dir was built
# with (the wall-clock floor aside); it is rewritten when they change, and
# every binary and object depends on it (STAMPED, below), so switching
# EXTRA_CFLAGS on a build dir (build/asan, build/tsan, ...) rebuilds it.
FLAGS_STAMP = $(BUILD)/.cflags
FLAGS_NOW = $(CC) $(CFLAGS_BASE) $(EXTRA_CFLAGS)
$(FLAGS_STAMP): FORCE
@mkdir -p $(BUILD)
@if [ "$$(cat $@ 2>/dev/null)" != '$(FLAGS_NOW)' ]; then echo '$(FLAGS_NOW)' > $@; fi
.PHONY: FORCE
FORCE:
TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/vm/test/test_term.c runtime/vm/test/test_alloc.c runtime/vm/test/test_image.c runtime/vm/test/test_heap.c runtime/vm/test/test_identity.c runtime/vm/test/test_msg.c runtime/vm/test/test_interp.c runtime/vm/test/test_signals.c runtime/vm/test/test_timer.c runtime/vm/test/test_call.c runtime/vm/test/test_names.c runtime/vm/test/test_out.c runtime/vm/test/test_evq.c runtime/vm/test/test_port.c runtime/vm/test/test_strs.c runtime/vm/test/test_slices.c runtime/vm/test/test_bytes.c runtime/vm/test/test_netlink.c runtime/vm/test/test_module.c runtime/vm/test/test_walltime.c runtime/vm/test/test_step.c runtime/vm/test/test_float.c runtime/vm/test/test_params.c $(PARAMS_SRCS)
# The VM's parameters (runtime/board/params.c: resolution, keys, checks; not
# VM core): every platform that boots a VM links it.
PARAMS_SRCS = runtime/board/params.c
# The net stack (pure C99, chip-independent): linked into every
# unix build (platform_unix.c lists its drivers and feeds it frames).
NET_SRCS = $(wildcard runtime/net/*.c)
# runtime/stream/ (pure C99): the stream protocol (Chunk / Out / Done) of every byte port.
STREAM_SRCS = $(wildcard runtime/stream/*.c)
NET_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/net/test/*.c)
# runtime/floatlib/ (C99): the float library (gogo/math, strconv.FormatFloat
# and ParseFloat), linked wherever the VM core is (it is not VM core: `make
# vmsize` does not count it). Empty when built with -DGOGO_FLOAT=0.
FLOATLIB_SRCS = $(wildcard runtime/floatlib/*.c)
# VM core + unix platform + net stack and the stream protocol it speaks, without the unix main (shared with the C tests).
VM_SRCS = $(wildcard runtime/vm/*.c) $(FLOATLIB_SRCS) platform/unix/platform_unix.c runtime/gpio/gpio.c platform/unix/gpio_unix.c platform/unix/input_unix.c $(NET_SRCS) $(STREAM_SRCS)
VM_SRCS := $(filter-out runtime/vm/check32.c,$(VM_SRCS))
VM_CORE_SRCS = $(filter-out runtime/vm/check32.c,$(wildcard runtime/vm/*.c))
# runtime/screen/ (pure C99): the "screen" port's grid and driver; render.c
# (pixels, for the LCD) is not in gogovm, which draws on the terminal
# (platform/unix/screen_unix.c). The grid's width rule is the console's.
SCREEN_SRCS = runtime/screen/screen.c runtime/screen/screen_port.c runtime/console/console.c runtime/console/font.c
# runtime/dist/ (pure C99): the "node" port of distributed actors; hostnet.c:
# the "tcp" and "tcp_listen" ports on host sockets (gogovm --host-net),
# their socket options in sockopts.c.
DIST_SRCS = $(wildcard runtime/dist/*.c)
# Independent host peer protocol. Kept out of v1/MCU source wildcards.
PEER_SRCS = runtime/dist/peer/protocol.c runtime/dist/peer/registry.c runtime/dist/hmac.c
PEER_SESSION_SRCS = runtime/dist/peer/session.c runtime/dist/peer/protocol.c runtime/dist/hmac.c
PEER_VALUE_SRCS = runtime/dist/peer/value.c runtime/dist/peer/vm.c
PEER_DISPATCH_SRCS = runtime/dist/peer/dispatch.c
PEER_HDRS = $(wildcard runtime/dist/peer/*.h) runtime/dist/hmac.h runtime/vm/term.h
# Host-only transport. Define before executable prerequisites are expanded;
# MCU firmware uses its own source list and does not link these files.
SERVER_INBOX_SRCS = runtime/server/inbox_posix.c runtime/server/budget_posix.c
SERVER_REACTOR_SRCS = $(SERVER_INBOX_SRCS) runtime/server/poller_posix.c runtime/server/reactor_posix.c
SERVER_HDRS = $(wildcard runtime/server/*.h)
# Board ports (runtime/board/board_ports.c, gogo.h GOGO_BOARD_PORT): every
# gogovm has the host-port layer (runtime/embed's hostport.c, inbox.c and
# poster.c), idle unless a driver of the build registers a port: with up to
# 8 of them beside the board's drivers (BOARD_PORTS_FLAGS), and one more
# event source for the post inbox when DRIVERS are given.
BOARD_PORTS_SRCS = runtime/board/board_ports.c runtime/embed/hostport.c runtime/embed/inbox.c runtime/embed/poster.c runtime/embed/version.c
BOARD_PORTS_FLAGS = -DGOGO_BOARD_PORTS=1 -DEMBED_HOST_PORTS=8 -DEMBED_BOARD_PORTS_MAX=32 -DGOGO_BOARD_POST_BYTES=1048576u -Iruntime/include
MAIN_SRCS = platform/unix/main.c platform/unix/screen_unix.c platform/unix/hostnet.c platform/unix/sockopts.c $(BLE_SRCS) platform/unix/ble_unix.c runtime/board/board_main.c $(PARAMS_SRCS) runtime/embed/fs_dir.c $(wildcard runtime/vfs/*.c) $(wildcard runtime/input/*.c) $(SCREEN_SRCS) $(DIST_SRCS) $(BOARD_PORTS_SRCS) $(SERVER_REACTOR_SRCS)
# runtime/ble/ (BLE_SRCS, pure C99): the "ble" port; ble_unix.c: its radio,
# a Unix-domain socket a test client plays the phone on (a thread: -pthread).
# Its event source, taken while the port is open, is one more than the
# default 4 (GOGOVM_SOURCES).
GOGOVM_FLAGS = -Iruntime/ble -pthread
GOGOVM_SOURCES = -DGOGO_MAX_SOURCES=5u
# make vm DRIVERS="dir|file.c ...": gogovm with those board-port drivers
# compiled in (an ESP-IDF driver component's directory: its *.c but the
# *_esp.c hardware files, which only the firmware builds), to test them on
# the host. The list is recorded in $(BUILD)/.drivers, so a plain `make vm`
# after it rebuilds gogovm without them.
DRIVERS ?=
DRIVER_SRCS = $(foreach d,$(DRIVERS),$(if $(filter %.c,$(d)),$(d),$(filter-out %_esp.c,$(wildcard $(d)/*.c))))
# A DRIVERS entry that names no source is a mistake, not a gogovm without it.
$(foreach d,$(DRIVERS),$(if $(if $(filter %.c,$(d)),$(wildcard $(d)),$(filter-out %_esp.c,$(wildcard $(d)/*.c))),,$(error DRIVERS: $(d) is not a .c file nor a directory with .c files (a component's sources are its top-level *.c, but *_esp.c))))
DRIVERS_STAMP = $(BUILD)/.drivers
$(DRIVERS_STAMP): FORCE
@mkdir -p $(BUILD)
@if [ "$$(cat $@ 2>/dev/null)" != '$(DRIVER_SRCS)' ]; then echo '$(DRIVER_SRCS)' > $@; fi
PLAT_HDRS = $(wildcard runtime/ble/*.h) $(wildcard runtime/dist/*.h) $(wildcard platform/unix/*.h) runtime/gpio/gpio.h runtime/board/board_main.h runtime/board/board_ports.h runtime/embed/ports.h runtime/embed/inbox.h runtime/include/gogo.h runtime/embed/fs_dir.h $(wildcard runtime/net/*.h) $(wildcard runtime/vfs/*.h) $(wildcard runtime/input/*.h) $(wildcard runtime/stream/*.h) $(wildcard runtime/screen/*.h) $(wildcard runtime/console/*.h)
PLAT_HDRS += $(SERVER_HDRS)
# The "tls" port (runtime/net/tls/, spec HTTPS): mbedTLS 4.x from ESP-IDF's source tree,
# built here with runtime/net/tls/config (gogo_*_config.h) into its own static library,
# linked into gogovm / gogovm_mcu only (never the VM core: `make vmsize` is
# unaffected; `make tlssize` reports it). Without the source tree gogovm is
# built without the port (and the tls tests skip).
MBEDTLS_DIR ?= $(HOME)/esp/esp-idf/components/mbedtls/mbedtls
ifneq ($(wildcard $(MBEDTLS_DIR)/library/ssl_tls.c),)
MBEDTLS_TF = $(MBEDTLS_DIR)/tf-psa-crypto
MBEDTLS_SRCS = $(wildcard $(MBEDTLS_DIR)/library/*.c) $(wildcard $(MBEDTLS_TF)/core/*.c) \
$(wildcard $(MBEDTLS_TF)/drivers/builtin/src/*.c) $(wildcard $(MBEDTLS_TF)/extras/*.c) \
$(wildcard $(MBEDTLS_TF)/platform/*.c) $(wildcard $(MBEDTLS_TF)/utilities/*.c)
MBEDTLS_OBJS = $(patsubst $(MBEDTLS_DIR)/%.c,$(BUILD)/mbedtls/%.o,$(MBEDTLS_SRCS))
MBEDTLS_CFG = -Iruntime/net/tls/config -DMBEDTLS_CONFIG_FILE='"gogo_mbedtls_config.h"' -DTF_PSA_CRYPTO_CONFIG_FILE='"gogo_crypto_config.h"'
MBEDTLS_PUB = $(MBEDTLS_CFG) -I$(MBEDTLS_DIR)/include -I$(MBEDTLS_TF)/include -I$(MBEDTLS_TF)/drivers/builtin/include
MBEDTLS_PRIV = $(MBEDTLS_PUB) -Iruntime/net/tls/host -I$(MBEDTLS_DIR)/library -I$(MBEDTLS_TF)/core -I$(MBEDTLS_TF)/drivers/builtin/src \
-I$(MBEDTLS_TF)/dispatch -I$(MBEDTLS_TF)/utilities -I$(MBEDTLS_TF)/platform -I$(MBEDTLS_TF)/extras
MBEDTLS_LIB = $(BUILD)/libgogo_mbedtls.a
TLS_SRCS = runtime/net/tls/tls.c runtime/net/tls/anchor.c platform/unix/tls_unix.c
TLS_CFLAGS = -DGOGO_TLS -pthread -Iruntime/net/tls $(MBEDTLS_PUB)
TLS_LINK = $(TLS_SRCS) $(MBEDTLS_LIB)
TLS_DEPS = $(TLS_SRCS) $(wildcard runtime/net/tls/*.h) $(wildcard runtime/net/tls/config/*.h) $(MBEDTLS_LIB)
$(BUILD)/mbedtls/%.o: $(MBEDTLS_DIR)/%.c $(wildcard runtime/net/tls/config/*.h)
@mkdir -p $(dir $@)
@$(CC) -std=c99 -O2 -g -w $(EXTRA_CFLAGS) $(MBEDTLS_PRIV) -c $< -o $@
$(MBEDTLS_LIB): $(MBEDTLS_OBJS)
@rm -f $@
ar rcs $@ $(MBEDTLS_OBJS)
endif
.PHONY: test-sockopts test-board-ports test-board-ports-tsan test-ble-tsan test-dist-c test-dist-scale test-dist-san distsize float-corpus lint gogo-cmd test-examples test-book site site-check lib libgogoc test-libgogo test-gogoc test-gobind example-embed example-driver test-embed test-embed-tsan test-embed-leaks embed-images vmsize netsize tlssize test-tls-asan test-tls-threads test-tls-tsan all vm test test-c test-c-mcu test-net-c test-tls-c test-net-mcu test-vfs test-input test-stream test-ble test-screen test-screen-asan test-c-asan test-fs-host test-configsvc test-prov vfssize screensize floatlibsize test-console test-go test-lib check32 globals globals-selftest console-ppm bytecode-doc clean
all: test
test: lint test-c test-c-mcu test-dist-c test-sockopts test-net-c test-tls-c test-tls-threads test-vfs test-input test-stream test-ble test-screen test-fs-host test-configsvc test-prov test-gpio test-fat test-lfs test-console test-embed test-libgogo test-gogoc test-gobind example-embed example-driver test-board-ports check32 globals globals-selftest test-go test-examples test-book site-check test-net-mcu vmsize netsize vfssize screensize floatlibsize distsize
vm: $(BUILD)/gogovm $(BUILD)/gogo-sim
# gogo-sim is gogovm under the board simulator's name: run as gogo-sim it
# requires --board and its help speaks of boards (platform/unix/main.c).
$(BUILD)/gogo-sim: $(BUILD)/gogovm
cp $(BUILD)/gogovm $@
# gofmt on .go and .gg files, go vet, shellcheck on tools/*.sh when installed (tools/lint.sh).
lint:
tools/lint.sh
# Every examples/*/ and platform/esp32s3/examples/*/ program builds; the ones
# with an expected.out run with gogo run and print it (tools/examples.sh).
test-examples: vm server $(BUILD)/gogovm_mcu gogo-cmd
tools/examples.sh $(BUILD)
# Every example in the book runs and prints what the book shows
# (docs/book/examples/run.sh, with this build's gogo, gogo-server, which
# gogo run uses and chapter 24's server programs run in, and gogo-sim for
# the board programs).
test-book: vm gogo-cmd server
GOGO_CMD=$(CURDIR)/$(BUILD)/gogo GOGO_SERVER=$(CURDIR)/$(BUILD)/gogo-server GOGO_SIM=$(CURDIR)/$(BUILD)/gogo-sim docs/book/examples/run.sh
# The website, plain files with relative links: the landing page
# (site/index.html) as $(BUILD)/site/index.html and the book built by
# mdBook (docs/book/book.toml, SUMMARY.md, theme/) in $(BUILD)/site/book.
# mdBook copies every non-markdown file of docs/book; the example programs
# and book.toml are removed again (the book links examples/ on GitHub).
# The brand marks come from logos/: the mascot for the landing page, the
# Gogo Lang lockup for the book's sidebar (theme/gogo.css); the favicon is
# the book's (docs/book/theme/favicon.*), shared by the landing page.
SITE_LOGOS = logos/gogo-octopus-color.svg
BOOK_LOGOS = logos/gogo-lang-color.svg
MDBOOK ?= mdbook
SITE = $(BUILD)/site
MDBOOK_HINT = install mdBook 0.5: brew install mdbook, or a release binary from https://github.com/rust-lang/mdBook/releases
site:
@command -v $(MDBOOK) >/dev/null 2>&1 || { echo "make site: $(MDBOOK) not found; $(MDBOOK_HINT)" >&2; exit 1; }
rm -rf $(SITE)
$(MDBOOK) build docs/book -d $(CURDIR)/$(SITE)/book
rm -rf $(SITE)/book/examples $(SITE)/book/book.toml
cp site/index.html $(SITE)/index.html
cp -R site/.well-known $(SITE)/.well-known
mkdir -p $(SITE)/logos $(SITE)/book/logos
cp $(SITE_LOGOS) $(SITE)/logos/
cp $(BOOK_LOGOS) $(SITE)/book/logos/
cp docs/book/theme/favicon.svg docs/book/theme/favicon.png $(SITE)/
@echo "site: open $(SITE)/index.html"
# make site, then every relative link and #anchor of the site resolves and
# no markdown is left unconverted (tools/sitecheck); skipped without mdbook.
site-check:
@if command -v $(MDBOOK) >/dev/null 2>&1; then \
$(MAKE) --no-print-directory site && go run ./tools/sitecheck $(SITE); \
else \
echo "site-check: skipped: mdbook not installed ($(MDBOOK_HINT))"; \
fi
# COMPACT builds a host program with the compact identity, for the host
# runtimes that run it (gogovm, libgogo, the v1 star gogo-server --star):
# gogo build builds target host wide by default. -actor-identity compact is
# the explicit way to ask for it (docs/plans/2026-12-01-toolchain-server.md).
COMPACT = -actor-identity compact
# The gogo command, one rule for every target that needs it, so that
# targets run in parallel (make -j) do not write it at the same time
# (go build itself decides whether it is stale).
gogo-cmd:
@mkdir -p $(BUILD)
go build -o $(BUILD)/gogo ./cmd/gogo
# gogovm's compile, with driver sources after it (gogovm_with SRCS).
GOGOVM_DEPS = $(VM_SRCS) $(MAIN_SRCS) $(wildcard runtime/vm/*.h) $(PLAT_HDRS) $(TLS_DEPS)
gogovm_with = $(CC) $(CFLAGS) $(TLS_CFLAGS) $(BOARD_PORTS_FLAGS) $(GOGOVM_FLAGS) $(if $(1),-DGOGO_MAX_SOURCES=6u,$(GOGOVM_SOURCES)) -Iruntime/vm -Iruntime/net -Iruntime/vfs -Iruntime/input -Iruntime/stream -Iruntime/screen -Iruntime/console -Iruntime/embed -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -o $@ $(VM_SRCS) $(MAIN_SRCS) $(1) $(TLS_LINK)
$(BUILD)/gogovm: $(GOGOVM_DEPS) $(DRIVER_SRCS) $(DRIVERS_STAMP)
@mkdir -p $(BUILD)
$(call gogovm_with,$(DRIVER_SRCS))
test-c: $(BUILD)/test_c
$(BUILD)/test_c
# The same tests with the small-platform (MCU) config.
MCU_FLAGS = -DGOGO_DEFAULT_MAX_WORDS=4096u -DGOGO_TABLE_CAP=1024u -DGOGO_ARENA_BYTES=163840u
test-c-mcu: $(BUILD)/test_c_mcu
$(BUILD)/test_c_mcu
$(BUILD)/test_c_mcu: $(TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -pthread -o $@ $(TEST_SRCS) $(VM_SRCS)
# Net stack C tests (parsers, malformed frames, ports), host and MCU config.
test-net-c: $(BUILD)/test_net $(BUILD)/test_net_mcu
$(BUILD)/test_net
$(BUILD)/test_net_mcu
$(BUILD)/test_net: $(NET_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix -o $@ $(NET_TEST_SRCS) $(VM_SRCS)
# The "tls" port's per-stack state (two Vms, two connections), against the
# mbedTLS library; skipped without the mbedTLS source tree.
TLS_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/net/tls/test/test_tls.c
# GCC warns, as an error under -Werror, that TSan does not model
# atomic_thread_fence (vm_barrier, which orders the event ring); clang has
# no such warning. TSan still checks every other access. This is shared
# by the hostnet/embed tests even when mbedTLS is not configured.
TSAN_WNO := $(shell $(CC) -Werror -Wno-tsan -E -x c /dev/null >/dev/null 2>&1 && echo -Wno-tsan)
ifneq ($(TLS_CFLAGS),)
test-tls-c: $(BUILD)/test_tls
$(BUILD)/test_tls
# Two Vms on two threads, TLS handshakes at once with different wall clocks
# (tls_threads.c), against a real TLS server the Go test starts; under
# ThreadSanitizer with test-tls-tsan.
test-tls-threads: $(BUILD)/test_tls_threads
GOGO_TLS_THREADS=$(CURDIR)/$(BUILD)/test_tls_threads go test -count=1 -run '^TestTLSThreads$$' ./tests/net/
test-tls-tsan:
$(MAKE) BUILD=build/tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" build/tsan/test_tls_threads
TSAN_OPTIONS="halt_on_error=1 suppressions=$(CURDIR)/runtime/net/tls/test/tsan.supp" \
GOGO_TLS_THREADS=$(CURDIR)/build/tsan/test_tls_threads go test -count=1 -run '^TestTLSThreads$$' ./tests/net/
else
test-tls-c:
@echo "test-tls-c: skipped (no mbedTLS source at $(MBEDTLS_DIR))"
test-tls-threads test-tls-tsan:
@echo "$@: skipped (no mbedTLS source at $(MBEDTLS_DIR))"
endif
$(BUILD)/test_tls_threads: runtime/net/tls/test/tls_threads.c $(VM_SRCS) $(wildcard runtime/vm/*.h) $(PLAT_HDRS) $(TLS_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(TLS_CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix -o $@ runtime/net/tls/test/tls_threads.c $(VM_SRCS) $(TLS_LINK)
$(BUILD)/test_tls: $(TLS_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS) $(TLS_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(TLS_CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix -o $@ $(TLS_TEST_SRCS) $(VM_SRCS) $(TLS_LINK)
$(BUILD)/test_net_mcu: $(NET_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix -o $@ $(NET_TEST_SRCS) $(VM_SRCS)
# vfs (pure C99): path rules, slot table, rules, and the B_FS builtin
# (builtin.c, the only file that sees VM types), against the memfs fake on
# a real VM. The MCU build uses the MCU VM config, the MCU slot parameters
# (the ESP32-S3 LittleFS slot, platform/esp32s3/main/CMakeLists.txt) and -Os.
VFS_SRCS = $(wildcard runtime/vfs/*.c)
VFS_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/vfs/test/*.c)
VFS_INC = -Iruntime/vfs -Iruntime/vfs/test -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix
VFS_DEPS = $(VFS_SRCS) $(VFS_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vfs/*.h) $(wildcard runtime/vfs/test/*.h) $(wildcard runtime/vm/*.h) $(PLAT_HDRS)
test-vfs: $(BUILD)/test_vfs $(BUILD)/test_vfs_mcu
$(BUILD)/test_vfs
$(BUILD)/test_vfs_mcu
$(BUILD)/test_vfs: $(VFS_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(VFS_INC) -o $@ $(VFS_SRCS) $(VFS_TEST_SRCS) $(VM_SRCS)
$(BUILD)/test_vfs_mcu: $(VFS_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Os -DGOGO_FS_MAX_OPEN=4u -DGOGO_FS_SLOT_BYTES=160u $(VFS_INC) -o $@ $(VFS_SRCS) $(VFS_TEST_SRCS) $(VM_SRCS)
# Non-blocking B_FS (runtime/vfs/vfs.h, GOGO_FS_ASYNC: server builds only):
# the builtin tests again through the server's blocking pool and fs executor
# (TEST_FS_ASYNC: same results as the synchronous run), the vfs core tests
# in that build, and the async tests (runtime/vfs/test/test_async.c: parked
# calls, a gate backend that holds, delays and fails, real directories for
# the 1 MiB pieces). -san / -tsan: sanitizers, as the server targets.
VFS_ASYNC_SRCS = runtime/server/blocking_posix.c runtime/server/fs_posix.c runtime/server/budget_posix.c runtime/server/inbox_posix.c runtime/embed/fs_dir.c
VFS_ASYNC_FLAGS = -DGOGO_FS_ASYNC=1 -DTEST_FS_ASYNC=1 -Iruntime/server -Iruntime/embed -Iruntime/include -pthread
.PHONY: test-vfs-async test-vfs-async-san test-vfs-async-tsan
test: test-vfs-async
test-vfs-async: $(BUILD)/test_vfs_async
$(BUILD)/test_vfs_async
$(BUILD)/test_vfs_async: $(VFS_DEPS) $(VFS_ASYNC_SRCS) $(SERVER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(VFS_ASYNC_FLAGS) $(VFS_INC) -o $@ $(VFS_SRCS) $(VFS_TEST_SRCS) $(VM_SRCS) $(VFS_ASYNC_SRCS)
test-vfs-async-san:
ASAN_OPTIONS=$(LEAK_CHECK) LSAN_OPTIONS=suppressions=$(CURDIR)/runtime/vfs/test/lsan.supp $(MAKE) BUILD=build/vfs-async-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-vfs-async
test-vfs-async-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/vfs-async-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-vfs-async
# input (pure C99): the kbd port and the input source against a fake InputHw
# (runtime/input/test/fakehw.c) on a real VM, in the host and MCU VM configs.
INPUT_SRCS = $(wildcard runtime/input/*.c)
INPUT_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/input/test/*.c)
INPUT_INC = -Iruntime/input -Iruntime/input/test -Iruntime/stream -Iruntime/vm -Iruntime/net -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix
INPUT_DEPS = $(INPUT_SRCS) $(INPUT_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/input/*.h) $(wildcard runtime/input/test/*.h) $(wildcard runtime/vm/*.h) $(PLAT_HDRS)
test-input: $(BUILD)/test_input $(BUILD)/test_input_mcu
$(BUILD)/test_input
$(BUILD)/test_input_mcu
$(BUILD)/test_input: $(INPUT_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(INPUT_INC) -o $@ $(INPUT_SRCS) $(INPUT_TEST_SRCS) $(VM_SRCS)
$(BUILD)/test_input_mcu: $(INPUT_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Os $(INPUT_INC) -o $@ $(INPUT_SRCS) $(INPUT_TEST_SRCS) $(VM_SRCS)
# stream (pure C99): Chunk delivery and Out bookkeeping against a fake "st"
# port on a real VM (and the port-send gate through the interpreter), in the
# host and MCU VM configs.
STREAM_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/stream/test/*.c)
STREAM_INC = -Iruntime/stream -Iruntime/vm -Iruntime/net -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix
STREAM_DEPS = $(STREAM_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/stream/*.h) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
test-stream: $(BUILD)/test_stream $(BUILD)/test_stream_mcu
$(BUILD)/test_stream
$(BUILD)/test_stream_mcu
$(BUILD)/test_stream: $(STREAM_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(STREAM_INC) -o $@ $(STREAM_TEST_SRCS) $(VM_SRCS)
$(BUILD)/test_stream_mcu: $(STREAM_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Os $(STREAM_INC) -o $@ $(STREAM_TEST_SRCS) $(VM_SRCS)
# ble (pure C99): the "ble" port's Config, event queue, held events and
# Notify flow control over a fake BleHal on a real VM, in the host and MCU
# VM configs.
BLE_SRCS = runtime/ble/ble.c
BLE_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/ble/test/*.c)
BLE_INC = -Iruntime/ble -Iruntime/stream -Iruntime/vm -Iruntime/net -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix
BLE_DEPS = $(BLE_SRCS) $(BLE_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/ble/*.h) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
test-ble: $(BUILD)/test_ble $(BUILD)/test_ble_mcu
$(BUILD)/test_ble
$(BUILD)/test_ble_mcu
$(BUILD)/test_ble: $(BLE_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -DGOGO_MAX_SOURCES=5u $(BLE_INC) -o $@ $(BLE_SRCS) $(BLE_TEST_SRCS) $(VM_SRCS)
$(BUILD)/test_ble_mcu: $(BLE_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -DGOGO_MAX_SOURCES=5u -Os $(BLE_INC) -o $@ $(BLE_SRCS) $(BLE_TEST_SRCS) $(VM_SRCS)
# screen (pure C99): the grid's operations, malformed and random sequences
# against guard words, the LCD renderer, and the "screen" port on a real VM
# (fake ScreenHw), in the host and MCU VM configs.
SCREEN_ALL_SRCS = $(wildcard runtime/screen/*.c) runtime/console/console.c runtime/console/font.c
SCREEN_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c $(wildcard runtime/screen/test/*.c)
SCREEN_INC = -Iruntime/screen -Iruntime/console -Iruntime/stream -Iruntime/vm -Iruntime/net -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix
SCREEN_DEPS = $(SCREEN_ALL_SRCS) $(SCREEN_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/screen/*.h) $(wildcard runtime/console/*.h) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
test-screen: $(BUILD)/test_screen $(BUILD)/test_screen_mcu
$(BUILD)/test_screen
$(BUILD)/test_screen_mcu
$(BUILD)/test_screen: $(SCREEN_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(SCREEN_INC) -o $@ $(SCREEN_ALL_SRCS) $(SCREEN_TEST_SRCS) $(VM_SRCS)
# The same tests under AddressSanitizer and UBSan (build/asan-ub: its own
# flags, so it does not rebuild build/asan's).
test-screen-asan:
$(MAKE) BUILD=build/asan-ub EXTRA_CFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -DGOGO_DEBUG=1" build/asan-ub/test_screen
build/asan-ub/test_screen
# The VM core's C tests (test_params' longest values among them) under
# ASan and UBSan: the host build with GOGO_DEBUG, the MCU build without
# (its arena has no room for the debug block headers, config.h).
test-c-asan:
$(MAKE) BUILD=build/asan-ub EXTRA_CFLAGS="-fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer -DGOGO_DEBUG=1" build/asan-ub/test_c
ASAN_OPTIONS=detect_leaks=0 build/asan-ub/test_c
$(MAKE) BUILD=build/asan-mcu EXTRA_CFLAGS="-fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer" build/asan-mcu/test_c_mcu
ASAN_OPTIONS=detect_leaks=0 build/asan-mcu/test_c_mcu
$(BUILD)/test_screen_mcu: $(SCREEN_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) -Os $(SCREEN_INC) -o $@ $(SCREEN_ALL_SRCS) $(SCREEN_TEST_SRCS) $(VM_SRCS)
# The FatFs backend (runtime/vfs/fat) over a RAM disk, with the vendored
# FatFs (platform/esp32s3/components/fatfs) built for the host with the
# Cardputer's options (runtime/vfs/fat/test/stub); host slots are 192
# bytes (64-bit pointers in FIL).
FATFS_DIR = platform/esp32s3/components/fatfs/src
FAT_TEST_SRCS = runtime/vfs/fat/test/test_fat.c runtime/vm/test/test_main.c runtime/vfs/fat/fat_be.c runtime/vfs/vfs.c runtime/vfs/path.c
test-fat: $(BUILD)/test_fat
$(BUILD)/test_fat
$(BUILD)/test_fat: $(FAT_TEST_SRCS) $(FATFS_DIR)/ff.c $(FATFS_DIR)/ffunicode.c $(wildcard runtime/vfs/fat/*.h) $(wildcard runtime/vfs/*.h) runtime/vm/test/test.h
@mkdir -p $(BUILD)/fatfs
$(CC) -std=gnu99 -O2 -g -w $(EXTRA_CFLAGS) -Iruntime/vfs/fat/test/stub -I$(FATFS_DIR) -c $(FATFS_DIR)/ff.c -o $(BUILD)/fatfs/ff.o
$(CC) -std=gnu99 -O2 -g -w $(EXTRA_CFLAGS) -Iruntime/vfs/fat/test/stub -I$(FATFS_DIR) -c $(FATFS_DIR)/ffunicode.c -o $(BUILD)/fatfs/ffunicode.o
$(CC) $(CFLAGS) -DGOGO_FS_SLOT_BYTES=192u -Iruntime/vfs/fat -Iruntime/vfs/fat/test/stub -I$(FATFS_DIR) -Iruntime/vfs -Iruntime/vm/test -Iruntime/vm -o $@ $(FAT_TEST_SRCS) $(BUILD)/fatfs/ff.o $(BUILD)/fatfs/ffunicode.o
# The LittleFS backend (runtime/vfs/lfs) over a RAM block device, with
# the LittleFS that the firmware build fetches (joltwallet/littlefs, a
# managed component; the repo does not carry it). Without it (no firmware
# built in this checkout yet) the test is skipped. Host slots are 192
# bytes (sizeof(Lf) with 64-bit pointers; 160 on the ESP32-S3).
LFS_DIR ?= platform/esp32s3/managed_components/joltwallet__littlefs/src/littlefs
ifneq ($(wildcard $(LFS_DIR)/lfs.c),)
LFS_TEST_SRCS = runtime/vfs/lfs/test/test_lfs.c runtime/vm/test/test_main.c runtime/vfs/lfs/lfs_be.c runtime/vfs/vfs.c runtime/vfs/path.c runtime/configsvc/configsvc.c
test-lfs: $(BUILD)/test_lfs
$(BUILD)/test_lfs
$(BUILD)/test_lfs: $(LFS_TEST_SRCS) $(LFS_DIR)/lfs.c $(LFS_DIR)/lfs_util.c $(wildcard runtime/vfs/lfs/*.h) $(wildcard runtime/vfs/*.h) $(wildcard runtime/configsvc/*.h) runtime/vm/test/test.h
@mkdir -p $(BUILD)/lfs
$(CC) -std=c99 -O2 -g -w $(EXTRA_CFLAGS) -DLFS_NO_MALLOC -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR -Dmalloc=gogo_lfs_malloc -Dfree=gogo_lfs_free -I$(LFS_DIR) -c $(LFS_DIR)/lfs.c -o $(BUILD)/lfs/lfs.o
$(CC) -std=c99 -O2 -g -w $(EXTRA_CFLAGS) -I$(LFS_DIR) -c $(LFS_DIR)/lfs_util.c -o $(BUILD)/lfs/lfs_util.o
$(CC) $(CFLAGS) -DGOGO_FS_SLOT_BYTES=192u -Iruntime/vfs/lfs -I$(LFS_DIR) -Iruntime/vfs -Iruntime/configsvc -Iruntime/vm/test -Iruntime/vm -o $@ $(LFS_TEST_SRCS) $(BUILD)/lfs/lfs.o $(BUILD)/lfs/lfs_util.o
else
test-lfs:
@echo "test-lfs: skipped (no LittleFS at $(LFS_DIR); a firmware build fetches it)"
endif
# The gpio driver (runtime/gpio) over a fake GpioHal on a real VM.
GPIO_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/gpio/test/test_gpio.c
test-gpio: $(BUILD)/test_gpio
$(BUILD)/test_gpio
$(BUILD)/test_gpio: $(GPIO_TEST_SRCS) $(VM_SRCS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h) $(PLAT_HDRS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iplatform/unix -o $@ $(GPIO_TEST_SRCS) $(VM_SRCS)
# The gogo-config protocol (runtime/configsvc, pure C99) against an
# in-memory store and the memfs backend as /flash.
CONFIGSVC_SRCS = runtime/configsvc/configsvc.c runtime/vfs/path.c runtime/vfs/test/memfs.c
test-configsvc: $(BUILD)/test_configsvc
$(BUILD)/test_configsvc
$(BUILD)/test_configsvc: $(CONFIGSVC_SRCS) runtime/configsvc/test/test_configsvc.c runtime/vm/test/test_main.c $(wildcard runtime/configsvc/*.h) $(wildcard runtime/vfs/*.h) $(wildcard runtime/vfs/test/*.h)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/configsvc -Iruntime/vfs -Iruntime/vfs/test -Iruntime/vm -Iruntime/vm/test -o $@ runtime/configsvc/test/test_configsvc.c runtime/vm/test/test_main.c $(CONFIGSVC_SRCS)
# The Wi-Fi provisioning messages (runtime/prov, the ESP32-S3 firmware's
# BLE provisioning): the protobuf codec against esp_prov.py's encoding.
test-prov: $(BUILD)/test_provmsg
$(BUILD)/test_provmsg
$(BUILD)/test_provmsg: runtime/prov/provmsg.c runtime/prov/provmsg.h runtime/prov/test/test_provmsg.c runtime/vm/test/test_main.c
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/prov -Iruntime/vm -Iruntime/vm/test -o $@ runtime/prov/test/test_provmsg.c runtime/vm/test/test_main.c runtime/prov/provmsg.c
# The host-directory backend (runtime/embed/fs_dir.c) against a temp dir:
# the vfs contract and the sandbox (symlinks, hard links, a swapped path).
test-fs-host: $(BUILD)/test_fs_host
$(BUILD)/test_fs_host
$(BUILD)/test_fs_host: platform/unix/test/test_fs_host.c runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/embed/fs_dir.c $(VFS_SRCS) $(VM_SRCS) $(wildcard runtime/vfs/*.h) $(PLAT_HDRS) $(wildcard runtime/vm/*.h) $(wildcard runtime/vm/test/*.h)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(VFS_INC) -Iruntime/embed -pthread -o $@ platform/unix/test/test_fs_host.c runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/embed/fs_dir.c $(VFS_SRCS) $(VM_SRCS)
# Embed mode (runtime/embed, runtime/include/gogo.h): the API, the post
# inbox and the POSIX host over the VM core alone (no board), against images
# compiled from runtime/embed/test/testdata (and the EMBED_EXAMPLES, whose
# output is compared with their embed.out). test-embed-tsan runs the same
# tests under ThreadSanitizer; test-embed-leaks checks that no memory leaks
# (LeakSanitizer on Linux, leaks(1) on macOS, where ASan has no leak check).
EMBED_SRCS = $(wildcard runtime/embed/*.c)
EMBED_TEST_SRCS = runtime/vm/test/test_main.c $(wildcard runtime/embed/test/*.c)
EMBED_PROGS = $(notdir $(wildcard runtime/embed/test/testdata/*))
# Examples run under a test host, their output compared with embed.out
# (hostecho) or with their expected.out (the rest, by test_multi.c: 8 VMs
# on 4 threads; hotload's modules go into $(BUILD)/embed/hotload-flash).
EMBED_EXAMPLES = hostecho many_idle httpparse hotload
EMBED_INC = -Iruntime/include -Iruntime/embed -Iruntime/vfs -Iruntime/vm -Iruntime/board -Iruntime/vm/test
$(BUILD)/test_embed: $(EMBED_SRCS) $(EMBED_TEST_SRCS) $(VM_CORE_SRCS) $(FLOATLIB_SRCS) $(VFS_SRCS) $(wildcard runtime/embed/*.h) $(wildcard runtime/include/*.h) $(wildcard runtime/vm/*.h) $(wildcard runtime/vfs/*.h) $(wildcard runtime/vm/test/*.h)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -DGOGO_EMBED $(EMBED_INC) -pthread -o $@ $(EMBED_TEST_SRCS) $(EMBED_SRCS) $(PARAMS_SRCS) $(VM_CORE_SRCS) $(FLOATLIB_SRCS) $(VFS_SRCS)
embed-images: gogo-cmd
@mkdir -p $(BUILD)/embed
for p in $(EMBED_PROGS); do $(BUILD)/gogo build $(COMPACT) runtime/embed/test/testdata/$$p -o $(BUILD)/embed/$$p.ggb || exit 1; done
for p in $(EMBED_EXAMPLES); do $(BUILD)/gogo build $(COMPACT) examples/$$p -o $(BUILD)/embed/$$p.ggb || exit 1; done
@mkdir -p $(BUILD)/embed/hotload-flash
for m in worker_v1 worker_v2; do $(BUILD)/gogo build $(COMPACT) examples/hotload/mods/$$m -o $(BUILD)/embed/hotload-flash/$$m.ggb || exit 1; done
test-embed: $(BUILD)/test_embed embed-images
GOGO_EMBED_IMAGES=$(BUILD)/embed $(BUILD)/test_embed
test-embed-tsan:
$(MAKE) BUILD=build/tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" build/tsan/test_embed embed-images
TSAN_OPTIONS="halt_on_error=1" GOGO_EMBED_IMAGES=build/tsan/embed build/tsan/test_embed
ifeq ($(shell uname -s),Darwin)
test-embed-leaks: $(BUILD)/test_embed embed-images
GOGO_EMBED_IMAGES=$(BUILD)/embed GOGO_EMBED_RACE_N=2000 leaks --atExit -- $(BUILD)/test_embed > $(BUILD)/embed/leaks.out 2>&1 || { cat $(BUILD)/embed/leaks.out; exit 1; }
grep -E "passed|leaks for" $(BUILD)/embed/leaks.out
else
test-embed-leaks:
$(MAKE) BUILD=build/asan EXTRA_CFLAGS="$(ASAN_FLAGS)" build/asan/test_embed embed-images
ASAN_OPTIONS=detect_leaks=1 GOGO_EMBED_IMAGES=build/asan/embed GOGO_EMBED_RACE_N=2000 build/asan/test_embed
endif
# libgogo.a: the embedding library (runtime/include/gogo.h). The VM core,
# vfs, stream and the embed layer, built as strict C99 (-pedantic) with
# -DGOGO_EMBED; no board, input, net or tls. Link it with -pthread.
# The objects are prelinked into one relocatable object (ld -r) that keeps
# only the gogo_* API global (an export list on Darwin, objcopy on ELF), so
# the library's internal functions never clash with the host's;
# tools/libsyms.sh checks that its globals are exactly the list in
# runtime/include/libgogo.syms, which must also be gogo.h's functions.
# libgogo-debug.a is the same objects archived as they are: on macOS the
# prelinked object's debug info lives in build/lib/*.o (ld -r keeps a debug
# map, not the DWARF), so a library copied elsewhere for debugging is that
# one; its internal symbols are not hidden.
LIB_SRCS = $(VM_CORE_SRCS) $(FLOATLIB_SRCS) $(VFS_SRCS) $(STREAM_SRCS) $(EMBED_SRCS) $(PARAMS_SRCS)
LIB_OBJS = $(foreach f,$(LIB_SRCS),$(BUILD)/lib/$(subst /,_,$(patsubst runtime/%.c,%,$(f))).o)
LIB_CFLAGS = -std=c99 -pedantic -Wall -Wextra -Werror -O2 -g -fvisibility=hidden -DGOGO_EMBED -DGOGO_BUILD_UNIX_MS=$(BUILD_UNIX_MS)LL $(EXTRA_CFLAGS) \
-Iruntime/include -Iruntime/embed -Iruntime/vm -Iruntime/vfs -Iruntime/stream -Iruntime/board
LIB_HDRS = $(wildcard runtime/include/*.h) $(wildcard runtime/board/params.h) $(wildcard runtime/embed/*.h) $(wildcard runtime/vm/*.h) $(wildcard runtime/vfs/*.h) $(wildcard runtime/stream/*.h)
LIB_LD ?= ld
LIB_OBJCOPY ?= objcopy
lib: $(BUILD)/libgogo.a $(BUILD)/libgogo-debug.a
$(BUILD)/libgogo.o: $(LIB_OBJS)
ifeq ($(shell uname -s),Darwin)
@echo '_gogo_*' > $(BUILD)/lib/exports.txt
$(LIB_LD) -r -exported_symbols_list $(BUILD)/lib/exports.txt -o $@ $(LIB_OBJS)
else
$(LIB_LD) -r -o $@ $(LIB_OBJS)
$(LIB_OBJCOPY) -w --keep-global-symbol='gogo_*' $@
endif
$(BUILD)/libgogo.a: $(BUILD)/libgogo.o runtime/include/gogo.h runtime/include/libgogo.syms
@rm -f $@
ar rcs $@ $(BUILD)/libgogo.o
tools/libsyms.sh $@ runtime/include/libgogo.syms runtime/include/gogo.h runtime/include/gogo_posix.h || { rm -f $@; exit 1; }
tools/globals.sh --objects $@ || { rm -f $@; exit 1; }
$(BUILD)/libgogo-debug.a: $(LIB_OBJS) runtime/include/libgogo.syms
@rm -f $@
ar rcs $@ $(LIB_OBJS)
tools/libsyms.sh --subset $@ runtime/include/libgogo.syms || { rm -f $@; exit 1; }
tools/globals.sh --objects $@ || { rm -f $@; exit 1; }
define LIB_OBJ_RULE
$(BUILD)/lib/$(subst /,_,$(patsubst runtime/%.c,%,$(1))).o: $(1) $(LIB_HDRS)
@mkdir -p $(BUILD)/lib
$(CC) $(LIB_CFLAGS) -c $(1) -o $$@
endef
$(foreach f,$(LIB_SRCS),$(eval $(call LIB_OBJ_RULE,$(f))))
# A host defining functions named like libgogo's internal ones links
# against libgogo.a and runs an image (the names must exist in the library,
# else the test proves nothing). It uses only the stable API: compiled with
# GOGO_EXPERIMENTAL as a deprecation, any experimental use would fail it.
CLASH_SYMS = msg_free heap_alloc vm_step bytes_new port_open
$(BUILD)/libgogo_clash: runtime/embed/test/clash/main.c $(wildcard runtime/include/*.h) $(BUILD)/libgogo.a
$(CC) -std=c99 -pedantic -Wall -Wextra -Werror -O2 $(EXTRA_CFLAGS) -Iruntime/include \
'-DGOGO_EXPERIMENTAL=__attribute__((deprecated("experimental")))' -o $@ $< $(BUILD)/libgogo.a -pthread
test-libgogo: $(BUILD)/libgogo_clash $(BUILD)/libgogo-debug.a gogo-cmd
for s in $(CLASH_SYMS); do nm -g $(BUILD)/libgogo-debug.a | grep -Eq " T _?$$s$$" || { echo "test-libgogo: $$s is not in the library"; exit 1; }; done
$(BUILD)/gogo build $(COMPACT) examples/many_idle -o $(BUILD)/libgogo_clash.ggb
$(BUILD)/libgogo_clash $(BUILD)/libgogo_clash.ggb > $(BUILD)/libgogo_clash.out
cmp $(BUILD)/libgogo_clash.out examples/many_idle/expected.out
# gogotools/embed, the Go binding over libgogo.a (build tag libgogo):
# vet, its tests, and the tests again under the race detector. cgo links
# $(BUILD)/libgogo.a (put ahead of the caller's CGO_LDFLAGS); go does not
# hash a C archive, so the archive's checksum goes into a link flag
# (GOBIND_FLAGS) to make go relink what it built against an older one.
GOBIND = CGO_LDFLAGS="-L$(abspath $(BUILD)) $$CGO_LDFLAGS" go
GOBIND_FLAGS = -tags libgogo -ldflags="-X=gogotools/embed.libgogoSum=$$(cksum < $(BUILD)/libgogo.a | tr -d ' ')"
test-gobind: $(BUILD)/libgogo.a
$(GOBIND) vet -tags libgogo ./embed/... ./examples/embed-go
$(GOBIND) test $(GOBIND_FLAGS) -count=1 -timeout 120s ./embed/
$(GOBIND) test $(GOBIND_FLAGS) -count=1 -timeout 120s -race ./embed/
# libgogoc.a: the compiler as a C library (embed/gogoc/gogoc.h), a Go
# c-archive prelinked so that only the gogoc_* functions are global
# (tools/libgogoc.sh, which checks them against embed/gogoc/libgogoc.syms).
# It carries the Go runtime. It is rebuilt when a Go source it is made of
# changes (the compiler, the gogo libraries it embeds, the embed package):
# go's archive differs at every build, so go cannot decide that alone. test-gogoc links it beside libgogo.a in a C program
# that compiles source and runs it, and that defines functions named like
# the Go runtime's C symbols.
libgogoc: $(BUILD)/libgogoc.a
GOGOC_SRCS = go.mod $(shell find compiler lib embed -name '*.go' -o -name '*.gg' -o -name '*.[ch]') tools/libgogoc.sh
$(BUILD)/libgogoc.a: $(GOGOC_SRCS)
LIB_LD='$(LIB_LD)' LIB_OBJCOPY='$(LIB_OBJCOPY)' tools/libgogoc.sh $(BUILD)
$(BUILD)/gogoc/test_gogoc: embed/gogoc/test/test_gogoc.c embed/gogoc/gogoc.h $(wildcard runtime/include/*.h) $(BUILD)/libgogoc.a $(BUILD)/libgogo.a
$(CC) -std=c99 -pedantic -Wall -Wextra -Werror -O2 -g $(EXTRA_CFLAGS) -Iembed/gogoc -Iruntime/include -o $@ $< $(BUILD)/libgogoc.a $(BUILD)/libgogo.a -pthread
test-gogoc: $(BUILD)/gogoc/test_gogoc
$(BUILD)/gogoc/test_gogoc examples/many_idle
# examples/embed-c: host programs on libgogo.a, compile.c on libgogoc.a
# too; examples/embed-go: a Go host (examples/embed-c/test.sh runs them
# and compares their output).
EXAMPLE_EMBED_PROGS = main post port compile
EXAMPLE_EMBED_BINS = $(addprefix $(BUILD)/embed-c/,$(EXAMPLE_EMBED_PROGS)) $(BUILD)/embed-go
$(BUILD)/embed-c/%: examples/embed-c/%.c $(wildcard runtime/include/*.h) $(BUILD)/libgogo.a
@mkdir -p $(BUILD)/embed-c
$(CC) -std=c99 -pedantic -Wall -Wextra -Werror -O2 -g $(EXTRA_CFLAGS) -Iruntime/include -o $@ $< $(BUILD)/libgogo.a -pthread
$(BUILD)/embed-c/compile: examples/embed-c/compile.c embed/gogoc/gogoc.h $(wildcard runtime/include/*.h) $(BUILD)/libgogoc.a $(BUILD)/libgogo.a
@mkdir -p $(BUILD)/embed-c
$(CC) -std=c99 -pedantic -Wall -Wextra -Werror -O2 -g $(EXTRA_CFLAGS) -Iembed/gogoc -Iruntime/include -o $@ $< $(BUILD)/libgogoc.a $(BUILD)/libgogo.a -pthread
$(BUILD)/embed-go: $(BUILD)/libgogo.a FORCE
$(GOBIND) build $(GOBIND_FLAGS) -o $@ ./examples/embed-go
example-embed: $(EXAMPLE_EMBED_BINS) gogo-cmd
examples/embed-c/test.sh $(BUILD)
# Board ports (runtime/board/board_ports.c): registration order, refusals
# and their boot lines, open codes and posts from a thread, on a gogovm with
# the test drivers of runtime/board/test/ports (runtime/board/test/test.sh).
BOARD_TEST_DRIVERS = $(addprefix runtime/board/test/ports/,named.c dup.c refuser.c ticker.c burst.c pair.c) # in link order: dup.c after named.c
$(BUILD)/board-ports/gogovm: $(GOGOVM_DEPS) $(BOARD_TEST_DRIVERS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)/board-ports
$(call gogovm_with,$(BOARD_TEST_DRIVERS))
test-board-ports: $(BUILD)/board-ports/gogovm gogo-cmd
runtime/board/test/test.sh $(BUILD)
# The same under ThreadSanitizer: posts from the test drivers' threads
# against the VM thread (the inbox, posters, the ports host's malloc).
test-board-ports-tsan:
$(MAKE) BUILD=build/tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" build/tsan/board-ports/gogovm gogo-cmd
TSAN_OPTIONS="halt_on_error=1" runtime/board/test/test.sh build/tsan
# The ble port's phone tests (tests/ble, part of test-go) on a gogovm under
# ThreadSanitizer: the socket thread (ble_unix.c) against the VM thread.
test-ble-tsan:
$(MAKE) BUILD=build/tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" build/tsan/gogovm
TSAN_OPTIONS="halt_on_error=1" GOGO_VM=$(CURDIR)/build/tsan/gogovm go test -count=1 ./tests/ble/
# examples/dice-driver: a third-party port driver on gogo.h alone (book
# chapter 22), an ESP-IDF component (dice/). test.sh runs its program on
# a gogovm built with the component (DICE_DRIVER: make vm DRIVERS=...
# does the same for $(BUILD)/gogovm) and in an embedding host that
# registers the same driver (host.c on libgogo.a), compares each output
# with driver.out, checks that a plain gogovm refuses the image and that
# the book's C and Go blocks are cut from the sources.
DICE_DRIVER = examples/dice-driver/dice/dice.c examples/dice-driver/dice/dice_port.c
$(BUILD)/dice-driver/gogovm: $(GOGOVM_DEPS) $(DICE_DRIVER) examples/dice-driver/dice/dice.h $(FLAGS_STAMP)
@mkdir -p $(BUILD)/dice-driver
$(call gogovm_with,$(DICE_DRIVER))
# The host and its driver use only the stable API, the driver API
# included (stable from v0.3): GOGO_EXPERIMENTAL as a deprecation would
# fail the build on any experimental use.
$(BUILD)/dice-driver/dice-host: examples/dice-driver/host.c examples/dice-driver/dice/dice.c examples/dice-driver/dice/dice.h $(wildcard runtime/include/*.h) $(BUILD)/libgogo.a
@mkdir -p $(BUILD)/dice-driver
$(CC) -std=c99 -pedantic -Wall -Wextra -Werror -O2 -g $(EXTRA_CFLAGS) -Iruntime/include -Iexamples/dice-driver \
'-DGOGO_EXPERIMENTAL=__attribute__((deprecated("experimental")))' \
-o $@ examples/dice-driver/host.c examples/dice-driver/dice/dice.c $(BUILD)/libgogo.a -pthread
example-driver: $(BUILD)/dice-driver/gogovm $(BUILD)/dice-driver/dice-host vm server gogo-cmd
examples/dice-driver/test.sh $(BUILD)
# Console text grid + font lookup (runtime/console), host build.
CONSOLE_SRCS = runtime/console/console.c runtime/console/font.c
test-console: $(BUILD)/test_console $(BUILD)/test_console_ascii
$(BUILD)/test_console
$(BUILD)/test_console_ascii
$(BUILD)/test_console: runtime/console/test/test_console.c runtime/vm/test/test_main.c runtime/vm/test/test.h $(CONSOLE_SRCS) $(wildcard runtime/console/*.h) runtime/console/font/gogo12.font
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/console -Iruntime/vm/test -Iruntime/vm -o $@ runtime/console/test/test_console.c runtime/vm/test/test_main.c $(CONSOLE_SRCS)
# The same tests against the ASCII-only font (GOGO_FONT_CJK=n firmware).
$(BUILD)/test_console_ascii: runtime/console/test/test_console.c runtime/vm/test/test_main.c runtime/vm/test/test.h $(CONSOLE_SRCS) $(wildcard runtime/console/*.h) runtime/console/font/gogo12-ascii.font
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -DFONT_ASCII -DFONT_PATH='"runtime/console/font/gogo12-ascii.font"' -Iruntime/console -Iruntime/vm/test -Iruntime/vm -o $@ runtime/console/test/test_console.c runtime/vm/test/test_main.c $(CONSOLE_SRCS)
# Render a text file through the console grid and font into a PPM:
# make console-ppm TEXT=runtime/console/font/sample.txt OUT=build/sample.ppm
TEXT ?= runtime/console/font/sample.txt
OUT ?= $(BUILD)/console.ppm
$(BUILD)/console_ppm: runtime/console/tools/console_ppm.c $(CONSOLE_SRCS) $(wildcard runtime/console/*.h)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/console -o $@ runtime/console/tools/console_ppm.c $(CONSOLE_SRCS)
console-ppm: $(BUILD)/console_ppm
$(BUILD)/console_ppm runtime/console/font/gogo12.font $(TEXT) $(OUT)
# docs/bytecode.md from the structured comments in runtime/vm/opcodes.h
# (tools/bcdoc); go test ./... (test-go) fails when it is stale.
bytecode-doc:
go run ./tools/bcdoc
# runtime/vm/test/float_corpus.h: Go's FormatFloat / println output for a
# corpus of floats (tools/floatcorpus), which test_float.c checks gogo
# against; go test ./... (test-go) fails when it is stale.
float-corpus:
go run ./tools/floatcorpus
test-go: vm server $(BUILD)/gogovm_mcu $(BUILD)/gogovm_nofloat
GOGO_SERVER=$(CURDIR)/$(BUILD)/gogo-server GOGO_VM=$(CURDIR)/$(BUILD)/gogovm GOGO_VM_MCU=$(CURDIR)/$(BUILD)/gogovm_mcu GOGO_VM_NOFLOAT=$(CURDIR)/$(BUILD)/gogovm_nofloat go test ./...
# gogovm without floating point (-DGOGO_FLOAT=0): the goldens marked
# `nofloat` run on it (an image that uses floats is refused at load).
$(BUILD)/gogovm_nofloat: $(VM_SRCS) $(MAIN_SRCS) $(wildcard runtime/vm/*.h) $(PLAT_HDRS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(BOARD_PORTS_FLAGS) $(GOGOVM_FLAGS) $(GOGOVM_SOURCES) -DGOGO_FLOAT=0 -Iruntime/vm -Iruntime/net -Iruntime/vfs -Iruntime/input -Iruntime/stream -Iruntime/screen -Iruntime/console -Iruntime/embed -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -o $@ $(VM_SRCS) $(MAIN_SRCS)
# The standard library (lib/*/*.gg) on the host toolchain, copied into a
# temporary Go module gogo by tests/lib_test.go: vet (stdmethods off: gogo's
# bytes.Buffer.WriteByte deliberately returns no error) and its host tests
# (gogo/irproto, build tag gogohost). Part of test-go (go test ./...).
test-lib:
go test -count=1 -run '^TestLibHost$$' ./tests/
# The network scenarios (dhcp, dns, ...) on a VM with the MCU actor memory
# limit (16 KB per actor): the library actors must fit.
$(BUILD)/gogovm_mcu: $(VM_SRCS) $(MAIN_SRCS) $(wildcard runtime/vm/*.h) $(PLAT_HDRS) $(TLS_DEPS)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(MCU_FLAGS) $(BOARD_PORTS_FLAGS) $(GOGOVM_FLAGS) $(GOGOVM_SOURCES) -DGOGO_HOST_PORTS=16 -DGOGO_HOST_LINKS=8 $(TLS_CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/vfs -Iruntime/input -Iruntime/stream -Iruntime/screen -Iruntime/console -Iruntime/embed -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -o $@ $(VM_SRCS) $(MAIN_SRCS) $(TLS_LINK)
test-net-mcu: $(BUILD)/gogovm_mcu
GOGO_VM=$(CURDIR)/$(BUILD)/gogovm_mcu go test -count=1 ./tests/net/
# The net and tls scenarios on a gogovm (and its mbedTLS) built with
# AddressSanitizer (build/asan). On macOS leaks are not reported (no
# LeakSanitizer); the tls tests check the TLS heap returns to 0 instead.
# GOGO_DEBUG=1 (runtime/vm/config.h): the sanitizer builds also check
# the runtime's internal invariants (GOGO_ASSERT).
ASAN_FLAGS = -fsanitize=address -fno-omit-frame-pointer -DGOGO_DEBUG=1
# ASAN_OPTIONS (the caller's, then these):
# - detect_leaks=0: LeakSanitizer (Linux only) would report the C suites'
# fixtures and gogovm's exit, which do not free their Vm; test-embed-leaks
# checks the embedding API for leaks.
# - detect_stack_use_after_return=0: with gcc's ASan it is on, and its fake
# stack frames make mbedTLS's many small calls about 60 times slower (1 MB
# over TLS: 0.18 s without, 10.6 s with, on Linux arm64), too slow for
# the net tests' real-time limits. clang's ASan on macOS leaves it off too.
TLS_ASAN_OPTIONS = $${ASAN_OPTIONS:+$$ASAN_OPTIONS:}detect_leaks=0:detect_stack_use_after_return=0
test-tls-asan:
$(MAKE) BUILD=build/asan EXTRA_CFLAGS="$(ASAN_FLAGS)" build/asan/gogovm build/asan/test_net build/asan/test_tls
ASAN_OPTIONS="$(TLS_ASAN_OPTIONS)" build/asan/test_net
ASAN_OPTIONS="$(TLS_ASAN_OPTIONS)" build/asan/test_tls
ASAN_OPTIONS="$(TLS_ASAN_OPTIONS)" GOGO_VM=$(CURDIR)/build/asan/gogovm go test -count=1 ./tests/net/ ./tests/dist/
# Distributed actors under AddressSanitizer and UndefinedBehaviorSanitizer
# (build/san): tests/dist, its Go peer sending malformed and random frames
# ($GOGO_DIST_FUZZ of them) at the node port's codec.
SAN_FLAGS = -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer -DGOGO_DEBUG=1
# runtime/dist's SHA-256 and HMAC-SHA-256 against known answers.
# hostnet's socket options read back with getsockopt (keepalive at the
# MCU stack's timings), and none with keepalive built off.
test-sockopts: $(BUILD)/test_sockopts $(BUILD)/test_sockopts_off
$(BUILD)/test_sockopts
$(BUILD)/test_sockopts_off
$(BUILD)/test_sockopts: platform/unix/test/test_sockopts.c platform/unix/sockopts.c platform/unix/sockopts.h runtime/net/net_keepalive.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iplatform/unix -Iruntime/net -o $@ platform/unix/test/test_sockopts.c platform/unix/sockopts.c
$(BUILD)/test_sockopts_off: platform/unix/test/test_sockopts.c platform/unix/sockopts.c platform/unix/sockopts.h runtime/net/net_keepalive.h
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -DGOGO_NET_KEEPALIVE_IDLE_MS=0 -Iplatform/unix -Iruntime/net -o $@ platform/unix/test/test_sockopts.c platform/unix/sockopts.c
DIST_FAILURE_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c runtime/dist/test/test_failure.c runtime/dist/hmac.c
test-dist-c: $(BUILD)/test_hmac $(BUILD)/test_dist_failure $(BUILD)/test_dist_failure_mcu $(BUILD)/test_carrier
$(BUILD)/test_hmac
$(BUILD)/test_dist_failure
$(BUILD)/test_dist_failure_mcu
$(BUILD)/test_carrier
CARRIER_TEST_SRCS = runtime/vm/test/test_main.c runtime/vm/test/test_host.c platform/unix/test/test_carrier.c platform/unix/sockopts.c $(DIST_SRCS) $(SERVER_REACTOR_SRCS)
$(BUILD)/test_carrier: $(CARRIER_TEST_SRCS) platform/unix/hostnet.c $(VM_SRCS) $(PLAT_HDRS) $(wildcard runtime/vm/*.h)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/vm/test -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -pthread -o $@ $(CARRIER_TEST_SRCS) $(VM_SRCS)
.PHONY: test-hostnet test-hostnet-san test-hostnet-tsan
# Host socket instance isolation is part of the standard regression.
test: test-hostnet
.PHONY: bench-runtime
bench-runtime: $(BUILD)/bench_vm vm
GOGO_VM=$(CURDIR)/$(BUILD)/gogovm go run ./tools/runtimebench -core $(BUILD)/bench_vm $(BENCH_ARGS)
$(BUILD)/bench_vm: runtime/server/bench/bench_vm.c runtime/dist/dist.c runtime/dist/hmac.c $(VM_SRCS) $(PLAT_HDRS) $(wildcard runtime/vm/*.h) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/vm -Iruntime/net -Iruntime/stream -Iruntime/gpio -Iruntime/board -Iruntime/dist -Iplatform/unix -pthread -o $@ runtime/server/bench/bench_vm.c runtime/dist/hmac.c $(VM_SRCS)
# Peer runtime matrix (tools/peerbench; docs/plans/2026-11-30-peer-performance.md).
# PEERBENCH_ARGS, e.g. -matrix full -reps 2 -out build/peerbench.jsonl.
.PHONY: peer-bench bench-peer
peer-bench: server gogo-cmd
$(BUILD)/gogo build runtime/server/bench/peer -o $(BUILD)/peer-bench.ggb
bench-peer: peer-bench
go run ./tools/peerbench $(PEERBENCH_ARGS)
.PHONY: test-server test-server-san test-server-tsan test-dist-reactor
# LeakSanitizer exists only on Linux; Apple's ASan aborts if asked for it.
LEAK_CHECK := detect_leaks=$(if $(filter Darwin,$(shell uname -s)),0,1)
SERVER_PEER_HOST_SRCS = runtime/server/peer_config_posix.c runtime/server/peer_host_posix.c $(PEER_SESSION_SRCS)
# Optional host-only TLS adapter. Default/MCU builds do not acquire OpenSSL.
# Without pkg-config (a stock macOS), Homebrew's openssl@3 is used if present.
OPENSSL_BREW := $(if $(shell command -v pkg-config),,$(shell brew --prefix openssl@3 2>/dev/null))
PEER_TLS_CFLAGS ?= $(if $(OPENSSL_BREW),-I$(OPENSSL_BREW)/include,$(shell pkg-config --cflags openssl))
PEER_TLS_LIBS ?= $(if $(OPENSSL_BREW),-L$(OPENSSL_BREW)/lib -lssl -lcrypto,$(shell pkg-config --libs openssl))
SERVER_PEER_TLS_SRCS = runtime/server/peer_tls_openssl.c runtime/server/peer_config_posix.c $(PEER_SRCS)
.PHONY: test-peer-tls test-peer-tls-san test-peer-tls-tsan
$(BUILD)/test_peer_tls: runtime/server/test/test_peer_tls.c runtime/server/test/peer_tls_fixture.h $(SERVER_PEER_TLS_SRCS) $(SERVER_REACTOR_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(PEER_TLS_CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_tls.c $(SERVER_PEER_TLS_SRCS) $(SERVER_REACTOR_SRCS) $(PEER_TLS_LIBS)
test-peer-tls: $(BUILD)/test_peer_tls
$(BUILD)/test_peer_tls
test-peer-tls-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-tls-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-tls
test-peer-tls-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-tls-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-tls
SERVER_PEER_NETWORK_SRCS = runtime/server/peer_network_posix.c runtime/dist/peer/heartbeat.c $(SERVER_PEER_HOST_SRCS) $(SERVER_REACTOR_SRCS)
.PHONY: test-peer-discovery
SERVER_PEER_DISCOVERY_SRCS = runtime/server/peer_discovery.c runtime/dist/peer/members.c
$(BUILD)/test_peer_discovery: runtime/server/test/test_peer_discovery.c runtime/server/test/peer_tls_fixture.h $(SERVER_PEER_DISCOVERY_SRCS) $(SERVER_PEER_TLS_SRCS) $(SERVER_REACTOR_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(PEER_TLS_CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_discovery.c $(SERVER_PEER_DISCOVERY_SRCS) $(SERVER_PEER_TLS_SRCS) $(SERVER_REACTOR_SRCS) $(PEER_TLS_LIBS)
test-peer-discovery: $(BUILD)/test_peer_discovery
$(BUILD)/test_peer_discovery
.PHONY: test-peer-tls-network test-peer-tls-network-san test-peer-tls-network-tsan
$(BUILD)/test_peer_tls_network: runtime/server/test/test_peer_tls_network.c runtime/server/test/peer_tls_fixture.h runtime/server/peer_tls_openssl.c $(SERVER_PEER_DISCOVERY_SRCS) $(SERVER_PEER_NETWORK_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $(PEER_TLS_CFLAGS) -DGOGO_PEER_TLS=1 -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_tls_network.c runtime/server/peer_tls_openssl.c $(SERVER_PEER_DISCOVERY_SRCS) $(SERVER_PEER_NETWORK_SRCS) $(PEER_TLS_LIBS)
test-peer-tls-network: $(BUILD)/test_peer_tls_network
$(BUILD)/test_peer_tls_network
test-peer-tls-network-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-tls-network-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-tls-network
test-peer-tls-network-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-tls-network-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-tls-network
.PHONY: test-peer-heartbeat test-peer-heartbeat-san test-peer-heartbeat-tsan
test: test-peer-heartbeat
$(BUILD)/test_peer_heartbeat: runtime/dist/peer/test/test_heartbeat.c runtime/dist/peer/heartbeat.c $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -o $@ runtime/dist/peer/test/test_heartbeat.c runtime/dist/peer/heartbeat.c
$(BUILD)/test_peer_heartbeat_net: runtime/server/test/test_peer_heartbeat.c runtime/server/test/peer_host_fixture.h $(SERVER_PEER_NETWORK_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_heartbeat.c $(SERVER_PEER_NETWORK_SRCS)
test-peer-heartbeat: $(BUILD)/test_peer_heartbeat $(BUILD)/test_peer_heartbeat_net
$(BUILD)/test_peer_heartbeat
$(BUILD)/test_peer_heartbeat_net
test-peer-heartbeat-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-heartbeat-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-heartbeat
test-peer-heartbeat-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-heartbeat-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-heartbeat
SERVER_PEER_MUX_SRCS = runtime/server/peer_mux.c $(SERVER_PEER_NETWORK_SRCS)
.PHONY: test-peer-mux test-peer-mux-san test-peer-mux-tsan
test: test-peer-mux
$(BUILD)/test_peer_mux: runtime/server/test/test_peer_mux.c runtime/server/test/peer_host_fixture.h $(SERVER_PEER_MUX_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_mux.c $(SERVER_PEER_MUX_SRCS)
test-peer-mux: $(BUILD)/test_peer_mux
$(BUILD)/test_peer_mux
test-peer-mux-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-mux-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-mux
test-peer-mux-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-mux-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-mux
.PHONY: test-peer-network test-peer-network-san test-peer-network-tsan
test: test-peer-network
$(BUILD)/test_peer_network: runtime/server/test/test_peer_network.c runtime/server/test/peer_host_fixture.h $(SERVER_PEER_NETWORK_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_network.c $(SERVER_PEER_NETWORK_SRCS)
test-peer-network: $(BUILD)/test_peer_network
$(BUILD)/test_peer_network
test-peer-network-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-network-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-network
test-peer-network-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-network-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-network
.PHONY: test-peer-host test-peer-host-san test-peer-host-tsan
test: test-peer-host
$(BUILD)/test_peer_host: runtime/server/test/test_peer_host.c runtime/server/test/peer_host_fixture.h $(SERVER_PEER_HOST_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_host.c $(SERVER_PEER_HOST_SRCS)
$(BUILD)/test_peer_host_fault: runtime/server/test/test_peer_host_fault.c runtime/server/test/peer_host_fixture.h $(SERVER_PEER_HOST_SRCS) $(SERVER_HDRS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_peer_host_fault.c runtime/server/peer_config_posix.c $(PEER_SESSION_SRCS)
test-peer-host: $(BUILD)/test_peer_host $(BUILD)/test_peer_host_fault
$(BUILD)/test_peer_host
$(BUILD)/test_peer_host_fault
test-peer-host-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-host-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-host
test-peer-host-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/peer-host-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-peer-host
test-dist-reactor: $(BUILD)/gogovm $(BUILD)/gogovm_mcu
GOGO_DIST_REACTOR=1 GOGO_VM=$(CURDIR)/$(BUILD)/gogovm GOGO_VM_MCU=$(CURDIR)/$(BUILD)/gogovm_mcu go test -count=1 ./tests/dist/
# v1 wire compatibility across releases: the star with nodes of an older
# build (COMPAT_REV, default e3c625a6: the last commit before the peer
# runtime; its gogovm, gogovm_mcu and gogo CLI, built from `git archive` in
# $(BUILD)/compat) and of this one (tests/dist/compat_test.go). Needs the
# revision in the local clone (a shallow CI checkout lacks it).
COMPAT_REV ?= e3c625a6
.PHONY: test-dist-compat
test-dist-compat: $(BUILD)/gogovm $(BUILD)/gogovm_mcu
rm -rf $(BUILD)/compat && mkdir -p $(BUILD)/compat
git archive $(COMPAT_REV) | tar -x -C $(BUILD)/compat
$(MAKE) -C $(BUILD)/compat vm build/gogovm_mcu gogo-cmd
GOGO_VM_OLD=$(CURDIR)/$(BUILD)/compat/build/gogovm GOGO_VM_MCU_OLD=$(CURDIR)/$(BUILD)/compat/build/gogovm_mcu \
GOGO_CLI_OLD=$(CURDIR)/$(BUILD)/compat/build/gogo GOGO_VM=$(CURDIR)/$(BUILD)/gogovm GOGO_VM_MCU=$(CURDIR)/$(BUILD)/gogovm_mcu \
go test -count=1 -run '^TestCrossVersion' -v ./tests/dist/
# The host single-worker fallback: every tests/dist v1 node that runs on a
# plain gogovm (no VM flags or program arguments) runs instead as the one
# domain of gogo-server --star; boards on gogovm_mcu stay as they are.
.PHONY: test-dist-server1
test-dist-server1: server $(BUILD)/gogovm $(BUILD)/gogovm_mcu
GOGO_DIST_SERVER=$(CURDIR)/$(BUILD)/gogo-server GOGO_VM=$(CURDIR)/$(BUILD)/gogovm GOGO_VM_MCU=$(CURDIR)/$(BUILD)/gogovm_mcu go test -count=1 ./tests/dist/
test: test-server
test-server: $(BUILD)/test_server_budget $(BUILD)/test_server_inbox $(BUILD)/test_server_reactor
$(BUILD)/test_server_budget
$(BUILD)/test_server_inbox
$(BUILD)/test_server_reactor
$(BUILD)/test_server_reactor: runtime/server/test/test_reactor.c $(SERVER_REACTOR_SRCS) $(SERVER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_reactor.c $(SERVER_REACTOR_SRCS)
$(BUILD)/test_server_budget: runtime/server/test/test_budget.c $(SERVER_INBOX_SRCS) $(SERVER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_budget.c $(SERVER_INBOX_SRCS)
$(BUILD)/test_server_inbox: runtime/server/test/test_inbox.c $(SERVER_INBOX_SRCS) $(SERVER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_inbox.c $(SERVER_INBOX_SRCS)
test-server-san:
$(MAKE) BUILD=build/server-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-server
test-server-tsan:
$(MAKE) BUILD=build/server-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" build/server-tsan/test_server_budget build/server-tsan/test_server_inbox build/server-tsan/test_server_reactor
TSAN_OPTIONS=halt_on_error=1 build/server-tsan/test_server_budget
TSAN_OPTIONS=halt_on_error=1 build/server-tsan/test_server_inbox
TSAN_OPTIONS=halt_on_error=1 build/server-tsan/test_server_reactor
# Bounded blocking pool (runtime/server/blocking.h): host threads only.
SERVER_BLOCKING_SRCS = runtime/server/blocking_posix.c
.PHONY: test-server-blocking test-server-blocking-san test-server-blocking-tsan
test: test-server-blocking
$(BUILD)/test_server_blocking: runtime/server/test/test_blocking.c $(SERVER_BLOCKING_SRCS) $(SERVER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -Iruntime/server -pthread -o $@ runtime/server/test/test_blocking.c $(SERVER_BLOCKING_SRCS)
test-server-blocking: $(BUILD)/test_server_blocking
$(BUILD)/test_server_blocking
test-server-blocking-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/server-blocking-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-server-blocking
test-server-blocking-tsan:
TSAN_OPTIONS=halt_on_error=1 $(MAKE) BUILD=build/server-blocking-tsan EXTRA_CFLAGS="-fsanitize=thread $(TSAN_WNO)" test-server-blocking
test-hostnet: $(BUILD)/test_hostnet
$(BUILD)/test_hostnet
.PHONY: test-peer-c test-peer-san fuzz-peer
test: test-peer-c test-peer-session
.PHONY: test-peer-members test-peer-members-san fuzz-peer-members
test: test-peer-members
PEER_MEMBERS_SRCS = runtime/dist/peer/members.c runtime/dist/peer/protocol.c runtime/dist/hmac.c
$(BUILD)/test_peer_members: runtime/dist/peer/test/test_members.c $(PEER_MEMBERS_SRCS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) -o $@ runtime/dist/peer/test/test_members.c $(PEER_MEMBERS_SRCS)
test-peer-members: $(BUILD)/test_peer_members
$(BUILD)/test_peer_members
test-peer-members-san:
ASAN_OPTIONS=$(LEAK_CHECK) $(MAKE) BUILD=build/peer-members-san EXTRA_CFLAGS="$(SAN_FLAGS)" test-peer-members
$(BUILD)/fuzz_peer_members: runtime/dist/peer/test/fuzz_members.c $(PEER_MEMBERS_SRCS) $(PEER_HDRS) $(FLAGS_STAMP)
@mkdir -p $(BUILD)
clang $(CFLAGS) -g -fsanitize=fuzzer,address,undefined -o $(BUILD)/fuzz_peer_members runtime/dist/peer/test/fuzz_members.c $(PEER_MEMBERS_SRCS)
fuzz-peer-members: $(BUILD)/fuzz_peer_members
python3 runtime/dist/peer/test/members_vectors.py --corpus $(BUILD)/peer-members-corpus
ASAN_OPTIONS=$(LEAK_CHECK) $(BUILD)/fuzz_peer_members -max_len=16384 -max_total_time=$(FUZZ_SECONDS) $(BUILD)/peer-members-corpus
.PHONY: test-peer-session test-peer-session-san test-peer-session-tsan
$(BUILD)/test_peer_session: runtime/dist/peer/test/test_session.c runtime/dist/peer/test/session_fixture.h $(PEER_SESSION_SRCS) $(PEER_HDRS) $(FLAGS_STAMP)