]> granicus.if.org Git - libevent/commitdiff
Convert RPC suite. There are still some places it can exit(1), but those always...
authorNick Mathewson <nickm@torproject.org>
Sat, 31 Jan 2009 18:36:24 +0000 (18:36 +0000)
committerNick Mathewson <nickm@torproject.org>
Sat, 31 Jan 2009 18:36:24 +0000 (18:36 +0000)
svn:r1083

test/regress.c
test/regress.h
test/regress_main.c
test/regress_rpc.c

index f48baddac1ee0fe383732c5ae9ff372ad3116313..488af2ac736993267a213c20ab833845fa8f1d3a 100644 (file)
@@ -2389,10 +2389,6 @@ legacy_main(void)
        regress_zlib();
 #endif
 
-#ifndef WIN32
-       rpc_suite();
-#endif
-
        evtag_test();
 
        rpc_test();
index 86209495c3a1eef52274d7e826fe6961f18edef8..26113ad84844a4824638861c165df0c05abd50e1 100644 (file)
@@ -39,6 +39,7 @@ extern struct testcase_t util_testcases[];
 extern struct testcase_t signal_testcases[];
 extern struct testcase_t http_testcases[];
 extern struct testcase_t dns_testcases[];
+extern struct testcase_t rpc_testcases[];
 
 int legacy_main(void);
 
index 305a61b1cb0c445db6619b68e67e127e1bdef667..a98404711c230ff35059f31266dc1dbcd1cdec32 100644 (file)
@@ -189,6 +189,7 @@ struct testgroup_t testgroups[] = {
         { "util/", util_testcases },
         { "http/", http_testcases },
         { "dns/", dns_testcases },
+        { "rpc/", rpc_testcases },
         END_OF_GROUPS
 };
 
index 879593c6cb7ce22b59170b1837c13b767dc474fe..ba3ef4cfb9c28fdad776105a4ef458775b8c713f 100644 (file)
@@ -60,9 +60,7 @@
 
 #include "regress.gen.h"
 
-void rpc_suite(void);
-
-extern int test_ok;
+#include "regress.h"
 
 static struct evhttp *
 http_setup(short *pport)
@@ -181,15 +179,10 @@ rpc_basic_test(void)
        struct evhttp_connection *evcon = NULL;
        struct evhttp_request *req = NULL;
 
-       fprintf(stdout, "Testing Basic RPC Support: ");
-
        rpc_setup(&http, &port, &base);
 
        evcon = evhttp_connection_new("127.0.0.1", port);
-       if (evcon == NULL) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
+       tt_assert(evcon);
 
        /*
         * At this point, we want to schedule an HTTP POST request
@@ -197,10 +190,7 @@ rpc_basic_test(void)
         */
 
        req = evhttp_request_new(rpc_postrequest_failure, NULL);
-       if (req == NULL) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
+       tt_assert(req);
 
        /* Add the information that we care about */
        evhttp_add_header(req->output_headers, "Host", "somehost");
@@ -209,8 +199,7 @@ rpc_basic_test(void)
        if (evhttp_make_request(evcon, req,
                EVHTTP_REQ_POST,
                "/.rpc.Message") == -1) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
+                tt_abort();
        }
 
        test_ok = 0;
@@ -221,13 +210,9 @@ rpc_basic_test(void)
 
        rpc_teardown(base);
 
-       if (test_ok != 1) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
-
-       fprintf(stdout, "OK\n");
+        tt_assert(test_ok == 1);
 
+end:
        evhttp_free(http);
 }
 
@@ -237,7 +222,6 @@ rpc_postrequest_done(struct evhttp_request *req, void *arg)
        struct kill* kill_reply = NULL;
 
        if (req->response_code != HTTP_OK) {
-
                fprintf(stderr, "FAILED (response code)\n");
                exit(1);
        }
@@ -265,15 +249,10 @@ rpc_basic_message(void)
        struct evhttp_request *req = NULL;
        struct msg *msg;
 
-       fprintf(stdout, "Testing Good RPC Post: ");
-
        rpc_setup(&http, &port, &base);
 
        evcon = evhttp_connection_new("127.0.0.1", port);
-       if (evcon == NULL) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
+        tt_assert(evcon);
 
        /*
         * At this point, we want to schedule an HTTP POST request
@@ -311,13 +290,7 @@ rpc_basic_message(void)
 
        rpc_teardown(base);
 
-       if (test_ok != 1) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
-
-       fprintf(stdout, "OK\n");
-
+end:
        evhttp_free(http);
 }
 
@@ -464,10 +437,8 @@ rpc_basic_client(void)
        struct evhttp *http = NULL;
        struct evrpc_base *base = NULL;
        struct evrpc_pool *pool = NULL;
-       struct msg *msg;
-       struct kill *kill;
-
-       fprintf(stdout, "Testing RPC Client: ");
+       struct msg *msg = NULL;
+       struct kill *kill = NULL;
 
        rpc_setup(&http, &port, &base);
 
@@ -497,10 +468,7 @@ rpc_basic_client(void)
 
        event_dispatch();
 
-       if (test_ok != 1) {
-               fprintf(stdout, "FAILED (1)\n");
-               exit(1);
-       }
+        tt_assert(test_ok == 1);
 
        /* we do it twice to make sure that reuse works correctly */
        kill_clear(kill);
@@ -509,11 +477,7 @@ rpc_basic_client(void)
 
        event_dispatch();
 
-       if (test_ok != 2) {
-               fprintf(stdout, "FAILED (2)\n");
-               exit(1);
-       }
-
+        tt_assert(test_ok == 2);
 
        /* we do it trice to make sure other stuff works, too */
        kill_clear(kill);
