diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile | 25 | ||||
| -rw-r--r-- | tests/src/test_preload.c (renamed from tests/src/main.c) | 0 | ||||
| -rw-r--r-- | tests/src/test_show.c | 25 |
3 files changed, 43 insertions, 7 deletions
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) diff --git a/tests/src/main.c b/tests/src/test_preload.c index 0ded605..0ded605 100644 --- a/tests/src/main.c +++ b/tests/src/test_preload.c diff --git a/tests/src/test_show.c b/tests/src/test_show.c new file mode 100644 index 0000000..e5e7dca --- /dev/null +++ b/tests/src/test_show.c @@ -0,0 +1,25 @@ +/** + * @file test_show.c + * @brief Test show_alloc_mem — links directly against libft_malloc. + */ + +#include "malloc.h" + +int +main (void) +{ + void *a = malloc (42); + void *b = malloc (100); + void *c = malloc (500); + void *d = malloc (2000); + (void)a; + (void)b; + (void)c; + (void)d; + show_alloc_mem (); + free (a); + free (b); + free (c); + free (d); + return (0); +} |
