Convert all uses of uint32/16/8 to _t in source3/torture.
[bbaumbach/samba-autobuild/.git] / source3 / torture / msgtest.c
index adb45f75e3a64aabc671a842a749fdafc8f555c2..1d2a8a9b1c86275a74d6cd11ec23cd6d6858e3a4 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #include "includes.h"
-#include "librpc/gen_ndr/messaging.h"
+#include "messages.h"
 
 static int pong_count;
 
@@ -46,22 +46,25 @@ static void pong_message(struct messaging_context *msg_ctx,
        int i, n;
        char buf[12];
        int ret;
+       TALLOC_CTX *frame = talloc_stackframe();
 
-       load_case_tables();
+       smb_init_locale();
 
        setup_logging(argv[0], DEBUG_STDOUT);
 
-       lp_load(get_dyn_CONFIGFILE(),False,False,False,True);
+       lp_load_global(get_dyn_CONFIGFILE());
 
-       if (!(evt_ctx = tevent_context_init(NULL)) ||
-           !(msg_ctx = messaging_init(NULL, procid_self(), evt_ctx))) {
+       if (!(evt_ctx = samba_tevent_context_init(NULL)) ||
+           !(msg_ctx = messaging_init(NULL, evt_ctx))) {
                fprintf(stderr, "could not init messaging context\n");
+               TALLOC_FREE(frame);
                exit(1);
        }
 
        if (argc != 3) {
                fprintf(stderr, "%s: Usage - %s pid count\n", argv[0],
                        argv[0]);
+               TALLOC_FREE(frame);
                exit(1);
        }
 
@@ -82,27 +85,37 @@ static void pong_message(struct messaging_context *msg_ctx,
                }
        }
 
-       /* Now test that the duplicate filtering code works. */
+       /* Ensure all messages get through to ourselves. */
        pong_count = 0;
 
-       safe_strcpy(buf, "1234567890", sizeof(buf)-1);
+       strlcpy(buf, "1234567890", sizeof(buf));
 
        for (i=0;i<n;i++) {
                messaging_send(msg_ctx, messaging_server_id(msg_ctx), MSG_PING,
                               &data_blob_null);
                messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
-                                  MSG_PING,(uint8 *)buf, 11);
+                                  MSG_PING,(uint8_t *)buf, 11);
        }
 
-       for (i=0;i<n;i++) {
+       /*
+        * We have to loop at least 2 times for
+        * each message as local ping messages are
+        * handled by an immediate callback, that
+        * has to be dispatched, which sends a pong
+        * message, which also has to be dispatched.
+        * Above we sent 2*n messages, which means
+        * we have to dispatch 4*n times.
+        */
+
+       while (pong_count < n*2) {
                ret = tevent_loop_once(evt_ctx);
                if (ret != 0) {
                        break;
                }
        }
 
-       if (pong_count != 2) {
-               fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count);
+       if (pong_count != 2*n) {
+               fprintf(stderr, "Message count failed (%d).\n", pong_count);
        }
 
        /* Speed testing */
@@ -119,7 +132,7 @@ static void pong_message(struct messaging_context *msg_ctx,
                        if(NT_STATUS_IS_OK(messaging_send_buf(
                                                   msg_ctx, pid_to_procid(pid),
                                                   MSG_PING,
-                                                  (uint8 *)buf, 11)))
+                                                  (uint8_t *)buf, 11)))
                           ping_count++;
                        if(NT_STATUS_IS_OK(messaging_send(
                                                   msg_ctx, pid_to_procid(pid),
@@ -152,6 +165,7 @@ static void pong_message(struct messaging_context *msg_ctx,
                       (ping_count+pong_count)/timeval_elapsed(&tv));
        }
 
+       TALLOC_FREE(frame);
        return (0);
 }