s4:RPC-ECHO: don't look at the internals of 'struct rpc_request'
[ira/wip.git] / source4 / torture / rpc / echo.c
index edc35c0aa746a494d2fbf9fab5205a151143c32f..2321500ca52c64857dc982f42c63ccf29b10b8f4 100644 (file)
@@ -21,7 +21,6 @@
 */
 
 #include "includes.h"
-#include "torture/torture.h"
 #include "torture/rpc/rpc.h"
 #include "lib/events/events.h"
 #include "librpc/gen_ndr/ndr_echo_c.h"
@@ -78,8 +77,8 @@ static bool test_echodata(struct torture_context *tctx,
                len = 1 + (random() % 5000);
        }
 
-       data_in = talloc_size(tctx, len);
-       data_out = talloc_size(tctx, len);
+       data_in = talloc_array(tctx, uint8_t, len);
+       data_out = talloc_array(tctx, uint8_t, len);
        for (i=0;i<len;i++) {
                data_in[i] = i;
        }
@@ -159,7 +158,7 @@ static bool test_sinkdata(struct torture_context *tctx,
                len = 200000 + (random() % 5000);
        }
 
-       data_in = talloc_size(tctx, len);
+       data_in = talloc_array(tctx, uint8_t, len);
        for (i=0;i<len;i++) {
                data_in[i] = i+1;
        }
@@ -219,6 +218,12 @@ static bool test_testcall2(struct torture_context *tctx,
        return true;
 }
 
+static void test_sleep_done(struct rpc_request *rreq)
+{
+       bool *done1 = (bool *)rreq->async.private_data;
+       *done1 = true;
+}
+
 /*
   test the TestSleep interface
 */
@@ -230,25 +235,29 @@ static bool test_sleep(struct torture_context *tctx,
 #define ASYNC_COUNT 3
        struct rpc_request *req[ASYNC_COUNT];
        struct echo_TestSleep r[ASYNC_COUNT];
-       BOOL done[ASYNC_COUNT];
+       bool done1[ASYNC_COUNT];
+       bool done2[ASYNC_COUNT];
        struct timeval snd[ASYNC_COUNT];
        struct timeval rcv[ASYNC_COUNT];
        struct timeval diff[ASYNC_COUNT];
-       struct event_context *ctx;
+       struct tevent_context *ctx;
        int total_done = 0;
 
        if (torture_setting_bool(tctx, "quick", false)) {
                torture_skip(tctx, "TestSleep disabled - use \"torture:quick=no\" to enable\n");
        }
-       torture_comment(tctx, "Testing TestSleep - use \"torture:quick=no\" to disable\n");
+       torture_comment(tctx, "Testing TestSleep - use \"torture:quick=yes\" to disable\n");
 
        for (i=0;i<ASYNC_COUNT;i++) {
-               done[i]         = False;
+               done1[i]        = false;
+               done2[i]        = false;
                snd[i]          = timeval_current();
                rcv[i]          = timeval_zero();
                r[i].in.seconds = ASYNC_COUNT-i;
                req[i] = dcerpc_echo_TestSleep_send(p, tctx, &r[i]);
                torture_assert(tctx, req[i], "Failed to send async sleep request\n");
+               req[i]->async.callback = test_sleep_done;
+               req[i]->async.private_data = &done1[i];
        }
 
        ctx = dcerpc_event_context(p);
@@ -256,38 +265,38 @@ static bool test_sleep(struct torture_context *tctx,
                torture_assert(tctx, event_loop_once(ctx) == 0, 
                                           "Event context loop failed");
                for (i=0;i<ASYNC_COUNT;i++) {
-                       if (done[i] == False && req[i]->state == RPC_REQUEST_DONE) {
+                       if (done2[i] == false && done1[i] == true) {
                                int rounded_tdiff;
                                total_done++;
-                               done[i] = True;
+                               done2[i] = true;
                                rcv[i]  = timeval_current();
                                diff[i] = timeval_until(&snd[i], &rcv[i]);
                                rounded_tdiff = (int)(0.5 + diff[i].tv_sec + (1.0e-6*diff[i].tv_usec));
-                               status  = dcerpc_ndr_request_recv(req[i]);
-                               printf("rounded_tdiff=%d\n", rounded_tdiff);
+                               status  = dcerpc_echo_TestSleep_recv(req[i]);
+                               torture_comment(tctx, "rounded_tdiff=%d\n", rounded_tdiff);
                                torture_assert_ntstatus_ok(tctx, status, 
                                                        talloc_asprintf(tctx, "TestSleep(%d) failed", i));
                                torture_assert(tctx, r[i].out.result == r[i].in.seconds,
                                        talloc_asprintf(tctx, "Failed - Asked to sleep for %u seconds (server replied with %u seconds and the reply takes only %u seconds)", 
-                                               r[i].out.result, r[i].in.seconds, (uint_t)diff[i].tv_sec));
+                                               r[i].out.result, r[i].in.seconds, (unsigned int)diff[i].tv_sec));
                                torture_assert(tctx, r[i].out.result <= rounded_tdiff, 
                                        talloc_asprintf(tctx, "Failed - Slept for %u seconds (but reply takes only %u.%06u seconds)", 
-                                               r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec));
+                                               r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec));
                                if (r[i].out.result+1 == rounded_tdiff) {
                                        torture_comment(tctx, "Slept for %u seconds (but reply takes %u.%06u seconds - busy server?)\n", 
-                                                       r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
+                                                       r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
                                } else if (r[i].out.result == rounded_tdiff) {
                                        torture_comment(tctx, "Slept for %u seconds (reply takes %u.%06u seconds - ok)\n", 
-                                                       r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
+                                                       r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
                                } else {
                                                torture_comment(tctx, "(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)", 
-                                                       r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
+                                                       r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
                                        /* TODO: let the test fail here, when we support async rpc on ncacn_np */
                                }
                        }
                }
        }
-       printf("\n");
+       torture_comment(tctx, "\n");
        return true;
 }
 
