summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-12-23 16:06:04 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-12-23 16:09:30 +0100
commitc154b2166173446df59b864ca997ba5ad6fd6c8e (patch)
tree2347723eeefdea4d78ad20609fe14d8e9678e436 /tests
parentb2a9d09d757d43aec620bc6a611c4ab810258891 (diff)
downloadcmocka-c154b2166173446df59b864ca997ba5ad6fd6c8e.tar.gz
cmocka-c154b2166173446df59b864ca997ba5ad6fd6c8e.tar.bz2
cmocka-c154b2166173446df59b864ca997ba5ad6fd6c8e.zip
tests: Add test_exception_handler_fail.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt11
-rw-r--r--tests/test_exception_handler.c28
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0e258b4..d2976f3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,7 +8,8 @@ include_directories(
set(CMOCKA_TESTS
test_assert_macros
- test_assert_macros_fail)
+ test_assert_macros_fail
+ test_exception_handler)
foreach(_CMOCKA_TEST ${CMOCKA_TESTS})
add_cmocka_test(${_CMOCKA_TEST} ${_CMOCKA_TEST}.c ${CMOCKA_SHARED_LIBRARY})
@@ -23,3 +24,11 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 1 test"
)
+
+# test_exception_handler
+set_tests_properties(
+ test_exception_handler
+ PROPERTIES
+ PASS_REGULAR_EXPRESSION
+ "Test failed with exception: (Segmentation fault|Segmentation Fault|11)"
+)
diff --git a/tests/test_exception_handler.c b/tests/test_exception_handler.c
new file mode 100644
index 0000000..5727d1e
--- /dev/null
+++ b/tests/test_exception_handler.c
@@ -0,0 +1,28 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdlib.h>
+
+struct test_segv {
+ int x;
+ int y;
+};
+
+static void test_segfault_recovery(void **state)
+{
+ struct test_segv *s = NULL;
+
+ (void) state; /* unused */
+
+ s->x = 1;
+}
+
+int main(void) {
+ const UnitTest tests[] = {
+ unit_test(test_segfault_recovery),
+ };
+
+ return run_tests(tests);
+}