diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-10-17 22:06:43 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:21:22 -0500 |
commit | 4517b7af0e867d7244d8fcb9af72358f3559660f (patch) | |
tree | 957f32d0005462ac6d6438e113c31c665de36333 /source4 | |
parent | c7090e666981eba30eb0553486bf782142e65a89 (diff) | |
download | samba-4517b7af0e867d7244d8fcb9af72358f3559660f.tar.gz samba-4517b7af0e867d7244d8fcb9af72358f3559660f.tar.bz2 samba-4517b7af0e867d7244d8fcb9af72358f3559660f.zip |
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)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/talloc/testsuite.c | 377 | ||||
-rw-r--r-- | source4/torture/smbtorture.c | 58 | ||||
-rw-r--r-- | source4/torture/subunit.c | 6 | ||||
-rw-r--r-- | source4/torture/torture.c | 15 | ||||
-rw-r--r-- | source4/torture/ui.c | 73 | ||||
-rw-r--r-- | source4/torture/ui.h | 19 |
6 files changed, 332 insertions, 216 deletions
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; } diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index 5740829d7d..fdd44ddc08 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -53,8 +53,7 @@ static bool run_matching(struct torture_context *torture, continue; } - ret &= run_matching(torture, - o->name, expr, o, matched); + ret &= run_matching(torture, o->name, expr, o, matched); } } else { char *name; @@ -435,6 +434,7 @@ const static struct torture_ui_ops quiet_ui_ops = { int max_runtime=0; int argc_new; struct torture_context *torture; + const struct torture_ui_ops *ui_ops; char **argv_new; poptContext pc; static const char *target = "other"; @@ -581,39 +581,73 @@ const static struct torture_ui_ops quiet_ui_ops = { lp_set_cmdline("torture:binding", binding); } - torture = talloc_zero(talloc_autofree_context(), struct torture_context); if (!strcmp(ui_ops_name, "simple")) { - torture->ui_ops = &std_ui_ops; + ui_ops = &std_ui_ops; } else if (!strcmp(ui_ops_name, "subunit")) { - torture->ui_ops = &subunit_ui_ops; + ui_ops = &subunit_ui_ops; } else if (!strcmp(ui_ops_name, "harness")) { - torture->ui_ops = &harness_ui_ops; + ui_ops = &harness_ui_ops; } else if (!strcmp(ui_ops_name, "quiet")) { - torture->ui_ops = &quiet_ui_ops; + ui_ops = &quiet_ui_ops; } else { printf("Unknown output format '%s'\n", ui_ops_name); exit(1); } + torture = torture_context_init(talloc_autofree_context(), "KNOWN_FAILURES", + ui_ops); + if (argc_new == 0) { printf("You must specify a test to run, or 'ALL'\n"); } else { int total; double rate; + int unexpected_failures; for (i=2;i<argc_new;i++) { if (!run_test(torture, argv_new[i])) { correct = false; } } - total = torture->skipped+torture->success+torture->failed; + + unexpected_failures = str_list_length(torture->results.unexpected_failures); + + total = torture->results.skipped+torture->results.success+torture->results.failed+torture->results.errors; if (total == 0) { printf("No tests run.\n"); } else { - rate = ((total - torture->failed) * (100.0 / total)); - printf("Tests: %d, Errors: %d, Skipped: %d. Success rate: %.2f%%\n", - total, torture->failed, torture->skipped, - rate); + rate = ((total - unexpected_failures - torture->results.errors) * (100.0 / total)); + + printf("Tests: %d, Failures: %d", total, torture->results.failed); + if (torture->results.failed - unexpected_failures) { + printf(" (%d expected)", torture->results.failed - unexpected_failures); + } + printf(", Errors: %d, Skipped: %d. Success rate: %.2f%%\n", + torture->results.errors, torture->results.skipped, rate); + } + + if (unexpected_failures) { + printf("The following tests failed:\n"); + for (i = 0; torture->results.unexpected_failures[i]; i++) { + printf(" %s\n", torture->results.unexpected_failures[i]); + } + printf("\n"); + } + + if (str_list_length(torture->results.unexpected_errors)) { + printf("Errors occurred while running the following tests:\n"); + for (i = 0; torture->results.unexpected_errors[i]; i++) { + printf(" %s\n", torture->results.unexpected_errors[i]); + } + printf("\n"); + } + + if (str_list_length(torture->results.unexpected_successes)) { + printf("The following tests were expected to fail but succeeded:\n"); + for (i = 0; torture->results.unexpected_successes[i]; i++) { + printf(" %s\n", torture->results.unexpected_successes[i]); + } + printf("\n"); } } diff --git a/source4/torture/subunit.c b/source4/torture/subunit.c index 3c4790b706..bed1972079 100644 --- a/source4/torture/subunit.c +++ b/source4/torture/subunit.c @@ -190,12 +190,12 @@ bool torture_subunit_run_suite(struct torture_context *context, return false; if (waitpid(pid, &status, 0) == -1) { - torture_comment(context, "waitpid(%d) failed\n", pid); + torture_result(context, TORTURE_ERROR, "waitpid(%d) failed\n", pid); return false; } if (WEXITSTATUS(status) != 0) { - torture_comment(context, "failed with status %d\n", WEXITSTATUS(status)); + torture_result(context, TORTURE_ERROR, "failed with status %d\n", WEXITSTATUS(status)); return false; } @@ -258,7 +258,7 @@ bool torture_subunit_run_suite(struct torture_context *context, } if (name != NULL) { - torture_comment(context, "Interrupted during %s\n", name); + torture_result(context, TORTURE_ERROR, "Interrupted during %s\n", name); return false; } diff --git a/source4/torture/torture.c b/source4/torture/torture.c index f83a7330c2..e6629eb214 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -43,6 +43,21 @@ bool torture_register_suite(struct torture_suite *suite) return torture_suite_add_suite(torture_root, suite); } +struct torture_context *torture_context_init(TALLOC_CTX *mem_ctx, + const char *known_failures_file, + const struct torture_ui_ops *ui_ops) +{ + int numlines; + struct torture_context *torture = talloc_zero(mem_ctx, + struct torture_context); + torture->expected_failures = file_lines_load(known_failures_file, &numlines, + torture); + torture->ui_ops = ui_ops; + + return torture; +} + + int torture_init(void) { init_module_fn static_init[] = STATIC_torture_MODULES; diff --git a/source4/torture/ui.c b/source4/torture/ui.c index 670b151686..1e404d55ad 100644 --- a/source4/torture/ui.c +++ b/source4/torture/ui.c @@ -128,11 +128,19 @@ BOOL torture_run_suite(struct torture_context *context, BOOL ret = True; struct torture_tcase *tcase; struct torture_suite *tsuite; + char *old_testname; context->level++; if (context->ui_ops->suite_start) context->ui_ops->suite_start(context, suite); + old_testname = context->active_testname; + if (context->active_testname) + context->active_testname = talloc_asprintf(context, "%s-%s", + old_testname, suite->name); + else + context->active_testname = talloc_strdup(context, suite->name); + if (suite->path) torture_subunit_run_suite(context, suite); @@ -144,6 +152,9 @@ BOOL torture_run_suite(struct torture_context *context, ret &= torture_run_suite(context, tsuite); } + talloc_free(context->active_testname); + context->active_testname = old_testname; + if (context->ui_ops->suite_finish) context->ui_ops->suite_finish(context, suite); @@ -160,6 +171,19 @@ void torture_ui_test_start(struct torture_context *context, context->ui_ops->test_start(context, tcase, test); } +int str_list_match(const char *name, char **list) +{ + int i, ret = 0; + if (list == NULL) + return 0; + + for (i = 0; list[i]; i++) { + if (gen_fnmatch(list[i], name) == 0) + ret++; + } + return ret; +} + void torture_ui_test_result(struct torture_context *context, enum torture_result result, const char *comment) @@ -167,13 +191,29 @@ void torture_ui_test_result(struct torture_context *context, if (context->ui_ops->test_result) context->ui_ops->test_result(context, result, comment); - /* FIXME: */ - - switch (result) { - case TORTURE_SKIP: context->skipped++; break; - case TORTURE_ERROR: context->errors++; break; - case TORTURE_FAIL: context->failed++; break; - case TORTURE_OK: context->success++; break; + if (result == TORTURE_SKIP) { + context->results.skipped++; + } else if (result == TORTURE_OK) { + if (str_list_match(context->active_testname, + context->expected_failures)) { + context->results.unexpected_successes = str_list_add( + context->results.unexpected_successes, + talloc_reference(context, context->active_testname)); + } + context->results.success++; + } else if (result == TORTURE_ERROR) { + context->results.unexpected_errors = str_list_add( + context->results.unexpected_errors, + talloc_reference(context, context->active_testname)); + context->results.errors++; + } else if (result == TORTURE_FAIL) { + if (0 == str_list_match(context->active_testname, + context->expected_failures)) { + context->results.unexpected_failures = str_list_add( + context->results.unexpected_failures, + talloc_reference(context, context->active_testname)); + } + context->results.failed++; } } @@ -183,6 +223,7 @@ static BOOL internal_torture_run_test(struct torture_context *context, BOOL already_setup) { BOOL ret; + char *old_testname; if (test->dangerous && !torture_setting_bool(context, "dangerous", False)) { torture_result(context, TORTURE_SKIP, @@ -194,16 +235,22 @@ static BOOL internal_torture_run_test(struct torture_context *context, !tcase->setup(context, &(tcase->data))) return False; + if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { + old_testname = context->active_testname; + context->active_testname = talloc_asprintf(context, "%s-%s", + old_testname, test->name); + } context->active_tcase = tcase; context->active_test = test; torture_ui_test_start(context, tcase, test); + context->last_reason = NULL; context->last_result = TORTURE_OK; ret = test->run(context, tcase, test); - if (!ret) { + if (!ret && context->last_result == TORTURE_OK) { if (context->last_reason == NULL) context->last_reason = talloc_strdup(context, "Unknown error/failure"); context->last_result = TORTURE_ERROR; @@ -213,6 +260,10 @@ static BOOL internal_torture_run_test(struct torture_context *context, talloc_free(context->last_reason); + if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { + talloc_free(context->active_testname); + context->active_testname = old_testname; + } context->active_test = NULL; context->active_tcase = NULL; @@ -226,6 +277,7 @@ BOOL torture_run_tcase(struct torture_context *context, struct torture_tcase *tcase) { BOOL ret = True; + char *old_testname; struct torture_test *test; context->level++; @@ -240,10 +292,15 @@ BOOL torture_run_tcase(struct torture_context *context, goto done; } + old_testname = context->active_testname; + context->active_testname = talloc_asprintf(context, "%s-%s", + old_testname, tcase->name); for (test = tcase->tests; test; test = test->next) { ret &= internal_torture_run_test(context, tcase, test, tcase->fixture_persistent); } + talloc_free(context->active_testname); + context->active_testname = old_testname; if (tcase->fixture_persistent && tcase->teardown && !tcase->teardown(context, tcase->data)) diff --git a/source4/torture/ui.h b/source4/torture/ui.h index f0628b7758..23988d9bf4 100644 --- a/source4/torture/ui.h +++ b/source4/torture/ui.h @@ -75,14 +75,23 @@ struct torture_context const struct torture_ui_ops *ui_ops; void *ui_data; + char *active_testname; struct torture_test *active_test; struct torture_tcase *active_tcase; - int skipped; - int todo; - int success; - int failed; - int errors; + char **expected_failures; + + struct torture_results { + int skipped; + int todo; + int success; + int failed; + int errors; + + const char **unexpected_failures; + const char **unexpected_successes; + const char **unexpected_errors; + } results; bool quiet; /* Whether tests should avoid writing output to stdout */ |