diff --git a/Makefile.am b/Makefile.am
index bcc7f94..1bffb46 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,6 +25,7 @@ EXTRA_DIST = config.rpath LICENSE
subdirincludedir = $(includedir)/criterion/
subdirinclude_HEADERS = \
include/criterion/assert.h \
+ include/criterion/abort.h \
include/criterion/common.h \
include/criterion/criterion.h \
include/criterion/event.h \
@@ -36,6 +37,8 @@ subdirinclude_HEADERS = \
include/criterion/stats.h
libcriterion_la_SOURCES = \
+ src/abort.c \
+ src/abort.h \
src/event.c \
src/event.h \
src/report.c \
diff --git a/include/criterion/abort.h b/include/criterion/abort.h
new file mode 100644
index 0000000..f20e300
--- /dev/null
+++ b/include/criterion/abort.h
@@ -0,0 +1,31 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright © 2015 Franklin "Snaipe" Mathieu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef CRITERION_ABORT_H_
+# define CRITERION_ABORT_H_
+
+# include "common.h"
+
+NORETURN void criterion_abort_test(void);
+
+#endif /* !CRITERION_ABORT_H_ */
diff --git a/include/criterion/assert.h b/include/criterion/assert.h
index f17de27..7f37705 100644
--- a/include/criterion/assert.h
+++ b/include/criterion/assert.h
@@ -31,6 +31,7 @@
# include "stats.h"
# include "hooks.h"
# include "event.h"
+# include "abort.h"
enum criterion_assert_kind {
NORMAL,
@@ -60,7 +61,7 @@ struct criterion_assert_args {
}; \
send_event(ASSERT, &stat, sizeof (stat)); \
if (!passed && (Kind) == FATAL) \
- return; \
+ criterion_abort_test(); \
} while (0)
// Common asserts
diff --git a/include/criterion/common.h b/include/criterion/common.h
index 342e6db..e5ebfd2 100644
--- a/include/criterion/common.h
+++ b/include/criterion/common.h
@@ -56,6 +56,7 @@
Type *const SECTION_END(Name) = &SECTION_END_(Name)
# define UNUSED __attribute__((unused))
+# define NORETURN __attribute__((noreturn))
# ifdef _WIN32
# define SIZE_T_FORMAT "%Iu"
diff --git a/src/abort.c b/src/abort.c
new file mode 100644
index 0000000..ea61bb9
--- /dev/null
+++ b/src/abort.c
@@ -0,0 +1,35 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright © 2015 Franklin "Snaipe" Mathieu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include
+#include "abort.h"
+
+static jmp_buf g_pre_test;
+
+int setup_abort_test(void) {
+ return !setjmp(g_pre_test);
+}
+
+void criterion_abort_test(void) {
+ longjmp(g_pre_test, 1);
+}
diff --git a/src/abort.h b/src/abort.h
new file mode 100644
index 0000000..4d85ba3
--- /dev/null
+++ b/src/abort.h
@@ -0,0 +1,31 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright © 2015 Franklin "Snaipe" Mathieu
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef ABORT_H_
+# define ABORT_H_
+
+# include
+
+int setup_abort_test(void);
+
+#endif /* !ABORT_H_ */
diff --git a/src/runner.c b/src/runner.c
index 4da3b28..b19ea48 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -34,6 +34,7 @@
#include "process.h"
#include "timer.h"
#include "posix-compat.h"
+#include "abort.h"
IMPL_SECTION_LIMITS(struct criterion_test, criterion_tests);
IMPL_SECTION_LIMITS(struct criterion_suite, crit_suites);
@@ -139,8 +140,11 @@ static void run_test_child(struct criterion_test *test,
send_event(PRE_TEST, NULL, 0);
struct timespec_compat ts;
- timer_start(&ts);
- (test->test ?: nothing)();
+ if (setup_abort_test()) {
+ timer_start(&ts);
+ (test->test ?: nothing)();
+ }
+
double elapsed_time;
if (!timer_end(&elapsed_time, &ts))
elapsed_time = -1;