r12608: Remove some unused #include lines.
[abartlet/samba.git/.git] / source4 / torture / local / messaging.c
index 958fcaa8f082b69d951c0b059ab5ee7e362ad93e..faba8304d7a1c7603244e3f0364f037fc18ec2a2 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "lib/events/events.h"
+#include "lib/messaging/irpc.h"
 
 enum {MY_PING=1000, MY_PONG, MY_EXIT};
 
@@ -54,27 +55,27 @@ static void exit_message(struct messaging_context *msg, void *private,
 */
 static BOOL test_ping_speed(TALLOC_CTX *mem_ctx)
 {
-       struct event_context *ev = event_context_init(mem_ctx);
+       struct event_context *ev;
        struct messaging_context *msg_ctx;
+       struct messaging_context *msg_ctx2;
        int ping_count = 0;
        int pong_count = 0;
        BOOL ret = True;
        struct timeval tv;
+       int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
 
-       if (fork() == 0) {
-               struct messaging_context *msg_ctx2 = messaging_init(mem_ctx, 1, ev);
+       lp_set_cmdline("lock dir", "lockdir.tmp");
+
+       ev = event_context_init(mem_ctx);
+
+       msg_ctx2 = messaging_init(mem_ctx, 1, ev);
        
-               if (!msg_ctx2) {
-                       exit(1);
-               }
-               
-               messaging_register(msg_ctx2, NULL, MY_PING, ping_message);
-               messaging_register(msg_ctx2, mem_ctx, MY_EXIT, exit_message);
-               event_loop_wait(ev);
-               exit(0);
+       if (!msg_ctx2) {
+               exit(1);
        }
-
-       sleep(2);
+               
+       messaging_register(msg_ctx2, NULL, MY_PING, ping_message);
+       messaging_register(msg_ctx2, mem_ctx, MY_EXIT, exit_message);
 
        msg_ctx = messaging_init(mem_ctx, 2, ev);
 
@@ -87,8 +88,8 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx)
 
        tv = timeval_current();
 
-       printf("Sending pings for 10 seconds\n");
-       while (timeval_elapsed(&tv) < 10.0) {
+       printf("Sending pings for %d seconds\n", timelimit);
+       while (timeval_elapsed(&tv) < timelimit) {
                DATA_BLOB data;
                NTSTATUS status1, status2;
 
@@ -100,14 +101,16 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx)
 
                if (!NT_STATUS_IS_OK(status1)) {
                        printf("msg1 failed - %s\n", nt_errstr(status1));
+               } else {
+                       ping_count++;
                }
 
                if (!NT_STATUS_IS_OK(status2)) {
                        printf("msg2 failed - %s\n", nt_errstr(status2));
+               } else {
+                       ping_count++;
                }
 
-               ping_count += 2;
-
                while (ping_count > pong_count + 20) {
                        event_loop_once(ev);
                }
@@ -123,7 +126,8 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx)
        messaging_send(msg_ctx, 1, MY_EXIT, NULL);
 
        if (ping_count != pong_count) {
-               printf("ping test failed! received %d, sent %d\n", pong_count, ping_count);
+               printf("ping test failed! received %d, sent %d\n", 
+                      pong_count, ping_count);
                ret = False;
        }
 
@@ -133,6 +137,7 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx)
        talloc_free(msg_ctx);
 
        talloc_free(ev);
+
        return ret;
 }
 
@@ -145,5 +150,5 @@ BOOL torture_local_messaging(void)
 
        talloc_free(mem_ctx);
 
-       return True;
+       return ret;
 }