From 65f96eba32b93ced0717c2639007bba59da55fa4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 07:47:34 +0000 Subject: r4473: - moved talloc into its own lib/talloc/ area - added gcov flags to Makefile.talloc - expanded talloc testsuite to add a test for realloc with a child ptr - fixed a bug in talloc_realloc() with realloc of a ptr that has child ptrs (This used to be commit 98b5f73c1ba34d7576c5995069b485c1c5ede324) --- source4/lib/talloc/testsuite.c | 785 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 source4/lib/talloc/testsuite.c (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c new file mode 100644 index 0000000000..22444b1116 --- /dev/null +++ b/source4/lib/talloc/testsuite.c @@ -0,0 +1,785 @@ +/* + Unix SMB/CIFS implementation. + + local testing of talloc routines. + + Copyright (C) Andrew Tridgell 2004 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifdef _SAMBA_BUILD_ +#include "includes.h" +#else +#include +#include +#include +#include +#include +#include +#include "talloc.h" +#endif + +/* the test suite can be built standalone, or as part of Samba */ +#ifndef _SAMBA_BUILD_ +typedef enum {False=0,True=1} BOOL; + +static struct timeval timeval_current(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv; +} + +static double timeval_elapsed(struct timeval *tv) +{ + struct timeval tv2 = timeval_current(); + return (tv2.tv_sec - tv->tv_sec) + + (tv2.tv_usec - tv->tv_usec)*1.0e-6; +} +#endif /* _SAMBA_BUILD_ */ + + +#define CHECK_SIZE(ptr, tsize) do { \ + if (talloc_total_size(ptr) != (tsize)) { \ + printf(__location__ " failed: wrong '%s' tree size: got %u expected %u\n", \ + #ptr, \ + (unsigned)talloc_total_size(ptr), \ + (unsigned)tsize); \ + talloc_report_full(ptr, stdout); \ + return False; \ + } \ +} while (0) + +#define CHECK_BLOCKS(ptr, tblocks) do { \ + if (talloc_total_blocks(ptr) != (tblocks)) { \ + printf(__location__ " failed: wrong '%s' tree blocks: got %u expected %u\n", \ + #ptr, \ + (unsigned)talloc_total_blocks(ptr), \ + (unsigned)tblocks); \ + talloc_report_full(ptr, stdout); \ + return False; \ + } \ +} while (0) + + +/* + test references +*/ +static BOOL test_ref1(void) +{ + void *root, *p1, *p2, *ref, *r1; + + printf("TESTING SINGLE REFERENCE FREE\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "p1"); + p2 = talloc_named_const(p1, 1, "p2"); + talloc_named_const(p1, 1, "x1"); + talloc_named_const(p1, 2, "x2"); + talloc_named_const(p1, 3, "x3"); + + r1 = talloc_named_const(root, 1, "r1"); + ref = talloc_reference(r1, p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 2); + + printf("Freeing p2\n"); + talloc_free(p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p1\n"); + talloc_free(p1); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(r1, 1); + + printf("Freeing r1\n"); + talloc_free(r1); + talloc_report_full(NULL, stdout); + + printf("Testing NULL\n"); + if (talloc_reference(root, NULL)) { + return False; + } + + CHECK_BLOCKS(root, 1); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + +/* + test references +*/ +static BOOL test_ref2(void) +{ + void *root, *p1, *p2, *ref, *r1; + + printf("TESTING DOUBLE REFERENCE FREE\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "p1"); + talloc_named_const(p1, 1, "x1"); + talloc_named_const(p1, 1, "x2"); + talloc_named_const(p1, 1, "x3"); + p2 = talloc_named_const(p1, 1, "p2"); + + r1 = talloc_named_const(root, 1, "r1"); + ref = talloc_reference(r1, p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 2); + + printf("Freeing ref\n"); + talloc_free(ref); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p2\n"); + talloc_free(p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 4); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p1\n"); + talloc_free(p1); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(r1, 1); + + printf("Freeing r1\n"); + talloc_free(r1); + talloc_report_full(root, stdout); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + +/* + test references +*/ +static BOOL test_ref3(void) +{ + void *root, *p1, *p2, *ref, *r1; + + printf("TESTING PARENT REFERENCE FREE\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "p1"); + p2 = talloc_named_const(root, 1, "p2"); + r1 = talloc_named_const(p1, 1, "r1"); + ref = talloc_reference(p2, r1); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 2); + CHECK_BLOCKS(p2, 2); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p1\n"); + talloc_free(p1); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p2, 2); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p2\n"); + talloc_free(p2); + talloc_report_full(root, stdout); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + +/* + test references +*/ +static BOOL test_ref4(void) +{ + void *root, *p1, *p2, *ref, *r1; + + printf("TESTING REFERRER REFERENCE FREE\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "p1"); + talloc_named_const(p1, 1, "x1"); + talloc_named_const(p1, 1, "x2"); + talloc_named_const(p1, 1, "x3"); + p2 = talloc_named_const(p1, 1, "p2"); + + r1 = talloc_named_const(root, 1, "r1"); + ref = talloc_reference(r1, p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 2); + + printf("Freeing r1\n"); + talloc_free(r1); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 5); + CHECK_BLOCKS(p2, 1); + + printf("Freeing p2\n"); + talloc_free(p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 4); + + printf("Freeing p1\n"); + talloc_free(p1); + talloc_report_full(root, stdout); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + + +/* + test references +*/ +static BOOL test_unlink1(void) +{ + void *root, *p1, *p2, *ref, *r1; + + printf("TESTING UNLINK\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "p1"); + talloc_named_const(p1, 1, "x1"); + talloc_named_const(p1, 1, "x2"); + talloc_named_const(p1, 1, "x3"); + p2 = talloc_named_const(p1, 1, "p2"); + + r1 = talloc_named_const(p1, 1, "r1"); + ref = talloc_reference(r1, p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 7); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 2); + + printf("Unreferencing r1\n"); + talloc_unlink(r1, p2); + talloc_report_full(root, stdout); + + CHECK_BLOCKS(p1, 6); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(r1, 1); + + printf("Freeing p1\n"); + talloc_free(p1); + talloc_report_full(root, stdout); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + +static int fail_destructor(void *ptr) +{ + return -1; +} + +/* + miscellaneous tests to try to get a higher test coverage percentage +*/ +static BOOL test_misc(void) +{ + void *root, *p1; + char *p2; + double *d; + + printf("TESTING MISCELLANEOUS\n"); + + root = talloc(NULL, 0); + + p1 = talloc(root, 0x7fffffff); + if (p1) { + printf("failed: large talloc allowed\n"); + return False; + } + + p1 = talloc_strdup(root, "foo"); + talloc_increase_ref_count(p1); + talloc_increase_ref_count(p1); + talloc_increase_ref_count(p1); + CHECK_BLOCKS(p1, 1); + CHECK_BLOCKS(root, 2); + talloc_free(p1); + CHECK_BLOCKS(p1, 1); + CHECK_BLOCKS(root, 2); + talloc_unlink(NULL, p1); + CHECK_BLOCKS(p1, 1); + CHECK_BLOCKS(root, 2); + p2 = talloc_strdup(p1, "foo"); + if (talloc_unlink(root, p2) != -1) { + printf("failed: talloc_unlink() of non-reference context should return -1\n"); + return False; + } + if (talloc_unlink(p1, p2) != 0) { + printf("failed: talloc_unlink() of parent should succeed\n"); + return False; + } + talloc_free(p1); + CHECK_BLOCKS(p1, 1); + CHECK_BLOCKS(root, 2); + + talloc_set_name(p1, "my name is %s", "foo"); + if (strcmp(talloc_get_name(p1), "my name is foo") != 0) { + printf("failed: wrong name after talloc_set_name\n"); + return False; + } + CHECK_BLOCKS(p1, 2); + CHECK_BLOCKS(root, 3); + + talloc_set_name_const(p1, NULL); + if (strcmp(talloc_get_name(p1), "UNNAMED") != 0) { + printf("failed: wrong name after talloc_set_name(NULL)\n"); + return False; + } + CHECK_BLOCKS(p1, 2); + CHECK_BLOCKS(root, 3); + + + if (talloc_free(NULL) != -1) { + printf("talloc_free(NULL) should give -1\n"); + return False; + } + + talloc_set_destructor(p1, fail_destructor); + if (talloc_free(p1) != -1) { + printf("Failed destructor should cause talloc_free to fail\n"); + return False; + } + talloc_set_destructor(p1, NULL); + + talloc_report(root, stdout); + + + p2 = talloc_zero(p1, 20); + if (p2[19] != 0) { + printf("Failed to give zero memory\n"); + return False; + } + talloc_free(p2); + + if (talloc_strdup(root, NULL) != NULL) { + printf("failed: strdup on NULL should give NULL\n"); + return False; + } + + p2 = talloc_strndup(p1, "foo", 2); + if (strcmp("fo", p2) != 0) { + printf("failed: strndup doesn't work\n"); + return False; + } + p2 = talloc_asprintf_append(p2, "o%c", 'd'); + if (strcmp("food", p2) != 0) { + printf("failed: talloc_asprintf_append doesn't work\n"); + return False; + } + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(p1, 3); + + p2 = talloc_asprintf_append(NULL, "hello %s", "world"); + if (strcmp("hello world", p2) != 0) { + printf("failed: talloc_asprintf_append doesn't work\n"); + return False; + } + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(p1, 3); + talloc_free(p2); + + d = talloc_array_p(p1, double, 0x20000000); + if (d) { + printf("failed: integer overflow not detected\n"); + return False; + } + + d = talloc_realloc_p(p1, d, double, 0x20000000); + if (d) { + printf("failed: integer overflow not detected\n"); + return False; + } + + talloc_free(p1); + CHECK_BLOCKS(root, 1); + + p1 = talloc_named(root, 100, "%d bytes", 100); + CHECK_BLOCKS(p1, 2); + CHECK_BLOCKS(root, 3); + talloc_unlink(root, p1); + + p1 = talloc_init("%d bytes", 200); + p2 = talloc_asprintf(p1, "my test '%s'", "string"); + CHECK_BLOCKS(p1, 3); + CHECK_SIZE(p2, 17); + CHECK_BLOCKS(root, 1); + talloc_unlink(NULL, p1); + + p1 = talloc_named_const(root, 10, "p1"); + p2 = talloc_named_const(root, 20, "p2"); + talloc_reference(p1, p2); + talloc_report_full(root, stdout); + talloc_unlink(root, p2); + talloc_report_full(root, stdout); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(p1, 2); + CHECK_BLOCKS(root, 3); + talloc_unlink(p1, p2); + talloc_unlink(root, p1); + + p1 = talloc_named_const(root, 10, "p1"); + p2 = talloc_named_const(root, 20, "p2"); + talloc_reference(NULL, p2); + talloc_report_full(root, stdout); + talloc_unlink(root, p2); + talloc_report_full(root, stdout); + CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS(p1, 1); + CHECK_BLOCKS(root, 2); + talloc_unlink(NULL, p2); + talloc_unlink(root, p1); + + /* Test that talloc_unlink is a no-op */ + + if (talloc_unlink(root, NULL) != -1) { + printf("failed: talloc_unlink(root, NULL) == -1\n"); + return False; + } + + talloc_report(root, stdout); + talloc_report(NULL, stdout); + + CHECK_SIZE(root, 0); + + talloc_free(root); + + CHECK_SIZE(NULL, 0); + + talloc_enable_leak_report(); + talloc_enable_leak_report_full(); + + return True; +} + + +/* + test realloc +*/ +static BOOL test_realloc(void) +{ + void *root, *p1, *p2; + + printf("TESTING REALLOC\n"); + + root = talloc(NULL, 0); + + p1 = talloc(root, 10); + CHECK_SIZE(p1, 10); + + p1 = talloc_realloc(NULL, p1, 20); + CHECK_SIZE(p1, 20); + + talloc(p1, 0); + + p2 = talloc_realloc(p1, NULL, 30); + + talloc(p1, 0); + + p2 = talloc_realloc(p1, p2, 40); + + CHECK_SIZE(p2, 40); + CHECK_SIZE(root, 60); + CHECK_BLOCKS(p1, 4); + + p1 = talloc_realloc(NULL, p1, 20); + CHECK_SIZE(p1, 60); + + talloc_increase_ref_count(p2); + if (talloc_realloc(NULL, p2, 5) != NULL) { + printf("failed: talloc_realloc() on a referenced pointer should fail\n"); + return False; + } + CHECK_BLOCKS(p1, 4); + + talloc_realloc(NULL, p2, 0); + talloc_realloc(NULL, p2, 0); + CHECK_BLOCKS(p1, 3); + + if (talloc_realloc(NULL, p1, 0x7fffffff) != NULL) { + printf("failed: oversize talloc should fail\n"); + return False; + } + + talloc_realloc(NULL, p1, 0); + + CHECK_BLOCKS(root, 1); + CHECK_SIZE(root, 0); + + talloc_free(root); + + return True; +} + + +/* + test realloc with a child +*/ +static BOOL test_realloc_child(void) +{ + void *root; + struct el1 { + int count; + struct el2 { + const char *name; + } **list; + } *el1; + struct el2 *el2; + + printf("TESTING REALLOC WITH CHILD\n"); + + root = talloc(NULL, 0); + + el1 = talloc_p(root, struct el1); + el1->list = talloc_p(el1, struct el2 *); + el1->list[0] = talloc_p(el1->list, struct el2); + el1->list[0]->name = talloc_strdup(el1->list[0], "testing"); + + el2 = talloc_p(el1->list, struct el2); + + el1->list = talloc_realloc_p(el1, el1->list, struct el2 *, 2); + el1->list[1] = el2; + + talloc_free(root); + + return True; +} + +/* + test steal +*/ +static BOOL test_steal(void) +{ + void *root, *p1, *p2; + + printf("TESTING STEAL\n"); + + root = talloc(NULL, 0); + + p1 = talloc_array_p(root, char, 10); + CHECK_SIZE(p1, 10); + + p2 = talloc_realloc_p(root, NULL, char, 20); + CHECK_SIZE(p1, 10); + CHECK_SIZE(root, 30); + + if (talloc_steal(p1, NULL) != NULL) { + printf("failed: stealing NULL should give NULL\n"); + return False; + } + + if (talloc_steal(p1, p1) != p1) { + printf("failed: stealing to ourselves is a nop\n"); + return False; + } + CHECK_BLOCKS(root, 3); + CHECK_SIZE(root, 30); + + talloc_steal(NULL, p1); + talloc_steal(NULL, p2); + CHECK_BLOCKS(root, 1); + CHECK_SIZE(root, 0); + + talloc_free(p1); + talloc_steal(root, p2); + CHECK_BLOCKS(root, 2); + CHECK_SIZE(root, 20); + + talloc_free(p2); + + CHECK_BLOCKS(root, 1); + CHECK_SIZE(root, 0); + + talloc_free(root); + + p1 = talloc(NULL, 3); + CHECK_SIZE(NULL, 3); + talloc_free(p1); + + return True; +} + +/* + test ldb alloc fn +*/ +static BOOL test_ldb(void) +{ + void *root, *p1; + + printf("TESTING LDB\n"); + + root = talloc(NULL, 0); + + p1 = talloc_realloc_fn(root, NULL, 10); + CHECK_BLOCKS(root, 2); + CHECK_SIZE(root, 10); + p1 = talloc_realloc_fn(root, p1, 20); + CHECK_BLOCKS(root, 2); + CHECK_SIZE(root, 20); + p1 = talloc_realloc_fn(root, p1, 0); + CHECK_BLOCKS(root, 1); + CHECK_SIZE(root, 0); + + talloc_free(root); + + + return True; +} + + +static BOOL test_unref_reparent(void) +{ + void *root, *p1, *p2, *c1; + + printf("TESTING UNREFERENCE AFTER PARENT FREED\n"); + + root = talloc_named_const(NULL, 0, "root"); + p1 = talloc_named_const(root, 1, "orig parent"); + p2 = talloc_named_const(root, 1, "parent by reference"); + + c1 = talloc_named_const(p1, 1, "child"); + talloc_reference(p2, c1); + + talloc_free(p1); + talloc_unlink(p2, c1); + + CHECK_SIZE(root, 1); + + talloc_free(p2); + talloc_free(root); + + return True; +} + +/* + measure the speed of talloc versus malloc +*/ +static BOOL test_speed(void) +{ + void *ctx = talloc(NULL, 0); + unsigned count; + struct timeval tv; + + printf("MEASURING TALLOC VS MALLOC SPEED\n"); + + tv = timeval_current(); + count = 0; + do { + void *p1, *p2, *p3; + p1 = talloc(ctx, count); + p2 = talloc_strdup(p1, "foo bar"); + p3 = talloc(p1, 300); + talloc_free(p1); + count += 3; + } while (timeval_elapsed(&tv) < 5.0); + + printf("talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); + + talloc_free(ctx); + + tv = timeval_current(); + count = 0; + do { + void *p1, *p2, *p3; + p1 = malloc(count); + p2 = strdup("foo bar"); + p3 = malloc(300); + free(p1); + free(p2); + free(p3); + count += 3; + } while (timeval_elapsed(&tv) < 5.0); + + printf("malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); + + return True; +} + + +BOOL torture_local_talloc(void) +{ + BOOL ret = True; + + ret &= test_ref1(); + ret &= test_ref2(); + ret &= test_ref3(); + ret &= test_ref4(); + ret &= test_unlink1(); + ret &= test_misc(); + ret &= test_realloc(); + ret &= test_realloc_child(); + ret &= test_steal(); + ret &= test_unref_reparent(); + ret &= test_ldb(); + if (ret) { + ret &= test_speed(); + } + + return ret; +} + + + +#ifndef _SAMBA_BUILD_ + int main(void) +{ + if (!torture_local_talloc()) { + printf("ERROR: TESTSUIE FAILED\n"); + return -1; + } + return 0; +} +#endif -- cgit From cc55aef7c116d03ba2817625b0ba9edb378525e3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 02:32:43 +0000 Subject: r4547: - added talloc_new(ctx) macro that is a neater form of the common talloc(ctx, 0) call. - cleaned up some talloc usage in various files I'd like to get to the point that we have no calls to talloc(), at which point we will rename talloc_p() to talloc(), to encourage everyone to use the typesafe functions. (This used to be commit e6c81d7c9f8a6938947d3c1c8a971a0d6d50b67a) --- source4/lib/talloc/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 22444b1116..a3a448ef40 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -333,7 +333,7 @@ static BOOL test_misc(void) printf("TESTING MISCELLANEOUS\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc(root, 0x7fffffff); if (p1) { @@ -515,7 +515,7 @@ static BOOL test_realloc(void) printf("TESTING REALLOC\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc(root, 10); CHECK_SIZE(p1, 10); -- cgit From ddc10d4d37984246a6547e34a32d629c689c40d1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 03:06:58 +0000 Subject: r4549: got rid of a lot more uses of plain talloc(), instead using talloc_size() or talloc_array_p() where appropriate. also fixed a memory leak in pvfs_copy_file() (failed to free a memory context) (This used to be commit 89b74b53546e1570b11b3702f40bee58aed8c503) --- source4/lib/talloc/testsuite.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index a3a448ef40..ced3217105 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -335,7 +335,7 @@ static BOOL test_misc(void) root = talloc_new(NULL); - p1 = talloc(root, 0x7fffffff); + p1 = talloc_size(root, 0x7fffffff); if (p1) { printf("failed: large talloc allowed\n"); return False; @@ -517,7 +517,7 @@ static BOOL test_realloc(void) root = talloc_new(NULL); - p1 = talloc(root, 10); + p1 = talloc_size(root, 10); CHECK_SIZE(p1, 10); p1 = talloc_realloc(NULL, p1, 20); @@ -581,7 +581,7 @@ static BOOL test_realloc_child(void) printf("TESTING REALLOC WITH CHILD\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); el1 = talloc_p(root, struct el1); el1->list = talloc_p(el1, struct el2 *); @@ -607,7 +607,7 @@ static BOOL test_steal(void) printf("TESTING STEAL\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc_array_p(root, char, 10); CHECK_SIZE(p1, 10); @@ -645,7 +645,7 @@ static BOOL test_steal(void) talloc_free(root); - p1 = talloc(NULL, 3); + p1 = talloc_new(NULL); CHECK_SIZE(NULL, 3); talloc_free(p1); @@ -661,7 +661,7 @@ static BOOL test_ldb(void) printf("TESTING LDB\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc_realloc_fn(root, NULL, 10); CHECK_BLOCKS(root, 2); @@ -709,7 +709,7 @@ static BOOL test_unref_reparent(void) */ static BOOL test_speed(void) { - void *ctx = talloc(NULL, 0); + void *ctx = talloc_new(NULL); unsigned count; struct timeval tv; @@ -719,9 +719,9 @@ static BOOL test_speed(void) count = 0; do { void *p1, *p2, *p3; - p1 = talloc(ctx, count); + p1 = talloc_size(ctx, count); p2 = talloc_strdup(p1, "foo bar"); - p3 = talloc(p1, 300); + p3 = talloc_size(p1, 300); talloc_free(p1); count += 3; } while (timeval_elapsed(&tv) < 5.0); -- cgit From e159e42d8472f36f51e400e351fc43f2a7dc44f5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 03:20:56 +0000 Subject: r4550: talloc() is now typesafe. It is exactly equivalent to the old talloc_p() macro. Use talloc_size() if you want the old behaviour. I have kept talloc_p() as an alias for now. Once we change all calls to be plain talloc() then we can remove it. (This used to be commit 2011bbeb841fd6bfccf3d44a49f79203f7f55baa) --- source4/lib/talloc/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index ced3217105..d46964d9b6 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -523,11 +523,11 @@ static BOOL test_realloc(void) p1 = talloc_realloc(NULL, p1, 20); CHECK_SIZE(p1, 20); - talloc(p1, 0); + talloc_new(p1); p2 = talloc_realloc(p1, NULL, 30); - talloc(p1, 0); + talloc_new(p1); p2 = talloc_realloc(p1, p2, 40); -- cgit From 11ce2cfd70df264c5c91b4daaa9a01c5abc673b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2005 04:39:16 +0000 Subject: r4591: - converted the other _p talloc functions to not need _p - added #if TALLOC_DEPRECATED around the _p functions - fixes the code that broke from the above while doing this I fixed quite a number of places that were incorrectly using the non type-safe talloc functions to use the type safe ones. Some were even doing multiplies for array allocation, which is potentially unsafe. (This used to be commit 6e7754abd0c225527fb38363996a6e241b87b37e) --- source4/lib/talloc/testsuite.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index d46964d9b6..e7934a10f3 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -398,7 +398,7 @@ static BOOL test_misc(void) talloc_report(root, stdout); - p2 = talloc_zero(p1, 20); + p2 = talloc_zero_size(p1, 20); if (p2[19] != 0) { printf("Failed to give zero memory\n"); return False; @@ -520,41 +520,41 @@ static BOOL test_realloc(void) p1 = talloc_size(root, 10); CHECK_SIZE(p1, 10); - p1 = talloc_realloc(NULL, p1, 20); + p1 = talloc_realloc_size(NULL, p1, 20); CHECK_SIZE(p1, 20); talloc_new(p1); - p2 = talloc_realloc(p1, NULL, 30); + p2 = talloc_realloc_size(p1, NULL, 30); talloc_new(p1); - p2 = talloc_realloc(p1, p2, 40); + p2 = talloc_realloc_size(p1, p2, 40); CHECK_SIZE(p2, 40); CHECK_SIZE(root, 60); CHECK_BLOCKS(p1, 4); - p1 = talloc_realloc(NULL, p1, 20); + p1 = talloc_realloc_size(NULL, p1, 20); CHECK_SIZE(p1, 60); talloc_increase_ref_count(p2); - if (talloc_realloc(NULL, p2, 5) != NULL) { + if (talloc_realloc_size(NULL, p2, 5) != NULL) { printf("failed: talloc_realloc() on a referenced pointer should fail\n"); return False; } CHECK_BLOCKS(p1, 4); - talloc_realloc(NULL, p2, 0); - talloc_realloc(NULL, p2, 0); + talloc_realloc_size(NULL, p2, 0); + talloc_realloc_size(NULL, p2, 0); CHECK_BLOCKS(p1, 3); - if (talloc_realloc(NULL, p1, 0x7fffffff) != NULL) { + if (talloc_realloc_size(NULL, p1, 0x7fffffff) != NULL) { printf("failed: oversize talloc should fail\n"); return False; } - talloc_realloc(NULL, p1, 0); + talloc_realloc_size(NULL, p1, 0); CHECK_BLOCKS(root, 1); CHECK_SIZE(root, 0); -- cgit From 8b1512fc9bf73ade637c9f04974d8c01797d7bdc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2005 04:45:11 +0000 Subject: r4592: fixed typo from talloc testsuite fixup for the new syntax (This used to be commit 1177200dd9392c088f5b009f55390ad31c367e5f) --- source4/lib/talloc/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index e7934a10f3..005474a2cc 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -645,7 +645,7 @@ static BOOL test_steal(void) talloc_free(root); - p1 = talloc_new(NULL); + p1 = talloc_size(NULL, 3); CHECK_SIZE(NULL, 3); talloc_free(p1); -- cgit From 35a2ced64a3c853289d7fa921e91724ce2998b79 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2005 04:47:58 +0000 Subject: r4593: don't use the _p function in the testsuite, as when built standalone it doesn't use TALLOC_DEPRECATED (This used to be commit 2fe0e2528f14627832942f6404a4b1be4b556c97) --- source4/lib/talloc/testsuite.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 005474a2cc..d93894b520 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -432,13 +432,13 @@ static BOOL test_misc(void) CHECK_BLOCKS(p1, 3); talloc_free(p2); - d = talloc_array_p(p1, double, 0x20000000); + d = talloc_array(p1, double, 0x20000000); if (d) { printf("failed: integer overflow not detected\n"); return False; } - d = talloc_realloc_p(p1, d, double, 0x20000000); + d = talloc_realloc(p1, d, double, 0x20000000); if (d) { printf("failed: integer overflow not detected\n"); return False; @@ -583,14 +583,14 @@ static BOOL test_realloc_child(void) root = talloc_new(NULL); - el1 = talloc_p(root, struct el1); - el1->list = talloc_p(el1, struct el2 *); - el1->list[0] = talloc_p(el1->list, struct el2); + el1 = talloc(root, struct el1); + el1->list = talloc(el1, struct el2 *); + el1->list[0] = talloc(el1->list, struct el2); el1->list[0]->name = talloc_strdup(el1->list[0], "testing"); - el2 = talloc_p(el1->list, struct el2); + el2 = talloc(el1->list, struct el2); - el1->list = talloc_realloc_p(el1, el1->list, struct el2 *, 2); + el1->list = talloc_realloc(el1, el1->list, struct el2 *, 2); el1->list[1] = el2; talloc_free(root); @@ -609,10 +609,10 @@ static BOOL test_steal(void) root = talloc_new(NULL); - p1 = talloc_array_p(root, char, 10); + p1 = talloc_array(root, char, 10); CHECK_SIZE(p1, 10); - p2 = talloc_realloc_p(root, NULL, char, 20); + p2 = talloc_realloc(root, NULL, char, 20); CHECK_SIZE(p1, 10); CHECK_SIZE(root, 30); -- cgit From 4b73689468ebe2e25a22d73fecb1a035b2303efd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Jan 2005 11:45:43 +0000 Subject: r4711: - deprecate talloc_destroy() - expanded the talloc_realloc() test a little (I was concerned about a possible bug, which turned out to be an illusion) - don't enable gcov by default in Makefile.talloc (This used to be commit 4ec47cc1083c4cdb780e548177631c5914bf677a) --- source4/lib/talloc/testsuite.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index d93894b520..bc1c18fdc1 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -575,7 +575,7 @@ static BOOL test_realloc_child(void) int count; struct el2 { const char *name; - } **list; + } **list, **list2, **list3; } *el1; struct el2 *el2; @@ -587,11 +587,22 @@ static BOOL test_realloc_child(void) el1->list = talloc(el1, struct el2 *); el1->list[0] = talloc(el1->list, struct el2); el1->list[0]->name = talloc_strdup(el1->list[0], "testing"); + + el1->list2 = talloc(el1, struct el2 *); + el1->list2[0] = talloc(el1->list2, struct el2); + el1->list2[0]->name = talloc_strdup(el1->list2[0], "testing2"); + + el1->list3 = talloc(el1, struct el2 *); + el1->list3[0] = talloc(el1->list3, struct el2); + el1->list3[0]->name = talloc_strdup(el1->list3[0], "testing2"); el2 = talloc(el1->list, struct el2); + el2 = talloc(el1->list2, struct el2); + el2 = talloc(el1->list3, struct el2); - el1->list = talloc_realloc(el1, el1->list, struct el2 *, 2); - el1->list[1] = el2; + el1->list = talloc_realloc(el1, el1->list, struct el2 *, 100); + el1->list2 = talloc_realloc(el1, el1->list2, struct el2 *, 200); + el1->list3 = talloc_realloc(el1, el1->list3, struct el2 *, 300); talloc_free(root); -- cgit From 7b79694eadc288592729567c3caa7c70f6662760 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 23:21:52 +0000 Subject: r4790: added type checking helper macros in talloc. These take advantage of the type names that talloc already keeps around for pointers, and allows the user to type check void* private pointers. It can also be used to implement polymorphism in C, as I'm sure someone would have pointed out to me sooner or later :-) (This used to be commit c283e1a3efac3a92e29a35856e20eb61ef4c221e) --- source4/lib/talloc/testsuite.c | 51 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index bc1c18fdc1..4a1074e045 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -609,6 +609,48 @@ static BOOL test_realloc_child(void) return True; } + +/* + test type checking +*/ +static BOOL test_type(void) +{ + void *root; + struct el1 { + int count; + }; + struct el2 { + int count; + }; + struct el1 *el1; + + printf("TESTING talloc type checking\n"); + + root = talloc_new(NULL); + + el1 = talloc(root, struct el1); + + el1->count = 1; + + if (talloc_get_type(el1, struct el1) != el1) { + printf("type check failed on el1\n"); + return False; + } + if (talloc_get_type(el1, struct el2) != NULL) { + printf("type check failed on el1 with el2\n"); + return False; + } + talloc_set_type(el1, struct el2); + if (talloc_get_type(el1, struct el2) != el1) { + printf("type set failed on el1 with el2\n"); + return False; + } + + talloc_free(root); + + return True; +} + /* test steal */ @@ -664,13 +706,13 @@ static BOOL test_steal(void) } /* - test ldb alloc fn + test talloc_realloc_fn */ -static BOOL test_ldb(void) +static BOOL test_realloc_fn(void) { void *root, *p1; - printf("TESTING LDB\n"); + printf("TESTING talloc_realloc_fn\n"); root = talloc_new(NULL); @@ -774,7 +816,8 @@ BOOL torture_local_talloc(void) ret &= test_realloc_child(); ret &= test_steal(); ret &= test_unref_reparent(); - ret &= test_ldb(); + ret &= test_realloc_fn(); + ret &= test_type(); if (ret) { ret &= test_speed(); } -- cgit From dd0d8b2a89309302e94c3fec1c06ce769a1fec60 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 31 Jan 2005 16:36:57 +0000 Subject: r5142: fix compiler warning metze (This used to be commit d8aeb69ea85cc0df89e213482c446eb8e793bc86) --- source4/lib/talloc/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 4a1074e045..967874917d 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -641,7 +641,7 @@ static BOOL test_type(void) return False; } talloc_set_type(el1, struct el2); - if (talloc_get_type(el1, struct el2) != el1) { + if (talloc_get_type(el1, struct el2) != (struct el2 *)el1) { printf("type set failed on el1 with el2\n"); return False; } -- cgit From c1d31ac8fc22a46d3ce7d99058e48058464f4e06 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 7 May 2005 22:10:26 +0000 Subject: r6660: Sorry for the spam... I think now I've got a version that should compile on trunk, 3_0 and 4_0. Volker (This used to be commit 777c489cad610fef140ec80d5644111b04a314c1) --- source4/lib/talloc/testsuite.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 967874917d..0447749abd 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -35,6 +35,10 @@ /* the test suite can be built standalone, or as part of Samba */ #ifndef _SAMBA_BUILD_ typedef enum {False=0,True=1} BOOL; +#endif + +/* Samba3 does not define the timeval functions below */ +#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) static struct timeval timeval_current(void) { @@ -51,6 +55,14 @@ static double timeval_elapsed(struct timeval *tv) } #endif /* _SAMBA_BUILD_ */ +#if SAMBA_VERSION_MAJOR<4 +#ifdef malloc +#undef malloc +#endif +#ifdef strdup +#undef strdup +#endif +#endif #define CHECK_SIZE(ptr, tsize) do { \ if (talloc_total_size(ptr) != (tsize)) { \ @@ -827,7 +839,7 @@ BOOL torture_local_talloc(void) -#ifndef _SAMBA_BUILD_ +#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) int main(void) { if (!torture_local_talloc()) { -- cgit From 1f474c2692af8ba704a4071fe6e496cb43e19bae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 May 2005 01:57:27 +0000 Subject: r6804: Add config.h for talloc (and use it) (This used to be commit c2ce09d38003fd43212de9cd08e4a781cc2aff88) --- source4/lib/talloc/testsuite.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 0447749abd..0e3d334316 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -20,17 +20,19 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef _SAMBA_BUILD_ -#include "includes.h" -#else +#include "config.h" #include #include #include + +#ifdef HAVE_STDARG_H #include +#endif + #include #include + #include "talloc.h" -#endif /* the test suite can be built standalone, or as part of Samba */ #ifndef _SAMBA_BUILD_ -- cgit From 5251703764846f0ed2c06127d67f4b4f65d08945 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 May 2005 02:38:50 +0000 Subject: r6807: Fix in-tree build of talloc testsuite (This used to be commit 3541ebe31bef8ccae7a8a1ea4f451ddfbd24460a) --- source4/lib/talloc/testsuite.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 0e3d334316..1d5665c338 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -34,13 +34,7 @@ #include "talloc.h" -/* the test suite can be built standalone, or as part of Samba */ -#ifndef _SAMBA_BUILD_ typedef enum {False=0,True=1} BOOL; -#endif - -/* Samba3 does not define the timeval functions below */ -#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) static struct timeval timeval_current(void) { @@ -55,7 +49,6 @@ static double timeval_elapsed(struct timeval *tv) return (tv2.tv_sec - tv->tv_sec) + (tv2.tv_usec - tv->tv_usec)*1.0e-6; } -#endif /* _SAMBA_BUILD_ */ #if SAMBA_VERSION_MAJOR<4 #ifdef malloc -- cgit From 9e044848e394e4395f88b77361e7be06833e3bb8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 May 2005 02:45:36 +0000 Subject: r6808: - test for gcov not needed - samba malloc wrapper avoidance not needed now we don't use includes.h - make testsuite work when BOOL, True, False already defined (This used to be commit c8a274c8735957a8a8dd21421abd65a8a1af20f7) --- source4/lib/talloc/testsuite.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 1d5665c338..60da1c3f87 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -34,7 +34,15 @@ #include "talloc.h" -typedef enum {False=0,True=1} BOOL; +#ifndef False +#define False 0 +#endif +#ifndef True +#define True 1 +#endif +#ifndef BOOL +#define BOOL int +#endif static struct timeval timeval_current(void) { @@ -706,6 +714,7 @@ static BOOL test_steal(void) talloc_free(root); p1 = talloc_size(NULL, 3); + talloc_report_full(NULL, stdout); CHECK_SIZE(NULL, 3); talloc_free(p1); -- cgit From 9cfe2d83f1103f83ace2ead46e31d7368a29f3c0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Jul 2005 01:25:55 +0000 Subject: r8032: added loop detection into talloc. Robert Collins found a way to make a memory loop with talloc_unlink(), so now we detect it and handle it (This used to be commit 563058e78b8c74e821fabf6a43fa861c1ad09944) --- source4/lib/talloc/testsuite.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 60da1c3f87..422cb8fee5 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -818,6 +818,26 @@ static BOOL test_speed(void) } +BOOL test_lifeless(void) +{ + char *top = talloc_new(NULL); + char *parent, *child; + char *child_owner = talloc_new(NULL); + + printf("TESTING TALLOC_UNLINK LOOP\n"); + + parent = talloc_strdup(top, "parent"); + child = talloc_strdup(parent, "child"); + talloc_reference(child, parent); + talloc_reference(child_owner, child); + talloc_unlink(top, parent); + talloc_free(child); + talloc_report_full(top, stdout); + talloc_free(top); + return True; +} + + BOOL torture_local_talloc(void) { BOOL ret = True; @@ -834,6 +854,7 @@ BOOL torture_local_talloc(void) ret &= test_unref_reparent(); ret &= test_realloc_fn(); ret &= test_type(); + ret &= test_lifeless(); if (ret) { ret &= test_speed(); } -- cgit From 4476dfd3bd34be68793a02ce0722b729528058fa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Dec 2005 00:25:06 +0000 Subject: r11984: LGPL on header and testsuite as well (This used to be commit ed90975bf50644f00da681eb7cc41123abc60f81) --- source4/lib/talloc/testsuite.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 422cb8fee5..a37f8c197e 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -5,19 +5,23 @@ Copyright (C) Andrew Tridgell 2004 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + ** NOTE! The following LGPL license applies to the talloc + ** library. This does NOT imply that all of Samba is released + ** under the LGPL - This program is distributed in the hope that it will be useful, + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" -- cgit From 909b111f587705a45f63540b39968f1af58a9b5d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 25 Mar 2006 16:01:28 +0000 Subject: r14720: Add torture_context argument to all torture tests (This used to be commit 3c7a5ce29108dd82210dc3e1f00414f545949e1d) --- source4/lib/talloc/testsuite.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index a37f8c197e..b03be98587 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -48,6 +48,8 @@ #define BOOL int #endif +struct torture_context; + static struct timeval timeval_current(void) { struct timeval tv; @@ -842,7 +844,7 @@ BOOL test_lifeless(void) } -BOOL torture_local_talloc(void) +BOOL torture_local_talloc(struct torture_context *torture) { BOOL ret = True; @@ -871,8 +873,8 @@ BOOL torture_local_talloc(void) #if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) int main(void) { - if (!torture_local_talloc()) { - printf("ERROR: TESTSUIE FAILED\n"); + if (!torture_local_talloc(NULL)) { + printf("ERROR: TESTSUITE FAILED\n"); return -1; } return 0; -- cgit From 5da75f5c3631247615efdf73fae2481df6908cb8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 23 May 2006 03:51:44 +0000 Subject: r15824: fixed a subtle talloc bug to do with memory context loops. When you have a structure that references one of its parents, and a parent of that parent is freed, then the whole structure should be freed, not just the reference. this was found by the change notify code, as a side effect of fixing the memory leak yesterday (This used to be commit 70531dcaeeb9314d410baa0d285df6a265311541) --- source4/lib/talloc/testsuite.c | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index b03be98587..018d734cc3 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -824,7 +824,7 @@ static BOOL test_speed(void) } -BOOL test_lifeless(void) +static BOOL test_lifeless(void) { char *top = talloc_new(NULL); char *parent, *child; @@ -836,10 +836,53 @@ BOOL test_lifeless(void) child = talloc_strdup(parent, "child"); talloc_reference(child, parent); talloc_reference(child_owner, child); + talloc_report_full(top, stdout); talloc_unlink(top, parent); talloc_free(child); talloc_report_full(top, stdout); talloc_free(top); + talloc_free(child_owner); +#if 0 + talloc_free(child); +#endif + return True; +} + +static int loop_destructor_count; + +static int test_loop_destructor(void *ptr) +{ + printf("loop destructor\n"); + loop_destructor_count++; + return 0; +} + +static BOOL test_loop(void) +{ + char *top = talloc_new(NULL); + char *parent; + struct req1 { + char *req2, *req3; + } *req1; + + printf("TESTING TALLOC LOOP DESTRUCTION\n"); + parent = talloc_strdup(top, "parent"); + req1 = talloc(parent, struct req1); + req1->req2 = talloc_strdup(req1, "req2"); + talloc_set_destructor(req1->req2, test_loop_destructor); + req1->req3 = talloc_strdup(req1, "req3"); + talloc_reference(req1->req3, req1); + talloc_report_full(top, stdout); + talloc_free(parent); + talloc_report_full(top, stdout); + talloc_report_full(NULL, stdout); + talloc_free(top); + + if (loop_destructor_count != 1) { + printf("FAILED TO FIRE LOOP DESTRUCTOR\n"); + return False; + } + return True; } @@ -861,6 +904,7 @@ BOOL torture_local_talloc(struct torture_context *torture) ret &= test_realloc_fn(); ret &= test_type(); ret &= test_lifeless(); + ret &= test_loop(); if (ret) { ret &= test_speed(); } -- cgit From a665cccd2ef81e704e90bb228bbd14c0afb031af Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:31:02 +0000 Subject: r15852: patch from Rusty to make talloc_set_destructor() and talloc_steal() type safe. This only works on recent gcc versions. With other compilers it reverts to a non-typesafe cast The patch also ensures that talloc_free() does not change error on systems where free() can change errno (This used to be commit babbff5f777642f559747f6d0697bc7c3a5e798d) --- source4/lib/talloc/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 018d734cc3..f1b19041fa 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -850,7 +850,7 @@ static BOOL test_lifeless(void) static int loop_destructor_count; -static int test_loop_destructor(void *ptr) +static int test_loop_destructor(char *ptr) { printf("loop destructor\n"); loop_destructor_count++; -- cgit From ca17b875b3b442704625f85afdd154c9b756ca5d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 21 Jun 2006 17:49:34 +0000 Subject: r16442: if we want to use CHECK_SIZE(NULL, 3) we need null tracking, so enable it explicit before running any tests metze (This used to be commit f3cd971ab70c3edee4da87b8ca38ec215c8bff49) --- source4/lib/talloc/testsuite.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index f1b19041fa..334aa3c2e1 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -891,6 +891,8 @@ BOOL torture_local_talloc(struct torture_context *torture) { BOOL ret = True; + talloc_enable_null_tracking(); + ret &= test_ref1(); ret &= test_ref2(); ret &= test_ref3(); -- cgit From 3a0a00f1b99757976218924b14082ce765ca1d7c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 21 Jun 2006 19:26:48 +0000 Subject: r16445: print out values metze (This used to be commit 972634b2021e60b27d68b0fd6d49ef95398d92e2) --- source4/lib/talloc/testsuite.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 334aa3c2e1..10810f30e9 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -389,7 +389,8 @@ static BOOL test_misc(void) talloc_set_name(p1, "my name is %s", "foo"); if (strcmp(talloc_get_name(p1), "my name is foo") != 0) { - printf("failed: wrong name after talloc_set_name\n"); + printf("failed: wrong name after talloc_set_name(my name is foo) - '%s'\n", + talloc_get_name(p1)); return False; } CHECK_BLOCKS(p1, 2); @@ -397,7 +398,8 @@ static BOOL test_misc(void) talloc_set_name_const(p1, NULL); if (strcmp(talloc_get_name(p1), "UNNAMED") != 0) { - printf("failed: wrong name after talloc_set_name(NULL)\n"); + printf("failed: wrong name after talloc_set_name(NULL) - '%s'\n", + talloc_get_name(p1)); return False; } CHECK_BLOCKS(p1, 2); -- cgit From 3cd96fd4f9d19ebd12c849ba6997ee8ea35a9646 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 21 Jun 2006 20:28:51 +0000 Subject: r16447: print the result of talloc_set_parent() trying to find the bug on HPUX metze (This used to be commit 3db6bd87158cd615a3e35009598863758099595b) --- source4/lib/talloc/testsuite.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 10810f30e9..477d9a5848 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -351,6 +351,7 @@ static BOOL test_misc(void) void *root, *p1; char *p2; double *d; + const char *name; printf("TESTING MISCELLANEOUS\n"); @@ -387,10 +388,10 @@ static BOOL test_misc(void) CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); - talloc_set_name(p1, "my name is %s", "foo"); + name = talloc_set_name(p1, "my name is %s", "foo"); if (strcmp(talloc_get_name(p1), "my name is foo") != 0) { - printf("failed: wrong name after talloc_set_name(my name is foo) - '%s'\n", - talloc_get_name(p1)); + printf("failed: wrong name after talloc_set_name(my name is foo) - '%s'=>'%s'\n", + (name?name:"NULL"), talloc_get_name(p1)); return False; } CHECK_BLOCKS(p1, 2); -- cgit From cab68a413b55818c3ed5003832d65f976abce28f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 15 Jul 2006 13:28:52 +0000 Subject: r17061: - remove the currect talloc chunk from it's parent before freeing the children this fixes an endless loop bug! - reenable the test for this should I merge this to samba3? metze (This used to be commit 0559222b62930765519aaab5d33609ece29014d6) --- source4/lib/talloc/testsuite.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 477d9a5848..2b04f66fc4 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -845,9 +845,8 @@ static BOOL test_lifeless(void) talloc_report_full(top, stdout); talloc_free(top); talloc_free(child_owner); -#if 0 talloc_free(child); -#endif + return True; } -- cgit From 14d322332185b311d7843508cc73684700cbae33 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 05:43:47 +0000 Subject: r17413: add a new case for the this: top->level1->level2->level3 level3 has a deny destructor talloc_free(level1) result: top->level3 metze (This used to be commit 3be930b81d2caf5e13105efa02280c4fc45181cb) --- source4/lib/talloc/testsuite.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 2b04f66fc4..947540d940 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -95,6 +95,19 @@ static double timeval_elapsed(struct timeval *tv) } \ } while (0) +#define CHECK_PARENT(ptr, parent) do { \ + if (talloc_parent(ptr) != (parent)) { \ + printf(__location__ " failed: '%s' has wrong parent: got %p expected %p\n", \ + #ptr, \ + talloc_parent(ptr), \ + (parent)); \ + talloc_report_full(ptr, stdout); \ + talloc_report_full(parent, stdout); \ + talloc_report_full(NULL, stdout); \ + return False; \ + } \ +} while (0) + /* test references @@ -771,7 +784,12 @@ static BOOL test_unref_reparent(void) c1 = talloc_named_const(p1, 1, "child"); talloc_reference(p2, c1); + CHECK_PARENT(c1, p1); + talloc_free(p1); + + CHECK_PARENT(c1, p2); + talloc_unlink(p2, c1); CHECK_SIZE(root, 1); @@ -888,6 +906,28 @@ static BOOL test_loop(void) return True; } +static BOOL test_free_parent_deny_child(void) +{ + char *top = talloc_new(NULL); + char *level1; + char *level2; + char *level3; + + printf("TESTING TALLOC FREE PARENT DENY CHILD\n"); + level1 = talloc_strdup(top, "level1"); + level2 = talloc_strdup(level1, "level2"); + level3 = talloc_strdup(level2, "level3"); + + talloc_set_destructor(level3, fail_destructor); + talloc_free(level1); + talloc_set_destructor(level3, NULL); + + CHECK_PARENT(level3, top); + + talloc_free(top); + + return True; +} BOOL torture_local_talloc(struct torture_context *torture) { @@ -909,6 +949,7 @@ BOOL torture_local_talloc(struct torture_context *torture) ret &= test_type(); ret &= test_lifeless(); ret &= test_loop(); + ret &= test_free_parent_deny_child(); if (ret) { ret &= test_speed(); } -- cgit From 31356c02838a678013f0ad9416f0b101b755bd90 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 22 Aug 2006 18:49:11 +0000 Subject: r17712: fix compiler warning metze (This used to be commit 669d1e5f923a5414b8ad2537da1723d50a240387) --- source4/lib/talloc/testsuite.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 947540d940..7cd6429085 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -906,6 +906,11 @@ static BOOL test_loop(void) return True; } +static int fail_destructor_str(char *ptr) +{ + return -1; +} + static BOOL test_free_parent_deny_child(void) { char *top = talloc_new(NULL); @@ -918,7 +923,7 @@ static BOOL test_free_parent_deny_child(void) level2 = talloc_strdup(level1, "level2"); level3 = talloc_strdup(level2, "level3"); - talloc_set_destructor(level3, fail_destructor); + talloc_set_destructor(level3, fail_destructor_str); talloc_free(level1); talloc_set_destructor(level3, NULL); -- cgit From 200619b3687e1eb07e87f7d32104effab1920d77 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 28 Aug 2006 14:06:23 +0000 Subject: r17883: check if talloc_asprintf() works correct metze (This used to be commit bb79542edbb290c7dbea7c921b0e911dd1b3366b) --- source4/lib/talloc/testsuite.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 7cd6429085..f3b20fe657 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -491,6 +491,10 @@ static BOOL test_misc(void) p1 = talloc_init("%d bytes", 200); p2 = talloc_asprintf(p1, "my test '%s'", "string"); + if (strcmp(p2, "my test 'string'") != 0) { + printf("failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\"\n", p2); + return False; + } CHECK_BLOCKS(p1, 3); CHECK_SIZE(p2, 17); CHECK_BLOCKS(root, 1); -- cgit From 5ed074715a7d63b803d5eaff3144a48304201df3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 28 Aug 2006 16:55:51 +0000 Subject: r17886: add talloc_ptrtype() and talloc_array_ptrtype(), see the manpage what they do:-) metze (This used to be commit bfca83c91e47e9017474809cd7bc8b2e6e20416a) --- source4/lib/talloc/testsuite.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index f3b20fe657..45d73bd1c0 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -938,6 +938,81 @@ static BOOL test_free_parent_deny_child(void) return True; } +static BOOL test_talloc_ptrtype(void) +{ + BOOL ret = True; + char *top = talloc_new(NULL); + struct struct1 { + int foo; + int bar; + } *s1, *s2, **s3, ***s4; + const char *location1; + const char *location2; + const char *location3; + const char *location4; + + printf("TESTING TALLOC PTRTYPE\n"); + s1 = talloc_ptrtype(top, s1);location1 = __location__; + + if (talloc_get_size(s1) != sizeof(struct struct1)) { + printf("%s: talloc_ptrtype() allocated the wrong size %u (should be %u)\n", + __location__, talloc_get_size(s1), sizeof(struct struct1)); + ret = False; + } + + if (strcmp(location1, talloc_get_name(s1)) != 0) { + printf("%s: talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n", + __location__, talloc_get_name(s1), location1); + ret = False; + } + + s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; + + if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) { + printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", + __location__, talloc_get_size(s2), (sizeof(struct struct1)*10)); + ret = False; + } + + if (strcmp(location2, talloc_get_name(s2)) != 0) { + printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", + __location__, talloc_get_name(s2), location2); + ret = False; + } + + s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; + + if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) { + printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", + __location__, talloc_get_size(s3), (sizeof(struct struct1 *)*10)); + ret = False; + } + + if (strcmp(location3, talloc_get_name(s3)) != 0) { + printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", + __location__, talloc_get_name(s3), location3); + ret = False; + } + + s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; + + if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { + printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", + __location__, talloc_get_size(s4), (sizeof(struct struct1 **)*10)); + ret = False; + } + + if (strcmp(location4, talloc_get_name(s4)) != 0) { + printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", + __location__, talloc_get_name(s4), location4); + ret = False; + } + + talloc_free(top); + + return ret; +} + BOOL torture_local_talloc(struct torture_context *torture) { BOOL ret = True; @@ -959,6 +1034,7 @@ BOOL torture_local_talloc(struct torture_context *torture) ret &= test_lifeless(); ret &= test_loop(); ret &= test_free_parent_deny_child(); + ret &= test_talloc_ptrtype(); if (ret) { ret &= test_speed(); } -- cgit From 3caba856238d985c31c5e3509336060b3d8fcc86 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 29 Aug 2006 09:46:59 +0000 Subject: r17905: fix c++ warnings metze (This used to be commit 972a84f220f0dabc4e1cc3ffd40a4bf4dedc74d9) --- source4/lib/talloc/testsuite.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 45d73bd1c0..5f7b68776b 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -435,7 +435,7 @@ static BOOL test_misc(void) talloc_report(root, stdout); - p2 = talloc_zero_size(p1, 20); + p2 = (char *)talloc_zero_size(p1, 20); if (p2[19] != 0) { printf("Failed to give zero memory\n"); return False; @@ -501,8 +501,8 @@ static BOOL test_misc(void) talloc_unlink(NULL, p1); p1 = talloc_named_const(root, 10, "p1"); - p2 = talloc_named_const(root, 20, "p2"); - talloc_reference(p1, p2); + p2 = (char *)talloc_named_const(root, 20, "p2"); + (void)talloc_reference(p1, p2); talloc_report_full(root, stdout); talloc_unlink(root, p2); talloc_report_full(root, stdout); @@ -513,8 +513,8 @@ static BOOL test_misc(void) talloc_unlink(root, p1); p1 = talloc_named_const(root, 10, "p1"); - p2 = talloc_named_const(root, 20, "p2"); - talloc_reference(NULL, p2); + p2 = (char *)talloc_named_const(root, 20, "p2"); + (void)talloc_reference(NULL, p2); talloc_report_full(root, stdout); talloc_unlink(root, p2); talloc_report_full(root, stdout); @@ -851,16 +851,16 @@ static BOOL test_speed(void) static BOOL test_lifeless(void) { - char *top = talloc_new(NULL); + void *top = talloc_new(NULL); char *parent, *child; - char *child_owner = talloc_new(NULL); + void *child_owner = talloc_new(NULL); printf("TESTING TALLOC_UNLINK LOOP\n"); parent = talloc_strdup(top, "parent"); child = talloc_strdup(parent, "child"); - talloc_reference(child, parent); - talloc_reference(child_owner, child); + (void)talloc_reference(child, parent); + (void)talloc_reference(child_owner, child); talloc_report_full(top, stdout); talloc_unlink(top, parent); talloc_free(child); @@ -883,7 +883,7 @@ static int test_loop_destructor(char *ptr) static BOOL test_loop(void) { - char *top = talloc_new(NULL); + void *top = talloc_new(NULL); char *parent; struct req1 { char *req2, *req3; @@ -895,7 +895,7 @@ static BOOL test_loop(void) req1->req2 = talloc_strdup(req1, "req2"); talloc_set_destructor(req1->req2, test_loop_destructor); req1->req3 = talloc_strdup(req1, "req3"); - talloc_reference(req1->req3, req1); + (void)talloc_reference(req1->req3, req1); talloc_report_full(top, stdout); talloc_free(parent); talloc_report_full(top, stdout); @@ -917,7 +917,7 @@ static int fail_destructor_str(char *ptr) static BOOL test_free_parent_deny_child(void) { - char *top = talloc_new(NULL); + void *top = talloc_new(NULL); char *level1; char *level2; char *level3; @@ -941,7 +941,7 @@ static BOOL test_free_parent_deny_child(void) static BOOL test_talloc_ptrtype(void) { BOOL ret = True; - char *top = talloc_new(NULL); + void *top = talloc_new(NULL); struct struct1 { int foo; int bar; -- cgit From 930edaaba75fe2112380f027e3f6d5626bea703c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 31 Aug 2006 07:43:09 +0000 Subject: r17952: merge changes from samba3 metze (This used to be commit ff8d044c2e14e81b4bb32eaacc56875e9602ce4d) --- source4/lib/talloc/testsuite.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 5f7b68776b..013f01cc2c 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -24,6 +24,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef _SAMBA_BUILD_ +#include "version.h" +#endif /* _SAMBA_BUILD_ */ + #include "config.h" #include #include @@ -64,7 +68,7 @@ static double timeval_elapsed(struct timeval *tv) (tv2.tv_usec - tv->tv_usec)*1.0e-6; } -#if SAMBA_VERSION_MAJOR<4 +#if SAMBA_VERSION_MAJOR==3 #ifdef malloc #undef malloc #endif -- cgit From 722d20f4ddef98ba8f305ea858c54e5df54ca27c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 31 Aug 2006 09:26:43 +0000 Subject: r17958: as talloc_init() enabled null tracking, we should avoid to use it in smbtorture, and in the LOCAL-TALLOC we should reset the null tracking also make bin/smbtorture //url/foo LOCAL-TALLOC LOCAL-TALLOC possible metze (This used to be commit d1dd3df5e4fd21f5cbd00e472438fe3eadb266e5) --- source4/lib/talloc/testsuite.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 013f01cc2c..ca5e9042d3 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -910,6 +910,7 @@ static BOOL test_loop(void) printf("FAILED TO FIRE LOOP DESTRUCTOR\n"); return False; } + loop_destructor_count = 0; return True; } @@ -1021,6 +1022,7 @@ BOOL torture_local_talloc(struct torture_context *torture) { BOOL ret = True; + talloc_disable_null_tracking(); talloc_enable_null_tracking(); ret &= test_ref1(); -- cgit From f6f4d868ea7d3a01ec28c6855240882911cae039 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Sep 2006 08:55:58 +0000 Subject: r18027: Fix some 64-bit warnings (This used to be commit cd495d89314a653b5976b1690e075fd7bac2f59b) --- source4/lib/talloc/testsuite.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index ca5e9042d3..8640e9475e 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -960,8 +960,10 @@ static BOOL test_talloc_ptrtype(void) s1 = talloc_ptrtype(top, s1);location1 = __location__; if (talloc_get_size(s1) != sizeof(struct struct1)) { - printf("%s: talloc_ptrtype() allocated the wrong size %u (should be %u)\n", - __location__, talloc_get_size(s1), sizeof(struct struct1)); + printf("%s: talloc_ptrtype() allocated the wrong size %lu " + "(should be %lu)\n", + __location__, (unsigned long)talloc_get_size(s1), + (unsigned long)sizeof(struct struct1)); ret = False; } @@ -974,22 +976,27 @@ static BOOL test_talloc_ptrtype(void) s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", - __location__, talloc_get_size(s2), (sizeof(struct struct1)*10)); + printf("%s: talloc_array_ptrtype() allocated the wrong size " + "%lu (should be %lu)\n", + __location__, (unsigned long)talloc_get_size(s2), + (unsigned long)(sizeof(struct struct1)*10)); ret = False; } if (strcmp(location2, talloc_get_name(s2)) != 0) { printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", - __location__, talloc_get_name(s2), location2); + __location__, talloc_get_name(s2), + location2); ret = False; } s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", - __location__, talloc_get_size(s3), (sizeof(struct struct1 *)*10)); + printf("%s: talloc_array_ptrtype() allocated the wrong size " + "%lu (should be %lu)\n", + __location__, (unsigned long)talloc_get_size(s3), + (unsigned long)(sizeof(struct struct1 *)*10)); ret = False; } @@ -1002,8 +1009,10 @@ static BOOL test_talloc_ptrtype(void) s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size %u (should be %u)\n", - __location__, talloc_get_size(s4), (sizeof(struct struct1 **)*10)); + printf("%s: talloc_array_ptrtype() allocated the wrong size " + "%lu (should be %lu)\n", + __location__, (unsigned long)talloc_get_size(s4), + (unsigned long)(sizeof(struct struct1 **)*10)); ret = False; } -- cgit From 10d58661be5588e8877c696abf67a932d5a5373c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Sep 2006 06:40:39 +0000 Subject: r18064: merge from samba3 metze (This used to be commit c60deff667941e462fd9c8a894a723c792fe465e) --- source4/lib/talloc/testsuite.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 8640e9475e..ae533399bc 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -609,6 +609,14 @@ static BOOL test_realloc(void) return True; } +struct el2 { + const char *name; +}; + +struct el1 { + int count; + struct el2 **list, **list2, **list3; +}; /* test realloc with a child @@ -616,12 +624,7 @@ static BOOL test_realloc(void) static BOOL test_realloc_child(void) { void *root; - struct el1 { - int count; - struct el2 { - const char *name; - } **list, **list2, **list3; - } *el1; + struct el1 *el1; struct el2 *el2; printf("TESTING REALLOC WITH CHILD\n"); -- cgit From 7a29fb6dd77922e179300a458949bc22280bdb34 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Sep 2006 15:03:06 +0000 Subject: r18096: try to make tcc happy and don't the same struct names in a global and a local scope metze (This used to be commit b787259365eb3dbbc5e8a82a95f0beeea0015682) --- source4/lib/talloc/testsuite.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index ae533399bc..766cf039c0 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -609,23 +609,19 @@ static BOOL test_realloc(void) return True; } -struct el2 { - const char *name; -}; - -struct el1 { - int count; - struct el2 **list, **list2, **list3; -}; - /* test realloc with a child */ static BOOL test_realloc_child(void) { void *root; - struct el1 *el1; - struct el2 *el2; + struct el2 { + const char *name; + } *el2; + struct el1 { + int count; + struct el2 **list, **list2, **list3; + } *el1; printf("TESTING REALLOC WITH CHILD\n"); -- cgit From a983b06d37c3b87a02444d9a9862777b88629344 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 04:44:32 +0000 Subject: r18129: moved the system includes into libreplace - this gives much more isolation of our portability environment from the main code, and also simplifies the includes system (no separate #ifdef _SAMBA_BUILD for tdb. ldb etc now) (This used to be commit 77d1a468e06290aba789e2f3affc769fc5159a21) --- source4/lib/talloc/testsuite.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 766cf039c0..1fa2c7bfe4 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -28,18 +28,8 @@ #include "version.h" #endif /* _SAMBA_BUILD_ */ -#include "config.h" -#include -#include -#include - -#ifdef HAVE_STDARG_H -#include -#endif - -#include -#include - +#include "replace.h" +#include "system/time.h" #include "talloc.h" #ifndef False -- cgit From 1869a8cc6653ad2977b9baf3a88dc8c1a8b67fb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 6 Sep 2006 12:10:25 +0000 Subject: r18163: Remove defines for BOOL, False and True (This used to be commit 6f5e7df6f2cf67731e596b1d1d6fafbb76123e89) --- source4/lib/talloc/testsuite.c | 154 +++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 82 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 1fa2c7bfe4..2faa6d64c4 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -32,16 +32,6 @@ #include "system/time.h" #include "talloc.h" -#ifndef False -#define False 0 -#endif -#ifndef True -#define True 1 -#endif -#ifndef BOOL -#define BOOL int -#endif - struct torture_context; static struct timeval timeval_current(void) @@ -74,7 +64,7 @@ static double timeval_elapsed(struct timeval *tv) (unsigned)talloc_total_size(ptr), \ (unsigned)tsize); \ talloc_report_full(ptr, stdout); \ - return False; \ + return false; \ } \ } while (0) @@ -85,7 +75,7 @@ static double timeval_elapsed(struct timeval *tv) (unsigned)talloc_total_blocks(ptr), \ (unsigned)tblocks); \ talloc_report_full(ptr, stdout); \ - return False; \ + return false; \ } \ } while (0) @@ -98,7 +88,7 @@ static double timeval_elapsed(struct timeval *tv) talloc_report_full(ptr, stdout); \ talloc_report_full(parent, stdout); \ talloc_report_full(NULL, stdout); \ - return False; \ + return false; \ } \ } while (0) @@ -106,7 +96,7 @@ static double timeval_elapsed(struct timeval *tv) /* test references */ -static BOOL test_ref1(void) +static bool test_ref1(void) { void *root, *p1, *p2, *ref, *r1; @@ -147,7 +137,7 @@ static BOOL test_ref1(void) printf("Testing NULL\n"); if (talloc_reference(root, NULL)) { - return False; + return false; } CHECK_BLOCKS(root, 1); @@ -156,13 +146,13 @@ static BOOL test_ref1(void) talloc_free(root); - return True; + return true; } /* test references */ -static BOOL test_ref2(void) +static bool test_ref2(void) { void *root, *p1, *p2, *ref, *r1; @@ -212,13 +202,13 @@ static BOOL test_ref2(void) talloc_free(root); - return True; + return true; } /* test references */ -static BOOL test_ref3(void) +static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; @@ -250,13 +240,13 @@ static BOOL test_ref3(void) talloc_free(root); - return True; + return true; } /* test references */ -static BOOL test_ref4(void) +static bool test_ref4(void) { void *root, *p1, *p2, *ref, *r1; @@ -298,14 +288,14 @@ static BOOL test_ref4(void) talloc_free(root); - return True; + return true; } /* test references */ -static BOOL test_unlink1(void) +static bool test_unlink1(void) { void *root, *p1, *p2, *ref, *r1; @@ -342,7 +332,7 @@ static BOOL test_unlink1(void) talloc_free(root); - return True; + return true; } static int fail_destructor(void *ptr) @@ -353,7 +343,7 @@ static int fail_destructor(void *ptr) /* miscellaneous tests to try to get a higher test coverage percentage */ -static BOOL test_misc(void) +static bool test_misc(void) { void *root, *p1; char *p2; @@ -367,7 +357,7 @@ static BOOL test_misc(void) p1 = talloc_size(root, 0x7fffffff); if (p1) { printf("failed: large talloc allowed\n"); - return False; + return false; } p1 = talloc_strdup(root, "foo"); @@ -385,11 +375,11 @@ static BOOL test_misc(void) p2 = talloc_strdup(p1, "foo"); if (talloc_unlink(root, p2) != -1) { printf("failed: talloc_unlink() of non-reference context should return -1\n"); - return False; + return false; } if (talloc_unlink(p1, p2) != 0) { printf("failed: talloc_unlink() of parent should succeed\n"); - return False; + return false; } talloc_free(p1); CHECK_BLOCKS(p1, 1); @@ -399,7 +389,7 @@ static BOOL test_misc(void) if (strcmp(talloc_get_name(p1), "my name is foo") != 0) { printf("failed: wrong name after talloc_set_name(my name is foo) - '%s'=>'%s'\n", (name?name:"NULL"), talloc_get_name(p1)); - return False; + return false; } CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); @@ -408,7 +398,7 @@ static BOOL test_misc(void) if (strcmp(talloc_get_name(p1), "UNNAMED") != 0) { printf("failed: wrong name after talloc_set_name(NULL) - '%s'\n", talloc_get_name(p1)); - return False; + return false; } CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); @@ -416,13 +406,13 @@ static BOOL test_misc(void) if (talloc_free(NULL) != -1) { printf("talloc_free(NULL) should give -1\n"); - return False; + return false; } talloc_set_destructor(p1, fail_destructor); if (talloc_free(p1) != -1) { printf("Failed destructor should cause talloc_free to fail\n"); - return False; + return false; } talloc_set_destructor(p1, NULL); @@ -432,24 +422,24 @@ static BOOL test_misc(void) p2 = (char *)talloc_zero_size(p1, 20); if (p2[19] != 0) { printf("Failed to give zero memory\n"); - return False; + return false; } talloc_free(p2); if (talloc_strdup(root, NULL) != NULL) { printf("failed: strdup on NULL should give NULL\n"); - return False; + return false; } p2 = talloc_strndup(p1, "foo", 2); if (strcmp("fo", p2) != 0) { printf("failed: strndup doesn't work\n"); - return False; + return false; } p2 = talloc_asprintf_append(p2, "o%c", 'd'); if (strcmp("food", p2) != 0) { printf("failed: talloc_asprintf_append doesn't work\n"); - return False; + return false; } CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); @@ -457,7 +447,7 @@ static BOOL test_misc(void) p2 = talloc_asprintf_append(NULL, "hello %s", "world"); if (strcmp("hello world", p2) != 0) { printf("failed: talloc_asprintf_append doesn't work\n"); - return False; + return false; } CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); @@ -466,13 +456,13 @@ static BOOL test_misc(void) d = talloc_array(p1, double, 0x20000000); if (d) { printf("failed: integer overflow not detected\n"); - return False; + return false; } d = talloc_realloc(p1, d, double, 0x20000000); if (d) { printf("failed: integer overflow not detected\n"); - return False; + return false; } talloc_free(p1); @@ -487,7 +477,7 @@ static BOOL test_misc(void) p2 = talloc_asprintf(p1, "my test '%s'", "string"); if (strcmp(p2, "my test 'string'") != 0) { printf("failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\"\n", p2); - return False; + return false; } CHECK_BLOCKS(p1, 3); CHECK_SIZE(p2, 17); @@ -522,7 +512,7 @@ static BOOL test_misc(void) if (talloc_unlink(root, NULL) != -1) { printf("failed: talloc_unlink(root, NULL) == -1\n"); - return False; + return false; } talloc_report(root, stdout); @@ -537,14 +527,14 @@ static BOOL test_misc(void) talloc_enable_leak_report(); talloc_enable_leak_report_full(); - return True; + return true; } /* test realloc */ -static BOOL test_realloc(void) +static bool test_realloc(void) { void *root, *p1, *p2; @@ -576,7 +566,7 @@ static BOOL test_realloc(void) talloc_increase_ref_count(p2); if (talloc_realloc_size(NULL, p2, 5) != NULL) { printf("failed: talloc_realloc() on a referenced pointer should fail\n"); - return False; + return false; } CHECK_BLOCKS(p1, 4); @@ -586,7 +576,7 @@ static BOOL test_realloc(void) if (talloc_realloc_size(NULL, p1, 0x7fffffff) != NULL) { printf("failed: oversize talloc should fail\n"); - return False; + return false; } talloc_realloc_size(NULL, p1, 0); @@ -596,13 +586,13 @@ static BOOL test_realloc(void) talloc_free(root); - return True; + return true; } /* test realloc with a child */ -static BOOL test_realloc_child(void) +static bool test_realloc_child(void) { void *root; struct el2 { @@ -640,14 +630,14 @@ static BOOL test_realloc_child(void) talloc_free(root); - return True; + return true; } /* test type checking */ -static BOOL test_type(void) +static bool test_type(void) { void *root; struct el1 { @@ -668,27 +658,27 @@ static BOOL test_type(void) if (talloc_get_type(el1, struct el1) != el1) { printf("type check failed on el1\n"); - return False; + return false; } if (talloc_get_type(el1, struct el2) != NULL) { printf("type check failed on el1 with el2\n"); - return False; + return false; } talloc_set_type(el1, struct el2); if (talloc_get_type(el1, struct el2) != (struct el2 *)el1) { printf("type set failed on el1 with el2\n"); - return False; + return false; } talloc_free(root); - return True; + return true; } /* test steal */ -static BOOL test_steal(void) +static bool test_steal(void) { void *root, *p1, *p2; @@ -705,12 +695,12 @@ static BOOL test_steal(void) if (talloc_steal(p1, NULL) != NULL) { printf("failed: stealing NULL should give NULL\n"); - return False; + return false; } if (talloc_steal(p1, p1) != p1) { printf("failed: stealing to ourselves is a nop\n"); - return False; + return false; } CHECK_BLOCKS(root, 3); CHECK_SIZE(root, 30); @@ -737,13 +727,13 @@ static BOOL test_steal(void) CHECK_SIZE(NULL, 3); talloc_free(p1); - return True; + return true; } /* test talloc_realloc_fn */ -static BOOL test_realloc_fn(void) +static bool test_realloc_fn(void) { void *root, *p1; @@ -764,11 +754,11 @@ static BOOL test_realloc_fn(void) talloc_free(root); - return True; + return true; } -static BOOL test_unref_reparent(void) +static bool test_unref_reparent(void) { void *root, *p1, *p2, *c1; @@ -794,13 +784,13 @@ static BOOL test_unref_reparent(void) talloc_free(p2); talloc_free(root); - return True; + return true; } /* measure the speed of talloc versus malloc */ -static BOOL test_speed(void) +static bool test_speed(void) { void *ctx = talloc_new(NULL); unsigned count; @@ -838,11 +828,11 @@ static BOOL test_speed(void) printf("malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); - return True; + return true; } -static BOOL test_lifeless(void) +static bool test_lifeless(void) { void *top = talloc_new(NULL); char *parent, *child; @@ -862,7 +852,7 @@ static BOOL test_lifeless(void) talloc_free(child_owner); talloc_free(child); - return True; + return true; } static int loop_destructor_count; @@ -874,7 +864,7 @@ static int test_loop_destructor(char *ptr) return 0; } -static BOOL test_loop(void) +static bool test_loop(void) { void *top = talloc_new(NULL); char *parent; @@ -897,11 +887,11 @@ static BOOL test_loop(void) if (loop_destructor_count != 1) { printf("FAILED TO FIRE LOOP DESTRUCTOR\n"); - return False; + return false; } loop_destructor_count = 0; - return True; + return true; } static int fail_destructor_str(char *ptr) @@ -909,7 +899,7 @@ static int fail_destructor_str(char *ptr) return -1; } -static BOOL test_free_parent_deny_child(void) +static bool test_free_parent_deny_child(void) { void *top = talloc_new(NULL); char *level1; @@ -929,12 +919,12 @@ static BOOL test_free_parent_deny_child(void) talloc_free(top); - return True; + return true; } -static BOOL test_talloc_ptrtype(void) +static bool test_talloc_ptrtype(void) { - BOOL ret = True; + bool ret = true; void *top = talloc_new(NULL); struct struct1 { int foo; @@ -953,13 +943,13 @@ static BOOL test_talloc_ptrtype(void) "(should be %lu)\n", __location__, (unsigned long)talloc_get_size(s1), (unsigned long)sizeof(struct struct1)); - ret = False; + ret = false; } if (strcmp(location1, talloc_get_name(s1)) != 0) { printf("%s: talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n", __location__, talloc_get_name(s1), location1); - ret = False; + ret = false; } s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; @@ -969,14 +959,14 @@ static BOOL test_talloc_ptrtype(void) "%lu (should be %lu)\n", __location__, (unsigned long)talloc_get_size(s2), (unsigned long)(sizeof(struct struct1)*10)); - ret = False; + ret = false; } if (strcmp(location2, talloc_get_name(s2)) != 0) { printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", __location__, talloc_get_name(s2), location2); - ret = False; + ret = false; } s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; @@ -986,13 +976,13 @@ static BOOL test_talloc_ptrtype(void) "%lu (should be %lu)\n", __location__, (unsigned long)talloc_get_size(s3), (unsigned long)(sizeof(struct struct1 *)*10)); - ret = False; + ret = false; } if (strcmp(location3, talloc_get_name(s3)) != 0) { printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", __location__, talloc_get_name(s3), location3); - ret = False; + ret = false; } s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; @@ -1002,13 +992,13 @@ static BOOL test_talloc_ptrtype(void) "%lu (should be %lu)\n", __location__, (unsigned long)talloc_get_size(s4), (unsigned long)(sizeof(struct struct1 **)*10)); - ret = False; + ret = false; } if (strcmp(location4, talloc_get_name(s4)) != 0) { printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", __location__, talloc_get_name(s4), location4); - ret = False; + ret = false; } talloc_free(top); @@ -1016,9 +1006,9 @@ static BOOL test_talloc_ptrtype(void) return ret; } -BOOL torture_local_talloc(struct torture_context *torture) +bool torture_local_talloc(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; talloc_disable_null_tracking(); talloc_enable_null_tracking(); -- cgit From 1a5978445199a1d8697a5604761899aa065059fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 00:05:07 +0000 Subject: r18435: added a function talloc_move() which is like talloc_steal(), but is meant for moving pointers between structures. The difference is that talloc_move() will zero the source pointer, thus ensuring you don't reference the pointer in the old context. talloc_move() is appropriate in some, but not all cases where we use talloc_steal() now. The interface came out of a discussion with Jeremy. (This used to be commit 200756017e1867faa207703eddc00a75ae4527df) --- source4/lib/talloc/testsuite.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 2faa6d64c4..38039c11bf 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -730,6 +730,40 @@ static bool test_steal(void) return true; } +/* + test move +*/ +static bool test_move(void) +{ + void *root; + struct t_move { + char *p; + int *x; + } *t1, *t2; + printf("TESTING MOVE\n"); + + root = talloc_new(NULL); + + t1 = talloc(root, struct t_move); + t2 = talloc(root, struct t_move); + t1->p = talloc_strdup(t1, "foo"); + t1->x = talloc(t1, int); + *t1->x = 42; + + t2->p = talloc_move(t2, t1->p); + t2->x = talloc_move(t2, t1->x); + if (t1->p != NULL || t1->x != NULL || + strcmp(t2->p, "foo") || + *t2->x != 42) { + printf("talloc move failed\n"); + return false; + } + + talloc_free(root); + + return true; +} + /* test talloc_realloc_fn */ @@ -1022,6 +1056,7 @@ bool torture_local_talloc(struct torture_context *torture) ret &= test_realloc(); ret &= test_realloc_child(); ret &= test_steal(); + ret &= test_move(); ret &= test_unref_reparent(); ret &= test_realloc_fn(); ret &= test_type(); -- cgit From 05cdd9ccafeeb384792b9ce7ca044bcec1bfc839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:33:51 +0000 Subject: r18439: 2nd try at a talloc_move() api. This type with the ** ptr interface exposed. Unfortunately this generates a large number of type punning warnings. We'll have to find some magic to hide those. (This used to be commit 254cbf09dee5a1e20c47e47a298f1a8d172b41b9) --- source4/lib/talloc/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 38039c11bf..00ea212e58 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -750,8 +750,8 @@ static bool test_move(void) t1->x = talloc(t1, int); *t1->x = 42; - t2->p = talloc_move(t2, t1->p); - t2->x = talloc_move(t2, t1->x); + t2->p = talloc_move(t2, &t1->p); + t2->x = talloc_move(t2, &t1->x); if (t1->p != NULL || t1->x != NULL || strcmp(t2->p, "foo") || *t2->x != 42) { -- cgit From 4ccdd5370416a90088ad5a5879eca5f7cb1161a4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 29 Sep 2006 10:50:12 +0000 Subject: r18995: - fix bug 4078 - talloc_free(talloc_autofree_context()); should not result in a SIGABORT on exit - add a test for this, but this test can also pass in the standalone build and samba3, as samba4 uses talloc_autofree_context() metze (This used to be commit 2be48c1b033dceb9517826054b8ea97df2c94472) --- source4/lib/talloc/testsuite.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 00ea212e58..70ee35cbef 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -24,10 +24,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef _SAMBA_BUILD_ -#include "version.h" -#endif /* _SAMBA_BUILD_ */ - #include "replace.h" #include "system/time.h" #include "talloc.h" @@ -48,7 +44,7 @@ static double timeval_elapsed(struct timeval *tv) (tv2.tv_usec - tv->tv_usec)*1.0e-6; } -#if SAMBA_VERSION_MAJOR==3 +#if _SAMBA_BUILD_==3 #ifdef malloc #undef malloc #endif @@ -1040,6 +1036,28 @@ static bool test_talloc_ptrtype(void) return ret; } +static bool test_autofree(void) +{ +#if _SAMBA_BUILD_>=4 + /* + * we can't run this inside smbtorture in samba4 + * as smbtorture uses talloc_autofree_context() + */ + printf("SKIPPING TALLOC AUTOFREE CONTEXT (not supported from smbtorture)\n"); +#else + void *p; + + printf("TESTING TALLOC AUTOFREE CONTEXT\n"); + + p = talloc_autofree_context(); + talloc_free(p); + + p = talloc_autofree_context(); + talloc_free(p); +#endif + return true; +} + bool torture_local_talloc(struct torture_context *torture) { bool ret = true; @@ -1067,13 +1085,14 @@ bool torture_local_talloc(struct torture_context *torture) if (ret) { ret &= test_speed(); } + ret &= test_autofree(); return ret; } -#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) +#if _SAMBA_BUILD_<4 int main(void) { if (!torture_local_talloc(NULL)) { -- cgit From 18278a5560db58d447f4b0a5701fefb70383a048 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Oct 2006 09:26:29 +0000 Subject: r19118: get rid of a bunch of bool misuse warnings (This used to be commit e620f44643caf93a8bcb203a966c986c14a8dc0e) --- source4/lib/talloc/testsuite.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 70ee35cbef..1a2a60a3a3 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1065,27 +1065,27 @@ bool torture_local_talloc(struct torture_context *torture) talloc_disable_null_tracking(); talloc_enable_null_tracking(); - ret &= test_ref1(); - ret &= test_ref2(); - ret &= test_ref3(); - ret &= test_ref4(); - ret &= test_unlink1(); - ret &= test_misc(); - ret &= test_realloc(); - ret &= test_realloc_child(); - ret &= test_steal(); - ret &= test_move(); - ret &= test_unref_reparent(); - ret &= test_realloc_fn(); - ret &= test_type(); - ret &= test_lifeless(); - ret &= test_loop(); - ret &= test_free_parent_deny_child(); - ret &= test_talloc_ptrtype(); + ret = ret && test_ref1(); + ret = ret && test_ref2(); + ret = ret && test_ref3(); + ret = ret && test_ref4(); + ret = ret && test_unlink1(); + ret = ret && test_misc(); + ret = ret && test_realloc(); + ret = ret && test_realloc_child(); + ret = ret && test_steal(); + ret = ret && test_move(); + ret = ret && test_unref_reparent(); + ret = ret && test_realloc_fn(); + ret = ret && test_type(); + ret = ret && test_lifeless(); + ret = ret && test_loop(); + ret = ret && test_free_parent_deny_child(); + ret = ret && test_talloc_ptrtype(); if (ret) { - ret &= test_speed(); + ret = ret && test_speed(); } - ret &= test_autofree(); + ret = ret && test_autofree(); return ret; } -- cgit From 8773e743c518578584d07d35ffdafdd598af88b0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Oct 2006 13:06:41 +0000 Subject: r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained output in the testsuite rather than just True or False for a set of tests. The aim is to use this for: * known failure lists (run all tests and detect tests that started working or started failing). This would allow us to get rid of the RPC-SAMBA3-* tests * nicer torture output * simplification of the testsuite system * compatibility with other unit testing systems * easier usage of smbtorture (being able to run one test and automatically set up the environment for that) This is still a work-in-progress; expect more updates over the next couple of days. (This used to be commit 0eb6097305776325c75081356309115f445a7218) --- source4/lib/talloc/testsuite.c | 499 ++++++++++++++++------------------------- 1 file changed, 195 insertions(+), 304 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 1a2a60a3a3..f2e61157e4 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -27,8 +27,17 @@ #include "replace.h" #include "system/time.h" #include "talloc.h" +#ifdef _SAMBA_BUILD_ +#include "includes.h" +#include "torture/ui.h" +#else +#define torture_comment printf +#define torture_assert(tctx, expr, str) if (!(expr)) { printf str; return false; } +#define torture_suite_add_simple_tcase(suite,name,fn) \ + ret &= printf("TESTING %s\n", name), fn(); +#define torture_out stdout -struct torture_context; +struct torture_suite; static struct timeval timeval_current(void) { @@ -43,6 +52,7 @@ static double timeval_elapsed(struct timeval *tv) return (tv2.tv_sec - tv->tv_sec) + (tv2.tv_usec - tv->tv_usec)*1.0e-6; } +#endif /* _SAMBA_BUILD_ */ #if _SAMBA_BUILD_==3 #ifdef malloc @@ -55,10 +65,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_SIZE(ptr, tsize) do { \ if (talloc_total_size(ptr) != (tsize)) { \ - printf(__location__ " failed: wrong '%s' tree size: got %u expected %u\n", \ + torture_comment(tctx, talloc_asprintf(tctx, "failed: wrong '%s' tree size: got %u expected %u\n", \ #ptr, \ (unsigned)talloc_total_size(ptr), \ - (unsigned)tsize); \ + (unsigned)tsize)); \ talloc_report_full(ptr, stdout); \ return false; \ } \ @@ -66,10 +76,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_BLOCKS(ptr, tblocks) do { \ if (talloc_total_blocks(ptr) != (tblocks)) { \ - printf(__location__ " failed: wrong '%s' tree blocks: got %u expected %u\n", \ + torture_comment(tctx, talloc_asprintf(tctx, "failed: wrong '%s' tree blocks: got %u expected %u\n", \ #ptr, \ (unsigned)talloc_total_blocks(ptr), \ - (unsigned)tblocks); \ + (unsigned)tblocks)); \ talloc_report_full(ptr, stdout); \ return false; \ } \ @@ -77,10 +87,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_PARENT(ptr, parent) do { \ if (talloc_parent(ptr) != (parent)) { \ - printf(__location__ " failed: '%s' has wrong parent: got %p expected %p\n", \ + torture_comment(tctx, talloc_asprintf(tctx, "failed: '%s' has wrong parent: got %p expected %p\n", \ #ptr, \ talloc_parent(ptr), \ - (parent)); \ + (parent))); \ talloc_report_full(ptr, stdout); \ talloc_report_full(parent, stdout); \ talloc_report_full(NULL, stdout); \ @@ -92,12 +102,10 @@ static double timeval_elapsed(struct timeval *tv) /* test references */ -static bool test_ref1(void) +static bool test_ref1(struct torture_context *tctx) { void *root, *p1, *p2, *ref, *r1; - printf("TESTING SINGLE REFERENCE FREE\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(p1, 1, "p2"); @@ -107,31 +115,31 @@ static bool test_ref1(void) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - printf("Freeing p2\n"); + torture_comment(tctx, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - printf("Freeing p1\n"); + torture_comment(tctx, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(r1, 1); - printf("Freeing r1\n"); + torture_comment(tctx, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(NULL, stdout); + talloc_report_full(NULL, torture_out); - printf("Testing NULL\n"); + torture_comment(tctx, "Testing NULL\n"); if (talloc_reference(root, NULL)) { return false; } @@ -141,19 +149,16 @@ static bool test_ref1(void) CHECK_SIZE(root, 0); talloc_free(root); - return true; } /* test references */ -static bool test_ref2(void) +static bool test_ref2(struct torture_context *tctx) { void *root, *p1, *p2, *ref, *r1; - printf("TESTING DOUBLE REFERENCE FREE\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -163,91 +168,85 @@ static bool test_ref2(void) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - printf("Freeing ref\n"); + torture_comment(tctx, "Freeing ref\n"); talloc_free(ref); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - printf("Freeing p2\n"); + torture_comment(tctx, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 4); CHECK_BLOCKS(r1, 1); - printf("Freeing p1\n"); + torture_comment(tctx, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(r1, 1); - printf("Freeing r1\n"); + torture_comment(tctx, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_SIZE(root, 0); talloc_free(root); - return true; } /* test references */ -static bool test_ref3(void) +static bool test_ref3(struct torture_context *tctx) { void *root, *p1, *p2, *ref, *r1; - printf("TESTING PARENT REFERENCE FREE\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(root, 1, "p2"); r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(p2, r1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(p2, 2); CHECK_BLOCKS(r1, 1); - printf("Freeing p1\n"); + torture_comment(tctx, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p2, 2); CHECK_BLOCKS(r1, 1); - printf("Freeing p2\n"); + torture_comment(tctx, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_SIZE(root, 0); talloc_free(root); - return true; } /* test references */ -static bool test_ref4(void) +static bool test_ref4(struct torture_context *tctx) { void *root, *p1, *p2, *ref, *r1; - printf("TESTING REFERRER REFERENCE FREE\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -257,33 +256,32 @@ static bool test_ref4(void) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - printf("Freeing r1\n"); + torture_comment(tctx, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); - printf("Freeing p2\n"); + torture_comment(tctx, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 4); - printf("Freeing p1\n"); + torture_comment(tctx, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_SIZE(root, 0); talloc_free(root); - return true; } @@ -291,12 +289,10 @@ static bool test_ref4(void) /* test references */ -static bool test_unlink1(void) +static bool test_unlink1(struct torture_context *tctx) { void *root, *p1, *p2, *ref, *r1; - printf("TESTING UNLINK\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -306,28 +302,27 @@ static bool test_unlink1(void) r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 7); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - printf("Unreferencing r1\n"); + torture_comment(tctx, "Unreferencing r1\n"); talloc_unlink(r1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p1, 6); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - printf("Freeing p1\n"); + torture_comment(tctx, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_SIZE(root, 0); talloc_free(root); - return true; } @@ -339,22 +334,17 @@ static int fail_destructor(void *ptr) /* miscellaneous tests to try to get a higher test coverage percentage */ -static bool test_misc(void) +static bool test_misc(struct torture_context *tctx) { void *root, *p1; char *p2; double *d; const char *name; - printf("TESTING MISCELLANEOUS\n"); - root = talloc_new(NULL); p1 = talloc_size(root, 0x7fffffff); - if (p1) { - printf("failed: large talloc allowed\n"); - return false; - } + torture_assert(tctx, !p1, "failed: large talloc allowed\n"); p1 = talloc_strdup(root, "foo"); talloc_increase_ref_count(p1); @@ -369,97 +359,65 @@ static bool test_misc(void) CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); p2 = talloc_strdup(p1, "foo"); - if (talloc_unlink(root, p2) != -1) { - printf("failed: talloc_unlink() of non-reference context should return -1\n"); - return false; - } - if (talloc_unlink(p1, p2) != 0) { - printf("failed: talloc_unlink() of parent should succeed\n"); - return false; - } + torture_assert(tctx, talloc_unlink(root, p2) == -1, + "failed: talloc_unlink() of non-reference context should return -1\n"); + torture_assert(tctx, talloc_unlink(p1, p2) == 0, + "failed: talloc_unlink() of parent should succeed\n"); talloc_free(p1); CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); name = talloc_set_name(p1, "my name is %s", "foo"); - if (strcmp(talloc_get_name(p1), "my name is foo") != 0) { - printf("failed: wrong name after talloc_set_name(my name is foo) - '%s'=>'%s'\n", - (name?name:"NULL"), talloc_get_name(p1)); - return false; - } + torture_assert_str_equal(tctx, talloc_get_name(p1), "my name is foo", + "failed: wrong name after talloc_set_name(my name is foo)"); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); talloc_set_name_const(p1, NULL); - if (strcmp(talloc_get_name(p1), "UNNAMED") != 0) { - printf("failed: wrong name after talloc_set_name(NULL) - '%s'\n", - talloc_get_name(p1)); - return false; - } + torture_assert_str_equal (tctx, talloc_get_name(p1), "UNNAMED", + "failed: wrong name after talloc_set_name(NULL)"); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); - if (talloc_free(NULL) != -1) { - printf("talloc_free(NULL) should give -1\n"); - return false; - } + torture_assert(tctx, talloc_free(NULL) == -1, + "talloc_free(NULL) should give -1\n"); talloc_set_destructor(p1, fail_destructor); - if (talloc_free(p1) != -1) { - printf("Failed destructor should cause talloc_free to fail\n"); - return false; - } + torture_assert(tctx, talloc_free(p1) == -1, + "Failed destructor should cause talloc_free to fail\n"); talloc_set_destructor(p1, NULL); - talloc_report(root, stdout); + talloc_report(root, torture_out); p2 = (char *)talloc_zero_size(p1, 20); - if (p2[19] != 0) { - printf("Failed to give zero memory\n"); - return false; - } + torture_assert(tctx, p2[19] == 0, "Failed to give zero memory\n"); talloc_free(p2); - if (talloc_strdup(root, NULL) != NULL) { - printf("failed: strdup on NULL should give NULL\n"); - return false; - } + torture_assert(tctx, talloc_strdup(root, NULL) == NULL, + "failed: strdup on NULL should give NULL\n"); p2 = talloc_strndup(p1, "foo", 2); - if (strcmp("fo", p2) != 0) { - printf("failed: strndup doesn't work\n"); - return false; - } + torture_assert(tctx, strcmp("fo", p2) == 0, "failed: strndup doesn't work\n"); p2 = talloc_asprintf_append(p2, "o%c", 'd'); - if (strcmp("food", p2) != 0) { - printf("failed: talloc_asprintf_append doesn't work\n"); - return false; - } + torture_assert(tctx, strcmp("food", p2) == 0, + "failed: talloc_asprintf_append doesn't work\n"); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); p2 = talloc_asprintf_append(NULL, "hello %s", "world"); - if (strcmp("hello world", p2) != 0) { - printf("failed: talloc_asprintf_append doesn't work\n"); - return false; - } + torture_assert(tctx, strcmp("hello world", p2) == 0, + "failed: talloc_asprintf_append doesn't work\n"); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); talloc_free(p2); d = talloc_array(p1, double, 0x20000000); - if (d) { - printf("failed: integer overflow not detected\n"); - return false; - } + torture_assert(tctx, !d, "failed: integer overflow not detected\n"); d = talloc_realloc(p1, d, double, 0x20000000); - if (d) { - printf("failed: integer overflow not detected\n"); - return false; - } + torture_assert(tctx, !d, "failed: integer overflow not detected\n"); talloc_free(p1); CHECK_BLOCKS(root, 1); @@ -471,10 +429,8 @@ static bool test_misc(void) p1 = talloc_init("%d bytes", 200); p2 = talloc_asprintf(p1, "my test '%s'", "string"); - if (strcmp(p2, "my test 'string'") != 0) { - printf("failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\"\n", p2); - return false; - } + torture_assert_str_equal(tctx, p2, "my test 'string'", + "failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\""); CHECK_BLOCKS(p1, 3); CHECK_SIZE(p2, 17); CHECK_BLOCKS(root, 1); @@ -483,9 +439,9 @@ static bool test_misc(void) p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(p1, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); talloc_unlink(root, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); @@ -495,9 +451,9 @@ static bool test_misc(void) p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(NULL, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); talloc_unlink(root, p2); - talloc_report_full(root, stdout); + talloc_report_full(root, torture_out); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); @@ -506,13 +462,11 @@ static bool test_misc(void) /* Test that talloc_unlink is a no-op */ - if (talloc_unlink(root, NULL) != -1) { - printf("failed: talloc_unlink(root, NULL) == -1\n"); - return false; - } + torture_assert(tctx, talloc_unlink(root, NULL) == -1, + "failed: talloc_unlink(root, NULL) == -1\n"); - talloc_report(root, stdout); - talloc_report(NULL, stdout); + talloc_report(root, torture_out); + talloc_report(NULL, torture_out); CHECK_SIZE(root, 0); @@ -522,7 +476,6 @@ static bool test_misc(void) talloc_enable_leak_report(); talloc_enable_leak_report_full(); - return true; } @@ -530,12 +483,10 @@ static bool test_misc(void) /* test realloc */ -static bool test_realloc(void) +static bool test_realloc(struct torture_context *tctx) { void *root, *p1, *p2; - printf("TESTING REALLOC\n"); - root = talloc_new(NULL); p1 = talloc_size(root, 10); @@ -560,20 +511,16 @@ static bool test_realloc(void) CHECK_SIZE(p1, 60); talloc_increase_ref_count(p2); - if (talloc_realloc_size(NULL, p2, 5) != NULL) { - printf("failed: talloc_realloc() on a referenced pointer should fail\n"); - return false; - } + torture_assert(tctx, talloc_realloc_size(NULL, p2, 5) == NULL, + "failed: talloc_realloc() on a referenced pointer should fail\n"); CHECK_BLOCKS(p1, 4); talloc_realloc_size(NULL, p2, 0); talloc_realloc_size(NULL, p2, 0); CHECK_BLOCKS(p1, 3); - if (talloc_realloc_size(NULL, p1, 0x7fffffff) != NULL) { - printf("failed: oversize talloc should fail\n"); - return false; - } + torture_assert(tctx, talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL, + "failed: oversize talloc should fail\n"); talloc_realloc_size(NULL, p1, 0); @@ -581,14 +528,13 @@ static bool test_realloc(void) CHECK_SIZE(root, 0); talloc_free(root); - return true; } /* test realloc with a child */ -static bool test_realloc_child(void) +static bool test_realloc_child(struct torture_context *tctx) { void *root; struct el2 { @@ -599,8 +545,6 @@ static bool test_realloc_child(void) struct el2 **list, **list2, **list3; } *el1; - printf("TESTING REALLOC WITH CHILD\n"); - root = talloc_new(NULL); el1 = talloc(root, struct el1); @@ -625,15 +569,13 @@ static bool test_realloc_child(void) el1->list3 = talloc_realloc(el1, el1->list3, struct el2 *, 300); talloc_free(root); - return true; } - /* test type checking */ -static bool test_type(void) +static bool test_type(struct torture_context *tctx) { void *root; struct el1 { @@ -644,42 +586,31 @@ static bool test_type(void) }; struct el1 *el1; - printf("TESTING talloc type checking\n"); - root = talloc_new(NULL); el1 = talloc(root, struct el1); el1->count = 1; - if (talloc_get_type(el1, struct el1) != el1) { - printf("type check failed on el1\n"); - return false; - } - if (talloc_get_type(el1, struct el2) != NULL) { - printf("type check failed on el1 with el2\n"); - return false; - } + torture_assert(tctx, talloc_get_type(el1, struct el1) == el1, + "type check failed on el1\n"); + torture_assert(tctx, talloc_get_type(el1, struct el2) == NULL, + "type check failed on el1 with el2\n"); talloc_set_type(el1, struct el2); - if (talloc_get_type(el1, struct el2) != (struct el2 *)el1) { - printf("type set failed on el1 with el2\n"); - return false; - } + torture_assert(tctx, talloc_get_type(el1, struct el2) == (struct el2 *)el1, + "type set failed on el1 with el2\n"); talloc_free(root); - return true; } /* test steal */ -static bool test_steal(void) +static bool test_steal(struct torture_context *tctx) { void *root, *p1, *p2; - printf("TESTING STEAL\n"); - root = talloc_new(NULL); p1 = talloc_array(root, char, 10); @@ -689,15 +620,11 @@ static bool test_steal(void) CHECK_SIZE(p1, 10); CHECK_SIZE(root, 30); - if (talloc_steal(p1, NULL) != NULL) { - printf("failed: stealing NULL should give NULL\n"); - return false; - } + torture_assert(tctx, talloc_steal(p1, NULL) == NULL, + "failed: stealing NULL should give NULL\n"); - if (talloc_steal(p1, p1) != p1) { - printf("failed: stealing to ourselves is a nop\n"); - return false; - } + torture_assert(tctx, talloc_steal(p1, p1) == p1, + "failed: stealing to ourselves is a nop\n"); CHECK_BLOCKS(root, 3); CHECK_SIZE(root, 30); @@ -719,24 +646,22 @@ static bool test_steal(void) talloc_free(root); p1 = talloc_size(NULL, 3); - talloc_report_full(NULL, stdout); + talloc_report_full(NULL, torture_out); CHECK_SIZE(NULL, 3); talloc_free(p1); - return true; } /* test move */ -static bool test_move(void) +static bool test_move(struct torture_context *tctx) { void *root; struct t_move { char *p; int *x; } *t1, *t2; - printf("TESTING MOVE\n"); root = talloc_new(NULL); @@ -748,12 +673,9 @@ static bool test_move(void) t2->p = talloc_move(t2, &t1->p); t2->x = talloc_move(t2, &t1->x); - if (t1->p != NULL || t1->x != NULL || - strcmp(t2->p, "foo") || - *t2->x != 42) { - printf("talloc move failed\n"); - return false; - } + torture_assert(tctx, t1->p == NULL && t1->x == NULL && + strcmp(t2->p, "foo") == 0 && *t2->x == 42, + "talloc move failed"); talloc_free(root); @@ -763,12 +685,10 @@ static bool test_move(void) /* test talloc_realloc_fn */ -static bool test_realloc_fn(void) +static bool test_realloc_fn(struct torture_context *tctx) { void *root, *p1; - printf("TESTING talloc_realloc_fn\n"); - root = talloc_new(NULL); p1 = talloc_realloc_fn(root, NULL, 10); @@ -782,18 +702,14 @@ static bool test_realloc_fn(void) CHECK_SIZE(root, 0); talloc_free(root); - - return true; } -static bool test_unref_reparent(void) +static bool test_unref_reparent(struct torture_context *tctx) { void *root, *p1, *p2, *c1; - printf("TESTING UNREFERENCE AFTER PARENT FREED\n"); - root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "orig parent"); p2 = talloc_named_const(root, 1, "parent by reference"); @@ -813,21 +729,18 @@ static bool test_unref_reparent(void) talloc_free(p2); talloc_free(root); - return true; } /* measure the speed of talloc versus malloc */ -static bool test_speed(void) +static bool test_speed(struct torture_context *tctx) { void *ctx = talloc_new(NULL); unsigned count; struct timeval tv; - printf("MEASURING TALLOC VS MALLOC SPEED\n"); - tv = timeval_current(); count = 0; do { @@ -839,7 +752,7 @@ static bool test_speed(void) count += 3; } while (timeval_elapsed(&tv) < 5.0); - printf("talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); + torture_comment(tctx, talloc_asprintf(tctx, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv))); talloc_free(ctx); @@ -856,32 +769,27 @@ static bool test_speed(void) count += 3; } while (timeval_elapsed(&tv) < 5.0); - printf("malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); - - return true; + torture_comment(tctx, talloc_asprintf(tctx, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv))); + return true; } - -static bool test_lifeless(void) +static bool test_lifeless(struct torture_context *tctx) { void *top = talloc_new(NULL); char *parent, *child; void *child_owner = talloc_new(NULL); - printf("TESTING TALLOC_UNLINK LOOP\n"); - parent = talloc_strdup(top, "parent"); child = talloc_strdup(parent, "child"); (void)talloc_reference(child, parent); (void)talloc_reference(child_owner, child); - talloc_report_full(top, stdout); + talloc_report_full(top, torture_out); talloc_unlink(top, parent); talloc_free(child); - talloc_report_full(top, stdout); + talloc_report_full(top, torture_out); talloc_free(top); talloc_free(child_owner); talloc_free(child); - return true; } @@ -889,12 +797,11 @@ static int loop_destructor_count; static int test_loop_destructor(char *ptr) { - printf("loop destructor\n"); loop_destructor_count++; return 0; } -static bool test_loop(void) +static bool test_loop(struct torture_context *tctx) { void *top = talloc_new(NULL); char *parent; @@ -902,25 +809,21 @@ static bool test_loop(void) char *req2, *req3; } *req1; - printf("TESTING TALLOC LOOP DESTRUCTION\n"); parent = talloc_strdup(top, "parent"); req1 = talloc(parent, struct req1); req1->req2 = talloc_strdup(req1, "req2"); talloc_set_destructor(req1->req2, test_loop_destructor); req1->req3 = talloc_strdup(req1, "req3"); (void)talloc_reference(req1->req3, req1); - talloc_report_full(top, stdout); + talloc_report_full(top, torture_out); talloc_free(parent); - talloc_report_full(top, stdout); - talloc_report_full(NULL, stdout); + talloc_report_full(top, torture_out); + talloc_report_full(NULL, torture_out); talloc_free(top); - if (loop_destructor_count != 1) { - printf("FAILED TO FIRE LOOP DESTRUCTOR\n"); - return false; - } + torture_assert(tctx, loop_destructor_count == 1, + "FAILED TO FIRE LOOP DESTRUCTOR\n"); loop_destructor_count = 0; - return true; } @@ -929,14 +832,13 @@ static int fail_destructor_str(char *ptr) return -1; } -static bool test_free_parent_deny_child(void) +static bool test_free_parent_deny_child(struct torture_context *tctx) { void *top = talloc_new(NULL); char *level1; char *level2; char *level3; - printf("TESTING TALLOC FREE PARENT DENY CHILD\n"); level1 = talloc_strdup(top, "level1"); level2 = talloc_strdup(level1, "level2"); level3 = talloc_strdup(level2, "level3"); @@ -948,13 +850,11 @@ static bool test_free_parent_deny_child(void) CHECK_PARENT(level3, top); talloc_free(top); - return true; } -static bool test_talloc_ptrtype(void) +static bool test_talloc_ptrtype(struct torture_context *tctx) { - bool ret = true; void *top = talloc_new(NULL); struct struct1 { int foo; @@ -965,90 +865,73 @@ static bool test_talloc_ptrtype(void) const char *location3; const char *location4; - printf("TESTING TALLOC PTRTYPE\n"); s1 = talloc_ptrtype(top, s1);location1 = __location__; - if (talloc_get_size(s1) != sizeof(struct struct1)) { - printf("%s: talloc_ptrtype() allocated the wrong size %lu " - "(should be %lu)\n", - __location__, (unsigned long)talloc_get_size(s1), - (unsigned long)sizeof(struct struct1)); - ret = false; - } + torture_assert(tctx, talloc_get_size(s1) == sizeof(struct struct1), + talloc_asprintf(tctx, + "talloc_ptrtype() allocated the wrong size %lu " + "(should be %lu)\n", (unsigned long)talloc_get_size(s1), + (unsigned long)sizeof(struct struct1))); - if (strcmp(location1, talloc_get_name(s1)) != 0) { - printf("%s: talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n", - __location__, talloc_get_name(s1), location1); - ret = false; - } + torture_assert(tctx, strcmp(location1, talloc_get_name(s1)) == 0, + talloc_asprintf(tctx, + "talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n", + talloc_get_name(s1), location1)); s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; - if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size " + torture_assert(tctx, talloc_get_size(s2) == (sizeof(struct struct1) * 10), + talloc_asprintf(tctx, + "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n", - __location__, (unsigned long)talloc_get_size(s2), - (unsigned long)(sizeof(struct struct1)*10)); - ret = false; - } + (unsigned long)talloc_get_size(s2), + (unsigned long)(sizeof(struct struct1)*10))); - if (strcmp(location2, talloc_get_name(s2)) != 0) { - printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", - __location__, talloc_get_name(s2), - location2); - ret = false; - } + torture_assert(tctx, strcmp(location2, talloc_get_name(s2)) == 0, + talloc_asprintf(tctx, + "talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", + talloc_get_name(s2), location2)); s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; - if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size " + torture_assert(tctx, talloc_get_size(s3) == (sizeof(struct struct1 *) * 10), + talloc_asprintf(tctx, + "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n", - __location__, (unsigned long)talloc_get_size(s3), - (unsigned long)(sizeof(struct struct1 *)*10)); - ret = false; - } + (unsigned long)talloc_get_size(s3), + (unsigned long)(sizeof(struct struct1 *)*10))); - if (strcmp(location3, talloc_get_name(s3)) != 0) { - printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", - __location__, talloc_get_name(s3), location3); - ret = false; - } + torture_assert_str_equal(tctx, location3, talloc_get_name(s3), + "talloc_array_ptrtype() sets the wrong name"); s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; - if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { - printf("%s: talloc_array_ptrtype() allocated the wrong size " + torture_assert(tctx, talloc_get_size(s4) == (sizeof(struct struct1 **) * 10), + talloc_asprintf(tctx, + "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n", - __location__, (unsigned long)talloc_get_size(s4), - (unsigned long)(sizeof(struct struct1 **)*10)); - ret = false; - } + (unsigned long)talloc_get_size(s4), + (unsigned long)(sizeof(struct struct1 **)*10))); - if (strcmp(location4, talloc_get_name(s4)) != 0) { - printf("%s: talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", - __location__, talloc_get_name(s4), location4); - ret = false; - } + torture_assert_str_equal(tctx, location4, talloc_get_name(s4), + "talloc_array_ptrtype() sets the wrong name"); talloc_free(top); - - return ret; + return true; } -static bool test_autofree(void) +static bool test_autofree(struct torture_context *tctx) { #if _SAMBA_BUILD_>=4 /* * we can't run this inside smbtorture in samba4 * as smbtorture uses talloc_autofree_context() */ - printf("SKIPPING TALLOC AUTOFREE CONTEXT (not supported from smbtorture)\n"); + torture_skip(tctx, + "SKIPPING TALLOC AUTOFREE CONTEXT (not supported from smbtorture)"); #else void *p; - printf("TESTING TALLOC AUTOFREE CONTEXT\n"); - p = talloc_autofree_context(); talloc_free(p); @@ -1058,34 +941,42 @@ static bool test_autofree(void) return true; } -bool torture_local_talloc(struct torture_context *torture) +bool torture_local_talloc(struct torture_suite *tsuite) { bool ret = true; talloc_disable_null_tracking(); talloc_enable_null_tracking(); - ret = ret && test_ref1(); - ret = ret && test_ref2(); - ret = ret && test_ref3(); - ret = ret && test_ref4(); - ret = ret && test_unlink1(); - ret = ret && test_misc(); - ret = ret && test_realloc(); - ret = ret && test_realloc_child(); - ret = ret && test_steal(); - ret = ret && test_move(); - ret = ret && test_unref_reparent(); - ret = ret && test_realloc_fn(); - ret = ret && test_type(); - ret = ret && test_lifeless(); - ret = ret && test_loop(); - ret = ret && test_free_parent_deny_child(); - ret = ret && test_talloc_ptrtype(); + torture_suite_add_simple_test(tsuite, "SINGLE REFERENCE FREE", test_ref1); + torture_suite_add_simple_test(tsuite, "DOUBLE REFERENCE FREE", test_ref2); + torture_suite_add_simple_test(tsuite, "PARENT REFERENCE FREE", test_ref3); + torture_suite_add_simple_test(tsuite, "REFERRER REFERENCE FREE", test_ref4); + torture_suite_add_simple_test(tsuite, "UNLINK", test_unlink1); + torture_suite_add_simple_test(tsuite, "MISCELLANEOUS", test_misc); + torture_suite_add_simple_test(tsuite, "REALLOC", test_realloc); + torture_suite_add_simple_test(tsuite, "REALLOC WITH CHILD", + test_realloc_child); + torture_suite_add_simple_test(tsuite, "STEAL", test_steal); + torture_suite_add_simple_test(tsuite, "MOVE", test_move); + torture_suite_add_simple_test(tsuite, "UNREFERENCE AFTER PARENT FREED", + test_unref_reparent); + torture_suite_add_simple_test(tsuite, "talloc_realloc_fn", + test_realloc_fn); + torture_suite_add_simple_test(tsuite, "talloc type checking", test_type); + torture_suite_add_simple_test(tsuite, "TALLOC_UNLINK LOOP", test_lifeless); + torture_suite_add_simple_test(tsuite, "TALLOC LOOP DESTRUCTION", test_loop); + torture_suite_add_simple_test(tsuite, "TALLOC FREE PARENT DENY CHILD", + test_free_parent_deny_child); + torture_suite_add_simple_test(tsuite, "TALLOC PTRTYPE", + test_talloc_ptrtype); + if (ret) { - ret = ret && test_speed(); + torture_suite_add_simple_test(tsuite, "TALLOC VS MALLOC SPEED", + test_speed); } - ret = ret && test_autofree(); + torture_suite_add_simple_test(tsuite, "TALLOC AUTOFREE CONTEXT", + test_autofree); return ret; } -- cgit From 52e3f69a36b6ba6a589a8f768fbee77ee06b281c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Oct 2006 20:05:19 +0000 Subject: r19343: Add support for external scripts/binaries that write results using the 'subunit' protocol. This allows us to easily plug EJS scripts or binaries that can't depend on -ltorture into smbtorture. The protocol is very simple: - write "comments" to stderr Example output on stdout: test: foo success: foo test: bar success: bar test: blah failure: blah [ dummy.c:30: Expression 1 != 2 failed! ] test: blie skip: blie [ Iconv support not built in ] I've already converted the talloc testsuite. (This used to be commit e1742c14a247fabba969f8698108e73997d3f420) --- source4/lib/talloc/testsuite.c | 436 +++++++++++++++++++++++------------------ 1 file changed, 248 insertions(+), 188 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index f2e61157e4..14222c75af 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -27,17 +27,6 @@ #include "replace.h" #include "system/time.h" #include "talloc.h" -#ifdef _SAMBA_BUILD_ -#include "includes.h" -#include "torture/ui.h" -#else -#define torture_comment printf -#define torture_assert(tctx, expr, str) if (!(expr)) { printf str; return false; } -#define torture_suite_add_simple_tcase(suite,name,fn) \ - ret &= printf("TESTING %s\n", name), fn(); -#define torture_out stdout - -struct torture_suite; static struct timeval timeval_current(void) { @@ -52,7 +41,18 @@ static double timeval_elapsed(struct timeval *tv) return (tv2.tv_sec - tv->tv_sec) + (tv2.tv_usec - tv->tv_usec)*1.0e-6; } -#endif /* _SAMBA_BUILD_ */ + +#define torture_assert(expr, str) if (!(expr)) { \ + printf("failure: xx [\n%s: Expression %s failed: %s\n]\n", \ + __location__, #expr, str); \ + return false; \ +} + +#define torture_assert_str_equal(arg1, arg2, desc) if (strcmp(arg1, arg2)) { \ + printf("failure: xx [\n%s: Expected %s, got %s: %s\n]\n", \ + __location__, arg1, arg2, desc); \ + return false; \ +} #if _SAMBA_BUILD_==3 #ifdef malloc @@ -65,10 +65,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_SIZE(ptr, tsize) do { \ if (talloc_total_size(ptr) != (tsize)) { \ - torture_comment(tctx, talloc_asprintf(tctx, "failed: wrong '%s' tree size: got %u expected %u\n", \ + fprintf(stderr, "failed: wrong '%s' tree size: got %u expected %u\n", \ #ptr, \ (unsigned)talloc_total_size(ptr), \ - (unsigned)tsize)); \ + (unsigned)tsize); \ talloc_report_full(ptr, stdout); \ return false; \ } \ @@ -76,10 +76,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_BLOCKS(ptr, tblocks) do { \ if (talloc_total_blocks(ptr) != (tblocks)) { \ - torture_comment(tctx, talloc_asprintf(tctx, "failed: wrong '%s' tree blocks: got %u expected %u\n", \ + fprintf(stderr, "failed: wrong '%s' tree blocks: got %u expected %u\n", \ #ptr, \ (unsigned)talloc_total_blocks(ptr), \ - (unsigned)tblocks)); \ + (unsigned)tblocks); \ talloc_report_full(ptr, stdout); \ return false; \ } \ @@ -87,10 +87,10 @@ static double timeval_elapsed(struct timeval *tv) #define CHECK_PARENT(ptr, parent) do { \ if (talloc_parent(ptr) != (parent)) { \ - torture_comment(tctx, talloc_asprintf(tctx, "failed: '%s' has wrong parent: got %p expected %p\n", \ + fprintf(stderr, "failed: '%s' has wrong parent: got %p expected %p\n", \ #ptr, \ talloc_parent(ptr), \ - (parent))); \ + (parent)); \ talloc_report_full(ptr, stdout); \ talloc_report_full(parent, stdout); \ talloc_report_full(NULL, stdout); \ @@ -102,10 +102,12 @@ static double timeval_elapsed(struct timeval *tv) /* test references */ -static bool test_ref1(struct torture_context *tctx) +static bool test_ref1(void) { void *root, *p1, *p2, *ref, *r1; + printf("test: SINGLE REFERENCE FREE\n"); + root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(p1, 1, "p2"); @@ -115,31 +117,31 @@ static bool test_ref1(struct torture_context *tctx) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - torture_comment(tctx, "Freeing p2\n"); + fprintf(stderr, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p1\n"); + fprintf(stderr, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing r1\n"); + fprintf(stderr, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(NULL, torture_out); + talloc_report_full(NULL, stderr); - torture_comment(tctx, "Testing NULL\n"); + fprintf(stderr, "Testing NULL\n"); if (talloc_reference(root, NULL)) { return false; } @@ -149,16 +151,18 @@ static bool test_ref1(struct torture_context *tctx) CHECK_SIZE(root, 0); talloc_free(root); + printf("success: SINGLE REFERENCE FREE\n"); return true; } /* test references */ -static bool test_ref2(struct torture_context *tctx) +static bool test_ref2(void) { void *root, *p1, *p2, *ref, *r1; + printf("test: DOUBLE REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -168,85 +172,92 @@ static bool test_ref2(struct torture_context *tctx) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - torture_comment(tctx, "Freeing ref\n"); + fprintf(stderr, "Freeing ref\n"); talloc_free(ref); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p2\n"); + fprintf(stderr, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 4); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p1\n"); + fprintf(stderr, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing r1\n"); + fprintf(stderr, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_SIZE(root, 0); talloc_free(root); + printf("success: DOUBLE REFERENCE FREE\n"); return true; } /* test references */ -static bool test_ref3(struct torture_context *tctx) +static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; + printf("test: PARENT REFERENCE FREE\n"); + root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); p2 = talloc_named_const(root, 1, "p2"); r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(p2, r1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(p2, 2); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p1\n"); + fprintf(stderr, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p2, 2); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p2\n"); + fprintf(stderr, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_SIZE(root, 0); talloc_free(root); + + printf("success: PARENT REFERENCE FREE\n"); return true; } /* test references */ -static bool test_ref4(struct torture_context *tctx) +static bool test_ref4(void) { void *root, *p1, *p2, *ref, *r1; + printf("test: REFERRER REFERENCE FREE\n"); + root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -256,32 +267,34 @@ static bool test_ref4(struct torture_context *tctx) r1 = talloc_named_const(root, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - torture_comment(tctx, "Freeing r1\n"); + fprintf(stderr, "Freeing r1\n"); talloc_free(r1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 5); CHECK_BLOCKS(p2, 1); - torture_comment(tctx, "Freeing p2\n"); + fprintf(stderr, "Freeing p2\n"); talloc_free(p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 4); - torture_comment(tctx, "Freeing p1\n"); + fprintf(stderr, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_SIZE(root, 0); talloc_free(root); + + printf("success: REFERRER REFERENCE FREE\n"); return true; } @@ -289,10 +302,12 @@ static bool test_ref4(struct torture_context *tctx) /* test references */ -static bool test_unlink1(struct torture_context *tctx) +static bool test_unlink1(void) { void *root, *p1, *p2, *ref, *r1; + printf("test: UNLINK\n"); + root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -302,27 +317,29 @@ static bool test_unlink1(struct torture_context *tctx) r1 = talloc_named_const(p1, 1, "r1"); ref = talloc_reference(r1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 7); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 2); - torture_comment(tctx, "Unreferencing r1\n"); + fprintf(stderr, "Unreferencing r1\n"); talloc_unlink(r1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p1, 6); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(r1, 1); - torture_comment(tctx, "Freeing p1\n"); + fprintf(stderr, "Freeing p1\n"); talloc_free(p1); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_SIZE(root, 0); talloc_free(root); + + printf("success: UNLINK\n"); return true; } @@ -334,17 +351,19 @@ static int fail_destructor(void *ptr) /* miscellaneous tests to try to get a higher test coverage percentage */ -static bool test_misc(struct torture_context *tctx) +static bool test_misc(void) { void *root, *p1; char *p2; double *d; const char *name; + printf("test: MISCELLANEOUS\n"); + root = talloc_new(NULL); p1 = talloc_size(root, 0x7fffffff); - torture_assert(tctx, !p1, "failed: large talloc allowed\n"); + torture_assert(!p1, "failed: large talloc allowed\n"); p1 = talloc_strdup(root, "foo"); talloc_increase_ref_count(p1); @@ -359,65 +378,65 @@ static bool test_misc(struct torture_context *tctx) CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); p2 = talloc_strdup(p1, "foo"); - torture_assert(tctx, talloc_unlink(root, p2) == -1, + torture_assert(talloc_unlink(root, p2) == -1, "failed: talloc_unlink() of non-reference context should return -1\n"); - torture_assert(tctx, talloc_unlink(p1, p2) == 0, + torture_assert(talloc_unlink(p1, p2) == 0, "failed: talloc_unlink() of parent should succeed\n"); talloc_free(p1); CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); name = talloc_set_name(p1, "my name is %s", "foo"); - torture_assert_str_equal(tctx, talloc_get_name(p1), "my name is foo", + torture_assert_str_equal(talloc_get_name(p1), "my name is foo", "failed: wrong name after talloc_set_name(my name is foo)"); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); talloc_set_name_const(p1, NULL); - torture_assert_str_equal (tctx, talloc_get_name(p1), "UNNAMED", + torture_assert_str_equal (talloc_get_name(p1), "UNNAMED", "failed: wrong name after talloc_set_name(NULL)"); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); - torture_assert(tctx, talloc_free(NULL) == -1, + torture_assert(talloc_free(NULL) == -1, "talloc_free(NULL) should give -1\n"); talloc_set_destructor(p1, fail_destructor); - torture_assert(tctx, talloc_free(p1) == -1, + torture_assert(talloc_free(p1) == -1, "Failed destructor should cause talloc_free to fail\n"); talloc_set_destructor(p1, NULL); - talloc_report(root, torture_out); + talloc_report(root, stderr); p2 = (char *)talloc_zero_size(p1, 20); - torture_assert(tctx, p2[19] == 0, "Failed to give zero memory\n"); + torture_assert(p2[19] == 0, "Failed to give zero memory\n"); talloc_free(p2); - torture_assert(tctx, talloc_strdup(root, NULL) == NULL, + torture_assert(talloc_strdup(root, NULL) == NULL, "failed: strdup on NULL should give NULL\n"); p2 = talloc_strndup(p1, "foo", 2); - torture_assert(tctx, strcmp("fo", p2) == 0, "failed: strndup doesn't work\n"); + torture_assert(strcmp("fo", p2) == 0, "failed: strndup doesn't work\n"); p2 = talloc_asprintf_append(p2, "o%c", 'd'); - torture_assert(tctx, strcmp("food", p2) == 0, + torture_assert(strcmp("food", p2) == 0, "failed: talloc_asprintf_append doesn't work\n"); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); p2 = talloc_asprintf_append(NULL, "hello %s", "world"); - torture_assert(tctx, strcmp("hello world", p2) == 0, + torture_assert(strcmp("hello world", p2) == 0, "failed: talloc_asprintf_append doesn't work\n"); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 3); talloc_free(p2); d = talloc_array(p1, double, 0x20000000); - torture_assert(tctx, !d, "failed: integer overflow not detected\n"); + torture_assert(!d, "failed: integer overflow not detected\n"); d = talloc_realloc(p1, d, double, 0x20000000); - torture_assert(tctx, !d, "failed: integer overflow not detected\n"); + torture_assert(!d, "failed: integer overflow not detected\n"); talloc_free(p1); CHECK_BLOCKS(root, 1); @@ -429,7 +448,7 @@ static bool test_misc(struct torture_context *tctx) p1 = talloc_init("%d bytes", 200); p2 = talloc_asprintf(p1, "my test '%s'", "string"); - torture_assert_str_equal(tctx, p2, "my test 'string'", + torture_assert_str_equal(p2, "my test 'string'", "failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\""); CHECK_BLOCKS(p1, 3); CHECK_SIZE(p2, 17); @@ -439,9 +458,9 @@ static bool test_misc(struct torture_context *tctx) p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(p1, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); talloc_unlink(root, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 2); CHECK_BLOCKS(root, 3); @@ -451,9 +470,9 @@ static bool test_misc(struct torture_context *tctx) p1 = talloc_named_const(root, 10, "p1"); p2 = (char *)talloc_named_const(root, 20, "p2"); (void)talloc_reference(NULL, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); talloc_unlink(root, p2); - talloc_report_full(root, torture_out); + talloc_report_full(root, stderr); CHECK_BLOCKS(p2, 1); CHECK_BLOCKS(p1, 1); CHECK_BLOCKS(root, 2); @@ -462,11 +481,11 @@ static bool test_misc(struct torture_context *tctx) /* Test that talloc_unlink is a no-op */ - torture_assert(tctx, talloc_unlink(root, NULL) == -1, + torture_assert(talloc_unlink(root, NULL) == -1, "failed: talloc_unlink(root, NULL) == -1\n"); - talloc_report(root, torture_out); - talloc_report(NULL, torture_out); + talloc_report(root, stderr); + talloc_report(NULL, stderr); CHECK_SIZE(root, 0); @@ -476,6 +495,9 @@ static bool test_misc(struct torture_context *tctx) talloc_enable_leak_report(); talloc_enable_leak_report_full(); + + printf("success: MISCELLANEOUS\n"); + return true; } @@ -483,10 +505,12 @@ static bool test_misc(struct torture_context *tctx) /* test realloc */ -static bool test_realloc(struct torture_context *tctx) +static bool test_realloc(void) { void *root, *p1, *p2; + printf("test: REALLOC\n"); + root = talloc_new(NULL); p1 = talloc_size(root, 10); @@ -511,7 +535,7 @@ static bool test_realloc(struct torture_context *tctx) CHECK_SIZE(p1, 60); talloc_increase_ref_count(p2); - torture_assert(tctx, talloc_realloc_size(NULL, p2, 5) == NULL, + torture_assert(talloc_realloc_size(NULL, p2, 5) == NULL, "failed: talloc_realloc() on a referenced pointer should fail\n"); CHECK_BLOCKS(p1, 4); @@ -519,7 +543,7 @@ static bool test_realloc(struct torture_context *tctx) talloc_realloc_size(NULL, p2, 0); CHECK_BLOCKS(p1, 3); - torture_assert(tctx, talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL, + torture_assert(talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL, "failed: oversize talloc should fail\n"); talloc_realloc_size(NULL, p1, 0); @@ -528,13 +552,16 @@ static bool test_realloc(struct torture_context *tctx) CHECK_SIZE(root, 0); talloc_free(root); + + printf("success: REALLOC\n"); + return true; } /* test realloc with a child */ -static bool test_realloc_child(struct torture_context *tctx) +static bool test_realloc_child(void) { void *root; struct el2 { @@ -545,6 +572,8 @@ static bool test_realloc_child(struct torture_context *tctx) struct el2 **list, **list2, **list3; } *el1; + printf("test: REALLOC WITH CHILD\n"); + root = talloc_new(NULL); el1 = talloc(root, struct el1); @@ -569,13 +598,15 @@ static bool test_realloc_child(struct torture_context *tctx) el1->list3 = talloc_realloc(el1, el1->list3, struct el2 *, 300); talloc_free(root); + + printf("success: REALLOC WITH CHILD\n"); return true; } /* test type checking */ -static bool test_type(struct torture_context *tctx) +static bool test_type(void) { void *root; struct el1 { @@ -586,31 +617,37 @@ static bool test_type(struct torture_context *tctx) }; struct el1 *el1; + printf("test: talloc type checking\n"); + root = talloc_new(NULL); el1 = talloc(root, struct el1); el1->count = 1; - torture_assert(tctx, talloc_get_type(el1, struct el1) == el1, + torture_assert(talloc_get_type(el1, struct el1) == el1, "type check failed on el1\n"); - torture_assert(tctx, talloc_get_type(el1, struct el2) == NULL, + torture_assert(talloc_get_type(el1, struct el2) == NULL, "type check failed on el1 with el2\n"); talloc_set_type(el1, struct el2); - torture_assert(tctx, talloc_get_type(el1, struct el2) == (struct el2 *)el1, + torture_assert(talloc_get_type(el1, struct el2) == (struct el2 *)el1, "type set failed on el1 with el2\n"); talloc_free(root); + + printf("success: talloc type checking\n"); return true; } /* test steal */ -static bool test_steal(struct torture_context *tctx) +static bool test_steal(void) { void *root, *p1, *p2; + printf("test: STEAL\n"); + root = talloc_new(NULL); p1 = talloc_array(root, char, 10); @@ -620,10 +657,10 @@ static bool test_steal(struct torture_context *tctx) CHECK_SIZE(p1, 10); CHECK_SIZE(root, 30); - torture_assert(tctx, talloc_steal(p1, NULL) == NULL, + torture_assert(talloc_steal(p1, NULL) == NULL, "failed: stealing NULL should give NULL\n"); - torture_assert(tctx, talloc_steal(p1, p1) == p1, + torture_assert(talloc_steal(p1, p1) == p1, "failed: stealing to ourselves is a nop\n"); CHECK_BLOCKS(root, 3); CHECK_SIZE(root, 30); @@ -646,16 +683,18 @@ static bool test_steal(struct torture_context *tctx) talloc_free(root); p1 = talloc_size(NULL, 3); - talloc_report_full(NULL, torture_out); + talloc_report_full(NULL, stderr); CHECK_SIZE(NULL, 3); talloc_free(p1); + + printf("success: STEAL\n"); return true; } /* test move */ -static bool test_move(struct torture_context *tctx) +static bool test_move(void) { void *root; struct t_move { @@ -663,6 +702,8 @@ static bool test_move(struct torture_context *tctx) int *x; } *t1, *t2; + printf("test: MOVE\n"); + root = talloc_new(NULL); t1 = talloc(root, struct t_move); @@ -673,22 +714,26 @@ static bool test_move(struct torture_context *tctx) t2->p = talloc_move(t2, &t1->p); t2->x = talloc_move(t2, &t1->x); - torture_assert(tctx, t1->p == NULL && t1->x == NULL && + torture_assert(t1->p == NULL && t1->x == NULL && strcmp(t2->p, "foo") == 0 && *t2->x == 42, "talloc move failed"); talloc_free(root); + printf("success: MOVE\n"); + return true; } /* test talloc_realloc_fn */ -static bool test_realloc_fn(struct torture_context *tctx) +static bool test_realloc_fn(void) { void *root, *p1; + printf("test: talloc_realloc_fn\n"); + root = talloc_new(NULL); p1 = talloc_realloc_fn(root, NULL, 10); @@ -702,14 +747,18 @@ static bool test_realloc_fn(struct torture_context *tctx) CHECK_SIZE(root, 0); talloc_free(root); + + printf("success: talloc_realloc_fn\n"); return true; } -static bool test_unref_reparent(struct torture_context *tctx) +static bool test_unref_reparent(void) { void *root, *p1, *p2, *c1; + printf("test: UNREFERENCE AFTER PARENT FREED\n"); + root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "orig parent"); p2 = talloc_named_const(root, 1, "parent by reference"); @@ -729,18 +778,22 @@ static bool test_unref_reparent(struct torture_context *tctx) talloc_free(p2); talloc_free(root); + + printf("success: UNREFERENCE AFTER PARENT FREED\n"); return true; } /* measure the speed of talloc versus malloc */ -static bool test_speed(struct torture_context *tctx) +static bool test_speed(void) { void *ctx = talloc_new(NULL); unsigned count; struct timeval tv; + printf("test: TALLOC VS MALLOC SPEED\n"); + tv = timeval_current(); count = 0; do { @@ -752,7 +805,7 @@ static bool test_speed(struct torture_context *tctx) count += 3; } while (timeval_elapsed(&tv) < 5.0); - torture_comment(tctx, talloc_asprintf(tctx, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv))); + fprintf(stderr, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); talloc_free(ctx); @@ -769,27 +822,34 @@ static bool test_speed(struct torture_context *tctx) count += 3; } while (timeval_elapsed(&tv) < 5.0); - torture_comment(tctx, talloc_asprintf(tctx, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv))); + fprintf(stderr, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); + + printf("success: TALLOC VS MALLOC SPEED\n"); + return true; } -static bool test_lifeless(struct torture_context *tctx) +static bool test_lifeless(void) { void *top = talloc_new(NULL); char *parent, *child; void *child_owner = talloc_new(NULL); + printf("test: TALLOC_UNLINK LOOP\n"); + parent = talloc_strdup(top, "parent"); child = talloc_strdup(parent, "child"); (void)talloc_reference(child, parent); (void)talloc_reference(child_owner, child); - talloc_report_full(top, torture_out); + talloc_report_full(top, stderr); talloc_unlink(top, parent); talloc_free(child); - talloc_report_full(top, torture_out); + talloc_report_full(top, stderr); talloc_free(top); talloc_free(child_owner); talloc_free(child); + + printf("success: TALLOC_UNLINK LOOP\n"); return true; } @@ -801,7 +861,7 @@ static int test_loop_destructor(char *ptr) return 0; } -static bool test_loop(struct torture_context *tctx) +static bool test_loop(void) { void *top = talloc_new(NULL); char *parent; @@ -809,21 +869,25 @@ static bool test_loop(struct torture_context *tctx) char *req2, *req3; } *req1; + printf("test: TALLOC LOOP DESTRUCTION\n"); + parent = talloc_strdup(top, "parent"); req1 = talloc(parent, struct req1); req1->req2 = talloc_strdup(req1, "req2"); talloc_set_destructor(req1->req2, test_loop_destructor); req1->req3 = talloc_strdup(req1, "req3"); (void)talloc_reference(req1->req3, req1); - talloc_report_full(top, torture_out); + talloc_report_full(top, stderr); talloc_free(parent); - talloc_report_full(top, torture_out); - talloc_report_full(NULL, torture_out); + talloc_report_full(top, stderr); + talloc_report_full(NULL, stderr); talloc_free(top); - torture_assert(tctx, loop_destructor_count == 1, + torture_assert(loop_destructor_count == 1, "FAILED TO FIRE LOOP DESTRUCTOR\n"); loop_destructor_count = 0; + + printf("success: TALLOC LOOP DESTRUCTION\n"); return true; } @@ -832,13 +896,15 @@ static int fail_destructor_str(char *ptr) return -1; } -static bool test_free_parent_deny_child(struct torture_context *tctx) +static bool test_free_parent_deny_child(void) { void *top = talloc_new(NULL); char *level1; char *level2; char *level3; + printf("test: TALLOC FREE PARENT DENY CHILD\n"); + level1 = talloc_strdup(top, "level1"); level2 = talloc_strdup(level1, "level2"); level3 = talloc_strdup(level2, "level3"); @@ -850,10 +916,12 @@ static bool test_free_parent_deny_child(struct torture_context *tctx) CHECK_PARENT(level3, top); talloc_free(top); + + printf("success: TALLOC FREE PARENT DENY CHILD\n"); return true; } -static bool test_talloc_ptrtype(struct torture_context *tctx) +static bool test_talloc_ptrtype(void) { void *top = talloc_new(NULL); struct struct1 { @@ -865,131 +933,123 @@ static bool test_talloc_ptrtype(struct torture_context *tctx) const char *location3; const char *location4; + printf("test: TALLOC PTRTYPE\n"); + s1 = talloc_ptrtype(top, s1);location1 = __location__; - torture_assert(tctx, talloc_get_size(s1) == sizeof(struct struct1), - talloc_asprintf(tctx, - "talloc_ptrtype() allocated the wrong size %lu " - "(should be %lu)\n", (unsigned long)talloc_get_size(s1), - (unsigned long)sizeof(struct struct1))); + if (talloc_get_size(s1) != sizeof(struct struct1)) { + printf("failure: TALLOC PTRTYPE [\n" + "talloc_ptrtype() allocated the wrong size %lu (should be %lu)\n" + "]\n", (unsigned long)talloc_get_size(s1), + (unsigned long)sizeof(struct struct1)); + return false; + } - torture_assert(tctx, strcmp(location1, talloc_get_name(s1)) == 0, - talloc_asprintf(tctx, - "talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n", - talloc_get_name(s1), location1)); + if (strcmp(location1, talloc_get_name(s1)) != 0) { + printf("failure: TALLOC PTRTYPE [\n" + "talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n", + talloc_get_name(s1), location1); + return false; + } s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; - torture_assert(tctx, talloc_get_size(s2) == (sizeof(struct struct1) * 10), - talloc_asprintf(tctx, - "talloc_array_ptrtype() allocated the wrong size " - "%lu (should be %lu)\n", + if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) { + printf("failure: TALLOC PTRTYPE [\n" + "talloc_array_ptrtype() allocated the wrong size " + "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s2), - (unsigned long)(sizeof(struct struct1)*10))); + (unsigned long)(sizeof(struct struct1)*10)); + return false; + } - torture_assert(tctx, strcmp(location2, talloc_get_name(s2)) == 0, - talloc_asprintf(tctx, - "talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n", - talloc_get_name(s2), location2)); + if (strcmp(location2, talloc_get_name(s2)) != 0) { + printf("failure: TALLOC PTRTYPE [\n" + "talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n", + talloc_get_name(s2), location2); + return false; + } s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; - torture_assert(tctx, talloc_get_size(s3) == (sizeof(struct struct1 *) * 10), - talloc_asprintf(tctx, - "talloc_array_ptrtype() allocated the wrong size " - "%lu (should be %lu)\n", + if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) { + printf("failure: TALLOC PTRTYPE [\n" + "talloc_array_ptrtype() allocated the wrong size " + "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s3), - (unsigned long)(sizeof(struct struct1 *)*10))); + (unsigned long)(sizeof(struct struct1 *)*10)); + return false; + } - torture_assert_str_equal(tctx, location3, talloc_get_name(s3), + torture_assert_str_equal(location3, talloc_get_name(s3), "talloc_array_ptrtype() sets the wrong name"); s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; - torture_assert(tctx, talloc_get_size(s4) == (sizeof(struct struct1 **) * 10), - talloc_asprintf(tctx, + if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { + printf("failure: TALLOC PTRTYPE [\n" "talloc_array_ptrtype() allocated the wrong size " - "%lu (should be %lu)\n", + "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s4), - (unsigned long)(sizeof(struct struct1 **)*10))); + (unsigned long)(sizeof(struct struct1 **)*10)); + return false; + } - torture_assert_str_equal(tctx, location4, talloc_get_name(s4), + torture_assert_str_equal(location4, talloc_get_name(s4), "talloc_array_ptrtype() sets the wrong name"); talloc_free(top); + + printf("success: TALLOC PTRTYPE\n"); return true; } -static bool test_autofree(struct torture_context *tctx) +static bool test_autofree(void) { -#if _SAMBA_BUILD_>=4 - /* - * we can't run this inside smbtorture in samba4 - * as smbtorture uses talloc_autofree_context() - */ - torture_skip(tctx, - "SKIPPING TALLOC AUTOFREE CONTEXT (not supported from smbtorture)"); -#else void *p; + printf("test: TALLOC AUTOFREE CONTEXT\n"); p = talloc_autofree_context(); talloc_free(p); p = talloc_autofree_context(); talloc_free(p); -#endif + + printf("success: TALLOC AUTOFREE CONTEXT\n"); return true; } -bool torture_local_talloc(struct torture_suite *tsuite) +int main(void) { bool ret = true; talloc_disable_null_tracking(); talloc_enable_null_tracking(); - torture_suite_add_simple_test(tsuite, "SINGLE REFERENCE FREE", test_ref1); - torture_suite_add_simple_test(tsuite, "DOUBLE REFERENCE FREE", test_ref2); - torture_suite_add_simple_test(tsuite, "PARENT REFERENCE FREE", test_ref3); - torture_suite_add_simple_test(tsuite, "REFERRER REFERENCE FREE", test_ref4); - torture_suite_add_simple_test(tsuite, "UNLINK", test_unlink1); - torture_suite_add_simple_test(tsuite, "MISCELLANEOUS", test_misc); - torture_suite_add_simple_test(tsuite, "REALLOC", test_realloc); - torture_suite_add_simple_test(tsuite, "REALLOC WITH CHILD", - test_realloc_child); - torture_suite_add_simple_test(tsuite, "STEAL", test_steal); - torture_suite_add_simple_test(tsuite, "MOVE", test_move); - torture_suite_add_simple_test(tsuite, "UNREFERENCE AFTER PARENT FREED", - test_unref_reparent); - torture_suite_add_simple_test(tsuite, "talloc_realloc_fn", - test_realloc_fn); - torture_suite_add_simple_test(tsuite, "talloc type checking", test_type); - torture_suite_add_simple_test(tsuite, "TALLOC_UNLINK LOOP", test_lifeless); - torture_suite_add_simple_test(tsuite, "TALLOC LOOP DESTRUCTION", test_loop); - torture_suite_add_simple_test(tsuite, "TALLOC FREE PARENT DENY CHILD", - test_free_parent_deny_child); - torture_suite_add_simple_test(tsuite, "TALLOC PTRTYPE", - test_talloc_ptrtype); + ret &= test_ref1(); + ret &= test_ref2(); + ret &= test_ref3(); + ret &= test_ref4(); + ret &= test_unlink1(); + ret &= test_misc(); + ret &= test_realloc(); + ret &= test_realloc_child(); + ret &= test_steal(); + ret &= test_move(); + ret &= test_unref_reparent(); + ret &= test_realloc_fn(); + ret &= test_type(); + ret &= test_lifeless(); + ret &= test_loop(); + ret &= test_free_parent_deny_child(); + ret &= test_talloc_ptrtype(); if (ret) { - torture_suite_add_simple_test(tsuite, "TALLOC VS MALLOC SPEED", - test_speed); + ret &= test_speed(); } - torture_suite_add_simple_test(tsuite, "TALLOC AUTOFREE CONTEXT", - test_autofree); + ret &= test_autofree(); - return ret; -} - - - -#if _SAMBA_BUILD_<4 - int main(void) -{ - if (!torture_local_talloc(NULL)) { - printf("ERROR: TESTSUITE FAILED\n"); + if (!ret) return -1; - } return 0; } -#endif -- cgit From 4517b7af0e867d7244d8fcb9af72358f3559660f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 17 Oct 2006 22:06:43 +0000 Subject: r19381: Print out the specific tests that failed after a smbtorture run. Support listing known failures as a list of wildcards in the file `KNOWN_FAILURES'. (This used to be commit 23f66efd564d1ad549fc0cd60348f54808f5cafa) --- source4/lib/talloc/testsuite.c | 377 +++++++++++++++++++++-------------------- 1 file changed, 189 insertions(+), 188 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 14222c75af..0658a931d0 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -42,17 +42,18 @@ static double timeval_elapsed(struct timeval *tv) (tv2.tv_usec - tv->tv_usec)*1.0e-6; } -#define torture_assert(expr, str) if (!(expr)) { \ - printf("failure: xx [\n%s: Expression %s failed: %s\n]\n", \ - __location__, #expr, str); \ +#define torture_assert(test, expr, str) if (!(expr)) { \ + printf("failure: %s [\n%s: Expression %s failed: %s\n]\n", \ + test, __location__, #expr, str); \ return false; \ } -#define torture_assert_str_equal(arg1, arg2, desc) if (strcmp(arg1, arg2)) { \ - printf("failure: xx [\n%s: Expected %s, got %s: %s\n]\n", \ - __location__, arg1, arg2, desc); \ - return false; \ -} +#define torture_assert_str_equal(test, arg1, arg2, desc) \ + if (strcmp(arg1, arg2)) { \ + printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \ + test, __location__, arg1, arg2, desc); \ + return false; \ + } #if _SAMBA_BUILD_==3 #ifdef malloc @@ -63,10 +64,10 @@ static double timeval_elapsed(struct timeval *tv) #endif #endif -#define CHECK_SIZE(ptr, tsize) do { \ +#define CHECK_SIZE(test, ptr, tsize) do { \ if (talloc_total_size(ptr) != (tsize)) { \ - fprintf(stderr, "failed: wrong '%s' tree size: got %u expected %u\n", \ - #ptr, \ + printf("failed: %s [\nwrong '%s' tree size: got %u expected %u\n]\n", \ + test, #ptr, \ (unsigned)talloc_total_size(ptr), \ (unsigned)tsize); \ talloc_report_full(ptr, stdout); \ @@ -74,10 +75,10 @@ static double timeval_elapsed(struct timeval *tv) } \ } while (0) -#define CHECK_BLOCKS(ptr, tblocks) do { \ +#define CHECK_BLOCKS(test, ptr, tblocks) do { \ if (talloc_total_blocks(ptr) != (tblocks)) { \ - fprintf(stderr, "failed: wrong '%s' tree blocks: got %u expected %u\n", \ - #ptr, \ + printf("failed: %s [\nwrong '%s' tree blocks: got %u expected %u\n]\n", \ + test, #ptr, \ (unsigned)talloc_total_blocks(ptr), \ (unsigned)tblocks); \ talloc_report_full(ptr, stdout); \ @@ -85,10 +86,10 @@ static double timeval_elapsed(struct timeval *tv) } \ } while (0) -#define CHECK_PARENT(ptr, parent) do { \ +#define CHECK_PARENT(test, ptr, parent) do { \ if (talloc_parent(ptr) != (parent)) { \ - fprintf(stderr, "failed: '%s' has wrong parent: got %p expected %p\n", \ - #ptr, \ + printf("failed: %s [\n'%s' has wrong parent: got %p expected %p\n]\n", \ + test, #ptr, \ talloc_parent(ptr), \ (parent)); \ talloc_report_full(ptr, stdout); \ @@ -106,7 +107,7 @@ static bool test_ref1(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: SINGLE REFERENCE FREE\n"); + printf("test: ref1 [\nSINGLE REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -119,23 +120,23 @@ static bool test_ref1(void) ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 2); + CHECK_BLOCKS("ref1", p1, 5); + CHECK_BLOCKS("ref1", p2, 1); + CHECK_BLOCKS("ref1", r1, 2); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref1", p1, 5); + CHECK_BLOCKS("ref1", p2, 1); + CHECK_BLOCKS("ref1", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref1", r1, 1); fprintf(stderr, "Freeing r1\n"); talloc_free(r1); @@ -146,12 +147,12 @@ static bool test_ref1(void) return false; } - CHECK_BLOCKS(root, 1); + CHECK_BLOCKS("ref1", root, 1); - CHECK_SIZE(root, 0); + CHECK_SIZE("ref1", root, 0); talloc_free(root); - printf("success: SINGLE REFERENCE FREE\n"); + printf("success: ref1\n"); return true; } @@ -162,7 +163,7 @@ static bool test_ref2(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: DOUBLE REFERENCE FREE\n"); + printf("test: ref2 [\nDOUBLE REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -174,39 +175,39 @@ static bool test_ref2(void) ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 2); + CHECK_BLOCKS("ref2", p1, 5); + CHECK_BLOCKS("ref2", p2, 1); + CHECK_BLOCKS("ref2", r1, 2); fprintf(stderr, "Freeing ref\n"); talloc_free(ref); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref2", p1, 5); + CHECK_BLOCKS("ref2", p2, 1); + CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 4); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref2", p1, 4); + CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref2", r1, 1); fprintf(stderr, "Freeing r1\n"); talloc_free(r1); talloc_report_full(root, stderr); - CHECK_SIZE(root, 0); + CHECK_SIZE("ref2", root, 0); talloc_free(root); - printf("success: DOUBLE REFERENCE FREE\n"); + printf("success: ref2\n"); return true; } @@ -217,7 +218,7 @@ static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: PARENT REFERENCE FREE\n"); + printf("test: ref3 [\nPARENT REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -226,26 +227,26 @@ static bool test_ref3(void) ref = talloc_reference(p2, r1); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 2); - CHECK_BLOCKS(p2, 2); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref3", p1, 2); + CHECK_BLOCKS("ref3", p2, 2); + CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); - CHECK_BLOCKS(p2, 2); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("ref3", p2, 2); + CHECK_BLOCKS("ref3", r1, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); - CHECK_SIZE(root, 0); + CHECK_SIZE("ref3", root, 0); talloc_free(root); - printf("success: PARENT REFERENCE FREE\n"); + printf("success: ref3\n"); return true; } @@ -256,7 +257,7 @@ static bool test_ref4(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: REFERRER REFERENCE FREE\n"); + printf("test: ref4 [\nREFERRER REFERENCE FREE\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -269,32 +270,32 @@ static bool test_ref4(void) ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 2); + CHECK_BLOCKS("ref4", p1, 5); + CHECK_BLOCKS("ref4", p2, 1); + CHECK_BLOCKS("ref4", r1, 2); fprintf(stderr, "Freeing r1\n"); talloc_free(r1); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 5); - CHECK_BLOCKS(p2, 1); + CHECK_BLOCKS("ref4", p1, 5); + CHECK_BLOCKS("ref4", p2, 1); fprintf(stderr, "Freeing p2\n"); talloc_free(p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 4); + CHECK_BLOCKS("ref4", p1, 4); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); - CHECK_SIZE(root, 0); + CHECK_SIZE("ref4", root, 0); talloc_free(root); - printf("success: REFERRER REFERENCE FREE\n"); + printf("success: ref4\n"); return true; } @@ -306,7 +307,7 @@ static bool test_unlink1(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: UNLINK\n"); + printf("test: unlink [\nUNLINK\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -319,27 +320,27 @@ static bool test_unlink1(void) ref = talloc_reference(r1, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 7); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 2); + CHECK_BLOCKS("unlink", p1, 7); + CHECK_BLOCKS("unlink", p2, 1); + CHECK_BLOCKS("unlink", r1, 2); fprintf(stderr, "Unreferencing r1\n"); talloc_unlink(r1, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p1, 6); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(r1, 1); + CHECK_BLOCKS("unlink", p1, 6); + CHECK_BLOCKS("unlink", p2, 1); + CHECK_BLOCKS("unlink", r1, 1); fprintf(stderr, "Freeing p1\n"); talloc_free(p1); talloc_report_full(root, stderr); - CHECK_SIZE(root, 0); + CHECK_SIZE("unlink", root, 0); talloc_free(root); - printf("success: UNLINK\n"); + printf("success: unlink\n"); return true; } @@ -358,52 +359,51 @@ static bool test_misc(void) double *d; const char *name; - printf("test: MISCELLANEOUS\n"); + printf("test: misc [\nMISCELLANEOUS\n]\n"); root = talloc_new(NULL); p1 = talloc_size(root, 0x7fffffff); - torture_assert(!p1, "failed: large talloc allowed\n"); + torture_assert("misc", !p1, "failed: large talloc allowed\n"); p1 = talloc_strdup(root, "foo"); talloc_increase_ref_count(p1); talloc_increase_ref_count(p1); talloc_increase_ref_count(p1); - CHECK_BLOCKS(p1, 1); - CHECK_BLOCKS(root, 2); + CHECK_BLOCKS("misc", p1, 1); + CHECK_BLOCKS("misc", root, 2); talloc_free(p1); - CHECK_BLOCKS(p1, 1); - CHECK_BLOCKS(root, 2); + CHECK_BLOCKS("misc", p1, 1); + CHECK_BLOCKS("misc", root, 2); talloc_unlink(NULL, p1); - CHECK_BLOCKS(p1, 1); - CHECK_BLOCKS(root, 2); + CHECK_BLOCKS("misc", p1, 1); + CHECK_BLOCKS("misc", root, 2); p2 = talloc_strdup(p1, "foo"); - torture_assert(talloc_unlink(root, p2) == -1, + torture_assert("misc", talloc_unlink(root, p2) == -1, "failed: talloc_unlink() of non-reference context should return -1\n"); - torture_assert(talloc_unlink(p1, p2) == 0, + torture_assert("misc", talloc_unlink(p1, p2) == 0, "failed: talloc_unlink() of parent should succeed\n"); talloc_free(p1); - CHECK_BLOCKS(p1, 1); - CHECK_BLOCKS(root, 2); + CHECK_BLOCKS("misc", p1, 1); + CHECK_BLOCKS("misc", root, 2); name = talloc_set_name(p1, "my name is %s", "foo"); - torture_assert_str_equal(talloc_get_name(p1), "my name is foo", + torture_assert_str_equal("misc", talloc_get_name(p1), "my name is foo", "failed: wrong name after talloc_set_name(my name is foo)"); - CHECK_BLOCKS(p1, 2); - CHECK_BLOCKS(root, 3); + CHECK_BLOCKS("misc", p1, 2); + CHECK_BLOCKS("misc", root, 3); talloc_set_name_const(p1, NULL); - torture_assert_str_equal (talloc_get_name(p1), "UNNAMED", + torture_assert_str_equal ("misc", talloc_get_name(p1), "UNNAMED", "failed: wrong name after talloc_set_name(NULL)"); - CHECK_BLOCKS(p1, 2); - CHECK_BLOCKS(root, 3); - + CHECK_BLOCKS("misc", p1, 2); + CHECK_BLOCKS("misc", root, 3); - torture_assert(talloc_free(NULL) == -1, + torture_assert("misc", talloc_free(NULL) == -1, "talloc_free(NULL) should give -1\n"); talloc_set_destructor(p1, fail_destructor); - torture_assert(talloc_free(p1) == -1, + torture_assert("misc", talloc_free(p1) == -1, "Failed destructor should cause talloc_free to fail\n"); talloc_set_destructor(p1, NULL); @@ -411,48 +411,49 @@ static bool test_misc(void) p2 = (char *)talloc_zero_size(p1, 20); - torture_assert(p2[19] == 0, "Failed to give zero memory\n"); + torture_assert("misc", p2[19] == 0, "Failed to give zero memory\n"); talloc_free(p2); - torture_assert(talloc_strdup(root, NULL) == NULL, + torture_assert("misc", talloc_strdup(root, NULL) == NULL, "failed: strdup on NULL should give NULL\n"); p2 = talloc_strndup(p1, "foo", 2); - torture_assert(strcmp("fo", p2) == 0, "failed: strndup doesn't work\n"); + torture_assert("misc", strcmp("fo", p2) == 0, + "strndup doesn't work\n"); p2 = talloc_asprintf_append(p2, "o%c", 'd'); - torture_assert(strcmp("food", p2) == 0, - "failed: talloc_asprintf_append doesn't work\n"); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(p1, 3); + torture_assert("misc", strcmp("food", p2) == 0, + "talloc_asprintf_append doesn't work\n"); + CHECK_BLOCKS("misc", p2, 1); + CHECK_BLOCKS("misc", p1, 3); p2 = talloc_asprintf_append(NULL, "hello %s", "world"); - torture_assert(strcmp("hello world", p2) == 0, - "failed: talloc_asprintf_append doesn't work\n"); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(p1, 3); + torture_assert("misc", strcmp("hello world", p2) == 0, + "talloc_asprintf_append doesn't work\n"); + CHECK_BLOCKS("misc", p2, 1); + CHECK_BLOCKS("misc", p1, 3); talloc_free(p2); d = talloc_array(p1, double, 0x20000000); - torture_assert(!d, "failed: integer overflow not detected\n"); + torture_assert("misc", !d, "failed: integer overflow not detected\n"); d = talloc_realloc(p1, d, double, 0x20000000); - torture_assert(!d, "failed: integer overflow not detected\n"); + torture_assert("misc", !d, "failed: integer overflow not detected\n"); talloc_free(p1); - CHECK_BLOCKS(root, 1); + CHECK_BLOCKS("misc", root, 1); p1 = talloc_named(root, 100, "%d bytes", 100); - CHECK_BLOCKS(p1, 2); - CHECK_BLOCKS(root, 3); + CHECK_BLOCKS("misc", p1, 2); + CHECK_BLOCKS("misc", root, 3); talloc_unlink(root, p1); p1 = talloc_init("%d bytes", 200); p2 = talloc_asprintf(p1, "my test '%s'", "string"); - torture_assert_str_equal(p2, "my test 'string'", + torture_assert_str_equal("misc", p2, "my test 'string'", "failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\""); - CHECK_BLOCKS(p1, 3); - CHECK_SIZE(p2, 17); - CHECK_BLOCKS(root, 1); + CHECK_BLOCKS("misc", p1, 3); + CHECK_SIZE("misc", p2, 17); + CHECK_BLOCKS("misc", root, 1); talloc_unlink(NULL, p1); p1 = talloc_named_const(root, 10, "p1"); @@ -461,9 +462,9 @@ static bool test_misc(void) talloc_report_full(root, stderr); talloc_unlink(root, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(p1, 2); - CHECK_BLOCKS(root, 3); + CHECK_BLOCKS("misc", p2, 1); + CHECK_BLOCKS("misc", p1, 2); + CHECK_BLOCKS("misc", root, 3); talloc_unlink(p1, p2); talloc_unlink(root, p1); @@ -473,30 +474,30 @@ static bool test_misc(void) talloc_report_full(root, stderr); talloc_unlink(root, p2); talloc_report_full(root, stderr); - CHECK_BLOCKS(p2, 1); - CHECK_BLOCKS(p1, 1); - CHECK_BLOCKS(root, 2); + CHECK_BLOCKS("misc", p2, 1); + CHECK_BLOCKS("misc", p1, 1); + CHECK_BLOCKS("misc", root, 2); talloc_unlink(NULL, p2); talloc_unlink(root, p1); /* Test that talloc_unlink is a no-op */ - torture_assert(talloc_unlink(root, NULL) == -1, + torture_assert("misc", talloc_unlink(root, NULL) == -1, "failed: talloc_unlink(root, NULL) == -1\n"); talloc_report(root, stderr); talloc_report(NULL, stderr); - CHECK_SIZE(root, 0); + CHECK_SIZE("misc", root, 0); talloc_free(root); - CHECK_SIZE(NULL, 0); + CHECK_SIZE("misc", NULL, 0); talloc_enable_leak_report(); talloc_enable_leak_report_full(); - printf("success: MISCELLANEOUS\n"); + printf("success: misc\n"); return true; } @@ -509,15 +510,15 @@ static bool test_realloc(void) { void *root, *p1, *p2; - printf("test: REALLOC\n"); + printf("test: realloc [\nREALLOC\n]\n"); root = talloc_new(NULL); p1 = talloc_size(root, 10); - CHECK_SIZE(p1, 10); + CHECK_SIZE("realloc", p1, 10); p1 = talloc_realloc_size(NULL, p1, 20); - CHECK_SIZE(p1, 20); + CHECK_SIZE("realloc", p1, 20); talloc_new(p1); @@ -527,29 +528,29 @@ static bool test_realloc(void) p2 = talloc_realloc_size(p1, p2, 40); - CHECK_SIZE(p2, 40); - CHECK_SIZE(root, 60); - CHECK_BLOCKS(p1, 4); + CHECK_SIZE("realloc", p2, 40); + CHECK_SIZE("realloc", root, 60); + CHECK_BLOCKS("realloc", p1, 4); p1 = talloc_realloc_size(NULL, p1, 20); - CHECK_SIZE(p1, 60); + CHECK_SIZE("realloc", p1, 60); talloc_increase_ref_count(p2); - torture_assert(talloc_realloc_size(NULL, p2, 5) == NULL, + torture_assert("realloc", talloc_realloc_size(NULL, p2, 5) == NULL, "failed: talloc_realloc() on a referenced pointer should fail\n"); - CHECK_BLOCKS(p1, 4); + CHECK_BLOCKS("realloc", p1, 4); talloc_realloc_size(NULL, p2, 0); talloc_realloc_size(NULL, p2, 0); - CHECK_BLOCKS(p1, 3); + CHECK_BLOCKS("realloc", p1, 3); - torture_assert(talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL, + torture_assert("realloc", talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL, "failed: oversize talloc should fail\n"); talloc_realloc_size(NULL, p1, 0); - CHECK_BLOCKS(root, 1); - CHECK_SIZE(root, 0); + CHECK_BLOCKS("realloc", root, 1); + CHECK_SIZE("realloc", root, 0); talloc_free(root); @@ -617,7 +618,7 @@ static bool test_type(void) }; struct el1 *el1; - printf("test: talloc type checking\n"); + printf("test: type [\ntalloc type checking\n]\n"); root = talloc_new(NULL); @@ -625,17 +626,17 @@ static bool test_type(void) el1->count = 1; - torture_assert(talloc_get_type(el1, struct el1) == el1, + torture_assert("type", talloc_get_type(el1, struct el1) == el1, "type check failed on el1\n"); - torture_assert(talloc_get_type(el1, struct el2) == NULL, + torture_assert("type", talloc_get_type(el1, struct el2) == NULL, "type check failed on el1 with el2\n"); talloc_set_type(el1, struct el2); - torture_assert(talloc_get_type(el1, struct el2) == (struct el2 *)el1, + torture_assert("type", talloc_get_type(el1, struct el2) == (struct el2 *)el1, "type set failed on el1 with el2\n"); talloc_free(root); - printf("success: talloc type checking\n"); + printf("success: type\n"); return true; } @@ -646,48 +647,48 @@ static bool test_steal(void) { void *root, *p1, *p2; - printf("test: STEAL\n"); + printf("test: steal [\nSTEAL\n]\n"); root = talloc_new(NULL); p1 = talloc_array(root, char, 10); - CHECK_SIZE(p1, 10); + CHECK_SIZE("steal", p1, 10); p2 = talloc_realloc(root, NULL, char, 20); - CHECK_SIZE(p1, 10); - CHECK_SIZE(root, 30); + CHECK_SIZE("steal", p1, 10); + CHECK_SIZE("steal", root, 30); - torture_assert(talloc_steal(p1, NULL) == NULL, + torture_assert("steal", talloc_steal(p1, NULL) == NULL, "failed: stealing NULL should give NULL\n"); - torture_assert(talloc_steal(p1, p1) == p1, + torture_assert("steal", talloc_steal(p1, p1) == p1, "failed: stealing to ourselves is a nop\n"); - CHECK_BLOCKS(root, 3); - CHECK_SIZE(root, 30); + CHECK_BLOCKS("steal", root, 3); + CHECK_SIZE("steal", root, 30); talloc_steal(NULL, p1); talloc_steal(NULL, p2); - CHECK_BLOCKS(root, 1); - CHECK_SIZE(root, 0); + CHECK_BLOCKS("steal", root, 1); + CHECK_SIZE("steal", root, 0); talloc_free(p1); talloc_steal(root, p2); - CHECK_BLOCKS(root, 2); - CHECK_SIZE(root, 20); + CHECK_BLOCKS("steal", root, 2); + CHECK_SIZE("steal", root, 20); talloc_free(p2); - CHECK_BLOCKS(root, 1); - CHECK_SIZE(root, 0); + CHECK_BLOCKS("steal", root, 1); + CHECK_SIZE("steal", root, 0); talloc_free(root); p1 = talloc_size(NULL, 3); talloc_report_full(NULL, stderr); - CHECK_SIZE(NULL, 3); + CHECK_SIZE("steal", NULL, 3); talloc_free(p1); - printf("success: STEAL\n"); + printf("success: steal\n"); return true; } @@ -702,7 +703,7 @@ static bool test_move(void) int *x; } *t1, *t2; - printf("test: MOVE\n"); + printf("test: move [\nMOVE\n]\n"); root = talloc_new(NULL); @@ -714,13 +715,13 @@ static bool test_move(void) t2->p = talloc_move(t2, &t1->p); t2->x = talloc_move(t2, &t1->x); - torture_assert(t1->p == NULL && t1->x == NULL && + torture_assert("move", t1->p == NULL && t1->x == NULL && strcmp(t2->p, "foo") == 0 && *t2->x == 42, "talloc move failed"); talloc_free(root); - printf("success: MOVE\n"); + printf("success: move\n"); return true; } @@ -732,23 +733,23 @@ static bool test_realloc_fn(void) { void *root, *p1; - printf("test: talloc_realloc_fn\n"); + printf("test: realloc_fn [\ntalloc_realloc_fn\n]\n"); root = talloc_new(NULL); p1 = talloc_realloc_fn(root, NULL, 10); - CHECK_BLOCKS(root, 2); - CHECK_SIZE(root, 10); + CHECK_BLOCKS("realloc_fn", root, 2); + CHECK_SIZE("realloc_fn", root, 10); p1 = talloc_realloc_fn(root, p1, 20); - CHECK_BLOCKS(root, 2); - CHECK_SIZE(root, 20); + CHECK_BLOCKS("realloc_fn", root, 2); + CHECK_SIZE("realloc_fn", root, 20); p1 = talloc_realloc_fn(root, p1, 0); - CHECK_BLOCKS(root, 1); - CHECK_SIZE(root, 0); + CHECK_BLOCKS("realloc_fn", root, 1); + CHECK_SIZE("realloc_fn", root, 0); talloc_free(root); - printf("success: talloc_realloc_fn\n"); + printf("success: realloc_fn\n"); return true; } @@ -757,7 +758,7 @@ static bool test_unref_reparent(void) { void *root, *p1, *p2, *c1; - printf("test: UNREFERENCE AFTER PARENT FREED\n"); + printf("test: unref_reparent [\nUNREFERENCE AFTER PARENT FREED\n]\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "orig parent"); @@ -766,20 +767,20 @@ static bool test_unref_reparent(void) c1 = talloc_named_const(p1, 1, "child"); talloc_reference(p2, c1); - CHECK_PARENT(c1, p1); + CHECK_PARENT("unref_reparent", c1, p1); talloc_free(p1); - CHECK_PARENT(c1, p2); + CHECK_PARENT("unref_reparent", c1, p2); talloc_unlink(p2, c1); - CHECK_SIZE(root, 1); + CHECK_SIZE("unref_reparent", root, 1); talloc_free(p2); talloc_free(root); - printf("success: UNREFERENCE AFTER PARENT FREED\n"); + printf("success: unref_reparent\n"); return true; } @@ -792,7 +793,7 @@ static bool test_speed(void) unsigned count; struct timeval tv; - printf("test: TALLOC VS MALLOC SPEED\n"); + printf("test: speed [\nTALLOC VS MALLOC SPEED\n]\n"); tv = timeval_current(); count = 0; @@ -824,7 +825,7 @@ static bool test_speed(void) fprintf(stderr, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); - printf("success: TALLOC VS MALLOC SPEED\n"); + printf("success: speed\n"); return true; } @@ -835,7 +836,7 @@ static bool test_lifeless(void) char *parent, *child; void *child_owner = talloc_new(NULL); - printf("test: TALLOC_UNLINK LOOP\n"); + printf("test: lifeless [\nTALLOC_UNLINK LOOP\n]\n"); parent = talloc_strdup(top, "parent"); child = talloc_strdup(parent, "child"); @@ -849,7 +850,7 @@ static bool test_lifeless(void) talloc_free(child_owner); talloc_free(child); - printf("success: TALLOC_UNLINK LOOP\n"); + printf("success: lifeless\n"); return true; } @@ -869,7 +870,7 @@ static bool test_loop(void) char *req2, *req3; } *req1; - printf("test: TALLOC LOOP DESTRUCTION\n"); + printf("test: loop [\nTALLOC LOOP DESTRUCTION\n]\n"); parent = talloc_strdup(top, "parent"); req1 = talloc(parent, struct req1); @@ -883,11 +884,11 @@ static bool test_loop(void) talloc_report_full(NULL, stderr); talloc_free(top); - torture_assert(loop_destructor_count == 1, + torture_assert("loop", loop_destructor_count == 1, "FAILED TO FIRE LOOP DESTRUCTOR\n"); loop_destructor_count = 0; - printf("success: TALLOC LOOP DESTRUCTION\n"); + printf("success: loop\n"); return true; } @@ -903,7 +904,7 @@ static bool test_free_parent_deny_child(void) char *level2; char *level3; - printf("test: TALLOC FREE PARENT DENY CHILD\n"); + printf("test: free_parent_deny_child [\nTALLOC FREE PARENT DENY CHILD\n]\n"); level1 = talloc_strdup(top, "level1"); level2 = talloc_strdup(level1, "level2"); @@ -913,11 +914,11 @@ static bool test_free_parent_deny_child(void) talloc_free(level1); talloc_set_destructor(level3, NULL); - CHECK_PARENT(level3, top); + CHECK_PARENT("free_parent_deny_child", level3, top); talloc_free(top); - printf("success: TALLOC FREE PARENT DENY CHILD\n"); + printf("success: free_parent_deny_child\n"); return true; } @@ -933,12 +934,12 @@ static bool test_talloc_ptrtype(void) const char *location3; const char *location4; - printf("test: TALLOC PTRTYPE\n"); + printf("test: ptrtype [\nTALLOC PTRTYPE\n]\n"); s1 = talloc_ptrtype(top, s1);location1 = __location__; if (talloc_get_size(s1) != sizeof(struct struct1)) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_ptrtype() allocated the wrong size %lu (should be %lu)\n" "]\n", (unsigned long)talloc_get_size(s1), (unsigned long)sizeof(struct struct1)); @@ -946,7 +947,7 @@ static bool test_talloc_ptrtype(void) } if (strcmp(location1, talloc_get_name(s1)) != 0) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n", talloc_get_name(s1), location1); return false; @@ -955,7 +956,7 @@ static bool test_talloc_ptrtype(void) s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__; if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s2), @@ -964,7 +965,7 @@ static bool test_talloc_ptrtype(void) } if (strcmp(location2, talloc_get_name(s2)) != 0) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n", talloc_get_name(s2), location2); return false; @@ -973,7 +974,7 @@ static bool test_talloc_ptrtype(void) s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__; if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s3), @@ -981,7 +982,7 @@ static bool test_talloc_ptrtype(void) return false; } - torture_assert_str_equal(location3, talloc_get_name(s3), + torture_assert_str_equal("ptrtype", location3, talloc_get_name(s3), "talloc_array_ptrtype() sets the wrong name"); s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; @@ -995,19 +996,19 @@ static bool test_talloc_ptrtype(void) return false; } - torture_assert_str_equal(location4, talloc_get_name(s4), + torture_assert_str_equal("ptrtype", location4, talloc_get_name(s4), "talloc_array_ptrtype() sets the wrong name"); talloc_free(top); - printf("success: TALLOC PTRTYPE\n"); + printf("success: ptrtype\n"); return true; } static bool test_autofree(void) { void *p; - printf("test: TALLOC AUTOFREE CONTEXT\n"); + printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); p = talloc_autofree_context(); talloc_free(p); @@ -1015,7 +1016,7 @@ static bool test_autofree(void) p = talloc_autofree_context(); talloc_free(p); - printf("success: TALLOC AUTOFREE CONTEXT\n"); + printf("success: autofree\n"); return true; } -- cgit From cd2bc5854ca4f5aefb80e3599c1639c2badc7da9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 19 Oct 2006 00:59:33 +0000 Subject: r19405: the talloc speed test suite was not giving an accurate picture of the cost of talloc versus malloc. The size parameter in the test suite was constantly increasing, leading to a worst case for malloc. It is far more common to have talloc calls of 100 bytes or lower, so change the benchmark to reflect this. This makes talloc look much worse - on my laptop I now get: talloc: 5615164 ops/sec malloc: 14337130 ops/sec I'm working on improving that. (This used to be commit db273ef4dd6ab58da57bb4b59fb1fd5568585ed8) --- source4/lib/talloc/testsuite.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 0658a931d0..f51252e57b 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -791,6 +791,8 @@ static bool test_speed(void) { void *ctx = talloc_new(NULL); unsigned count; + const int loop = 1000; + int i; struct timeval tv; printf("test: speed [\nTALLOC VS MALLOC SPEED\n]\n"); @@ -799,11 +801,13 @@ static bool test_speed(void) count = 0; do { void *p1, *p2, *p3; - p1 = talloc_size(ctx, count); - p2 = talloc_strdup(p1, "foo bar"); - p3 = talloc_size(p1, 300); - talloc_free(p1); - count += 3; + for (i=0;i Date: Sat, 21 Oct 2006 06:40:39 +0000 Subject: r19434: we need to force line buffering as the new torture code doesn't create a pty in the piped_child() code Jelmer, if you want to fix this on platforms that support it, see the forkpty() call, or see http://junkcode.samba.org/ftp/unpacked/junkcode/rline/ (This used to be commit 35908a29922b93d133b19881dc8205a7116cae8e) --- source4/lib/talloc/testsuite.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index f51252e57b..4904b21f9b 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1029,6 +1029,8 @@ int main(void) { bool ret = true; + setlinebuf(stdout); + talloc_disable_null_tracking(); talloc_enable_null_tracking(); -- cgit From bc596cf917a25569f71d7d2b72ba11f3cb34dd54 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 25 Oct 2006 14:58:05 +0000 Subject: r19495: Stop linking binaries twice (once before installation, once during build). Make TORTURE-TALLOC and TORTURE-REPLACE builtin again rather than separate binaries. (This used to be commit 8913d60c72a67b041b08d569c9bd048953106c85) --- source4/lib/talloc/testsuite.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 4904b21f9b..8f2a211b47 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1025,7 +1025,8 @@ static bool test_autofree(void) return true; } -int main(void) +struct torture_context; +bool torture_local_talloc(struct torture_context *tctx) { bool ret = true; @@ -1057,7 +1058,15 @@ int main(void) } ret &= test_autofree(); + return ret; +} + +#ifndef _SAMBA_BUILD_ +int main(void) +{ + bool ret = torture_local_talloc(NULL); if (!ret) return -1; return 0; } +#endif -- cgit From 5438fc6c6288f092f58932b44fa25cc517972517 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 26 Oct 2006 03:26:53 +0000 Subject: r19498: the autofree test cannot be run as part of smbtorture (This used to be commit ebf1d523da45fe19757bca45262f7514702ee108) --- source4/lib/talloc/testsuite.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 8f2a211b47..88ed638252 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1012,6 +1012,8 @@ static bool test_talloc_ptrtype(void) static bool test_autofree(void) { +#ifndef _SAMBA_BUILD_ + /* autofree test would kill smbtorture */ void *p; printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); @@ -1022,6 +1024,7 @@ static bool test_autofree(void) talloc_free(p); printf("success: autofree\n"); +#endif return true; } -- cgit From f6274959ba381b6b5d025cb0cee78665107a72a6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jan 2007 11:16:11 +0000 Subject: r20647: add cluster code (This used to be commit 5870830b99a8d76bda1ff5af3fcf8dda9aba50ec) --- source4/lib/talloc/testsuite.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 88ed638252..dbfe3e4417 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1028,6 +1028,39 @@ static bool test_autofree(void) return true; } +static bool test_incref(void) +{ + void *top = talloc_new(NULL); + char *a = talloc_strdup(top, "/"); + char *b = talloc_strdup(a,"/b"); + char *c = talloc_strdup(b,"/b/a"); + + // Make a have some more children + talloc_strdup(a,"/c"); + talloc_strdup(a,"/d"); + talloc_strdup(a,"/e"); + + // Now b has some more other children. + talloc_strdup(b,"/b/b"); + + //Now we incref c presumably because we want to keep it valid: + talloc_increase_ref_count(c); + + // I am freeing a here, but I expect c to still be valid because I have + // increased reference for it just above. + talloc_free(a); + + talloc_report_full(NULL, stdout); + + // This is where talloc aborts, valgrind indicates a double free + talloc_free(c); + + CHECK_BLOCKS("top", top, 1); + + return true; +}; + + struct torture_context; bool torture_local_talloc(struct torture_context *tctx) { @@ -1044,6 +1077,7 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_ref4(); ret &= test_unlink1(); ret &= test_misc(); + ret &= test_incref(); ret &= test_realloc(); ret &= test_realloc_child(); ret &= test_steal(); -- cgit From 1c211a2e43db46c649a963ec883481cc4321870a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jan 2007 11:50:33 +0000 Subject: r20650: revert a bunch of code I didn't mean to commit yet (This used to be commit b3e2d4908781781a487eaeb683d22eb967e5597d) --- source4/lib/talloc/testsuite.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index dbfe3e4417..88ed638252 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1028,39 +1028,6 @@ static bool test_autofree(void) return true; } -static bool test_incref(void) -{ - void *top = talloc_new(NULL); - char *a = talloc_strdup(top, "/"); - char *b = talloc_strdup(a,"/b"); - char *c = talloc_strdup(b,"/b/a"); - - // Make a have some more children - talloc_strdup(a,"/c"); - talloc_strdup(a,"/d"); - talloc_strdup(a,"/e"); - - // Now b has some more other children. - talloc_strdup(b,"/b/b"); - - //Now we incref c presumably because we want to keep it valid: - talloc_increase_ref_count(c); - - // I am freeing a here, but I expect c to still be valid because I have - // increased reference for it just above. - talloc_free(a); - - talloc_report_full(NULL, stdout); - - // This is where talloc aborts, valgrind indicates a double free - talloc_free(c); - - CHECK_BLOCKS("top", top, 1); - - return true; -}; - - struct torture_context; bool torture_local_talloc(struct torture_context *tctx) { @@ -1077,7 +1044,6 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_ref4(); ret &= test_unlink1(); ret &= test_misc(); - ret &= test_incref(); ret &= test_realloc(); ret &= test_realloc_child(); ret &= test_steal(); -- cgit From 361e0b0bd7af14ca8e9c7fb442c90029e07b9ea2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 09:08:30 +0000 Subject: r22365: prepare merge to samba3 metze (This used to be commit 6780c234275b29192c49bf6d45204b0ac458faaf) --- source4/lib/talloc/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 88ed638252..d122a5de0d 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -1012,7 +1012,7 @@ static bool test_talloc_ptrtype(void) static bool test_autofree(void) { -#ifndef _SAMBA_BUILD_ +#if _SAMBA_BUILD_ < 4 /* autofree test would kill smbtorture */ void *p; printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); @@ -1064,7 +1064,7 @@ bool torture_local_talloc(struct torture_context *tctx) return ret; } -#ifndef _SAMBA_BUILD_ +#if _SAMBA_BUILD_ < 4 int main(void) { bool ret = torture_local_talloc(NULL); -- cgit From aa4ab6d3c195ca5f0f53e5a25b0839ce8a0fa580 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 8 May 2007 08:49:52 +0000 Subject: r22757: test if calling talloc_free() works on parent elements from within a destrutor metze (This used to be commit 305117fae0b4692b27b9cc7204fc59fb1312eabb) --- source4/lib/talloc/testsuite.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index d122a5de0d..587f270553 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -993,7 +993,7 @@ static bool test_talloc_ptrtype(void) s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s4), @@ -1010,6 +1010,45 @@ static bool test_talloc_ptrtype(void) return true; } +static int _test_talloc_free_in_destructor(void **ptr) +{ + talloc_free(*ptr); + return 0; +} + +static bool test_talloc_free_in_destructor(void) +{ + void *level0; + void *level1; + void *level2; + void *level3; + void *level4; + void **level5; + + printf("test: free_in_destructor [\nTALLOC FREE IN DESTRUCTOR\n]\n"); + + level0 = talloc_new(NULL); + level1 = talloc_new(level0); + level2 = talloc_new(level1); + level3 = talloc_new(level2); + level4 = talloc_new(level3); + level5 = talloc(level4, void *); + + *level5 = level3; + (void)talloc_reference(level0, level3); + (void)talloc_reference(level3, level3); + (void)talloc_reference(level5, level3); + + talloc_set_destructor(level5, _test_talloc_free_in_destructor); + + talloc_free(level1); + + talloc_free(level0); + + printf("success: free_in_destructor\n"); + return true; +} + static bool test_autofree(void) { #if _SAMBA_BUILD_ < 4 @@ -1055,6 +1094,7 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_loop(); ret &= test_free_parent_deny_child(); ret &= test_talloc_ptrtype(); + ret &= test_talloc_free_in_destructor(); if (ret) { ret &= test_speed(); -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/talloc/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 587f270553..2e6f85370d 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -12,7 +12,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/talloc/testsuite.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 2e6f85370d..2e3ae65082 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -20,8 +20,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ #include "replace.h" -- cgit From dfc0fd9eec32fbaada087531d36b9f13f316f2e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 00:19:45 +0000 Subject: r24688: Make output subunit-parseable. (This used to be commit 2585c6feb22b4409a635017875a2e93fe7c436ba) --- source4/lib/talloc/testsuite.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 2e3ae65082..ddf6865b1a 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -106,7 +106,7 @@ static bool test_ref1(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: ref1 [\nSINGLE REFERENCE FREE\n]\n"); + printf("test: ref1\n# SINGLE REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -162,7 +162,7 @@ static bool test_ref2(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: ref2 [\nDOUBLE REFERENCE FREE\n]\n"); + printf("test: ref2\n# DOUBLE REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); talloc_named_const(p1, 1, "x1"); @@ -217,7 +217,7 @@ static bool test_ref3(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: ref3 [\nPARENT REFERENCE FREE\n]\n"); + printf("test: ref3\n# PARENT REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -256,7 +256,7 @@ static bool test_ref4(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: ref4 [\nREFERRER REFERENCE FREE\n]\n"); + printf("test: ref4\n# REFERRER REFERENCE FREE\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -306,7 +306,7 @@ static bool test_unlink1(void) { void *root, *p1, *p2, *ref, *r1; - printf("test: unlink [\nUNLINK\n]\n"); + printf("test: unlink\n# UNLINK\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "p1"); @@ -358,7 +358,7 @@ static bool test_misc(void) double *d; const char *name; - printf("test: misc [\nMISCELLANEOUS\n]\n"); + printf("test: misc\n# MISCELLANEOUS\n"); root = talloc_new(NULL); @@ -509,7 +509,7 @@ static bool test_realloc(void) { void *root, *p1, *p2; - printf("test: realloc [\nREALLOC\n]\n"); + printf("test: realloc\n# REALLOC\n"); root = talloc_new(NULL); @@ -553,7 +553,7 @@ static bool test_realloc(void) talloc_free(root); - printf("success: REALLOC\n"); + printf("success: realloc\n"); return true; } @@ -617,7 +617,7 @@ static bool test_type(void) }; struct el1 *el1; - printf("test: type [\ntalloc type checking\n]\n"); + printf("test: type\n# talloc type checking\n"); root = talloc_new(NULL); @@ -646,7 +646,7 @@ static bool test_steal(void) { void *root, *p1, *p2; - printf("test: steal [\nSTEAL\n]\n"); + printf("test: steal\n# STEAL\n"); root = talloc_new(NULL); @@ -702,7 +702,7 @@ static bool test_move(void) int *x; } *t1, *t2; - printf("test: move [\nMOVE\n]\n"); + printf("test: move\n# MOVE\n"); root = talloc_new(NULL); @@ -732,7 +732,7 @@ static bool test_realloc_fn(void) { void *root, *p1; - printf("test: realloc_fn [\ntalloc_realloc_fn\n]\n"); + printf("test: realloc_fn\n# talloc_realloc_fn\n"); root = talloc_new(NULL); @@ -757,7 +757,7 @@ static bool test_unref_reparent(void) { void *root, *p1, *p2, *c1; - printf("test: unref_reparent [\nUNREFERENCE AFTER PARENT FREED\n]\n"); + printf("test: unref_reparent\n# UNREFERENCE AFTER PARENT FREED\n"); root = talloc_named_const(NULL, 0, "root"); p1 = talloc_named_const(root, 1, "orig parent"); @@ -794,7 +794,7 @@ static bool test_speed(void) int i; struct timeval tv; - printf("test: speed [\nTALLOC VS MALLOC SPEED\n]\n"); + printf("test: speed\n# TALLOC VS MALLOC SPEED\n"); tv = timeval_current(); count = 0; @@ -840,7 +840,7 @@ static bool test_lifeless(void) char *parent, *child; void *child_owner = talloc_new(NULL); - printf("test: lifeless [\nTALLOC_UNLINK LOOP\n]\n"); + printf("test: lifeless\n# TALLOC_UNLINK LOOP\n"); parent = talloc_strdup(top, "parent"); child = talloc_strdup(parent, "child"); @@ -874,7 +874,7 @@ static bool test_loop(void) char *req2, *req3; } *req1; - printf("test: loop [\nTALLOC LOOP DESTRUCTION\n]\n"); + printf("test: loop\n# TALLOC LOOP DESTRUCTION\n"); parent = talloc_strdup(top, "parent"); req1 = talloc(parent, struct req1); @@ -908,7 +908,7 @@ static bool test_free_parent_deny_child(void) char *level2; char *level3; - printf("test: free_parent_deny_child [\nTALLOC FREE PARENT DENY CHILD\n]\n"); + printf("test: free_parent_deny_child\n# TALLOC FREE PARENT DENY CHILD\n"); level1 = talloc_strdup(top, "level1"); level2 = talloc_strdup(level1, "level2"); @@ -938,7 +938,7 @@ static bool test_talloc_ptrtype(void) const char *location3; const char *location4; - printf("test: ptrtype [\nTALLOC PTRTYPE\n]\n"); + printf("test: ptrtype\n# TALLOC PTRTYPE\n"); s1 = talloc_ptrtype(top, s1);location1 = __location__; @@ -1024,7 +1024,7 @@ static bool test_talloc_free_in_destructor(void) void *level4; void **level5; - printf("test: free_in_destructor [\nTALLOC FREE IN DESTRUCTOR\n]\n"); + printf("test: free_in_destructor\n# TALLOC FREE IN DESTRUCTOR\n"); level0 = talloc_new(NULL); level1 = talloc_new(level0); @@ -1053,7 +1053,7 @@ static bool test_autofree(void) #if _SAMBA_BUILD_ < 4 /* autofree test would kill smbtorture */ void *p; - printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); + printf("test: autofree\n# TALLOC AUTOFREE CONTEXT\n"); p = talloc_autofree_context(); talloc_free(p); -- cgit From 9a012df08ee829c1d40fc88ba12a0ea479f60be0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 23:21:00 +0000 Subject: r25175: Change to talloc_asprintf_append_buffer(). Jeremy. (This used to be commit 0844dbf597191b3e4d35a696695b229e986daec4) --- source4/lib/talloc/testsuite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index ddf6865b1a..e16c91f8b9 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -419,15 +419,15 @@ static bool test_misc(void) p2 = talloc_strndup(p1, "foo", 2); torture_assert("misc", strcmp("fo", p2) == 0, "strndup doesn't work\n"); - p2 = talloc_asprintf_append(p2, "o%c", 'd'); + p2 = talloc_asprintf_append_buffer(p2, "o%c", 'd'); torture_assert("misc", strcmp("food", p2) == 0, - "talloc_asprintf_append doesn't work\n"); + "talloc_asprintf_append_buffer doesn't work\n"); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 3); - p2 = talloc_asprintf_append(NULL, "hello %s", "world"); + p2 = talloc_asprintf_append_buffer(NULL, "hello %s", "world"); torture_assert("misc", strcmp("hello world", p2) == 0, - "talloc_asprintf_append doesn't work\n"); + "talloc_asprintf_append_buffer doesn't work\n"); CHECK_BLOCKS("misc", p2, 1); CHECK_BLOCKS("misc", p1, 3); talloc_free(p2); -- cgit From 7a9033fb2d2057dc8104d9b6f22c94e83e36f8ce Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 5 Jan 2008 18:26:54 +0100 Subject: Implement talloc_pool() A talloc pool is a chunk of memory that can be used as a context for further talloc calls. Allocations with the pool as the parent just chew from that memory by incrementing a pointer. If the talloc pool is full, then we fall back to the normal system-level malloc(3) to get memory. The use case for talloc pools is the transient memory that is used for handling a single SMB request. Incrementing a pointer will be way faster than any malloc implementation. There is a downside of this: If you use talloc_steal() to move something out of the pool, the whole pool memory is kept around until the last object inside the pool is freed. So if you talloc_free() the pool, it might happen that the memory is freed later. So don't hang anything off a talloc pool that should live long. Volker (This used to be commit 60ef9a84f0bd18d48e453c08aa420d17275e0881) --- source4/lib/talloc/testsuite.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index e16c91f8b9..fedbda95aa 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -813,6 +813,25 @@ static bool test_speed(void) talloc_free(ctx); + ctx = talloc_pool(NULL, 1024); + + tv = timeval_current(); + count = 0; + do { + void *p1, *p2, *p3; + for (i=0;i Date: Thu, 17 Apr 2008 11:22:23 +0200 Subject: Skip strcmp() on 2 NULL pointers. Andrew Bartlett (This used to be commit 7b9a647ebbbe9ec9e1b82b42e3a8916396f91273) --- source4/lib/talloc/testsuite.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/talloc/testsuite.c') diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index fedbda95aa..3f06eee566 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -48,7 +48,8 @@ static double timeval_elapsed(struct timeval *tv) } #define torture_assert_str_equal(test, arg1, arg2, desc) \ - if (strcmp(arg1, arg2)) { \ + if (arg1 == NULL && arg2 == NULL) { \ + } else if (strcmp(arg1, arg2)) { \ printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \ test, __location__, arg1, arg2, desc); \ return false; \ -- cgit