From 4bf87f329493cdbb8acef403be2a26a325da97cc Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 15 Apr 2014 16:58:25 +0200 Subject: [PATCH] cmocka: Add CMOCKA_TEST_ABORT env variable to leave threading apps. BUG: https://open.cryptomilk.org/issues/26 Reviewed-by: Jakub Hrozek --- doc/mainpage.dox | 14 ++++++++++++++ src/cmocka.c | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 4b7acb0..d159bf0 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -82,4 +82,18 @@ the mock object to return. CMocka provides and API to easily mock code. Learn more ... +@section main-threads Threading + +cmocka is not thread safe and it is not the goal of it to be it. However if +you use cmocka for writing tests in an application which uses threads, you +can set the following envionment variable: + +
+    CMOCKA_TEST_ABORT='1' ./my_threading_test
+
+ +With this environment variable set to '1', cmocka will call abort() if +a test fails. Else it is likely that you will run into deadlocks with mutexes +or other funny errors. + */ diff --git a/src/cmocka.c b/src/cmocka.c index 78bd5d9..19147f6 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -297,8 +297,13 @@ static const ExceptionCodeInfo exception_codes[] = { /* Exit the currently executing test. */ -static void exit_test(const int quit_application) { - if (global_running_test) { +static void exit_test(const int quit_application) +{ + const char *abort_test = getenv("CMOCKA_TEST_ABORT"); + + if (abort_test != NULL && abort_test[0] == '1') { + abort(); + } else if (global_running_test) { longjmp(global_run_test_env, 1); } else if (quit_application) { exit(-1); -- 2.34.1