From b40ba9754b92508737d70364e7b39a7c7828edec Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 30 Apr 2019 16:54:58 -0400 Subject: [PATCH] add malloc_info test --- test/.gitignore | 1 + test/Makefile | 3 +++ test/malloc_info.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/malloc_info.c diff --git a/test/.gitignore b/test/.gitignore index 1259e1e..591cace 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,3 +1,4 @@ large_array_growth mallinfo +malloc_info offset diff --git a/test/Makefile b/test/Makefile index dbcaa09..d772f05 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,12 +4,15 @@ ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false)) $(error CONFIG_SLAB_CANARY must be true or false) endif +LDLIBS := -lpthread + CPPFLAGS += \ -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) EXECUTABLES := \ offset \ mallinfo \ + malloc_info \ large_array_growth all: $(EXECUTABLES) diff --git a/test/malloc_info.c b/test/malloc_info.c new file mode 100644 index 0000000..c1590af --- /dev/null +++ b/test/malloc_info.c @@ -0,0 +1,28 @@ +#include + +#include + +__attribute__((optimize(0))) +void leak_memory(void) { + (void)malloc(1024 * 1024 * 1024); + (void)malloc(16); + (void)malloc(32); + (void)malloc(4096); +} + +void *do_work(void *p) { + leak_memory(); + return NULL; +} + +int main(void) { + pthread_t thread[4]; + for (int i = 0; i < 4; i++) { + pthread_create(&thread[i], NULL, do_work, NULL); + } + for (int i = 0; i < 4; i++) { + pthread_join(thread[i], NULL); + } + + malloc_info(0, stdout); +}