cmocka: Add CMOCKA_TEST_ABORT env variable to leave threading apps.
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 15 Apr 2014 14:58:25 +0000 (16:58 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 15 Apr 2014 15:01:12 +0000 (17:01 +0200)
BUG: https://open.cryptomilk.org/issues/26

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
doc/mainpage.dox
src/cmocka.c

index 4b7acb02ad946b5ed86feecc80b726c317ec6544..d159bf0d90c617ccc6bc69ecc360b42dfda7d0da 100644 (file)
@@ -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.
+
 */
index 78bd5d9fd71eb29b26bec4ff6888761595529a81..19147f67d36aa852dbac67401133b53dd2db907c 100644 (file)
@@ -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);