@@ -529,18 +493,18 @@ rpc_basic_client(void)
 
        rpc_teardown(base);
 
-       if (test_ok != 3) {
-               fprintf(stdout, "FAILED (3)\n");
-               exit(1);
-       }
+        tt_assert(test_ok == 3);
 
-       fprintf(stdout, "OK\n");
-
-       msg_free(msg);
-       kill_free(kill);
+end:
+        if (msg)
+                msg_free(msg);
+        if (kill)
+                kill_free(kill);
 
-       evrpc_pool_free(pool);
-       evhttp_free(http);
+        if (pool)
+                evrpc_pool_free(pool);
+        if (http)
+                evhttp_free(http);
 
        need_input_hook = 0;
        need_output_hook = 0;
@@ -557,10 +521,8 @@ rpc_basic_queued_client(void)
        struct evhttp *http = NULL;
        struct evrpc_base *base = NULL;
        struct evrpc_pool *pool = NULL;
-       struct msg *msg;
-       struct kill *kill_one, *kill_two;
-
-       fprintf(stdout, "Testing RPC (Queued) Client: ");
+       struct msg *msg=NULL;
+       struct kill *kill_one=NULL, *kill_two=NULL;
 
        rpc_setup(&http, &port, &base);
 
@@ -583,19 +545,20 @@ rpc_basic_queued_client(void)
 
        rpc_teardown(base);
 
-       if (test_ok != 2) {
-               fprintf(stdout, "FAILED (1)\n");
-               exit(1);
-       }
-
-       fprintf(stdout, "OK\n");
+        tt_assert(test_ok == 2);
 
-       msg_free(msg);
-       kill_free(kill_one);
-       kill_free(kill_two);
+end:
+        if (msg)
+                msg_free(msg);
+        if (kill_one)
+                kill_free(kill_one);
+        if (kill_two)
+                kill_free(kill_two);
 
-       evrpc_pool_free(pool);
-       evhttp_free(http);
+        if (pool)
+                evrpc_pool_free(pool);
+        if (http)
+                evhttp_free(http);
 }
 
 static void
@@ -622,7 +585,7 @@ struct _rpc_hook_ctx {
        void *ctx;
 };
 
-static int hook_pause_cb_called;
+static int hook_pause_cb_called=0;
 
 static void
 rpc_hook_pause_cb(int fd, short what, void *arg)
@@ -655,10 +618,8 @@ rpc_basic_client_with_pause(void)
        struct evhttp *http = NULL;
        struct evrpc_base *base = NULL;
        struct evrpc_pool *pool = NULL;
-       struct msg *msg;
-       struct kill *kill;
-
-       fprintf(stdout, "Testing RPC Client with pause hooks: ");
+       struct msg *msg = NULL;
+       struct kill *kill= NULL;
 
        rpc_setup(&http, &port, &base);
 
@@ -683,20 +644,22 @@ rpc_basic_client_with_pause(void)
 
        event_dispatch();
 
-       if (test_ok != 1 || hook_pause_cb_called != 4) {
-               fprintf(stdout, "FAILED\n");
-               exit(1);
-       }
-
-       rpc_teardown(base);
+        tt_int_op(test_ok, ==, 1);
+        tt_int_op(hook_pause_cb_called, ==, 4);
 
-       fprintf(stdout, "OK\n");
+end:
+        if (base)
+                rpc_teardown(base);
 
-       msg_free(msg);
-       kill_free(kill);
+        if (msg)
+                msg_free(msg);
+        if (kill)
+                kill_free(kill);
 
-       evrpc_pool_free(pool);
-       evhttp_free(http);
+        if (pool)
+                evrpc_pool_free(pool);
+        if (http)
+                evhttp_free(http);
 }
 
 static void
@@ -706,10 +669,8 @@ rpc_client_timeout(void)
        struct evhttp *http = NULL;
        struct evrpc_base *base = NULL;
        struct evrpc_pool *pool = NULL;
-       struct msg *msg;
-       struct kill *kill;
-
-       fprintf(stdout, "Testing RPC Client Timeout: ");
+       struct msg *msg = NULL;
+       struct kill *kill = NULL;
 
        rpc_setup(&http, &port, &base);
 
@@ -736,20 +697,35 @@ rpc_client_timeout(void)
 
        rpc_teardown(base);
 
-       if (test_ok != 2) {
-               fprintf(stdout, "FAILED (1)\n");
-               exit(1);
-       }
-
-       fprintf(stdout, "OK\n");
+        tt_assert(test_ok == 2);
 
-       msg_free(msg);
-       kill_free(kill);
+end:
+        if (msg)
+                msg_free(msg);
+        if (kill)
+                kill_free(kill);
 
-       evrpc_pool_free(pool);
-       evhttp_free(http);
+        if (pool)
+                evrpc_pool_free(pool);
+        if (http)
+                evhttp_free(http);
 }
 
+#define RPC_LEGACY(name)                                               \
+       { #name, run_legacy_test_fn, TT_FORK|TT_NEED_BASE, &legacy_setup, \
+                    rpc_##name }
+
+struct testcase_t rpc_testcases[] = {
+        RPC_LEGACY(basic_test),
+        RPC_LEGACY(basic_message),
+        RPC_LEGACY(basic_client),
+        RPC_LEGACY(basic_queued_client),
+        RPC_LEGACY(basic_client_with_pause),
+        RPC_LEGACY(client_timeout),
+
+        END_OF_TESTCASES,
+};
+
 void
 rpc_suite(void)
 {