diff options
author | Paul Fagerburg <pfagerburg@google.com> | 2021-01-22 09:52:45 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-22 20:19:57 +0000 |
commit | 147e95ad2452b0637481b4418209115269762a94 (patch) | |
tree | 65716087428dcf33bbc22b2bc79890ccaef379c6 /include/test_util.h | |
parent | 2e2a2bef93c14d927b26b9e4877344ba28d07499 (diff) | |
download | chrome-ec-147e95ad2452b0637481b4418209115269762a94.tar.gz |
zephyr: test_util: improve EC compatibility
When building a unit test that compiles for either EC or Ztest, the
TEST_MAIN macro should call test_reset and test_print_results as
part of running the tests. This allows the test code to omit the
functions (which are not defined when building for Ztest).
Also add the format parameter so that when testing for floating-point
values being near (zassert_within or TEST_NEAR) we can specify the
format for the EC assertion to print the result.
BUG=b:172240633
BRANCH=None
TEST=`make runhosttests` and `zmake testall`
Signed-off-by: Paul Fagerburg <pfagerburg@google.com>
Change-Id: I23dc933ed4ba0f386fcae68d257161ffffe226eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2645197
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'include/test_util.h')
-rw-r--r-- | include/test_util.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/test_util.h b/include/test_util.h index 4cc150bb67..ff2c99d950 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -373,7 +373,9 @@ int test_attach_i2c(const int port, const uint16_t addr_flags); void test_main(void); \ void run_test(int argc, char **argv) \ { \ + test_reset(); \ test_main(); \ + test_print_result(); \ } \ void test_main(void) #endif @@ -484,7 +486,7 @@ void z_ztest_run_test_suite(const char *name, struct unit_test *suite); #define zassert_not_equal(a, b, msg, ...) TEST_NE((a), (b), "0x%x") #define zassert_equal_ptr(a, b, msg, ...) \ TEST_EQ((void *)(a), (void *)(b), "0x%x") -#define zassert_within(a, b, d, msg, ...) TEST_NEAR((a), (b), (d), "0x%x") +#define zassert_within(a, b, d, msg, ...) TEST_NEAR((a), (b), (d), msg) #define zassert_mem_equal(buf, exp, size, msg, ...) \ TEST_ASSERT_ARRAY_EQ(buf, exp, size) #endif /* CONFIG_ZEPHYR */ |