From 49ad475df150584a9e59649b48dec1f3bed2bffb Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 30 Jun 2020 12:54:40 -0400 Subject: add simple realloc() test --- .gitignore | 1 + Makefile | 14 +++++++++----- test/realloc.c | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/realloc.c diff --git a/.gitignore b/.gitignore index d07f0ab..7f24563 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ lib/ obj/ +bin/ diff --git a/Makefile b/Makefile index e8a413f..accf611 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,11 @@ TESTDIR=test CFLAGS=-I$(INCDIR) -Wall -Wextra -Wpedantic -g OBJECTS=$(OBJDIR)/mapalloc.o -TESTS=$(BINDIR)/overflow $(BINDIR)/underflow $(BINDIR)/zero +TESTS=$(BINDIR)/overflow $(BINDIR)/underflow $(BINDIR)/zero $(BINDIR)/realloc -all: $(LIBDIR)/libmapalloc.a $(LIBDIR)/libmapalloc.so +all: $(LIBDIR)/libmapalloc.a + +#$(LIBDIR)/libmapalloc.so tests: $(TESTS) @@ -27,9 +29,11 @@ $(LIBDIR)/libmapalloc.so: $(OBJECTS) @mkdir -p $(@D) $(CC) -o $@ -shared $(OBJECTS) -$(BINDIR)/overflow: $(TESTDIR)/overflow.c $(LIBDIR)/libmapalloc.a -$(BINDIR)/underflow: $(TESTDIR)/underflow.c $(LIBDIR)/libmapalloc.a -$(BINDIR)/zero: $(TESTDIR)/zero.c $(LIBDIR)/libmapalloc.a +$(TESTS): $(LIBDIR)/libmapalloc.a +$(BINDIR)/overflow: $(TESTDIR)/overflow.c +$(BINDIR)/underflow: $(TESTDIR)/underflow.c +$(BINDIR)/zero: $(TESTDIR)/zero.c +$(BINDIR)/realloc: $(TESTDIR)/realloc.c $(TESTS): @mkdir -p $(@D) diff --git a/test/realloc.c b/test/realloc.c new file mode 100644 index 0000000..c54f270 --- /dev/null +++ b/test/realloc.c @@ -0,0 +1,18 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "mapalloc.h" + +int main(void) +{ + const char buf[] = "THIS IS A CONSTANT STRING"; + + char *ptr = map_realloc(NULL, sizeof(buf)); + memcpy(ptr, buf, sizeof(buf)); + printf("%p: %s\n", ptr, ptr); + + ptr = map_realloc(ptr, sizeof(buf) * 2); + memcpy(ptr + sizeof(buf), buf, sizeof(buf)); + printf("%p: %s\n", ptr, ptr); +} -- cgit v1.2.1