summaryrefslogtreecommitdiffstats
path: root/lib/talloc/testsuite.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/talloc/testsuite.c')
-rw-r--r--lib/talloc/testsuite.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index ba583ab84ec..90417c6ade5 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1128,23 +1128,31 @@ static bool test_pool(void)
pool = talloc_pool(NULL, 1024);
p1 = talloc_size(pool, 80);
+ memset(p1, 0x11, talloc_get_size(p1));
p2 = talloc_size(pool, 20);
+ memset(p2, 0x11, talloc_get_size(p2));
p3 = talloc_size(p1, 50);
+ memset(p3, 0x11, talloc_get_size(p3));
p4 = talloc_size(p3, 1000);
+ memset(p4, 0x11, talloc_get_size(p4));
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
p2_2 = talloc_realloc_size(pool, p2, 20+1);
torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
p2_2 = talloc_realloc_size(pool, p2, 20-1);
torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
p2_2 = talloc_realloc_size(pool, p2, 20-1);
torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
talloc_free(p3);
/* this should reclaim the memory of p4 and p3 */
p2_2 = talloc_realloc_size(pool, p2, 400);
torture_assert("pool realloc 400", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
talloc_free(p1);
@@ -1152,37 +1160,46 @@ static bool test_pool(void)
p2_2 = talloc_realloc_size(pool, p2, 800);
torture_assert("pool realloc 800", p2_2 == p1, "failed: pointer not changed");
p2 = p2_2;
+ memset(p2, 0x11, talloc_get_size(p2));
/* this should do a malloc */
p2_2 = talloc_realloc_size(pool, p2, 1800);
torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
p2 = p2_2;
+ memset(p2, 0x11, talloc_get_size(p2));
/* this should reclaim the memory from the pool */
p3 = talloc_size(pool, 80);
torture_assert("pool alloc 80", p3 == p1, "failed: pointer changed");
+ memset(p3, 0x11, talloc_get_size(p3));
talloc_free(p2);
talloc_free(p3);
p1 = talloc_size(pool, 80);
+ memset(p1, 0x11, talloc_get_size(p1));
p2 = talloc_size(pool, 20);
+ memset(p2, 0x11, talloc_get_size(p2));
talloc_free(p1);
p2_2 = talloc_realloc_size(pool, p2, 20-1);
torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
p2_2 = talloc_realloc_size(pool, p2, 20-1);
torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
+ memset(p2, 0x11, talloc_get_size(p2));
/* this should do a malloc */
p2_2 = talloc_realloc_size(pool, p2, 1800);
torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
p2 = p2_2;
+ memset(p2, 0x11, talloc_get_size(p2));
/* this should reclaim the memory from the pool */
p3 = talloc_size(pool, 800);
torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed");
+ memset(p3, 0x11, talloc_get_size(p3));
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
@@ -1191,6 +1208,73 @@ static bool test_pool(void)
return true;
}
+static bool test_pool_steal(void)
+{
+ void *root;
+ void *pool;
+ void *p1, *p2;
+ void *p1_2, *p2_2;
+ size_t hdr;
+ size_t ofs1, ofs2;
+
+ root = talloc_new(NULL);
+ pool = talloc_pool(root, 1024);
+
+ p1 = talloc_size(pool, 4 * 16);
+ torture_assert("pool allocate 4 * 16", p1 != NULL, "failed ");
+ memset(p1, 0x11, talloc_get_size(p1));
+ p2 = talloc_size(pool, 4 * 16);
+ torture_assert("pool allocate 4 * 16", p2 > p1, "failed: !(p2 > p1) ");
+ memset(p2, 0x11, talloc_get_size(p2));
+
+ ofs1 = PTR_DIFF(p2, p1);
+ hdr = ofs1 - talloc_get_size(p1);
+
+ talloc_steal(root, p1);
+ talloc_steal(root, p2);
+
+ talloc_free(pool);
+
+ p1_2 = p1;
+
+#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+ p1_2 = talloc_realloc_size(root, p1, 5 * 16);
+ torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed");
+ memset(p1_2, 0x11, talloc_get_size(p1_2));
+ ofs1 = PTR_DIFF(p1_2, p2);
+ ofs2 = talloc_get_size(p2) + hdr;
+
+ torture_assert("pool realloc ", ofs1 == ofs2, "failed: pointer offset unexpected");
+
+ p2_2 = talloc_realloc_size(root, p2, 3 * 16);
+ torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed");
+ memset(p2_2, 0x11, talloc_get_size(p2_2));
+#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+
+ talloc_free(p1_2);
+
+ p2_2 = p2;
+
+#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+ /* now we should reclaim the full pool */
+ p2_2 = talloc_realloc_size(root, p2, 8 * 16);
+ torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected");
+ p2 = p2_2;
+ memset(p2_2, 0x11, talloc_get_size(p2_2));
+
+ /* now we malloc and free the full pool space */
+ p2_2 = talloc_realloc_size(root, p2, 2 * 1024);
+ torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected");
+ memset(p2_2, 0x11, talloc_get_size(p2_2));
+
+#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
+
+ talloc_free(p2_2);
+
+ talloc_free(root);
+
+ return true;
+}
static bool test_free_ref_null_context(void)
{
@@ -1290,6 +1374,8 @@ bool torture_local_talloc(struct torture_context *tctx)
test_reset();
ret &= test_pool();
test_reset();
+ ret &= test_pool_steal();
+ test_reset();
ret &= test_free_ref_null_context();
test_reset();
ret &= test_rusty();