r3959: fix compiler warnings
[samba.git] / source4 / torture / rpc / echo.c
index be70939de1c2fbd3e1838b7ac31f9d752b1dba3f..c141d4be9c0c9a962c3068330c9a382ecdac2ea6 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include "includes.h"
+#include "librpc/gen_ndr/ndr_echo.h"
 
 
 /*
@@ -33,7 +34,7 @@ static BOOL test_addone(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        printf("\nTesting AddOne\n");
 
        for (i=0;i<10;i++) {
-               uint32 n = i;
+               uint32_t n = i;
                struct echo_AddOne r;
                r.in.v = &n;
                r.out.v = &n;
@@ -55,7 +56,7 @@ static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 {
        int i;
        NTSTATUS status;
-       char *data_in, *data_out;
+       uint8_t *data_in, *data_out;
        int len = 1 + (random() % 5000);
        struct echo_EchoData r;
 
@@ -103,7 +104,7 @@ static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        int i;
        NTSTATUS status;
        int len = 200000 + (random() % 5000);
-       char *data_out;
+       uint8_t *data_out;
        struct echo_SourceData r;
 
        printf("\nTesting SourceData\n");
@@ -120,9 +121,9 @@ static BOOL test_sourcedata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        }
 
        for (i=0;i<len;i++) {
-               unsigned char *v = (unsigned char *)data_out;
+               uint8_t *v = (uint8_t *)data_out;
                if (v[i] != (i & 0xFF)) {
-                       printf("bad data 0x%x at %d\n", (unsigned char)data_out[i], i);
+                       printf("bad data 0x%x at %d\n", (uint8_t)data_out[i], i);
                        return False;
                }
        }
@@ -137,7 +138,7 @@ static BOOL test_sinkdata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 {
        int i;
        NTSTATUS status;
-       char *data_in;
+       uint8_t *data_in;
        int len = 200000 + (random() % 5000);
        struct echo_SinkData r;
 
@@ -207,7 +208,61 @@ static BOOL test_testcall2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        return ret;
 }
 
-BOOL torture_rpc_echo(int dummy)
+#if 0
+/*
+  test the TestSleep interface
+*/
+static BOOL test_sleep(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
+{
+       int i;
+       NTSTATUS status;
+#define ASYNC_COUNT 5
+       struct rpc_request *req[ASYNC_COUNT];
+       struct echo_TestSleep r[ASYNC_COUNT];
+       int done[ASYNC_COUNT];
+       struct event_context *ctx;
+       int total_done = 0;
+       BOOL ret = True;
+
+       printf("\nTesting TestSleep\n");
+
+       for (i=0;i<ASYNC_COUNT;i++) {
+               done[i] = 0;
+               r[i].in.seconds = ASYNC_COUNT-i;
+               req[i] = dcerpc_echo_TestSleep_send(p, mem_ctx, &r[i]);
+               if (!req[i]) {
+                       printf("Failed to send async sleep request\n");
+                       return False;
+               }
+       }
+
+       ctx = dcerpc_event_context(p);
+       while (total_done < ASYNC_COUNT) {
+               if (event_loop_once(ctx) != 0) {
+                       return False;
+               }
+               for (i=0;i<ASYNC_COUNT;i++) {
+                       if (done[i] == 0 && req[i]->state == RPC_REQUEST_DONE) {
+                               total_done++;
+                               done[i] = 1;
+                               status = dcerpc_ndr_request_recv(req[i]);
+                               if (!NT_STATUS_IS_OK(status)) {
+                                       printf("TestSleep(%d) failed - %s\n",
+                                              i, nt_errstr(status));
+                                       ret = False;
+                               } else {
+                                       printf("Sleep for %d seconds\n", 
+                                              r[i].out.result);
+                               }
+                       }
+               }
+       }
+
+       return ret;
+}
+#endif
+
+BOOL torture_rpc_echo(void)
 {
         NTSTATUS status;
         struct dcerpc_pipe *p;
@@ -224,25 +279,21 @@ BOOL torture_rpc_echo(int dummy)
                return False;
        }
 
-#if 1
        if (!test_addone(p, mem_ctx)) {
                ret = False;
        }
 
-       if (!test_echodata(p, mem_ctx)) {
+       if (!test_sinkdata(p, mem_ctx)) {
                ret = False;
        }
 
-       if (!test_sourcedata(p, mem_ctx)) {
+       if (!test_echodata(p, mem_ctx)) {
                ret = False;
        }
 
-       if (!test_sinkdata(p, mem_ctx)) {
+       if (!test_sourcedata(p, mem_ctx)) {
                ret = False;
        }
-#endif
-
-       p->flags |= DCERPC_DEBUG_PRINT_BOTH;
 
        if (!test_testcall(p, mem_ctx)) {
                ret = False;
@@ -252,9 +303,14 @@ BOOL torture_rpc_echo(int dummy)
                ret = False;
        }
 
+/*
+       if (!test_sleep(p, mem_ctx)) {
+               ret = False;
+       }
+*/
        printf("\n");
        
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
 
         torture_rpc_close(p);
        return ret;