@@ -372,6 +381,7 @@ static bool test_doublepointer(struct torture_context *tctx,
 /*
   test request timeouts
 */
+#if 0 /* this test needs fixing to work over ncacn_np */
 static bool test_timeout(struct torture_context *tctx,
                                                 struct dcerpc_pipe *p)
 {
@@ -393,9 +403,9 @@ static bool test_timeout(struct torture_context *tctx,
                torture_comment(tctx, "Failed to send async sleep request\n");
                goto failed;
        }
-       req->ignore_timeout = True;
+       req->ignore_timeout = true;
 
-       status  = dcerpc_ndr_request_recv(req);
+       status  = dcerpc_echo_TestSleep_recv(req);
        torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
                                                                  "request should have timed out");
 
@@ -412,8 +422,8 @@ static bool test_timeout(struct torture_context *tctx,
                torture_comment(tctx, "Failed to send async sleep request\n");
                goto failed;
        }
-       req->ignore_timeout = True;
-       status  = dcerpc_ndr_request_recv(req);
+       req->ignore_timeout = true;
+       status  = dcerpc_echo_TestSleep_recv(req);
        torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
                "request should have timed out");
 
@@ -425,12 +435,12 @@ failed:
        p->request_timeout = timeout_saved;
        return false;
 }
+#endif
 
-
-struct torture_suite *torture_rpc_echo(void)
+struct torture_suite *torture_rpc_echo(TALLOC_CTX *mem_ctx)
 {
        struct torture_suite *suite = torture_suite_create(
-               talloc_autofree_context(), "ECHO");
+               mem_ctx, "ECHO");
        struct torture_rpc_tcase *tcase;
 
        tcase = torture_suite_add_rpc_iface_tcase(suite, "echo", 
@@ -446,7 +456,9 @@ struct torture_suite *torture_rpc_echo(void)
        torture_rpc_tcase_add_test(tcase, "surrounding", test_surrounding);
        torture_rpc_tcase_add_test(tcase, "doublepointer", test_doublepointer);
        torture_rpc_tcase_add_test(tcase, "sleep", test_sleep);
+#if 0 /* this test needs fixing to work over ncacn_np */
        torture_rpc_tcase_add_test(tcase, "timeout", test_timeout);
+#endif
 
        return suite;
 }