From 8849d801b9d3767390e3e1ed6b562db738ac1bcb Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Fri, 27 Feb 2026 11:04:07 +0100 Subject: Add show_alloc_mem and test_show, rename test to test_preload Implement show_alloc_mem() to print all zones and allocations by ascending address. Add test_show binary that links directly against libft_malloc.so to exercise it. --- tests/Makefile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'tests/Makefile') diff --git a/tests/Makefile b/tests/Makefile index 04d7c1f..b964db5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,18 +5,26 @@ SRCDIR = src OBJDIR = obj BINDIR = bin -NAME = $(BINDIR)/test +NAME_PRELOAD = $(BINDIR)/test_preload +NAME_SHOW = $(BINDIR)/test_show -SRCS = main.c +SRCS = test_preload.c OBJS = $(SRCS:%.c=$(OBJDIR)/%.o) MALLOC_LIB = ../lib/libft_malloc.so +MALLOC_INC = ../inc -$(NAME): $(OBJS) | $(BINDIR) +$(NAME_PRELOAD): $(OBJS) | $(BINDIR) $(CC) $(CFLAGS) -o $@ $(OBJS) -all: $(NAME) +$(NAME_SHOW): $(OBJDIR)/test_show.o $(MALLOC_LIB) | $(BINDIR) + $(CC) $(CFLAGS) -o $@ $(OBJDIR)/test_show.o -L ../lib -lft_malloc -Wl,-rpath,'$$ORIGIN/../../lib' + +$(OBJDIR)/test_show.o: $(SRCDIR)/test_show.c | $(OBJDIR) + $(CC) $(CFLAGS) -I $(MALLOC_INC) -c $< -o $@ + +all: $(NAME_PRELOAD) $(NAME_SHOW) $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR) $(CC) $(CFLAGS) -c $< -o $@ @@ -27,12 +35,15 @@ $(OBJDIR): $(BINDIR): mkdir -p $(BINDIR) -test: $(NAME) +test: $(NAME_PRELOAD) $(NAME_SHOW) @echo "=== system malloc ===" - @$(NAME) + @$(NAME_PRELOAD) @echo "" @echo "=== ft_malloc ===" - @LD_PRELOAD=$(MALLOC_LIB) $(NAME) + @LD_PRELOAD=$(MALLOC_LIB) $(NAME_PRELOAD) + @echo "" + @echo "=== show_alloc_mem ===" + @$(NAME_SHOW) clean: rm -rf $(OBJDIR) $(BINDIR) -- cgit v1.2.3