mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 04:19:10 -04:00
Add a tinytest flag to initialize threading.
svn:r1357
This commit is contained in:
parent
4ba6eda48f
commit
61f2a45de1
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user