]> granicus.if.org Git - libevent/commitdiff
Refactor the zlib and pthreads tests to appear in the regular tinytest tree structure.
authorNick Mathewson <nickm@torproject.org>
Tue, 7 Apr 2009 04:49:25 +0000 (04:49 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 7 Apr 2009 04:49:25 +0000 (04:49 +0000)
svn:r1141

test/regress.c
test/regress.h
test/regress_bufferevent.c
test/regress_main.c
test/regress_pthread.c
test/regress_zlib.c

index 1d54b7bc022e46816be340cf5fe465c5d4753b4b..de49131a4e43489b6482d29652932b7fe4c4f4a5 100644 (file)
@@ -1439,20 +1439,3 @@ struct testcase_t signal_testcases[] = {
         END_OF_TESTCASES
 };
 
-int
-legacy_main(void)
-{
-       /* Initalize the event library */
-       global_base = event_init();
-
-#if defined(_EVENT_HAVE_PTHREADS) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
-       regress_pthread();
-#endif
-
-#if defined(_EVENT_HAVE_LIBZ)
-       regress_zlib();
-#endif
-
-       return (0);
-}
-
index 16ede4e850d24b72c0b369708000a54a9a7a1165..0d0ce1a057b0d8956fb04511a761d84a9674c483 100644 (file)
@@ -44,10 +44,8 @@ extern struct testcase_t dns_testcases[];
 extern struct testcase_t rpc_testcases[];
 extern struct testcase_t edgetriggered_testcases[];
 
-int legacy_main(void);
-
-void regress_pthread(void);
-void regress_zlib(void);
+void regress_threads(void *);
+void test_bufferevent_zlib(void *);
 
 /* Helpers to wrap old testcases */
 extern int pair[2];
index 4a0bd56cb1b1b0a69c110e84c0e2e54c3dc18dc4..5578d320bf1ba83ce738a02d349dc846d0f77574 100644 (file)
@@ -55,6 +55,7 @@
 #include <errno.h>
 #include <assert.h>
 
+#include "event-config.h"
 #include "event2/event.h"
 #include "event2/event_struct.h"
 #include "event2/event_compat.h"
@@ -304,6 +305,11 @@ struct testcase_t bufferevent_testcases[] = {
         LEGACY(bufferevent, TT_ISOLATED),
         LEGACY(bufferevent_watermarks, TT_ISOLATED),
         LEGACY(bufferevent_filters, TT_ISOLATED),
+#ifdef _EVENT_HAVE_LIBZ
+        LEGACY(bufferevent_zlib, TT_ISOLATED),
+#else
+        { "bufferevent_zlib", NULL, TT_SKIP, NULL, NULL },
+#endif
 
         END_OF_TESTCASES,
 };
index 4d518b24b50398082d22b2cc661adda49d2e6b15..7d31ad44e68a5c084071320d5b97337ebcfcf6dd 100644 (file)
@@ -66,6 +66,7 @@
 #include <event2/dns.h>
 #include <event2/dns_compat.h>
 
+#include "event-config.h"
 #include "regress.h"
 #include "tinytest.h"
 #include "tinytest_macros.h"
@@ -208,16 +209,26 @@ const struct testcase_setup_t legacy_setup = {
 /* ============================================================ */
 
 
+struct testcase_t thread_testcases[] = {
+#if defined(_EVENT_HAVE_PTHREADS) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
+       { "pthreads", regress_threads, TT_FORK, NULL, NULL, },
+#else
+       { "pthreads", NULL, TT_SKIP, NULL, NULL },
+#endif
+       END_OF_TESTCASES
+};
+
 struct testgroup_t testgroups[] = {
-        { "main/", legacy_testcases },
-               { "et/", edgetriggered_testcases },
-               { "evbuffer/", evbuffer_testcases },
-        { "signal/", signal_testcases },
-        { "util/", util_testcases },
-        { "bufferevent/", bufferevent_testcases },
-        { "http/", http_testcases },
-        { "dns/", dns_testcases },
-        { "rpc/", rpc_testcases },
+       { "main/", legacy_testcases },
+       { "et/", edgetriggered_testcases },
+       { "evbuffer/", evbuffer_testcases },
+       { "signal/", signal_testcases },
+       { "util/", util_testcases },
+       { "bufferevent/", bufferevent_testcases },
+       { "http/", http_testcases },
+       { "dns/", dns_testcases },
+       { "rpc/", rpc_testcases },
+       { "thread/", thread_testcases },
         END_OF_GROUPS
 };
 
@@ -246,7 +257,6 @@ main(int argc, const char **argv)
         if (tinytest_main(argc,argv,testgroups))
                 return 1;
 
-        in_legacy_test_wrapper = 0;
-        return legacy_main();
+       return 0;
 }
 
index 2fff24b025a05bb1ecc99d9535cd92d006dc106a..9d782939b4e62e45e8948757ff772748962850cf 100644 (file)
@@ -39,8 +39,8 @@
 #include "event2/event.h"
 #include "event2/event_struct.h"
 #include "event2/thread.h"
-
-void regress_pthread(void);
+#include "regress.h"
+#include "tinytest_macros.h"
 
 struct cond_wait {
        pthread_mutex_t lock;
@@ -107,8 +107,6 @@ pthread_basic(struct event_base *base)
        struct timeval tv;
        int i;
 
-       fprintf(stdout, "Testing basic pthreads support: ");
-
        for (i = 0; i < NUM_THREADS; ++i)
                pthread_create(&threads[i], NULL, basic_thread, base);
 
@@ -124,14 +122,13 @@ pthread_basic(struct event_base *base)
                pthread_join(threads[i], NULL);
 
        event_del(&ev);
-
-       fprintf(stdout, "OK\n");
 }
 
 void
-regress_pthread(void)
+regress_threads(void *arg)
 {
        struct event_base *base;
+        (void) arg;
 
        pthread_mutex_init(&count_lock, NULL);
 
@@ -139,8 +136,7 @@ regress_pthread(void)
 
         base = event_base_new();
         if (evthread_make_base_notifiable(base)<0) {
-                puts("Couldn't make base notifiable!");
-                return;
+                tt_abort_msg("Couldn't make base notifiable!");
         }
 
        pthread_basic(base);
@@ -148,4 +144,6 @@ regress_pthread(void)
        pthread_mutex_destroy(&count_lock);
 
        event_base_free(base);
+end:
+        ;
 }
index 4e4af4646270065351407c1ea76020efc121a879..6dabfb2f37cf8c579fd4a1ac7d4e7296bb348bc9 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <zlib.h>
 #include <assert.h>
+#include <errno.h>
 
 #include "event2/util.h"
 #include "event2/event.h"
@@ -54,7 +55,7 @@
 #include "event2/buffer.h"
 #include "event2/bufferevent.h"
 
-void regress_zlib(void);
+#include "regress.h"
 
 static int infilter_calls;
 static int outfilter_calls;
@@ -228,23 +229,20 @@ errorcb(struct bufferevent *bev, short what, void *arg)
        errorcb_invoked = 1;
 }
 
