diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-12-27 09:14:45 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-12-27 09:14:45 +0000 |
commit | f163450fc0969ebd6f63c5d9bd059f6f0d107d75 (patch) | |
tree | 1d7cb198dead8b16362e6ed6b8f71f52fb50a0d0 /malloc/tst-trim1.c | |
parent | c5899b63ebb80de72b909a475e1dd41b99a4080c (diff) |
Updated to fedora-glibc-20071227T0908cvs/fedora-glibc-2_7_90-2
Diffstat (limited to 'malloc/tst-trim1.c')
-rw-r--r-- | malloc/tst-trim1.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/malloc/tst-trim1.c b/malloc/tst-trim1.c new file mode 100644 index 0000000000..310707e0e1 --- /dev/null +++ b/malloc/tst-trim1.c @@ -0,0 +1,56 @@ +#include <malloc.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define N 10000 + +static void *arr[N]; + +static int +do_test (void) +{ + for (int i = 0; i < N; ++i) + { + size_t size = random () % 16384; + + if ((arr[i] = malloc (size)) == NULL) + { + nomem: + puts ("not enough memory"); + return 0; + } + + memset (arr[i], size, size); + } + + void *p = malloc (256); + if (p == NULL) + goto nomem; + memset (p, 1, 256); + + puts ("=================================================================="); + + for (int i = 0; i < N; ++i) + if (i % 13 != 0) + free (arr[i]); + + puts ("=================================================================="); + + malloc_trim (0); + + puts ("=================================================================="); + + p = malloc (30000); + if (p == NULL) + goto nomem; + + memset (p, 2, 30000); + + malloc_trim (0); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |