interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / mk / osh.mk

161 lines · 10278 bytes Raw Blame History
1# osh shell core (aien-architecture#158). Picked up by `-include mk/*.mk`; not part of `all` or `test`.
2# src/osh/osh_lex.osc and osh_parse.osc are generated from the .osc.in templates and osh_layout.lst by osh_gen.sh
3# (checked in with their output); the drivers tests/osh/test_osh_lex.c and test_osh_parse.c run them in the OSC
4# interpreter and as native AArch64.
5# make osh-gen regenerate src/osh/osh_lex.osc, osh_parse.osc and osh_layout.h
6# make osh-gen-check regenerating gives byte-identical files
7# make test-osh-lex check + lexer driver, plain and ASan/UBSan (exact-size buffers); OSH_FUZZ=N (default 100000), OSH_FUZZ_SEED=S
8# make osh-bash-verify prove tests/osh/vectors/bash_vectors.tsv against real bash 5.2 (needs bash, not part of test-osh-lex)
9# make test-osh-parse check + parser driver (lexer + parser units, reference tokenizer + parser), plain and ASan/UBSan
10ifndef OSH_MK
11OSH_MK := 1
12.PHONY: osh-gen osh-gen-check test-osh-lex test-osh-parse test-osh-expand osh test-osh-e2e osh-bash-verify osh-bash-diff
13OSH_DIR = $(OUT_DIR)/osh
14OSH_FUZZ ?= 100000
15OSH_GEN = src/osh/osh_gen.sh
16OSH_GEN_ARGS = src/osh/osh_layout.lst src/osh/osh_lex.osc.in src/osh/osh_lex.osc src/osh/osh_layout.h
17OSH_GEN_ARGS_P = src/osh/osh_layout.lst src/osh/osh_parse.osc.in src/osh/osh_parse.osc src/osh/osh_layout.h
18OSH_GEN_ARGS_X = src/osh/osh_layout.lst src/osh/osh_expand.osc.in src/osh/osh_expand.osc src/osh/osh_layout.h
19OSH_SRCS = tests/osh/test_osh_lex.c src/osh/osh_lex_ref.c $(OSC_LIB)
20OSH_PSRCS = tests/osh/test_osh_parse.c src/osh/osh_lex_ref.c src/osh/osh_parse_ref.c $(OSC_LIB)
21OSH_HDRS = src/osh/osh_layout.h src/osh/osh_lex_ref.h src/osh/osh_parse_ref.h $(OSC_HDRS)
22OSH_FLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -Isrc -Isrc/compiler -Isrc/osh
23
24osh-gen:
25 sh $(OSH_GEN) gen $(OSH_GEN_ARGS)
26 sh $(OSH_GEN) gen $(OSH_GEN_ARGS_P)
27 sh $(OSH_GEN) gen $(OSH_GEN_ARGS_X)
28
29osh-bash-verify:
30 bash tests/osh/vectors/bash_verify.sh
31
32osh-gen-check:
33 sh $(OSH_GEN) check $(OSH_GEN_ARGS)
34 sh $(OSH_GEN) check $(OSH_GEN_ARGS_P)
35 sh $(OSH_GEN) check $(OSH_GEN_ARGS_X)
36
37$(OSH_DIR)/test_osh_lex: $(OSH_SRCS) $(OSH_HDRS)
38 @mkdir -p $(OSH_DIR)
39 $(CC) $(OSH_FLAGS) -O2 -o $@ $(OSH_SRCS)
40
41$(OSH_DIR)/test_osh_lex_asan: $(OSH_SRCS) $(OSH_HDRS)
42 @mkdir -p $(OSH_DIR)
43 $(CC) $(OSH_FLAGS) $(OSC_ASAN) -o $@ $(OSH_SRCS)
44
45$(OSH_DIR)/test_osh_parse: $(OSH_PSRCS) $(OSH_HDRS)
46 @mkdir -p $(OSH_DIR)
47 $(CC) $(OSH_FLAGS) -O2 -o $@ $(OSH_PSRCS)
48
49$(OSH_DIR)/test_osh_parse_asan: $(OSH_PSRCS) $(OSH_HDRS)
50 @mkdir -p $(OSH_DIR)
51 $(CC) $(OSH_FLAGS) $(OSC_ASAN) -o $@ $(OSH_PSRCS)
52
53test-osh-lex: osh-gen-check $(OSH_DIR)/test_osh_lex $(OSH_DIR)/test_osh_lex_asan
54 $(abspath $(OSH_DIR)/test_osh_lex) src/osh/osh_lex.osc tests/osh/vectors $(OSH_FUZZ) > $(OSH_DIR)/lex.out
55 @tail -12 $(OSH_DIR)/lex.out; tail -1 $(OSH_DIR)/lex.out | grep -q '^OSH_LEX_PASS$$'
56 $(abspath $(OSH_DIR)/test_osh_lex_asan) src/osh/osh_lex.osc tests/osh/vectors $(OSH_FUZZ) > $(OSH_DIR)/lex_asan.out
57 @tail -3 $(OSH_DIR)/lex_asan.out; tail -1 $(OSH_DIR)/lex_asan.out | grep -q '^OSH_LEX_PASS$$'
58 @echo "test-osh-lex: PASS (lexer unit only; interp + native + C reference + chunked + vectors + fuzz; plain and ASan/UBSan)"
59
60test-osh-parse: osh-gen-check $(OSH_DIR)/test_osh_parse $(OSH_DIR)/test_osh_parse_asan
61 $(abspath $(OSH_DIR)/test_osh_parse) src/osh/osh_lex.osc src/osh/osh_parse.osc tests/osh/vectors tests/osh/parse_vectors $(OSH_FUZZ) > $(OSH_DIR)/parse.out
62 @tail -14 $(OSH_DIR)/parse.out; tail -1 $(OSH_DIR)/parse.out | grep -q '^OSH_PARSE_PASS$$'
63 $(abspath $(OSH_DIR)/test_osh_parse_asan) src/osh/osh_lex.osc src/osh/osh_parse.osc tests/osh/vectors tests/osh/parse_vectors $(OSH_FUZZ) > $(OSH_DIR)/parse_asan.out
64 @tail -3 $(OSH_DIR)/parse_asan.out; tail -1 $(OSH_DIR)/parse_asan.out | grep -q '^OSH_PARSE_PASS$$'
65 @echo "test-osh-parse: PASS (lexer + parser units; interp + native + C reference lexer and parser + chunked + vectors + fuzz; plain and ASan/UBSan)"
66
67OSH_XSRCS = tests/osh/test_osh_expand.c src/osh/osh_lex_ref.c src/osh/osh_parse_ref.c src/osh/osh_expand_ref.c src/osh/host/osh_core.c src/osh/host/osh_codes.c src/osh/host/osh_req.c $(OSC_LIB)
68OSH_XHDRS = $(OSH_HDRS) src/osh/osh_expand_ref.h src/osh/host/osh_core.h src/osh/host/osh_host.h
69OSH_XFLAGS = $(OSH_FLAGS) -Isrc/osh/host -Isrc/runtime
70
71$(OSH_DIR)/test_osh_expand: $(OSH_XSRCS) $(OSH_XHDRS)
72 @mkdir -p $(OSH_DIR)
73 $(CC) $(OSH_XFLAGS) -O2 -o $@ $(OSH_XSRCS)
74
75$(OSH_DIR)/test_osh_expand_asan: $(OSH_XSRCS) $(OSH_XHDRS)
76 @mkdir -p $(OSH_DIR)
77 $(CC) $(OSH_XFLAGS) $(OSC_ASAN) -o $@ $(OSH_XSRCS)
78
79test-osh-expand: osh-gen-check $(OSH_DIR)/test_osh_expand $(OSH_DIR)/test_osh_expand_asan
80 $(abspath $(OSH_DIR)/test_osh_expand) src/osh/osh_lex.osc src/osh/osh_parse.osc src/osh/osh_expand.osc tests/osh/vectors $(OSH_FUZZ) > $(OSH_DIR)/expand.out
81 @tail -16 $(OSH_DIR)/expand.out; tail -1 $(OSH_DIR)/expand.out | grep -q '^OSH_EXPAND_PASS$$'
82 $(abspath $(OSH_DIR)/test_osh_expand_asan) src/osh/osh_lex.osc src/osh/osh_parse.osc src/osh/osh_expand.osc tests/osh/vectors $(OSH_FUZZ) > $(OSH_DIR)/expand_asan.out
83 @tail -3 $(OSH_DIR)/expand_asan.out; tail -1 $(OSH_DIR)/expand_asan.out | grep -q '^OSH_EXPAND_PASS$$'
84 @echo "test-osh-expand: PASS"
85
86OSH_UNIT_SRCS = src/osh/osh_lex.osc src/osh/osh_parse.osc src/osh/osh_expand.osc
87OSH_PROG_HOSTSRCS = $(wildcard src/osh/host/osh_*.c)
88OSH_BIN_SRCS = $(OSH_DIR)/osh_units.c $(filter-out src/osh/host/osh_codes.c,$(OSH_PROG_HOSTSRCS)) src/osh/host/osh_codes.c $(OSC_LIB) src/runtime/rx_caproot.c
89
90# the three unit sources become C arrays (od + sed, no scripting language)
91$(OSH_DIR)/osh_units.c: $(OSH_UNIT_SRCS)
92 @mkdir -p $(OSH_DIR)
93 { echo "#include <stddef.h>"; \
94 for u in lex parse expand; do \
95 echo "const unsigned char osh_unit_$$u[] = {"; \
96 od -An -v -tu1 src/osh/osh_$$u.osc | sed 's/^ *//; s/ */,/g; s/$$/,/'; \
97 echo "0};"; \
98 echo "const size_t osh_unit_$${u}_len = sizeof osh_unit_$$u - 1;"; \
99 done; } > $@
100
101$(OSH_DIR)/osh: $(OSH_BIN_SRCS) $(OSH_XHDRS) src/osh/host/osh_shell.h src/osh/host/osh_priv.h
102 $(CC) $(OSH_XFLAGS) -O2 -o $@ $(OSH_BIN_SRCS)
103
104osh: $(OSH_DIR)/osh
105
106$(OSH_DIR)/argprint: tests/osh/e2e/argprint.c
107 @mkdir -p $(OSH_DIR)
108 $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 -o $@ $<
109
110$(OSH_DIR)/test_osh_e2e: tests/osh/e2e/test_osh_e2e.c
111 @mkdir -p $(OSH_DIR)
112 $(CC) -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -o $@ $<
113
114test-osh-e2e: osh-gen-check $(OSH_DIR)/osh $(OSH_DIR)/argprint $(OSH_DIR)/test_osh_e2e
115 rm -rf $(abspath $(OSH_DIR))/state; XDG_STATE_HOME=$(abspath $(OSH_DIR))/state $(abspath $(OSH_DIR)/test_osh_e2e) $(abspath $(OSH_DIR)/osh) $(abspath $(OSH_DIR)/argprint) > $(OSH_DIR)/e2e.out
116 @tail -3 $(OSH_DIR)/e2e.out; tail -1 $(OSH_DIR)/e2e.out | grep -q '^OSH_E2E_PASS$$'
117 @echo "test-osh-e2e: PASS"
118
119# omega#344: osh against /usr/bin/bash case by case (stdout, stderr, status, files), then the negative control
120# (every expectation corrupted must be detected). Needs bash 5.2 at /usr/bin/bash.
121osh-bash-diff: $(OSH_DIR)/osh
122 bash tests/osh/bashdiff/bashdiff.sh $(abspath $(OSH_DIR)/osh) tests/osh/bashdiff/cases.txt
123 BASHDIFF_NEGCTL=1 bash tests/osh/bashdiff/bashdiff.sh $(abspath $(OSH_DIR)/osh) tests/osh/bashdiff/cases.txt
124
125# Core-only step trace (OSH-AIENOS-0): the lexer, parser and expander run over fixture scripts through osh_core_call, nothing
126# is executed. `make osh-trace` runs every tests/osh/trace/*.sh native AND interpreted, requires the two traces to be
127# identical, and requires them to equal the committed .trace file. `make osh-trace-gen` rewrites the .trace files.
128# Optional per fixture: tNN.status (fake pipeline statuses) and tNN.args (positionals); see tests/osh/osh_trace.c.
129.PHONY: osh-trace osh-trace-gen
130OSH_TRSRCS = tests/osh/osh_trace.c src/osh/host/osh_core.c src/osh/host/osh_codes.c $(OSC_LIB)
131
132$(OSH_DIR)/osh_trace: $(OSH_TRSRCS) $(OSH_XHDRS)
133 @mkdir -p $(OSH_DIR)
134 $(CC) $(OSH_XFLAGS) -O2 -o $@ $(OSH_TRSRCS)
135
136# Each trace must end with "event exit=" (the driver prints it last) and hold at least one other line: an
137# empty, cut-off or do-nothing trace never passes and is never written.
138# A .trace, .status or .args with no .sh fails. osh-trace-gen writes all traces to a scratch directory first and copies
139# only when every script passed.
140osh-trace-gen: osh-gen-check $(OSH_DIR)/osh_trace
141 @for x in tests/osh/trace/*.trace tests/osh/trace/*.status tests/osh/trace/*.args; do [ -e "$$x" ] || continue; [ -f "$${x%.*}.sh" ] || { echo "$@: $$x has no matching .sh"; exit 1; }; done; \
142 g=$(OSH_DIR)/trace-gen; rm -rf $$g; mkdir -p $$g; \
143 for f in tests/osh/trace/*.sh; do b=$$(basename $$f .sh); \
144 $(OSH_DIR)/osh_trace interp $(OSH_UNIT_SRCS) $$f > $$g/$$b.interp || exit 1; \
145 $(OSH_DIR)/osh_trace native $(OSH_UNIT_SRCS) $$f > $$g/$$b.native || exit 1; \
146 cmp $$g/$$b.interp $$g/$$b.native || { echo "osh-trace-gen: native and interpreter differ on $$f"; exit 1; }; \
147 { tail -n 1 $$g/$$b.native | grep -q '^event exit=' && grep -v '^event exit=' $$g/$$b.native | grep -q .; } || { echo "osh-trace-gen: empty or cut-off trace for $$f"; exit 1; }; \
148 done; \
149 for f in tests/osh/trace/*.sh; do b=$$(basename $$f .sh); cp $$g/$$b.native tests/osh/trace/$$b.trace || exit 1; done; \
150 echo "osh-trace-gen: wrote traces"
151
152osh-trace: osh-gen-check $(OSH_DIR)/osh_trace
153 @for x in tests/osh/trace/*.trace tests/osh/trace/*.status tests/osh/trace/*.args; do [ -e "$$x" ] || continue; [ -f "$${x%.*}.sh" ] || { echo "$@: $$x has no matching .sh"; exit 1; }; done; \
154 n=0; for f in tests/osh/trace/*.sh; do b=$$(basename $$f .sh); \
155 $(OSH_DIR)/osh_trace interp $(OSH_UNIT_SRCS) $$f > $(OSH_DIR)/$$b.interp || exit 1; \
156 $(OSH_DIR)/osh_trace native $(OSH_UNIT_SRCS) $$f > $(OSH_DIR)/$$b.native || exit 1; \
157 cmp $(OSH_DIR)/$$b.interp $(OSH_DIR)/$$b.native || { echo "osh-trace: native and interpreter differ on $$f"; exit 1; }; \
158 { tail -n 1 $(OSH_DIR)/$$b.native | grep -q '^event exit=' && grep -v '^event exit=' $(OSH_DIR)/$$b.native | grep -q .; } || { echo "osh-trace: empty or cut-off trace for $$f"; exit 1; }; \
159 cmp $(OSH_DIR)/$$b.native tests/osh/trace/$$b.trace || { echo "osh-trace: $$f differs from the committed trace"; exit 1; }; \
160 n=$$((n+1)); done; echo "osh-trace: PASS ($$n scripts, native == interpreter == committed trace)"
161endif