summaryrefslogtreecommitdiff
path: root/tests/test_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_common.c')
-rw-r--r--tests/test_common.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_common.c b/tests/test_common.c
index ddd81052..02cbc165 100644
--- a/tests/test_common.c
+++ b/tests/test_common.c
@@ -9,10 +9,13 @@
#include <stdio.h>
#include <string.h>
+#include "2common.h"
#include "test_common.h"
/* Global test success flag. */
int gTestSuccess = 1;
+int gTestAbortArmed = 0;
+jmp_buf gTestJmpEnv;
int test_eq(int result, int expected,
const char *preamble, const char *desc, const char *comment)
@@ -173,3 +176,33 @@ int test_false(int result,
}
return !result;
}
+
+int test_abort(int aborted,
+ const char *preamble, const char *desc, const char *comment)
+{
+ if (aborted) {
+ fprintf(stderr, "%s: %s ... " COL_GREEN "PASSED\n" COL_STOP,
+ preamble, comment ? comment : desc);
+ } else {
+ fprintf(stderr, "%s: %s ... " COL_RED "FAILED\n" COL_STOP,
+ preamble, comment ? comment : desc);
+ fprintf(stderr, " Expected ABORT, but did not get it\n");
+ gTestSuccess = 0;
+ }
+ return aborted;
+}
+
+void vb2ex_abort(void)
+{
+ /*
+ * If expecting an abort call, jump back to TEST_ABORT macro.
+ * Otherwise, force exit to ensure the test fails.
+ */
+ if (gTestAbortArmed) {
+ longjmp(gTestJmpEnv, 1);
+ } else {
+ fprintf(stderr, COL_RED "Unexpected ABORT encountered, "
+ "exiting\n" COL_STOP);
+ exit(1);
+ }
+}