Add a tinytest flag to initialize threading.

svn:r1357
This commit is contained in:
Nick Mathewson 2009-07-17 20:23:05 +00:00
parent 4ba6eda48f
commit 61f2a45de1
3 changed files with 22 additions and 0 deletions

View File

@ -63,6 +63,8 @@ struct basic_test_data {
int pair[2]; int pair[2];
void (*legacy_test_fn)(void); void (*legacy_test_fn)(void);
void *setup_data;
}; };
extern const struct testcase_setup_t basic_setup; 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_BASE (TT_FIRST_USER_FLAG<<1)
#define TT_NEED_DNS (TT_FIRST_USER_FLAG<<2) #define TT_NEED_DNS (TT_FIRST_USER_FLAG<<2)
#define TT_LEGACY (TT_FIRST_USER_FLAG<<3) #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. */ /* All the flags that a legacy test needs. */
#define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE #define TT_ISOLATED TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE

View File

@ -65,6 +65,7 @@
#include <event2/event_compat.h> #include <event2/event_compat.h>
#include <event2/dns.h> #include <event2/dns.h>
#include <event2/dns_compat.h> #include <event2/dns_compat.h>
#include <event2/thread.h>
#include "event-config.h" #include "event-config.h"
#include "regress.h" #include "regress.h"
@ -122,6 +123,20 @@ basic_test_setup(const struct testcase_t *testcase)
int spair[2] = { -1, -1 }; int spair[2] = { -1, -1 };
struct basic_test_data *data = NULL; 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 (testcase->flags & TT_NEED_SOCKETPAIR) {
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, spair) == -1) { if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, spair) == -1) {
fprintf(stderr, "%s: socketpair\n", __func__); fprintf(stderr, "%s: socketpair\n", __func__);
@ -147,6 +162,7 @@ basic_test_setup(const struct testcase_t *testcase)
exit(1); exit(1);
} }
if (testcase->flags & TT_NEED_DNS) { if (testcase->flags & TT_NEED_DNS) {
evdns_set_log_fn(dnslogcb); evdns_set_log_fn(dnslogcb);
if (evdns_init()) if (evdns_init())
@ -159,6 +175,7 @@ basic_test_setup(const struct testcase_t *testcase)
data->base = base; data->base = base;
data->pair[0] = spair[0]; data->pair[0] = spair[0];
data->pair[1] = spair[1]; data->pair[1] = spair[1];
data->setup_data = testcase->setup_data;
return data; return data;
} }

View File

@ -71,6 +71,8 @@ _testcase_run_bare(const struct testcase_t *testcase)
env = testcase->setup->setup_fn(testcase); env = testcase->setup->setup_fn(testcase);
if (!env) if (!env)
return FAIL; return FAIL;
else if (env == (void*)TT_SKIP)
return SKIP;
} }
cur_test_outcome = OK; cur_test_outcome = OK;