From: Nick Mathewson Date: Fri, 17 Jul 2009 20:23:05 +0000 (+0000) Subject: Add a tinytest flag to initialize threading. X-Git-Tag: release-2.0.3-alpha~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61f2a45de165edbb149dd476ec03b9ff134afc63;p=libevent Add a tinytest flag to initialize threading. svn:r1357 --- diff --git a/test/regress.h b/test/regress.h index 824b8bc9..3365fcbb 100644 --- a/test/regress.h +++ b/test/regress.h @@ -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 diff --git a/test/regress_main.c b/test/regress_main.c index 4ce699b2..9ed62cf8 100644 --- a/test/regress_main.c +++ b/test/regress_main.c @@ -65,6 +65,7 @@ #include #include #include +#include #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; } diff --git a/test/tinytest.c b/test/tinytest.c index 3654e681..19d75dd1 100644 --- a/test/tinytest.c +++ b/test/tinytest.c @@ -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;