mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Merge pull request #1737 from libevent/signal-tests
Retry tests with SIGALRM on OSX (and fix some related stuff)
This commit is contained in:
commit
3c8d89b9b2
@ -1045,11 +1045,21 @@ signal_cb(evutil_socket_t fd, short event, void *arg)
|
||||
}
|
||||
|
||||
static void
|
||||
test_simplesignal_impl(int find_reorder)
|
||||
signal_alarm_fallback(int sig)
|
||||
{
|
||||
TT_DIE(("ALRM received not from event loop!"));
|
||||
end:
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_simple_signal_impl(int find_reorder)
|
||||
{
|
||||
struct event ev;
|
||||
struct itimerval itv;
|
||||
|
||||
signal(SIGALRM, signal_alarm_fallback);
|
||||
|
||||
evsignal_set(&ev, SIGALRM, signal_cb, &ev);
|
||||
evsignal_add(&ev, NULL);
|
||||
/* find bugs in which operations are re-ordered */
|
||||
@ -1061,11 +1071,10 @@ test_simplesignal_impl(int find_reorder)
|
||||
memset(&itv, 0, sizeof(itv));
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 100000;
|
||||
if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
|
||||
goto skip_simplesignal;
|
||||
tt_int_op(setitimer(ITIMER_REAL, &itv, NULL), ==, 0);
|
||||
|
||||
event_dispatch();
|
||||
skip_simplesignal:
|
||||
end:
|
||||
if (evsignal_del(&ev) == -1)
|
||||
test_ok = 0;
|
||||
|
||||
@ -1073,17 +1082,17 @@ test_simplesignal_impl(int find_reorder)
|
||||
}
|
||||
|
||||
static void
|
||||
test_simplestsignal(void)
|
||||
test_simple_signal(void)
|
||||
{
|
||||
setup_test("Simplest one signal: ");
|
||||
test_simplesignal_impl(0);
|
||||
test_simple_signal_impl(0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_simplesignal(void)
|
||||
test_simple_signal_re_order(void)
|
||||
{
|
||||
setup_test("Simple signal: ");
|
||||
test_simplesignal_impl(1);
|
||||
test_simple_signal_impl(1);
|
||||
}
|
||||
|
||||
/* signal_free_in_callback */
|
||||
@ -1125,6 +1134,8 @@ test_multiplesignal(void)
|
||||
|
||||
setup_test("Multiple signal: ");
|
||||
|
||||
signal(SIGALRM, signal_alarm_fallback);
|
||||
|
||||
evsignal_set(&ev_one, SIGALRM, signal_cb, &ev_one);
|
||||
evsignal_add(&ev_one, NULL);
|
||||
|
||||
@ -1134,12 +1145,11 @@ test_multiplesignal(void)
|
||||
memset(&itv, 0, sizeof(itv));
|
||||
itv.it_value.tv_sec = 0;
|
||||
itv.it_value.tv_usec = 100000;
|
||||
if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
|
||||
goto skip_simplesignal;
|
||||
tt_int_op(setitimer(ITIMER_REAL, &itv, NULL), ==, 0);
|
||||
|
||||
event_dispatch();
|
||||
|
||||
skip_simplesignal:
|
||||
end:
|
||||
if (evsignal_del(&ev_one) == -1)
|
||||
test_ok = 0;
|
||||
if (evsignal_del(&ev_two) == -1)
|
||||
@ -3774,7 +3784,9 @@ struct testcase_t evtag_testcases[] = {
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
#if defined(__darwin__)
|
||||
/* Apparently there is a bug in OSX that leads to subsequent ALRM signal
|
||||
* delievered even though it_interval is set to 0, so let's retry the tests */
|
||||
#if defined(__APPLE__)
|
||||
#define RETRY_ON_DARWIN TT_RETRIABLE
|
||||
#else
|
||||
#define RETRY_ON_DARWIN 0
|
||||
@ -3782,8 +3794,8 @@ struct testcase_t evtag_testcases[] = {
|
||||
|
||||
struct testcase_t signal_testcases[] = {
|
||||
#ifndef _WIN32
|
||||
LEGACY(simplestsignal, TT_ISOLATED|RETRY_ON_DARWIN),
|
||||
LEGACY(simplesignal, TT_ISOLATED|RETRY_ON_DARWIN),
|
||||
LEGACY(simple_signal, TT_ISOLATED|RETRY_ON_DARWIN),
|
||||
LEGACY(simple_signal_re_order, TT_ISOLATED|RETRY_ON_DARWIN),
|
||||
LEGACY(multiplesignal, TT_ISOLATED|RETRY_ON_DARWIN),
|
||||
LEGACY(immediatesignal, TT_ISOLATED),
|
||||
LEGACY(signal_dealloc, TT_ISOLATED),
|
||||
@ -3793,7 +3805,7 @@ struct testcase_t signal_testcases[] = {
|
||||
LEGACY(signal_restore, TT_ISOLATED),
|
||||
LEGACY(signal_assert, TT_ISOLATED),
|
||||
LEGACY(signal_while_processing, TT_ISOLATED),
|
||||
BASIC(signal_free_in_callback, TT_FORK|TT_NEED_BASE|RETRY_ON_DARWIN),
|
||||
BASIC(signal_free_in_callback, TT_FORK|TT_NEED_BASE),
|
||||
#endif
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
@ -74,6 +74,7 @@ static int opt_verbosity = 1; /**< -==quiet,0==terse,1==normal,2==verbose */
|
||||
static unsigned int opt_timeout = DEFAULT_TESTCASE_TIMEOUT; /**< Timeout for every test (using alarm()) */
|
||||
static unsigned int opt_retries = 3; /**< How much test with TT_RETRIABLE should be retried */
|
||||
static unsigned int opt_retries_delay = 1; /**< How much seconds to delay before retrying */
|
||||
static unsigned int opt_repeat = 0; /**< How much times to repeat the test */
|
||||
const char *verbosity_flag = "";
|
||||
|
||||
const struct testlist_alias_t *cfg_aliases=NULL;
|
||||
@ -409,6 +410,7 @@ usage(struct testgroup_t *groups, int list_groups)
|
||||
puts(" --timeout <sec>");
|
||||
puts(" --retries <n>");
|
||||
puts(" --retries-delay <n>");
|
||||
puts(" --repeat <n>");
|
||||
puts("");
|
||||
puts(" Specify tests by name, or using a prefix ending with '..'");
|
||||
puts(" To skip a test, prefix its name with a colon.");
|
||||
@ -527,6 +529,13 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
||||
return -1;
|
||||
}
|
||||
opt_retries_delay = (unsigned)atoi(v[i]);
|
||||
} else if (!strcmp(v[i], "--repeat")) {
|
||||
++i;
|
||||
if (i >= c) {
|
||||
fprintf(stderr, "--repeat requires argument\n");
|
||||
return -1;
|
||||
}
|
||||
opt_repeat = (unsigned)atoi(v[i]);
|
||||
} else {
|
||||
fprintf(stderr, "Unknown option %s. Try --help\n", v[i]);
|
||||
return -1;
|
||||
@ -552,24 +561,26 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
||||
struct testcase_t *testcase = &group->cases[j];
|
||||
int retriable = testcase->flags & TT_RETRIABLE;
|
||||
int attempts = retriable ? opt_retries : 0;
|
||||
int test_ret_err;
|
||||
int test_ret_err = FAIL;
|
||||
|
||||
if (!(testcase->flags & TT_ENABLED_))
|
||||
continue;
|
||||
|
||||
for (;;) {
|
||||
test_ret_err = testcase_run_one(group, testcase, attempts);
|
||||
for (unsigned k = 0; k < opt_repeat + 1; ++k) {
|
||||
for (;;) {
|
||||
test_ret_err = testcase_run_one(group, testcase, attempts);
|
||||
|
||||
if (test_ret_err == OK)
|
||||
break;
|
||||
if (!attempts--)
|
||||
break;
|
||||
printf("\n [RETRYING %s%s (attempts left %i, delay %i sec)]\n", group->prefix, testcase->name, attempts, opt_retries_delay);
|
||||
if (test_ret_err == OK)
|
||||
break;
|
||||
if (!attempts--)
|
||||
break;
|
||||
printf("\n [RETRYING %s%s (attempts left %i, delay %i sec)]\n", group->prefix, testcase->name, attempts, opt_retries_delay);
|
||||
#ifdef _WIN32
|
||||
Sleep(opt_retries_delay * 1000);
|
||||
Sleep(opt_retries_delay * 1000);
|
||||
#else
|
||||
sleep(opt_retries_delay);
|
||||
sleep(opt_retries_delay);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
switch (test_ret_err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user