aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Makefile
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-27 11:57:42 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-27 11:57:42 +0100
commitb8de4f339318dc245b073f05e186c4b2b1e8e758 (patch)
tree9c6210d482884064b4feef239bcece03e622ac14 /tests/Makefile
parent5ba7a73f97fe6880dc5328807a1cb9353e77b863 (diff)
downloadmalloc-b8de4f339318dc245b073f05e186c4b2b1e8e758.tar.gz
malloc-b8de4f339318dc245b073f05e186c4b2b1e8e758.zip
Add randomized correctness test
test_random allocates N blocks per category (TINY/SMALL/LARGE) with random sizes, fills them with a deterministic pattern, and verifies the data. Run with system malloc and LD_PRELOAD to compare output. Seed and count are parameterized via argv.
Diffstat (limited to 'tests/Makefile')
-rw-r--r--tests/Makefile17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/Makefile b/tests/Makefile
index b964db5..28a9741 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -7,6 +7,7 @@ BINDIR = bin
NAME_PRELOAD = $(BINDIR)/test_preload
NAME_SHOW = $(BINDIR)/test_show
+NAME_RANDOM = $(BINDIR)/test_random
SRCS = test_preload.c
@@ -24,7 +25,10 @@ $(NAME_SHOW): $(OBJDIR)/test_show.o $(MALLOC_LIB) | $(BINDIR)
$(OBJDIR)/test_show.o: $(SRCDIR)/test_show.c | $(OBJDIR)
$(CC) $(CFLAGS) -I $(MALLOC_INC) -c $< -o $@
-all: $(NAME_PRELOAD) $(NAME_SHOW)
+$(NAME_RANDOM): $(OBJDIR)/test_random.o | $(BINDIR)
+ $(CC) $(CFLAGS) -o $@ $(OBJDIR)/test_random.o
+
+all: $(NAME_PRELOAD) $(NAME_SHOW) $(NAME_RANDOM)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
@@ -35,7 +39,10 @@ $(OBJDIR):
$(BINDIR):
mkdir -p $(BINDIR)
-test: $(NAME_PRELOAD) $(NAME_SHOW)
+SEED ?= 42
+COUNT ?= 10
+
+test: $(NAME_PRELOAD) $(NAME_SHOW) $(NAME_RANDOM)
@echo "=== system malloc ==="
@$(NAME_PRELOAD)
@echo ""
@@ -44,6 +51,12 @@ test: $(NAME_PRELOAD) $(NAME_SHOW)
@echo ""
@echo "=== show_alloc_mem ==="
@$(NAME_SHOW)
+ @echo ""
+ @echo "=== random (system, seed=$(SEED) count=$(COUNT)) ==="
+ @$(NAME_RANDOM) $(SEED) $(COUNT)
+ @echo ""
+ @echo "=== random (ft_malloc, seed=$(SEED) count=$(COUNT)) ==="
+ @LD_PRELOAD=$(MALLOC_LIB) $(NAME_RANDOM) $(SEED) $(COUNT)
clean:
rm -rf $(OBJDIR) $(BINDIR)