summaryrefslogtreecommitdiff
path: root/tests/test_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_common.h')
-rw-r--r--tests/test_common.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_common.h b/tests/test_common.h
index 8d98f5cc..17689b71 100644
--- a/tests/test_common.h
+++ b/tests/test_common.h
@@ -6,6 +6,7 @@
#ifndef VBOOT_REFERENCE_TEST_COMMON_H_
#define VBOOT_REFERENCE_TEST_COMMON_H_
+#include <setjmp.h>
#include <stdio.h>
/* Used to get a line number as a constant string. Need to stringify it twice */
@@ -13,6 +14,8 @@
#define TOSTRING(x) STRINGIFY(x)
extern int gTestSuccess;
+extern int gTestAbortArmed;
+extern jmp_buf gTestJmpEnv;
/* Return 1 if result is equal to expected_result, else return 0.
* Also update the global gTestSuccess flag if test fails. */
@@ -117,6 +120,23 @@ int test_succ(int result,
#result " == 0", \
comment)
+/* Return 1 if vb2ex_abort() was called, else return 0.
+ * Also update the global gTestSuccess flag if test fails. */
+int test_abort(int aborted,
+ const char *preamble, const char *desc, const char *comment);
+
+#define TEST_ABORT(call, comment) do { \
+ gTestAbortArmed = 1; \
+ int jumped = setjmp(gTestJmpEnv); \
+ if (!jumped) \
+ call; \
+ gTestAbortArmed = 0; \
+ test_abort(jumped, \
+ __FILE__ ":" TOSTRING(__LINE__), \
+ #call " causes abort", \
+ comment); \
+} while (0)
+
/* ANSI Color coding sequences.
*
* Don't use \e as MSC does not recognize it as a valid escape sequence.