From be0024094aa6cf4dfd9ec02d0b722d396df1fbd6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 14 Jul 2009 12:28:35 +0200 Subject: [PATCH] fix tests --- lib/talloc/testsuite.c | 57 +++++++++++++----------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c index 03afd2702e0e..d999f6e23779 100644 --- a/lib/talloc/testsuite.c +++ b/lib/talloc/testsuite.c @@ -909,15 +909,13 @@ static bool test_implicit_explicit_free(void) In proposed talloc r1 will be the reference with no parent */ static bool test_ref_free_owner(void) { - void *root, *p1, *p2, *p3, *ref, *r1; + void *root, *p1, *p2, *ref, *r1; printf("test: ref_free_owner\n# SINGLE REFERENCE FREE OWNER FREE\n"); - talloc_erase_no_owner_context(); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(p1, 1, "p2"); - p3 = talloc_named_const(root, 1, "p3"); /* Now root owns p1 ,and p2 owns p2 */ r1 = talloc_named_const(root, 1, "r1"); @@ -925,6 +923,7 @@ static bool test_ref_free_owner(void) /* now r1 has ref reference to p2 */ talloc_report_full(root, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 7); CHECK_BLOCKS(__FUNCTION__, p1, 2); CHECK_BLOCKS(__FUNCTION__, p2, 1); CHECK_BLOCKS(__FUNCTION__, r1, 2); @@ -933,30 +932,20 @@ static bool test_ref_free_owner(void) talloc_free(p1); /* r1 should have ref reference to p2 still */ talloc_report_full(NULL, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 6); CHECK_BLOCKS(__FUNCTION__, r1, 2); - - /* if we talloc_steal p2 to p3, r1 should still have a reference - (unless it had been made the parent like in old talloc */ - fprintf(stderr, "Stealing p2 to p3\n"); - talloc_steal(p3, p2); - talloc_report_full(NULL, stderr); - CHECK_BLOCKS(__FUNCTION__, r1, 2); - - /* now we free p3 and r1 should still have a reference */ - fprintf(stderr, "free p3\n"); - talloc_free(p3); - talloc_report_full(NULL, stderr); - CHECK_BLOCKS(__FUNCTION__, r1, 2); + CHECK_BLOCKS(__FUNCTION__, p2, 1); /* if we free r1 then p2 should vanish */ fprintf(stderr, "Freeing r1\n"); talloc_free(r1); talloc_report_full(NULL, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 3); CHECK_BLOCKS(__FUNCTION__, root, 1); talloc_free(root); - printf("success: ref1\n"); + printf("success: ref_free_owner\n"); return true; } @@ -966,15 +955,13 @@ static bool test_ref_free_owner(void) In proposed talloc r1 will be the reference with no parent */ static bool test_ref_free_self(void) { - void *root, *p1, *p2, *p3, *ref, *r1; + void *root, *p1, *p2, *ref, *r1; printf("test: ref_free_self\n# SINGLE REFERENCE FREE SELF FREE\n"); - talloc_erase_no_owner_context(); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(p1, 1, "p2"); - p3 = talloc_named_const(root, 1, "p3"); /* Now root owns p1, and p1 owns p2 */ r1 = talloc_named_const(root, 1, "r1"); @@ -982,28 +969,18 @@ static bool test_ref_free_self(void) /* now r1 has ref reference to p2 */ talloc_report_full(NULL, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 7); CHECK_BLOCKS(__FUNCTION__, p1, 2); CHECK_BLOCKS(__FUNCTION__, p2, 1); - CHECK_BLOCKS(__FUNCTION__, p3, 1); CHECK_BLOCKS(__FUNCTION__, r1, 2); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); /* r1 should have ref reference to p2 still */ talloc_report_full(NULL, stderr); - CHECK_BLOCKS(__FUNCTION__, r1, 2); - - /* if we talloc_steal p2 to p3, r1 should still have a reference - (unless it had been made the parent like in old talloc */ - fprintf(stderr, "Steal p2 to p3\n"); - talloc_steal(p3, p2); - talloc_report_full(NULL, stderr); - CHECK_BLOCKS(__FUNCTION__, r1, 2); - - /* now we free p3 and r1 should still have a reference */ - fprintf(stderr, "free p3\n"); - talloc_free(p3); - talloc_report_full(NULL, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 7); + CHECK_BLOCKS(__FUNCTION__, p1, 1); + CHECK_BLOCKS(__FUNCTION__, p2, 1); CHECK_BLOCKS(__FUNCTION__, r1, 2); /* if we free r1 then p2 should also vanish */ @@ -1011,14 +988,17 @@ static bool test_ref_free_self(void) talloc_free(r1); fprintf(stderr, "Checking that p1 is empty and freeing p1\n"); + CHECK_BLOCKS(__FUNCTION__, NULL, 4); CHECK_BLOCKS(__FUNCTION__, p1, 1); talloc_free(p1); talloc_report_full(NULL, stderr); + CHECK_BLOCKS(__FUNCTION__, NULL, 3); CHECK_BLOCKS(__FUNCTION__, root, 1); talloc_free(root); - printf("success: ref1\n"); + CHECK_BLOCKS(__FUNCTION__, NULL, 2); + printf("success: ref_free_self\n"); return true; } @@ -1029,7 +1009,6 @@ static bool test_ref_free(void) void *root, *p1, *p2, *ref, *r1; printf("test: test_ref_free\n# FREE ON SINGLE REFERENCE FREE\n"); - talloc_erase_no_owner_context(); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -1063,7 +1042,7 @@ static bool test_ref_free(void) CHECK_BLOCKS(__FUNCTION__, p1, 1); talloc_free(root); - printf("success: ref1\n"); + printf("success: test_ref_free\n"); return true; } @@ -1076,7 +1055,6 @@ static bool test_dangling_loop(void) void *root, *p1, *p2, *ref, *r1, *r2; printf("test: %s\n# FREE ON SINGLE REFERENCE FREE\n",__FUNCTION__); - talloc_erase_no_owner_context(); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -1124,9 +1102,8 @@ static bool test_dangling_loop(void) CHECK_BLOCKS(__FUNCTION__, root, 1); talloc_free(root); - printf("success: ref1\n"); + printf("success: %s\n", __FUNCTION__); - talloc_erase_no_owner_context(); talloc_report_full(NULL, stderr); return true; } -- 2.34.1