unit-tests: Defer failures by worker threads

In some cases the main thread is not ready to immediately call siglongjmp(),
e.g. if it currently holds a mutex that is later required during
shutdown.

Therefore, we delay handling errors in worker threads until the main
thread performs the next check itself (or the test function ends).

The same issue remains with SIGALRM.
This commit is contained in:
Tobias Brunner
2014-05-19 14:06:55 +02:00
parent 435fecd751
commit 032dcb8989
2 changed files with 36 additions and 5 deletions
+21 -2
View File
@@ -40,6 +40,11 @@ static int failure_line;
*/
static backtrace_t *failure_backtrace;
/**
* Flag to indicate if a worker thread failed
*/
static bool worker_failed;
/**
* Longjump restore point when failing
*/
@@ -169,6 +174,17 @@ void test_fail_msg(const char *file, int line, char *fmt, ...)
test_failure();
}
/**
* See header.
*/
void test_fail_if_worker_failed()
{
if (pthread_self() == main_thread && worker_failed)
{
test_failure();
}
}
/**
* Signal handler catching critical and alarm signals
*/
@@ -180,8 +196,9 @@ static void test_sighandler(int signal)
switch (signal)
{
case SIGUSR1:
/* a different thread failed, abort test */
return test_failure();
/* a different thread failed, abort test at the next opportunity */
worker_failed = TRUE;
return;
case SIGSEGV:
signame = "SIGSEGV";
break;
@@ -251,6 +268,8 @@ void test_setup_timeout(int s)
sigaction(SIGUSR1, &action, NULL);
alarm(s);
worker_failed = FALSE;
}
/**