diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | tests/Makefile | 2 | ||||
| -rw-r--r-- | tests/inc/test_utils.h | 12 |
3 files changed, 16 insertions, 5 deletions
@@ -1,5 +1,5 @@ CC = cc -CFLAGS = -Wall -Wextra -Werror +CFLAGS = -Wall -Wextra -Werror $(EXTRA) SRCDIR = src INCDIR = inc @@ -45,8 +45,11 @@ re: fclean all test: $(NAME) $(MAKE) -C tests +sanitize: fclean + $(MAKE) EXTRA="-fsanitize=address -g" test + compile_commands.json: $(SRCS:%=$(SRCDIR)/%) @echo '$(foreach src,$(SRCS),{"directory":"$(CURDIR)","command":"$(CC) $(CFLAGS) -I $(INCDIR) -c $(SRCDIR)/$(src)","file":"$(SRCDIR)/$(src)"})' \ | jq -s '.' > $@ -.PHONY: all clean fclean re test +.PHONY: all clean fclean re test sanitize diff --git a/tests/Makefile b/tests/Makefile index 61b7d44..3fc0322 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ CC = cc -CFLAGS = -I ../inc -I inc +CFLAGS = -I ../inc -I inc $(EXTRA) SRCDIR = src BINDIR = bin diff --git a/tests/inc/test_utils.h b/tests/inc/test_utils.h index 0cb6655..56dbb94 100644 --- a/tests/inc/test_utils.h +++ b/tests/inc/test_utils.h @@ -115,21 +115,29 @@ _s_check_eq_int (const char *label, int got, int expected) /* ── crash detection ──────────────────────────────────────────────── */ -/** Run @p fn in a child process; return 1 if it was killed by a signal. */ +/** + * Run @p fn in a child process; return 1 if it crashed. + * Detects both raw signals (SEGV, BUS) and ASan-intercepted crashes + * (which exit with non-zero instead of being killed by a signal). + */ static int _s_crashes (void (*fn) (void)) { pid_t pid; int status; + fflush (stdout); pid = fork (); if (pid == 0) { + /* Suppress ASan crash reports from intentional NULL dereferences. */ + close (STDERR_FILENO); fn (); _exit (0); } waitpid (pid, &status, 0); - return (WIFSIGNALED (status)); + return (WIFSIGNALED (status) + || (WIFEXITED (status) && WEXITSTATUS (status) != 0)); } static void |
