diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-04-15 16:58:25 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-04-15 17:01:12 +0200 |
commit | 4bf87f329493cdbb8acef403be2a26a325da97cc (patch) | |
tree | 6ce2d56b3ae95442f9405e7c5385f8dfe3be4fa1 | |
parent | 3488c7fe316c9cae6c6f2891e5df4ee151401a52 (diff) | |
download | cmocka-4bf87f329493cdbb8acef403be2a26a325da97cc.tar.gz cmocka-4bf87f329493cdbb8acef403be2a26a325da97cc.tar.xz cmocka-4bf87f329493cdbb8acef403be2a26a325da97cc.zip |
cmocka: Add CMOCKA_TEST_ABORT env variable to leave threading apps.
BUG: https://open.cryptomilk.org/issues/26
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
-rw-r--r-- | doc/mainpage.dox | 14 | ||||
-rw-r--r-- | 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. <a href="https://lwn.net/Articles/558106/">Learn more ...</a> +@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: + +<pre> + CMOCKA_TEST_ABORT='1' ./my_threading_test +</pre> + +With this environment variable set to '1', cmocka will call <tt>abort()</tt> 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); |