Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion munit.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ static MUNIT_THREAD_LOCAL munit_bool munit_error_jmp_buf_valid = 0;
static MUNIT_THREAD_LOCAL jmp_buf munit_error_jmp_buf;
#endif

#if defined(MUNIT_THREAD_LOCAL) && defined(MUNIT_ALWAYS_TEAR_DOWN)
static MUNIT_THREAD_LOCAL bool munit_tear_down_jmp_buf_valid = false;
static MUNIT_THREAD_LOCAL jmp_buf munit_tear_down_jmp_buf;
#endif

/* At certain warning levels, mingw will trigger warnings about
* suggesting the format attribute, which we've explicity *not* set
* because it will then choke on our attempts to use the MS-specific
Expand Down Expand Up @@ -235,6 +240,11 @@ munit_errorf_ex(const char* filename, int line, const char* format, ...) {
munit_logf_exv(MUNIT_LOG_ERROR, stderr, filename, line, format, ap);
va_end(ap);

#if defined(MUNIT_THREAD_LOCAL) && defined(MUNIT_ALWAYS_TEAR_DOWN)
if (munit_tear_down_jmp_buf_valid)
longjmp(munit_tear_down_jmp_buf, 1);
#endif

#if defined(MUNIT_THREAD_LOCAL)
if (munit_error_jmp_buf_valid)
longjmp(munit_error_jmp_buf, 1);
Expand Down Expand Up @@ -1192,15 +1202,31 @@ munit_test_runner_exec(MunitTestRunner* runner, const MunitTest* test, const Mun
psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_begin);
#endif

#if defined(MUNIT_THREAD_LOCAL) && defined(MUNIT_ALWAYS_TEAR_DOWN)
if (test->tear_down != NULL) {
if (MUNIT_UNLIKELY(setjmp(munit_tear_down_jmp_buf) != 0)) {
munit_tear_down_jmp_buf_valid = false;
test->tear_down(data);
longjmp(munit_error_jmp_buf, 1);
} else {
munit_tear_down_jmp_buf_valid = true;
}
}
#endif

result = test->test(params, data);

#if defined(MUNIT_ENABLE_TIMING)
psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wall_clock_end);
psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_end);
#endif

if (test->tear_down != NULL)
if (test->tear_down != NULL) {
#if defined(MUNIT_THREAD_LOCAL) && defined(MUNIT_ALWAYS_TEAR_DOWN)
munit_tear_down_jmp_buf_valid = false;
#endif
test->tear_down(data);
}

if (MUNIT_LIKELY(result == MUNIT_OK)) {
report->successful++;
Expand Down