diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-06-16 22:48:50 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:09:09 -0500 |
commit | 69270cfff6e9eaa527969ce805471b200cfbf7fb (patch) | |
tree | 2229b0a9b07559eb5d8765e85cb25e2c10ef82e2 /source4/torture | |
parent | 582d46ec42144bddccddacadd52a0256f58cb453 (diff) | |
download | samba-69270cfff6e9eaa527969ce805471b200cfbf7fb.tar.gz samba-69270cfff6e9eaa527969ce805471b200cfbf7fb.tar.bz2 samba-69270cfff6e9eaa527969ce805471b200cfbf7fb.zip |
r16315: Convert to new API.
(This used to be commit 0e52a831ed88b5d61033aee56a17e49b84df6773)
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/local/sddl.c | 17 | ||||
-rw-r--r-- | source4/torture/local/socket.c | 171 | ||||
-rw-r--r-- | source4/torture/ui.c | 61 | ||||
-rw-r--r-- | source4/torture/ui.h | 1 |
4 files changed, 122 insertions, 128 deletions
diff --git a/source4/torture/local/sddl.c b/source4/torture/local/sddl.c index 20526d7323..cb5919283f 100644 --- a/source4/torture/local/sddl.c +++ b/source4/torture/local/sddl.c @@ -24,17 +24,20 @@ #include "libcli/security/security.h" #include "torture/torture.h" #include "librpc/gen_ndr/ndr_security.h" +#include "torture/ui.h" /* test one SDDL example */ -static BOOL test_sddl(TALLOC_CTX *mem_ctx, const char *sddl) +static BOOL test_sddl(struct torture_context *mem_ctx, const void *_sddl) { struct security_descriptor *sd, *sd2; struct dom_sid *domain; + const char *sddl = _sddl; const char *sddl2; + domain = dom_sid_parse_talloc(mem_ctx, "S-1-2-3-4"); sd = sddl_decode(mem_ctx, sddl, domain); if (sd == NULL) { @@ -97,14 +100,14 @@ static const char *examples[] = { /* test a set of example SDDL strings */ BOOL torture_local_sddl(struct torture_context *torture) { + struct torture_suite *suite = torture_suite_create(torture, "LOCAL-SDDL"); int i; - BOOL ret = True; - TALLOC_CTX *mem_ctx = talloc_new(NULL); - for (i=0;i<ARRAY_SIZE(examples);i++) { - ret &= test_sddl(mem_ctx, examples[i]); + for (i = 0; i < ARRAY_SIZE(examples); i++) { + torture_suite_add_simple_tcase(suite, + talloc_asprintf(suite, "%d", i), + test_sddl, examples[i]); } - talloc_free(mem_ctx); - return ret; + return torture_run_suite(torture, suite); } diff --git a/source4/torture/local/socket.c b/source4/torture/local/socket.c index 91bd3b5315..47fb98f96c 100644 --- a/source4/torture/local/socket.c +++ b/source4/torture/local/socket.c @@ -26,20 +26,12 @@ #include "system/network.h" #include "netif/netif.h" #include "torture/torture.h" - -#define CHECK_STATUS(status, correct) do { \ - if (!NT_STATUS_EQUAL(status, correct)) { \ - printf("(%s) Incorrect status %s - should be %s\n", \ - __location__, nt_errstr(status), nt_errstr(correct)); \ - ret = False; \ - goto done; \ - }} while (0) - +#include "torture/ui.h" /* basic testing of udp routines */ -static BOOL test_udp(TALLOC_CTX *mem_ctx) +static BOOL test_udp(struct torture_context *test, const void *data) { struct socket_context *sock1, *sock2; NTSTATUS status; @@ -49,86 +41,83 @@ static BOOL test_udp(TALLOC_CTX *mem_ctx) size_t sent, nread; BOOL ret = True; - printf("TESTING UDP SOCKETS\n"); - status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0); - CHECK_STATUS(status, NT_STATUS_OK); - talloc_steal(mem_ctx, sock1); + torture_assert_ntstatus_ok(test, status, NULL); + talloc_steal(test, sock1); status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0); - CHECK_STATUS(status, NT_STATUS_OK); - talloc_steal(mem_ctx, sock2); + torture_assert_ntstatus_ok(test, status, NULL); + talloc_steal(test, sock2); localhost = socket_address_from_strings(sock1, sock1->backend_name, iface_best_ip("127.0.0.1"), 0); - if (!localhost) { - return False; - } + + torture_assert(test, localhost, "Localhost not found"); status = socket_listen(sock1, localhost, 0, 0); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); - srv_addr = socket_get_my_addr(sock1, mem_ctx); + srv_addr = socket_get_my_addr(sock1, test); if (srv_addr == NULL || strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { - printf("Expected server address of %s but got %s\n", + torture_fail(test, "Expected server address of %s but got %s", iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL); return False; } - printf("server port is %d\n", srv_addr->port); + torture_comment(test, "server port is %d", srv_addr->port); - blob = data_blob_talloc(mem_ctx, NULL, size); - blob2 = data_blob_talloc(mem_ctx, NULL, size); + blob = data_blob_talloc(test, NULL, size); + blob2 = data_blob_talloc(test, NULL, size); generate_random_buffer(blob.data, blob.length); sent = size; status = socket_sendto(sock2, &blob, &sent, srv_addr); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); status = socket_recvfrom(sock1, blob2.data, size, &nread, sock1, &from_addr); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); if (strcmp(from_addr->addr, srv_addr->addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr->addr); - ret = False; + torture_fail(test, "Unexpected recvfrom addr %s", from_addr->addr); + return False; } if (nread != size) { - printf("Unexpected recvfrom size %d should be %d\n", (int)nread, (int)size); - ret = False; + torture_fail(test, "Unexpected recvfrom size %d should be %d\n", + (int)nread, (int)size); + return False; } - if (memcmp(blob2.data, blob.data, size) != 0) { - printf("Bad data in recvfrom\n"); - ret = False; - } + torture_assert(test, memcmp(blob2.data, blob.data, size) == 0, + "Bad data in recvfrom"); generate_random_buffer(blob.data, blob.length); status = socket_sendto(sock1, &blob, &sent, from_addr); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); status = socket_recvfrom(sock2, blob2.data, size, &nread, sock2, &from_addr); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); if (strcmp(from_addr->addr, srv_addr->addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr->addr); - ret = False; + torture_fail(test, "Unexpected recvfrom addr %s\n", from_addr->addr); + return False; } + if (nread != size) { - printf("Unexpected recvfrom size %d should be %d\n", (int)nread, (int)size); - ret = False; + torture_fail(test, "Unexpected recvfrom size %d should be %d\n", + (int)nread, (int)size); + return False; } + if (from_addr->port != srv_addr->port) { - printf("Unexpected recvfrom port %d should be %d\n", + torture_fail(test, "Unexpected recvfrom port %d should be %d\n", from_addr->port, srv_addr->port); - ret = False; - } - if (memcmp(blob2.data, blob.data, size) != 0) { - printf("Bad data in recvfrom\n"); - ret = False; + return False; } -done: + torture_assert(test, memcmp(blob2.data, blob.data, size) == 0, + "Bad data in recvfrom"); + talloc_free(sock1); talloc_free(sock2); @@ -138,7 +127,7 @@ done: /* basic testing of tcp routines */ -static BOOL test_tcp(TALLOC_CTX *mem_ctx) +static BOOL test_tcp(struct torture_context *test, const void *data) { struct socket_context *sock1, *sock2, *sock3; NTSTATUS status; @@ -147,92 +136,84 @@ static BOOL test_tcp(TALLOC_CTX *mem_ctx) DATA_BLOB blob, blob2; size_t sent, nread; BOOL ret = True; - struct event_context *ev = event_context_init(mem_ctx); - - printf("TESTING TCP SOCKETS\n"); + struct event_context *ev = event_context_init(test); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0); - CHECK_STATUS(status, NT_STATUS_OK); - talloc_steal(mem_ctx, sock1); + torture_assert_ntstatus_ok(test, status, NULL); + talloc_steal(test, sock1); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0); - CHECK_STATUS(status, NT_STATUS_OK); - talloc_steal(mem_ctx, sock2); + torture_assert_ntstatus_ok(test, status, NULL); + talloc_steal(test, sock2); localhost = socket_address_from_strings(sock1, sock1->backend_name, iface_best_ip("127.0.0.1"), 0); - if (!localhost) { - return False; - } + torture_assert(test, localhost, "Localhost not found"); status = socket_listen(sock1, localhost, 0, 0); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); - srv_addr = socket_get_my_addr(sock1, mem_ctx); - if (srv_addr == NULL || !srv_addr->addr) { - printf("Unexpected socket_get_my_addr NULL\n"); - return False; - } + srv_addr = socket_get_my_addr(sock1, test); + torture_assert(test, srv_addr && srv_addr->addr, + "Unexpected socket_get_my_addr NULL\n"); if (strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { - printf("Expected server address of %s but got %s\n", + torture_fail(test, "Expected server address of %s but got %s\n", iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL); return False; } - printf("server port is %d\n", srv_addr->port); + torture_comment(test, "server port is %d", srv_addr->port); status = socket_connect_ev(sock2, NULL, srv_addr, 0, ev); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); status = socket_accept(sock1, &sock3); - CHECK_STATUS(status, NT_STATUS_OK); - talloc_steal(mem_ctx, sock3); + torture_assert_ntstatus_ok(test, status, NULL); + talloc_steal(test, sock3); talloc_free(sock1); - blob = data_blob_talloc(mem_ctx, NULL, size); - blob2 = data_blob_talloc(mem_ctx, NULL, size); + blob = data_blob_talloc(test, NULL, size); + blob2 = data_blob_talloc(test, NULL, size); generate_random_buffer(blob.data, blob.length); sent = size; status = socket_send(sock2, &blob, &sent); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); status = socket_recv(sock3, blob2.data, size, &nread); - CHECK_STATUS(status, NT_STATUS_OK); + torture_assert_ntstatus_ok(test, status, NULL); - from_addr = socket_get_peer_addr(sock3, mem_ctx); + from_addr = socket_get_peer_addr(sock3, test); + + torture_assert(test, from_addr && from_addr->addr, + "Unexpected recvfrom addr NULL"); - if (!from_addr || !from_addr->addr) { - printf("Unexpected recvfrom addr NULL\n"); - return False; - } if (strcmp(from_addr->addr, srv_addr->addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr ? from_addr->addr : NULL); - ret = False; + torture_fail(test, "Unexpected recvfrom addr %s\n", + from_addr ? from_addr->addr : NULL); + return False; } if (nread != size) { - printf("Unexpected recvfrom size %d should be %d\n", (int)nread, (int)size); - ret = False; - } - - if (memcmp(blob2.data, blob.data, size) != 0) { - printf("Bad data in recv\n"); - ret = False; + torture_fail(test, "Unexpected recvfrom size %d should be %d\n", + (int)nread, (int)size); + return False; } -done: + torture_assert(test, + memcmp(blob2.data, blob.data, size) == 0, + "Bad data in recv"); - return ret; + return True; } BOOL torture_local_socket(struct torture_context *torture) { - BOOL ret = True; - TALLOC_CTX *mem_ctx = talloc_new(NULL); + struct torture_suite *suite = torture_suite_create(torture, + "LOCAL-SOCKET"); - ret &= test_udp(mem_ctx); - ret &= test_tcp(mem_ctx); + torture_suite_add_simple_tcase(suite, "udp", test_udp, NULL); + torture_suite_add_simple_tcase(suite, "tcp", test_tcp, NULL); - return ret; + return torture_run_suite(torture, suite); } diff --git a/source4/torture/ui.c b/source4/torture/ui.c index 5315640717..a4fa5eb525 100644 --- a/source4/torture/ui.c +++ b/source4/torture/ui.c @@ -102,6 +102,7 @@ struct torture_test *torture_tcase_add_test(struct torture_tcase *tcase, test->name = talloc_strdup(test, name); test->description = NULL; test->run = run; + test->dangerous = False; test->data = data; DLIST_ADD(tcase->tests, test); @@ -139,6 +140,37 @@ BOOL torture_run_suite(struct torture_context *context, return ret; } +static BOOL internal_torture_run_test(struct torture_context *context, + struct torture_tcase *tcase, + struct torture_test *test, + void *tcase_data) +{ + BOOL ret; + void *data = NULL; + + if (test->dangerous && !lp_parm_bool(-1, "torture", "dangerous", False)) { + torture_skip(context, "disabled %s - enable dangerous tests to use", + test->name); + return True; + } + + if (!tcase_data && tcase->setup && !tcase->setup(context, &data)) + return False; + + context->active_tcase = tcase; + context->active_test = test; + context->ui_ops->test_start(context, tcase, test); + + ret = test->run(context, tcase->setup?data:tcase->data, test->data); + context->active_test = NULL; + context->active_tcase = NULL; + + if (!tcase_data && tcase->teardown && !tcase->teardown(context, data)) + return False; + + return ret; +} + BOOL torture_run_tcase(struct torture_context *context, struct torture_tcase *tcase) { @@ -155,16 +187,9 @@ BOOL torture_run_tcase(struct torture_context *context, return False; for (test = tcase->tests; test; test = test->next) { - if (tcase->fixture_persistent) { - context->active_test = test; - context->ui_ops->test_start(context, tcase, test); - ret &= test->run(context, (tcase->setup?data:tcase->data), - test->data); - } else - ret &= torture_run_test(context, tcase, test); - + ret &= internal_torture_run_test(context, tcase, test, + (tcase->setup?data:tcase->data)); } - context->active_test = NULL; if (tcase->fixture_persistent && tcase->teardown && !tcase->teardown(context, data)) @@ -179,23 +204,7 @@ BOOL torture_run_test(struct torture_context *context, struct torture_tcase *tcase, struct torture_test *test) { - BOOL ret; - void *data = NULL; - - if (tcase->setup && !tcase->setup(context, &data)) - return False; - - context->active_tcase = tcase; - context->active_test = test; - context->ui_ops->test_start(context, tcase, test); - ret = test->run(context, tcase->setup?data:tcase->data, test->data); - context->active_test = NULL; - context->active_tcase = NULL; - - if (tcase->teardown && !tcase->teardown(context, data)) - return False; - - return ret; + return internal_torture_run_test(context, tcase, test, NULL); } const char *torture_setting(struct torture_context *test, const char *name, diff --git a/source4/torture/ui.h b/source4/torture/ui.h index ccd50095a5..b5417cfa9b 100644 --- a/source4/torture/ui.h +++ b/source4/torture/ui.h @@ -74,6 +74,7 @@ struct torture_suite const char *name; const char *description; const void *data; + BOOL dangerous; BOOL (*run) (struct torture_context *test, const void *tcase_data, const void *test_data); |