summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2013-08-27 13:09:03 -0700
committerJeremy Allison <jra@samba.org>2013-08-27 15:44:20 -0700
commitcbfc3efbfd4a3a6f3b031ce8ef375d37f2c545f3 (patch)
tree056ef6a2a250fee6b75df9ce001dc2f6068cbef3 /lib
parent3d0f717d437bb24f430fad788b9eb35e8fe8e0e8 (diff)
downloadsamba-cbfc3efbfd4a3a6f3b031ce8ef375d37f2c545f3.tar.gz
samba-cbfc3efbfd4a3a6f3b031ce8ef375d37f2c545f3.tar.bz2
samba-cbfc3efbfd4a3a6f3b031ce8ef375d37f2c545f3.zip
Add simple limited pool tests to test_memlimit().
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Simo Sorce <idra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/talloc/testsuite.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index d456cbb0c2..426c31a8f2 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1359,6 +1359,8 @@ static bool test_memlimit(void)
{
void *root;
char *l1, *l2, *l3, *l4, *l5, *t;
+ char *pool;
+ int i;
printf("test: memlimit\n# MEMORY LIMITS\n");
@@ -1520,6 +1522,31 @@ static bool test_memlimit(void)
talloc_report_full(root, stdout);
talloc_free(root);
+ /* Test memlimits with pools. */
+ pool = talloc_pool(NULL, 10*1024);
+ torture_assert("memlimit", pool != NULL,
+ "failed: alloc should not fail due to memory limit\n");
+ talloc_set_memlimit(pool, 10*1024);
+ for (i = 0; i < 9; i++) {
+ l1 = talloc_size(pool, 1024);
+ torture_assert("memlimit", l1 != NULL,
+ "failed: alloc should not fail due to memory limit\n");
+ }
+ /* The next alloc should fail. */
+ l2 = talloc_size(pool, 1024);
+ torture_assert("memlimit", l2 == NULL,
+ "failed: alloc should fail due to memory limit\n");
+
+ /* Moving one of the children shouldn't change the limit,
+ as it's still inside the pool. */
+ root = talloc_new(NULL);
+ talloc_steal(root, l1);
+ l2 = talloc_size(pool, 1024);
+ torture_assert("memlimit", l2 == NULL,
+ "failed: alloc should fail due to memory limit\n");
+
+ talloc_free(pool);
+ talloc_free(root);
printf("success: memlimit\n");
return true;