diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-09-22 14:59:17 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-23 19:21:34 +0000 |
commit | 9bfa3fbf1065c8a65acf3e33e28d6e61063d0de5 (patch) | |
tree | eae34e5c49808c6178b677c3ea480ccf49498359 | |
parent | f92ae98b517b89fa3755ea0d6eef91eb2398bd57 (diff) | |
download | chrome-ec-9bfa3fbf1065c8a65acf3e33e28d6e61063d0de5.tar.gz |
test: CBI version enabled system_get_board_version
Verify system_get_board_version() returns appropriate values when CBI
board version is enabled. Also splits out the default test for board
version when CBI board version is not enabled.
BRANCH=none
BUG=b:248106876
TEST=./twister --clobber -i -s zephyr/test/drivers/drivers.system
TEST=./twister --clobber -i -s
zephyr/test/drivers/drivers.system_board_version_cbi
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I7544d67e8d2a8435fb256f90aa26958cff357805
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3914182
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
-rw-r--r-- | common/cbi.c | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/system/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/system/src/system.c | 14 | ||||
-rw-r--r-- | zephyr/test/drivers/system/src/system_board_version_cbi.c | 41 | ||||
-rw-r--r-- | zephyr/test/drivers/system/src/system_board_version_default.c | 23 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 5 |
6 files changed, 76 insertions, 15 deletions
diff --git a/common/cbi.c b/common/cbi.c index 2024f05a68..2956621367 100644 --- a/common/cbi.c +++ b/common/cbi.c @@ -254,7 +254,7 @@ int cbi_write(void) return cbi_config.drv->store(cbi); } -int cbi_get_board_version(uint32_t *ver) +test_mockable int cbi_get_board_version(uint32_t *ver) { uint8_t size = sizeof(*ver); diff --git a/zephyr/test/drivers/system/CMakeLists.txt b/zephyr/test/drivers/system/CMakeLists.txt index e41696bca3..c6fc144eae 100644 --- a/zephyr/test/drivers/system/CMakeLists.txt +++ b/zephyr/test/drivers/system/CMakeLists.txt @@ -5,5 +5,11 @@ # Add source files target_sources(app PRIVATE src/system.c) +target_sources_ifdef(CONFIG_PLATFORM_EC_BOARD_VERSION_CBI app PRIVATE +src/system_board_version_cbi.c) + +target_sources_ifndef(CONFIG_PLATFORM_EC_BOARD_VERSION_CBI app PRIVATE +src/system_board_version_default.c) + target_sources_ifndef(CONFIG_HOST_CMD_AP_SET_SKUID app PRIVATE src/system_not_board_ap_set_sku_id.c) diff --git a/zephyr/test/drivers/system/src/system.c b/zephyr/test/drivers/system/src/system.c index f0db0be170..6c8bebf7be 100644 --- a/zephyr/test/drivers/system/src/system.c +++ b/zephyr/test/drivers/system/src/system.c @@ -30,20 +30,6 @@ ZTEST_USER(system, test_hostcmd_sysinfo) zassert_equal(response.flags, 0, "response.flags = %d", response.flags); } -ZTEST_USER(system, test_hostcmd_board_version) -{ - struct ec_response_board_version response; - struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE( - EC_CMD_GET_BOARD_VERSION, 0, response); - - /* Get the board version, which is default 0. */ - zassert_ok(host_command_process(&args), NULL); - zassert_ok(args.result, NULL); - zassert_equal(args.response_size, sizeof(response), NULL); - zassert_equal(response.board_version, 0, "response.board_version = %d", - response.board_version); -} - /* System Function Testing */ static void system_before_after(void *data) diff --git a/zephyr/test/drivers/system/src/system_board_version_cbi.c b/zephyr/test/drivers/system/src/system_board_version_cbi.c new file mode 100644 index 0000000000..d076716e23 --- /dev/null +++ b/zephyr/test/drivers/system/src/system_board_version_cbi.c @@ -0,0 +1,41 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> + +#include "ec_commands.h" +#include "host_command.h" +#include "system.h" +#include "test/drivers/test_state.h" +#include "test/drivers/test_mocks.h" + +FAKE_VALUE_FUNC(int, cbi_get_board_version, uint32_t *); + +#define ARBITRARY_VERSION 0x1234 + +static int system_test_cbi_get_board_version(uint32_t *ver) +{ + *ver = ARBITRARY_VERSION; + + return 0; +} + +ZTEST(system, test_system_get_board_version) +{ + RESET_FAKE(cbi_get_board_version); + cbi_get_board_version_fake.custom_fake = + system_test_cbi_get_board_version; + + zassert_equal(system_get_board_version(), ARBITRARY_VERSION); +} + +ZTEST(system, test_system_get_board_version__bad_cbi_read) +{ + RESET_FAKE(cbi_get_board_version); + cbi_get_board_version_fake.return_val = EC_ERROR_BUSY; + + zassert_equal(system_get_board_version(), -EC_ERROR_BUSY); +} diff --git a/zephyr/test/drivers/system/src/system_board_version_default.c b/zephyr/test/drivers/system/src/system_board_version_default.c new file mode 100644 index 0000000000..bcd28cc3de --- /dev/null +++ b/zephyr/test/drivers/system/src/system_board_version_default.c @@ -0,0 +1,23 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/ztest.h> + +#include "ec_commands.h" +#include "host_command.h" + +ZTEST_USER(system, test_hostcmd_board_version) +{ + struct ec_response_board_version response; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE( + EC_CMD_GET_BOARD_VERSION, 0, response); + + /* Get the board version, which is default 0. */ + zassert_ok(host_command_process(&args), NULL); + zassert_ok(args.result, NULL); + zassert_equal(args.response_size, sizeof(response), NULL); + zassert_equal(response.board_version, 0, "response.board_version = %d", + response.board_version); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index d457d92ca5..b06d40acba 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -68,6 +68,11 @@ tests: drivers.system: extra_configs: - CONFIG_LINK_TEST_SUITE_SYSTEM=y + drivers.system_board_version_cbi: + extra_configs: + - CONFIG_LINK_TEST_SUITE_SYSTEM=y + - CONFIG_PLATFORM_EC_BOARD_VERSION_CBI=y + - CONFIG_POWER_SEQUENCE_MOCK=y drivers.usb_port_power_dumb: extra_args: DTC_OVERLAY_FILE="./boards/native_posix.overlay;./usb_port_power_dumb/usba.dts" extra_configs: |