>From da3fe1701a6b633e93d24c9d02315721d8265fa1 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Sep 2012 16:35:21 -0400 Subject: [PATCH 2/2] Add tests for talloc_memlimit --- lib/talloc/testsuite.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c index eaab9d7cf0a8ad2ab72acc12d5add0eba1f0ba4a..2e66851a3a5fb38bcb90f470d8f9ef1b0656465f 100644 --- a/lib/talloc/testsuite.c +++ b/lib/talloc/testsuite.c @@ -1355,6 +1355,45 @@ static bool test_free_children(void) return true; } +static bool test_memlimit(void) +{ + void *root; + char *l1, *l2, *l3; + + printf("test: memlimit\n# MEMORY LIMITS\n"); + + root = talloc_new(NULL); + torture_assert("memlimit", talloc_set_memlimit(root, 1024) == 0, + "failed: setting memlimit should never fail\n"); + l1 = talloc_size(root, 2048); + torture_assert("memlimit", l1 == NULL, + "failed: alloc should fail due to memory limit\n"); + l1 = talloc_strdup(root, "level 1"); + torture_assert("memlimit", l1 != NULL, + "failed: alloc should not fail due to memory limit\n"); + l2 = talloc_size(l1, 2048); + torture_assert("memlimit", l2 == NULL, + "failed: alloc should fail due to memory limit\n"); + l2 = talloc_strdup(l1, "level 2"); + torture_assert("memlimit", l2 != NULL, + "failed: alloc should not fail due to memory limit\n"); + talloc_free(l2); + + l2 = talloc_size(NULL, 2048); + talloc_steal(l1, l2); + l3 = talloc_strdup(l2, "level 3"); + torture_assert("memlimit", l3 == NULL, + "failed: alloc should fail due to memory limit\n"); + talloc_free(l2); + + l2 = talloc_strdup(NULL, "new level 2"); + talloc_steal(l1, l2); + l3 = talloc_strdup(l2, "level 3"); + torture_assert("memlimit", l3 != NULL, + "failed: alloc should not fail due to memory limit\n"); + + return true; +} static void test_reset(void) { @@ -1416,6 +1455,9 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_rusty(); test_reset(); ret &= test_free_children(); + test_reset(); + ret &= test_memlimit(); + if (ret) { test_reset(); -- 1.7.11.4