diff options
author | Joel Kitching <kitching@google.com> | 2019-09-11 14:15:45 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-23 05:18:07 +0000 |
commit | aaf394335cc4e287a1ffb6332311559b2b29c41f (patch) | |
tree | 3d552e3e22f530ba564654b6979a4009fbd53d68 /tests/test_common.c | |
parent | d3efd73cbb1fb5cf133739622fe0bd49653fad2e (diff) | |
download | vboot-aaf394335cc4e287a1ffb6332311559b2b29c41f.tar.gz |
vboot: add VB2_ASSERT and VB2_DIE macros
Sometimes vboot needs to make assertions to work sanely without
always having to return VB2_ERROR_* values. Add VB2_ASSERT and
VB2_DIE macros to deal with these cases.
Convert existing VbAssert macro to use either VB2_ASSERT or
TEST_* macros depending on the case.
Implement testing infrastructure to check that aborts are being
triggered correctly. The TEST_ASSERT macro should be used.
BUG=b:124141368, chromium:1005700
TEST=make clean && make runtests
BRANCH=none
Change-Id: I298384ba50842a94a311df7f868f807bf2109cff
Signed-off-by: Joel Kitching <kitching@google.com>
Cq-Depend: chromium:1813277
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1800112
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'tests/test_common.c')
-rw-r--r-- | tests/test_common.c | 33 |
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); + } +} |