about summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-12-16 22:57:57 +0000
committerUlrich Drepper <drepper@redhat.com>2007-12-16 22:57:57 +0000
commitbe8c1500c7ce61b478cdc827705054c054386258 (patch)
tree14c1b55b8926a6a7ff7b80cf93f414c4968a5cdc /malloc
parent68631c8eb92ff38d9da1ae34f6aa048539b199cc (diff)
downloadglibc-be8c1500c7ce61b478cdc827705054c054386258.tar.gz
glibc-be8c1500c7ce61b478cdc827705054c054386258.tar.xz
glibc-be8c1500c7ce61b478cdc827705054c054386258.zip
* malloc/tst-trim1.c: New file.
	* malloc/Makefile (tests): Add tst-trim1.
Diffstat (limited to 'malloc')
-rw-r--r--malloc/Makefile4
-rw-r--r--malloc/tst-trim1.c56
2 files changed, 58 insertions, 2 deletions
diff --git a/malloc/Makefile b/malloc/Makefile
index c39eae5474..22b14eac77 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-1999, 2000, 2001, 2002, 2003, 2005, 2006
+# Copyright (C) 1991-1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007
 # Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
@@ -27,7 +27,7 @@ all:
 dist-headers := malloc.h
 headers := $(dist-headers) obstack.h mcheck.h
 tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
-	 tst-mallocstate tst-mcheck tst-mallocfork
+	 tst-mallocstate tst-mcheck tst-mallocfork tst-trim1
 test-srcs = tst-mtrace
 
 distribute = thread-m.h mtrace.pl mcheck-init.c stackinfo.h memusage.h \
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"