diff options
author | edisonhello <edisonhello@google.com> | 2021-07-29 20:50:12 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-04 02:51:16 +0000 |
commit | 3a1870160e12ccb0250fa2b56b2867aa9c02cfe8 (patch) | |
tree | 1d785006fef6b571948e6662d3f1323b45008f72 /tests | |
parent | c267a6908dcbffa8d683c25fc1ba87edf373acca (diff) | |
download | vboot-3a1870160e12ccb0250fa2b56b2867aa9c02cfe8.tar.gz |
vboot/tests: Add test_fail function and TEST_FAIL macro
Add test_fail function that will check whether the result value is
not 0.
Add TEST_FAIL macro that will call test_fail.
BUG=none
TEST=export CC=x86_64-pc-linux-gnu-clang DEBUG=1; \
make -j32 test_setup && make -j32 runtests;
BRANCH=none
Change-Id: I4dfe6a887780f70fbcb753828cfb5500ed810b72
Signed-off-by: edisonhello <edisonhello@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3060562
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_common.c | 14 | ||||
-rw-r--r-- | tests/test_common.h | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_common.c b/tests/test_common.c index 7e994f36..2ce3a5da 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -147,6 +147,20 @@ int test_succ(int result, return !result; } +int test_fail(int result, + const char *preamble, const char *desc, const char *comment) +{ + if (result != 0) { + print_passed(preamble, desc, comment); + } else { + print_failed(preamble, desc, comment); + fprintf(stderr, + " Didn't expect SUCCESS (0), but got it\n"); + gTestSuccess = 0; + } + return result; +} + int test_true(int result, const char *preamble, const char *desc, const char *comment) { diff --git a/tests/test_common.h b/tests/test_common.h index e0d8ef3b..c3da8805 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -120,6 +120,17 @@ int test_succ(int result, #result " == 0", \ comment) +/* Return 1 if result is not 0 (VB2_SUCCESS or other), else return 1. + * Also update the global gTestSuccess flag if test fails. */ +int test_fail(int result, + const char *preamble, const char *desc, const char *comment); + +#define TEST_FAIL(result, comment) \ + test_fail(result, \ + __FILE__ ":" TOSTRING(__LINE__), \ + #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, |