-static void
-test_bufferevent_zlib(void)
+void
+test_bufferevent_zlib(void *arg)
 {
-       struct bufferevent *bev1, *bev2, *bev1_orig, *bev2_orig;
+       struct bufferevent *bev1=NULL, *bev2=NULL, *bev1_orig, *bev2_orig;
        char buffer[8333];
        z_stream z_input, z_output;
-       int i, pair[2], r;
-        int test_ok;
+       int i, pair[2]={-1,-1}, r;
+        (void)arg;
 
        infilter_calls = outfilter_calls = readcb_finished = writecb_finished
             = errorcb_invoked = 0;
 
-       fprintf(stdout, "Testing Zlib Filter: ");
-
        if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
-               fprintf(stderr, "%s: socketpair\n", __func__);
-               exit(1);
+               tt_fail_perror("socketpair");
        }
 
        evutil_make_socket_nonblocking(pair[0]);
@@ -255,19 +253,18 @@ test_bufferevent_zlib(void)
 
        memset(&z_output, 0, sizeof(z_output));
        r = deflateInit(&z_output, Z_DEFAULT_COMPRESSION);
-       assert(r == Z_OK);
+       tt_int_op(r, ==, Z_OK);
        memset(&z_input, 0, sizeof(z_input));
        r = inflateInit(&z_input);
 
        /* initialize filters */
        bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter, 0,
-                                     zlib_deflate_free, &z_output);
+           zlib_deflate_free, &z_output);
        bev2 = bufferevent_filter_new(bev2, zlib_input_filter,
-                                     NULL, 0, zlib_inflate_free, &z_input);
+           NULL, 0, zlib_inflate_free, &z_input);
        bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL);
        bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);
 
-
        bufferevent_disable(bev1, EV_READ);
        bufferevent_enable(bev1, EV_WRITE);
 
@@ -285,34 +282,21 @@ test_bufferevent_zlib(void)
 
        event_dispatch();
 
-       bufferevent_free(bev1);
-       bufferevent_free(bev2);
-
-
-        test_ok = infilter_calls &&
-            outfilter_calls &&
-            readcb_finished &&
-            writecb_finished &&
-            !errorcb_invoked;
-
-        if (! test_ok) {
-               fprintf(stdout, "FAILED: %d\n", test_ok);
-               exit(1);
-       }
-
-#ifndef WIN32
-       close(pair[0]);
-       close(pair[1]);
-#else
-       CloseHandle((HANDLE)pair[0]);
-       CloseHandle((HANDLE)pair[1]);
-#endif
-
-       fprintf(stdout, "OK\n");
-}
-
-void
-regress_zlib(void)
-{
-       test_bufferevent_zlib();
+        tt_want(infilter_calls);
+        tt_want(outfilter_calls);
+        tt_want(readcb_finished);
+        tt_want(writecb_finished);
+        tt_want(!errorcb_invoked);
+
+        test_ok = 1;
+end:
+        if (bev1)
+                bufferevent_free(bev1);
+        if (bev2)
+               bufferevent_free(bev2);
+
+       if (pair[0] >= 0)
+               EVUTIL_CLOSESOCKET(pair[0]);
+       if (pair[1] >= 0)
+               EVUTIL_CLOSESOCKET(pair[1]);
 }