From 7f0fb635ecbe66cd88b3fb4b0b6f3634b90950d4 Mon Sep 17 00:00:00 2001 From: Meng xianglin Date: Fri, 1 Jul 2022 13:42:20 +0800 Subject: [PATCH] tests: bbram: move to new ztest API test case in bbram dosen't use ztest framework, but test cases in emul in bbram use it. Signed-off-by: Meng xianglin --- tests/drivers/bbram/emul/prj.conf | 1 + tests/drivers/bbram/emul/src/main.c | 35 +++++++++-------------------- tests/drivers/bbram/it8xxx2.conf | 1 + tests/drivers/bbram/npcx.conf | 1 + 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/drivers/bbram/emul/prj.conf b/tests/drivers/bbram/emul/prj.conf index a05c395f55d..22cd7f65d56 100644 --- a/tests/drivers/bbram/emul/prj.conf +++ b/tests/drivers/bbram/emul/prj.conf @@ -2,5 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_BBRAM=y CONFIG_BBRAM_EMUL=y diff --git a/tests/drivers/bbram/emul/src/main.c b/tests/drivers/bbram/emul/src/main.c index 4d0d6c69bf3..ac2d942df88 100644 --- a/tests/drivers/bbram/emul/src/main.c +++ b/tests/drivers/bbram/emul/src/main.c @@ -11,7 +11,7 @@ #define BBRAM_NODELABEL DT_NODELABEL(bbram) #define BBRAM_SIZE DT_PROP(BBRAM_NODELABEL, size) -static void test_get_size(void) +ZTEST(bbram, test_get_size) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); size_t size; @@ -22,7 +22,7 @@ static void test_get_size(void) zassert_equal(size, BBRAM_SIZE, NULL); } -static void test_bbram_out_of_bounds(void) +ZTEST(bbram, test_bbram_out_of_bounds) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); uint8_t buffer[BBRAM_SIZE]; @@ -35,7 +35,7 @@ static void test_bbram_out_of_bounds(void) zassert_equal(bbram_write(dev, BBRAM_SIZE - 1, 2, buffer), -EFAULT, NULL); } -static void test_read_write(void) +ZTEST(bbram, test_read_write) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); uint8_t buffer[BBRAM_SIZE]; @@ -50,7 +50,7 @@ static void test_read_write(void) zassert_mem_equal(buffer, expected, BBRAM_SIZE, NULL); } -static void test_set_invalid(void) +ZTEST(bbram, test_set_invalid) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); @@ -60,7 +60,7 @@ static void test_set_invalid(void) zassert_equal(bbram_check_invalid(dev), 0, NULL); } -static void test_set_standby(void) +ZTEST(bbram, test_set_standby) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); @@ -70,7 +70,7 @@ static void test_set_standby(void) zassert_equal(bbram_check_standby_power(dev), 0, NULL); } -static void test_set_power(void) +ZTEST(bbram, test_set_power) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); @@ -80,7 +80,7 @@ static void test_set_power(void) zassert_equal(bbram_check_power(dev), 0, NULL); } -static void test_reset_invalid_on_read(void) +ZTEST(bbram, test_reset_invalid_on_read) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); uint8_t buffer[BBRAM_SIZE]; @@ -90,7 +90,7 @@ static void test_reset_invalid_on_read(void) zassert_equal(bbram_check_invalid(dev), 0, NULL); } -static void test_reset_invalid_on_write(void) +ZTEST(bbram, test_reset_invalid_on_write) { const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); uint8_t buffer[BBRAM_SIZE]; @@ -100,26 +100,13 @@ static void test_reset_invalid_on_write(void) zassert_equal(bbram_check_invalid(dev), 0, NULL); } -static void setup(void) +static void before(void *data) { + ARG_UNUSED(data); const struct device *dev = DEVICE_DT_GET(BBRAM_NODELABEL); bbram_emul_set_invalid(dev, false); bbram_emul_set_standby_power_state(dev, false); bbram_emul_set_power_state(dev, false); } - -void test_main(void) -{ - ztest_test_suite( - bbram, - ztest_unit_test_setup_teardown(test_get_size, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_bbram_out_of_bounds, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_read_write, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_set_invalid, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_set_standby, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_set_power, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_reset_invalid_on_read, setup, unit_test_noop), - ztest_unit_test_setup_teardown(test_reset_invalid_on_write, setup, unit_test_noop)); - ztest_run_test_suite(bbram); -} +ZTEST_SUITE(bbram, NULL, NULL, before, NULL, NULL); diff --git a/tests/drivers/bbram/it8xxx2.conf b/tests/drivers/bbram/it8xxx2.conf index 7f0aa04e9a1..4d8276131ef 100644 --- a/tests/drivers/bbram/it8xxx2.conf +++ b/tests/drivers/bbram/it8xxx2.conf @@ -2,5 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_BBRAM=y CONFIG_BBRAM_IT8XXX2=y diff --git a/tests/drivers/bbram/npcx.conf b/tests/drivers/bbram/npcx.conf index 7af01707b0f..23f253b73a3 100644 --- a/tests/drivers/bbram/npcx.conf +++ b/tests/drivers/bbram/npcx.conf @@ -2,5 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_BBRAM=y CONFIG_BBRAM_NPCX=y