]> granicus.if.org Git - libevent/commitdiff
Add a tinytest flag to initialize threading.
authorNick Mathewson <nickm@torproject.org>
Fri, 17 Jul 2009 20:23:05 +0000 (20:23 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Jul 2009 20:23:05 +0000 (20:23 +0000)
svn:r1357

test/regress.h
test/regress_main.c
test/tinytest.c

index 824b8bc9b2314f4784866e03fb14f63d084b0f34..3365fcbb41d68e6de56b49c0c250cd961b51b7c4 100644 (file)
@@ -63,6 +63,8 @@ struct basic_test_data {
        int pair[2];
 
        void (*legacy_test_fn)(void);
+
+       void *setup_data;
 };
 extern const struct testcase_setup_t basic_setup;
 
@@ -75,6 +77,7 @@ void run_legacy_test_fn(void *ptr);
 #define TT_NEED_BASE         (TT_FIRST_USER_FLAG<<1)
 #define TT_NEED_DNS          (TT_FIRST_USER_FLAG<<2)
 #define TT_LEGACY            (TT_FIRST_USER_FLAG<<3)
+#define TT_NEED_THREADS      (TT_FIRST_USER_FLAG<<4)
 
 /* All the flags that a legacy test needs. */
 #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE
index 4ce699b2a7bca1c1abec148f063afa3290c46da6..9ed62cf801ba2fd708e72f7b13e11d43d41712bb 100644 (file)
@@ -65,6 +65,7 @@
 #include <event2/event_compat.h>
 #include <event2/dns.h>
 #include <event2/dns_compat.h>
+#include <event2/thread.h>
 
 #include "event-config.h"
 #include "regress.h"
@@ -122,6 +123,20 @@ basic_test_setup(const struct testcase_t *testcase)
        int spair[2] = { -1, -1 };
        struct basic_test_data *data = NULL;
 
+       if (testcase->flags & TT_NEED_THREADS) {
+               if (!(testcase->flags & TT_FORK))
+                       return NULL;
+#if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED)
+               if (evthread_use_pthreads())
+                       exit(1);
+#elif defined(EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED)
+               if (evthread_use_windows_threads())
+                       exit(1);
+#else
+               return (void*)TT_SKIP;
+#endif
+       }
+
        if (testcase->flags & TT_NEED_SOCKETPAIR) {
                if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, spair) == -1) {
                        fprintf(stderr, "%s: socketpair\n", __func__);
@@ -147,6 +162,7 @@ basic_test_setup(const struct testcase_t *testcase)
                        exit(1);
        }
 
+
         if (testcase->flags & TT_NEED_DNS) {
                 evdns_set_log_fn(dnslogcb);
                 if (evdns_init())
@@ -159,6 +175,7 @@ basic_test_setup(const struct testcase_t *testcase)
        data->base = base;
        data->pair[0] = spair[0];
        data->pair[1] = spair[1];
+       data->setup_data = testcase->setup_data;
        return data;
 }
 
index 3654e681d2d520e88677ec30f54fd03b2e14d0bd..19d75dd124a29f1c7269d37d458b34fa712b6c91 100644 (file)
@@ -71,6 +71,8 @@ _testcase_run_bare(const struct testcase_t *testcase)
                env = testcase->setup->setup_fn(testcase);
                 if (!env)
                        return FAIL;
+               else if (env == (void*)TT_SKIP)
+                       return SKIP;
        }
 
        cur_test_outcome = OK;