Commit 81a19c22

81a19c22e328Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

Merge pull request #206 from ledsun/codex/parallel-test-results

[codex] Run tests in parallel

Details

Commit
81a19c22e328
Parent
5a321da268b9
Merge parent
89485fec5bf3

MakefilemodifiedView file

@@ -91,7 +91,7 @@
9191 PRISM_OBJ = $(patsubst $(PRISM_DIR)/src/%.c,build/prism/%.o,$(PRISM_SRC))
9292 PRISM_LIB = build/libprism.a
9393
94-.PHONY: all parse bootstrap codegen test bench clean install uninstall deps
94+.PHONY: all parse bootstrap codegen test test-run clean-test-results bench clean install uninstall deps
9595
9696 all: parse regexp spinel_codegen$(EXE)
9797
@@ -193,45 +193,69 @@
193193
194194 # ---- Test ----
195195
196-test: spinel_parse$(EXE) $(SP_RT_LIB) spinel_codegen$(EXE)
196+TESTS := $(wildcard test/*.rb)
197+TEST_TARGETS := $(patsubst test/%.rb,build/test-results/%.ok,$(TESTS))
198+
199+test: clean-test-results
200+ @$(MAKE) --no-print-directory test-run
201+
202+test-run: $(TEST_TARGETS)
197203 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
198- @total=$$(ls test/*.rb | wc -l); \
199- if [ -t 1 ]; then tty=1; else tty=0; fi; \
200- pass=0; fail=0; err=0; i=0; \
201- for f in test/*.rb; do \
202- i=$$((i+1)); \
203- bn=$$(basename "$$f" .rb); \
204- if [ "$$tty" = 1 ]; then printf '\r\033[K [%d/%d] %s' "$$i" "$$total" "$$bn"; fi; \
205- ./spinel_parse$(EXE) "$$f" /tmp/_sp_t.ast 2>/dev/null && \
206- ./spinel_codegen$(EXE) /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \
207- $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_t_bin$(EXE) 2>/dev/null; \
208- if [ $$? -eq 0 ]; then \
209- $(TIMEOUT10) $(REF_RUBY) "$$f" >/tmp/_sp_t_exp 2>/dev/null; \
210- ruby_rc=$$?; \
211- if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
212- $(TIMEOUT10) ruby "$$f" >/tmp/_sp_t_exp 2>/dev/null; \
213- fi; \
214- $(TIMEOUT10) /tmp/_sp_t_bin$(EXE) >/tmp/_sp_t_act 2>/dev/null; \
215- LC_ALL=C sed 's/\r$$//' /tmp/_sp_t_exp >/tmp/_sp_t_exp.n; \
216- LC_ALL=C sed 's/\r$$//' /tmp/_sp_t_act >/tmp/_sp_t_act.n; \
217- if cmp -s /tmp/_sp_t_exp.n /tmp/_sp_t_act.n; then \
218- pass=$$((pass+1)); \
219- else \
220- if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \
221- echo "FAIL: $$bn"; \
222- diff -u /tmp/_sp_t_exp.n /tmp/_sp_t_act.n 2>&1 | head -40; \
223- fail=$$((fail+1)); \
224- fi; \
225- else \
226- if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \
227- echo "ERR: $$bn"; err=$$((err+1)); \
204+ @if [ -t 1 ]; then printf '\n'; fi
205+ @pass=$$(grep -l '^PASS' build/test-results/*.ok 2>/dev/null | wc -l); \
206+ fail=$$(grep -l '^FAIL' build/test-results/*.ok 2>/dev/null | wc -l); \
207+ err=$$(grep -l '^ERR' build/test-results/*.ok 2>/dev/null | wc -l); \
208+ for f in build/test-results/*.ok; do \
209+ bn=$$(basename "$$f" .ok); \
210+ status=$$(cat "$$f"); \
211+ if [ "$$status" = FAIL ]; then \
212+ echo "FAIL: $$bn"; \
213+ head -40 "$$f.diff"; \
214+ elif [ "$$status" = ERR ]; then \
215+ echo "ERR: $$bn"; \
228216 fi; \
229217 done; \
230- if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \
231- rm -f /tmp/_sp_t.ast /tmp/_sp_t.c /tmp/_sp_t_bin$(EXE) /tmp/_sp_t_exp /tmp/_sp_t_act /tmp/_sp_t_exp.n /tmp/_sp_t_act.n; \
232218 echo "Tests: $$pass pass, $$fail fail, $$err error"; \
233219 if [ $$fail -ne 0 ] || [ $$err -ne 0 ]; then exit 1; fi
234220
221+build/test-results/%.ok: test/%.rb spinel_parse$(EXE) $(SP_RT_LIB) spinel_codegen$(EXE)
222+ @mkdir -p build/test-results
223+ @tmpdir=$$(mktemp -d /tmp/spinel-test.XXXXXX); \
224+ ast=$$tmpdir/test.ast; \
225+ cfile=$$tmpdir/test.c; \
226+ bin=$$tmpdir/test_bin$(EXE); \
227+ exp=$$tmpdir/expected; \
228+ act=$$tmpdir/actual; \
229+ rm -f "[email protected]"; \
230+ ./spinel_parse$(EXE) "$<" "$$ast" 2>/dev/null && \
231+ ./spinel_codegen$(EXE) "$$ast" "$$cfile" 2>/dev/null && \
232+ $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib "$$cfile" $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o "$$bin" 2>/dev/null; \
233+ if [ $$? -eq 0 ]; then \
234+ $(TIMEOUT10) $(REF_RUBY) "$<" >"$$exp" 2>/dev/null; \
235+ ruby_rc=$$?; \
236+ if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
237+ $(TIMEOUT10) ruby "$<" >"$$exp" 2>/dev/null; \
238+ fi; \
239+ $(TIMEOUT10) "$$bin" >"$$act" 2>/dev/null; \
240+ LC_ALL=C sed 's/\r$$//' "$$exp" >"$$exp.n"; \
241+ LC_ALL=C sed 's/\r$$//' "$$act" >"$$act.n"; \
242+ if cmp -s "$$exp.n" "$$act.n"; then \
243+ echo PASS > "$@"; \
244+ if [ -t 1 ]; then printf .; fi; \
245+ else \
246+ echo FAIL > "$@"; \
247+ diff -u "$$exp.n" "$$act.n" > "[email protected]" 2>&1 || true; \
248+ if [ -t 1 ]; then printf F; fi; \
249+ fi; \
250+ else \
251+ echo ERR > "$@"; \
252+ if [ -t 1 ]; then printf E; fi; \
253+ fi; \
254+ rm -rf "$$tmpdir"
255+
256+clean-test-results:
257+ @rm -rf build/test-results
258+
235259 bench: spinel_parse$(EXE) $(SP_RT_LIB) spinel_codegen$(EXE)
236260 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
237261 @total=$$(ls benchmark/*.rb | wc -l); \