Commit e9810bca
e9810bca9387Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
build: temp-file harness for test/bench (binary-safe comparison)
The previous harness captured stdout into shell variables and normalized CRLF via 'tr -d "\r"'. Both steps are unsafe for binary output and break in three ways:
- Variable assignment truncates at the first NUL byte (POSIX shells can't store nulls), losing the rest of binary output.
- tr -d '\r' deletes ALL 0x0D bytes, not just trailing CR before LF, corrupting binary payloads where 0x0D is a valid byte.
- macOS BSD tr in a UTF-8 locale rejects non-UTF-8 byte sequences entirely with 'Illegal byte sequence', breaking PPM-emitting benchmarks (bm_ao_render.rb, bm_so_mandelbrot.rb).
Rewrite both targets to:
- Redirect program output directly to /tmp/sp{t,b}_{exp,act} files, never touching shell variables.
- Normalize line endings with 'LC_ALL=C sed s/\r$//', which only strips trailing CR before LF and is byte-oriented under LC_ALL=C (sidesteps the macOS tr regression cleanly).
- Compare with 'cmp -s' for byte-exact equality; on FAIL, render the diff with 'diff -u | head -40' (also handles binary files sensibly — diff prints 'Binary files differ' rather than a wall of garbage).
Closes #201 Closes #202
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- e9810bca9387
- Parent
- 8ca797f8e308
MakefilemodifiedView file
@@ -201,19 +201,20 @@
201201
./spinel_codegen$(EXE) /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \202202
$(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; \203203
if [ $$? -eq 0 ]; then \204-
expected=$$($(TIMEOUT10) $(REF_RUBY) "$$f" 2>/dev/null); \205-
if [ $$? -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \206-
expected=$$($(TIMEOUT10) ruby "$$f" 2>/dev/null); \204+
$(TIMEOUT10) $(REF_RUBY) "$$f" >/tmp/_sp_t_exp 2>/dev/null; \205+
ruby_rc=$$?; \206+
if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \207+
$(TIMEOUT10) ruby "$$f" >/tmp/_sp_t_exp 2>/dev/null; \207208
fi; \208-
actual=$$($(TIMEOUT10) /tmp/_sp_t_bin$(EXE) 2>/dev/null); \209-
expected=$$(printf "%s" "$$expected" | tr -d '\r'); \210-
actual=$$(printf "%s" "$$actual" | tr -d '\r'); \211-
if [ "$$expected" = "$$actual" ]; then \209+
$(TIMEOUT10) /tmp/_sp_t_bin$(EXE) >/tmp/_sp_t_act 2>/dev/null; \210+
LC_ALL=C sed 's/\r$$//' /tmp/_sp_t_exp >/tmp/_sp_t_exp.n; \211+
LC_ALL=C sed 's/\r$$//' /tmp/_sp_t_act >/tmp/_sp_t_act.n; \212+
if cmp -s /tmp/_sp_t_exp.n /tmp/_sp_t_act.n; then \212213
pass=$$((pass+1)); \213214
else \214215
if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \215216
echo "FAIL: $$bn"; \216-
printf '%s\n%s\n%s\n%s\n' "--- expected ---" "$$expected" "--- actual ---" "$$actual"; \217+
diff -u /tmp/_sp_t_exp.n /tmp/_sp_t_act.n 2>&1 | head -40; \217218
fail=$$((fail+1)); \218219
fi; \219220
else \@@ -222,7 +223,7 @@
222223
fi; \223224
done; \224225
if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \225-
rm -f /tmp/_sp_t.ast /tmp/_sp_t.c /tmp/_sp_t_bin$(EXE); \226+
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; \226227
echo "Tests: $$pass pass, $$fail fail, $$err error"; \227228
if [ $$fail -ne 0 ] || [ $$err -ne 0 ]; then exit 1; fi228229
@@ -239,25 +240,25 @@
239240
$(TIMEOUT10) ./spinel_codegen$(EXE) /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \240241
$(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_b_bin$(EXE) 2>/dev/null; \241242
if [ $$? -eq 0 ]; then \242-
expected=$$($(TIMEOUT60) $(REF_RUBY) "$$f" 2>/dev/null); \243+
$(TIMEOUT60) $(REF_RUBY) "$$f" >/tmp/_sp_b_exp 2>/dev/null; \243244
ruby_rc=$$?; \244245
if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \245-
expected=$$($(TIMEOUT60) ruby "$$f" 2>/dev/null); \246+
$(TIMEOUT60) ruby "$$f" >/tmp/_sp_b_exp 2>/dev/null; \246247
ruby_rc=$$?; \247248
fi; \248249
if [ $$ruby_rc -eq 124 ]; then \249250
if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \250251
echo "SKIP: $$bn (ruby timeout)"; skip=$$((skip+1)); \251252
else \252-
actual=$$($(TIMEOUT60) /tmp/_sp_b_bin$(EXE) 2>/dev/null); \253-
expected=$$(printf "%s" "$$expected" | tr -d '\r'); \254-
actual=$$(printf "%s" "$$actual" | tr -d '\r'); \255-
if [ "$$expected" = "$$actual" ]; then \253+
$(TIMEOUT60) /tmp/_sp_b_bin$(EXE) >/tmp/_sp_b_act 2>/dev/null; \254+
LC_ALL=C sed 's/\r$$//' /tmp/_sp_b_exp >/tmp/_sp_b_exp.n; \255+
LC_ALL=C sed 's/\r$$//' /tmp/_sp_b_act >/tmp/_sp_b_act.n; \256+
if cmp -s /tmp/_sp_b_exp.n /tmp/_sp_b_act.n; then \256257
pass=$$((pass+1)); \257258
else \258259
if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \259260
echo "FAIL: $$bn"; \260-
printf '%s\n%s\n%s\n%s\n' "--- expected ---" "$$expected" "--- actual ---" "$$actual"; \261+
diff -u /tmp/_sp_b_exp.n /tmp/_sp_b_act.n 2>&1 | head -40; \261262
fail=$$((fail+1)); \262263
fi; \263264
fi; \@@ -267,7 +268,7 @@
267268
fi; \268269
done; \269270
if [ "$$tty" = 1 ]; then printf '\r\033[K'; fi; \270-
rm -f /tmp/_sp_b.ast /tmp/_sp_b.c /tmp/_sp_b_bin$(EXE); \271+
rm -f /tmp/_sp_b.ast /tmp/_sp_b.c /tmp/_sp_b_bin$(EXE) /tmp/_sp_b_exp /tmp/_sp_b_act /tmp/_sp_b_exp.n /tmp/_sp_b_act.n; \271272
echo "Benchmarks: $$pass pass, $$fail fail, $$err error, $$skip skip"; \272273
if [ $$fail -ne 0 ] || [ $$err -ne 0 ]; then exit 1; fi273274