summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-01-15 23:29:00 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-21 17:49:23 +0000
commited57bea6f742b57d0314feafa7d4ecce24ab8480 (patch)
tree6bc5c2877b935b1cd7d2091d5df43a04b198ea5e /test
parent542725baca37eaf62be58af9da4a447bd4ba0236 (diff)
downloadchrome-ec-ed57bea6f742b57d0314feafa7d4ecce24ab8480.tar.gz
common:test: refactor test_util.h to accommodate Zephyr
This change refactors test functionality in test_util.h to better accomomdate zTests. This is done by: * Removing the shim version of test_util.h. This was causing a conflict that made it harder to tell what's being used. This involved migrating some needed code over: - Defining different TASK_PARAMS. - Defining test_pass for Zephyr tests. * Creating a macro (DECLARE_EC_TEST) that will automatically handle creating the individual test functions for both platform and Zephyr tests. * Creating a macro (TEST_MAIN) that will automatically handle creating the main test entry function. This use to be test_main(void) for Zephyr and run_test(int, char**) for platform/ec. To do this we'll be removing the int, char** arguments from platform/ec. This may result in some tests having to be refactored, but overall should improve the test codebase as tests should remain deterministic (i.e. not depend on any outside arguments/parameters). * Creating some common ztest_ function/macros that will allow writing platform/ec tests in a zephyr like style. see test/base32.c for an example. * Update the type of __shared_mem_buf to match Zephyr. This was causing an issue now with the full test_util.h in zephyr/test/system/. BRANCH=none BUG=b:168032590 TEST=make runhosttests TEST=zmake configure --test -B build/host/base32 zephyr/test/base32 Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I72173a3e94c7df09a2966e7ffeb9f5668d030f29 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2634401 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/base32.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/test/base32.c b/test/base32.c
index 54c5e15abc..faaefc266f 100644
--- a/test/base32.c
+++ b/test/base32.c
@@ -11,7 +11,7 @@
#include "test_util.h"
#include "util.h"
-static EC_TEST_RETURN test_crc5(void)
+DECLARE_EC_TEST(test_crc5)
{
uint32_t seen;
int i, j, c;
@@ -71,7 +71,7 @@ static int enctest(const void *src, int srcbits, int crc_every,
#define ENCTEST(a, b, c, d) zassert_equal(enctest(a, b, c, d), 0, NULL)
-static EC_TEST_RETURN test_encode(void)
+DECLARE_EC_TEST(test_encode)
{
const uint8_t src1[5] = {0xff, 0x00, 0xff, 0x00, 0xff};
char enc[32];
@@ -148,7 +148,7 @@ static int dectest(const void *dec, int decbits, int crc_every, const char *enc)
#define DECTEST(a, b, c, d) zassert_equal(dectest(a, b, c, d), 0, NULL)
-static EC_TEST_RETURN test_decode(void)
+DECLARE_EC_TEST(test_decode)
{
uint8_t dec[32];
@@ -199,13 +199,7 @@ static EC_TEST_RETURN test_decode(void)
return EC_SUCCESS;
}
-/*
- * Define the test cases to run. We need to do this twice, once in the format
- * that Ztest uses, and again in the format the the EC test framework uses.
- * If you add a test to one of them, make sure to add it to the other.
- */
-#ifdef CONFIG_ZEPHYR
-void test_main(void)
+TEST_MAIN()
{
ztest_test_suite(test_base32_lib,
ztest_unit_test(test_crc5),
@@ -213,15 +207,3 @@ void test_main(void)
ztest_unit_test(test_decode));
ztest_run_test_suite(test_base32_lib);
}
-#else
-void run_test(int argc, char **argv)
-{
- test_reset();
-
- RUN_TEST(test_crc5);
- RUN_TEST(test_encode);
- RUN_TEST(test_decode);
-
- test_print_result();
-}
-#endif /* CONFIG_ZEPHYR */