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/torture/local/messaging.c | 57 +++++++++++++++------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) (limited to 'source4/torture/local/messaging.c') diff --git a/source4/torture/local/messaging.c b/source4/torture/local/messaging.c index 8161c3ea4f..27c343948b 100644 --- a/source4/torture/local/messaging.c +++ b/source4/torture/local/messaging.c @@ -55,7 +55,7 @@ static void exit_message(struct messaging_context *msg, void *private, /* test ping speed */ -static BOOL test_ping_speed(struct torture_context *torture, const void *_data) +static bool test_ping_speed(struct torture_context *tctx) { struct event_context *ev; struct messaging_context *msg_client_ctx; @@ -63,35 +63,30 @@ static BOOL test_ping_speed(struct torture_context *torture, const void *_data) int ping_count = 0; int pong_count = 0; struct timeval tv; - int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); + int timelimit = torture_setting_int(tctx, "timelimit", 10); uint32_t msg_ping, msg_exit; + TALLOC_CTX *mem_ctx = tctx; lp_set_cmdline("lock dir", "lockdir.tmp"); - ev = event_context_init(torture); + ev = event_context_init(mem_ctx); - msg_server_ctx = messaging_init(torture, 1, ev); + msg_server_ctx = messaging_init(mem_ctx, 1, ev); - if (!msg_server_ctx) { - torture_fail(torture, "Failed to init ping messaging context"); - return False; - } + torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context"); messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping); - messaging_register_tmp(msg_server_ctx, torture, exit_message, &msg_exit); + messaging_register_tmp(msg_server_ctx, mem_ctx, exit_message, &msg_exit); - msg_client_ctx = messaging_init(torture, 2, ev); + msg_client_ctx = messaging_init(mem_ctx, 2, ev); - if (!msg_client_ctx) { - torture_fail(torture, "msg_client_ctx messaging_init() failed"); - return False; - } + torture_assert(tctx, msg_client_ctx != NULL, "msg_client_ctx messaging_init() failed"); messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong); tv = timeval_current(); - torture_comment(torture, "Sending pings for %d seconds", timelimit); + torture_comment(tctx, "Sending pings for %d seconds", timelimit); while (timeval_elapsed(&tv) < timelimit) { DATA_BLOB data; NTSTATUS status1, status2; @@ -102,51 +97,41 @@ static BOOL test_ping_speed(struct torture_context *torture, const void *_data) status1 = messaging_send(msg_client_ctx, 1, msg_ping, &data); status2 = messaging_send(msg_client_ctx, 1, msg_ping, NULL); - if (!NT_STATUS_IS_OK(status1)) { - torture_fail(torture, "msg1 failed - %s", nt_errstr(status1)); - } else { - ping_count++; - } + torture_assert_ntstatus_ok(tctx, status1, "msg1 failed"); + ping_count++; - if (!NT_STATUS_IS_OK(status2)) { - torture_fail(torture, "msg2 failed - %s", nt_errstr(status2)); - } else { - ping_count++; - } + torture_assert_ntstatus_ok(tctx, status2, "msg2 failed"); + ping_count++; while (ping_count > pong_count + 20) { event_loop_once(ev); } } - torture_comment(torture, "waiting for %d remaining replies (done %d)", + torture_comment(tctx, "waiting for %d remaining replies (done %d)", ping_count - pong_count, pong_count); while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { event_loop_once(ev); } - torture_comment(torture, "sending exit"); + torture_comment(tctx, "sending exit"); messaging_send(msg_client_ctx, 1, msg_exit, NULL); - if (ping_count != pong_count) { - torture_fail(torture, "ping test failed! received %d, sent %d", - pong_count, ping_count); - } + torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed"); - torture_comment(torture, "ping rate of %.0f messages/sec", + torture_comment(tctx, "ping rate of %.0f messages/sec", (ping_count+pong_count)/timeval_elapsed(&tv)); talloc_free(msg_client_ctx); talloc_free(msg_server_ctx); talloc_free(ev); - - return True; + return true; } struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx) { - struct torture_suite *s = torture_suite_create(mem_ctx, "LOCAL-MESSAGING"); - torture_suite_add_simple_tcase(s, "ping_speed", test_ping_speed, NULL); + struct torture_suite *s = torture_suite_create(mem_ctx, "MESSAGING"); + torture_suite_add_simple_test(s, "ping_speed", test_ping_speed); return s; } -- cgit