add malloc_info test
This commit is contained in:
parent
f6f4402ff3
commit
b40ba9754b
1
test/.gitignore
vendored
1
test/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
large_array_growth
|
||||
mallinfo
|
||||
malloc_info
|
||||
offset
|
||||
|
@ -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)
|
||||
|
28
test/malloc_info.c
Normal file
28
test/malloc_info.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <pthread.h>
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
__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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user