|
From: <sv...@va...> - 2006-10-06 11:45:07
|
Author: sewardj
Date: 2006-10-06 12:45:00 +0100 (Fri, 06 Oct 2006)
New Revision: 6198
Log:
Regression tests for Graydon Hoare's enhanced mempool stuff, from
Graydon himself.
Added:
trunk/memcheck/tests/leak-pool-0.stderr.exp
trunk/memcheck/tests/leak-pool-0.vgtest
trunk/memcheck/tests/leak-pool-1.stderr.exp
trunk/memcheck/tests/leak-pool-1.vgtest
trunk/memcheck/tests/leak-pool-2.stderr.exp
trunk/memcheck/tests/leak-pool-2.vgtest
trunk/memcheck/tests/leak-pool-3.stderr.exp
trunk/memcheck/tests/leak-pool-3.vgtest
trunk/memcheck/tests/leak-pool-4.stderr.exp
trunk/memcheck/tests/leak-pool-4.vgtest
trunk/memcheck/tests/leak-pool-5.stderr.exp
trunk/memcheck/tests/leak-pool-5.vgtest
trunk/memcheck/tests/leak-pool.c
Modified:
trunk/memcheck/tests/Makefile.am
Modified: trunk/memcheck/tests/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/Makefile.am 2006-10-05 17:59:23 UTC (rev 6197)
+++ trunk/memcheck/tests/Makefile.am 2006-10-06 11:45:00 UTC (rev 6198)
@@ -54,6 +54,12 @@
inline.stderr.exp inline.stdout.exp inline.vgtest \
leak-0.vgtest leak-0.stderr.exp \
leak-cycle.vgtest leak-cycle.stderr.exp leak-cycle.stderr.exp64 \
+ leak-pool-0.vgtest leak-pool-0.stderr.exp \
+ leak-pool-1.vgtest leak-pool-1.stderr.exp \
+ leak-pool-2.vgtest leak-pool-2.stderr.exp \
+ leak-pool-3.vgtest leak-pool-3.stderr.exp \
+ leak-pool-4.vgtest leak-pool-4.stderr.exp \
+ leak-pool-5.vgtest leak-pool-5.stderr.exp \
leak-tree.vgtest leak-tree.stderr.exp \
leak-tree.stderr.exp2 leak-tree.stderr.exp64 \
leak-regroot.vgtest leak-regroot.stderr.exp \
@@ -144,7 +150,7 @@
describe-block \
doublefree error_counts errs1 exitprog execve execve2 erringfds \
fprw fwrite hello inits inline \
- leak-0 leak-cycle leak-tree leak-regroot leakotron \
+ leak-0 leak-cycle leak-pool leak-tree leak-regroot leakotron \
malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
match-overrun \
memalign_test memalign2 memcmptest mempool mmaptest \
Added: trunk/memcheck/tests/leak-pool-0.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-0.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-0.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-0.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-0.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-0.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 0
Added: trunk/memcheck/tests/leak-pool-1.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-1.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-1.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-1.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-1.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-1.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 1
Added: trunk/memcheck/tests/leak-pool-2.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-2.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-2.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-2.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-2.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-2.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 2
Added: trunk/memcheck/tests/leak-pool-3.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-3.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-3.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-3.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-3.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-3.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 3
Added: trunk/memcheck/tests/leak-pool-4.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-4.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-4.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-4.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-4.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-4.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 4
Added: trunk/memcheck/tests/leak-pool-5.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-5.stderr.exp (=
rev 0)
+++ trunk/memcheck/tests/leak-pool-5.stderr.exp 2006-10-06 11:45:00 UTC (=
rev 6198)
@@ -0,0 +1,7 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 4,108 bytes in 2 blocks.
+malloc/free: 102 allocs, 0 frees, 4,908 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=3Dyes
+For counts of detected errors, rerun with: -v
Added: trunk/memcheck/tests/leak-pool-5.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool-5.vgtest (rev =
0)
+++ trunk/memcheck/tests/leak-pool-5.vgtest 2006-10-06 11:45:00 UTC (rev =
6198)
@@ -0,0 +1,2 @@
+prog: leak-pool
+args: 5
Added: trunk/memcheck/tests/leak-pool.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/leak-pool.c (rev 0)
+++ trunk/memcheck/tests/leak-pool.c 2006-10-06 11:45:00 UTC (rev 6198)
@@ -0,0 +1,126 @@
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
+
+#include "../memcheck.h"
+
+struct cell
+{ =20
+ struct cell *next;
+ int x;
+};
+
+struct pool
+{
+ size_t allocated;
+ size_t used;
+ uint8_t *buf;
+};
+
+void *=20
+allocate_from_pool(struct pool *p, size_t n)
+{
+ void *a =3D p->buf + p->used;
+ assert(p->used + n < p->allocated);
+ VALGRIND_MEMPOOL_ALLOC(p, a, n);
+ p->used +=3D n;
+ return a;
+}
+
+struct pool *
+allocate_pool()
+{
+ struct pool *p =3D malloc(sizeof(struct pool));
+ assert(p);
+ p->allocated =3D 4096;
+ p->used =3D 0;
+ p->buf =3D malloc(p->allocated);
+ assert(p->buf);
+ memset(p->buf, 0, p->allocated);
+ VALGRIND_CREATE_MEMPOOL(p, 0, 0);
+ VALGRIND_MAKE_NOACCESS(p->buf, p->allocated);
+ return p;
+}
+
+#define N 100
+
+/* flags */
+int static_roots =3D 0;
+int trim_pool =3D 0;
+int destroy_pool =3D 0;
+void set_flags ( int n )
+{
+ switch (n) {
+ case 0:
+ static_roots =3D 0;
+ trim_pool =3D 0;
+ destroy_pool =3D 0;
+ break;
+ case 1:
+ static_roots =3D 0;
+ trim_pool =3D 1;
+ destroy_pool =3D 0;
+ break;
+ case 2:
+ static_roots =3D 0;
+ trim_pool =3D 0;
+ destroy_pool =3D 1;
+ break;
+ case 3:
+ static_roots =3D 1;
+ trim_pool =3D 0;
+ destroy_pool =3D 0;
+ break;
+ case 4:
+ static_roots =3D 1;
+ trim_pool =3D 1;
+ destroy_pool =3D 0;
+ break;
+ case 5:
+ static_roots =3D 1;
+ trim_pool =3D 0;
+ destroy_pool =3D 1;
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+struct cell *cells_static[N];
+
+
+int main( int argc, char** argv )
+{
+ struct cell *cells_local[N];
+ int arg;
+ size_t i;
+ struct pool *p =3D allocate_pool();
+ struct cell **cells =3D static_roots ? cells_static : cells_local;
+
+ assert(argc =3D=3D 2);
+ assert(argv[1]);
+ assert(strlen(argv[1]) =3D=3D 1);
+ assert(argv[1][0] >=3D '0' && argv[1][0] <=3D '5');
+ arg =3D atoi( argv[1] );
+ set_flags( arg );
+
+ memset(cells_static, 0, sizeof(cells_static));
+ memset(cells_local, 0, sizeof(cells_local));
+
+ for (i =3D 0; i < N; ++i) {
+ cells[i] =3D allocate_from_pool(p, sizeof(struct cell)); =20
+ }
+
+ if (trim_pool)
+ VALGRIND_MEMPOOL_TRIM(p,=20
+ p->buf+(10 * sizeof(struct cell)),=20
+ 20 * sizeof(struct cell) + 2);
+
+ if (destroy_pool)
+ VALGRIND_DESTROY_MEMPOOL(p);
+
+ return 0;
+}
|