diff options
author | Yuval Peress <peress@google.com> | 2022-08-29 13:43:18 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-31 18:05:08 +0000 |
commit | f7a5bd15d01331e477d9409bab970d0248f861fc (patch) | |
tree | 01cdc391abef027d1015126a2299ec083a943989 | |
parent | 887a3f6c0e556bfb8308cf124edf087e53635ea8 (diff) | |
download | chrome-ec-f7a5bd15d01331e477d9409bab970d0248f861fc.tar.gz |
test: add tests for crash console command
Adds basic tests for the crash console command involving ASSERT()
crashes. This change enables the ASSERT_TEST config and creates a
new assert handler using FFF. We then can use that mock to verify
that the assert was called.
BRANCH=none
BUG=b:236074360
TEST=twister -s zephyr/test/drivers/drivers.default
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: I59c24bc4ed4ef81dde5cce16ac0ae4ef96f124cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863125
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | zephyr/test/drivers/common/include/test/drivers/test_mocks.h | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/test_mocks.c | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/default/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/default/src/console_cmd/crash.c | 34 | ||||
-rw-r--r-- | zephyr/test/drivers/prj.conf | 1 |
5 files changed, 39 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h index 7fd794dcaa..f77eb6fc10 100644 --- a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h +++ b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h @@ -107,3 +107,4 @@ DECLARE_FAKE_VALUE_FUNC(int, init_rom_copy, int, int, int); DECLARE_FAKE_VALUE_FUNC(int, system_jumped_late); DECLARE_FAKE_VOID_FUNC(system_reset, int); DECLARE_FAKE_VOID_FUNC(software_panic, uint32_t, uint32_t); +DECLARE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int); diff --git a/zephyr/test/drivers/common/src/test_mocks.c b/zephyr/test/drivers/common/src/test_mocks.c index fbc920d8f1..6c8db5c27a 100644 --- a/zephyr/test/drivers/common/src/test_mocks.c +++ b/zephyr/test/drivers/common/src/test_mocks.c @@ -18,6 +18,7 @@ DEFINE_FAKE_VALUE_FUNC(int, init_rom_copy, int, int, int); DEFINE_FAKE_VALUE_FUNC(int, system_jumped_late); DEFINE_FAKE_VOID_FUNC(system_reset, int); DEFINE_FAKE_VOID_FUNC(software_panic, uint32_t, uint32_t); +DEFINE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int); /** * @brief Reset all the fakes before each test. @@ -34,6 +35,7 @@ static void fff_reset_rule_before(const struct ztest_unit_test *test, RESET_FAKE(system_jumped_late); RESET_FAKE(system_reset); RESET_FAKE(software_panic); + RESET_FAKE(assert_post_action); } ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt index 53c5c9b376..5e5cd31c95 100644 --- a/zephyr/test/drivers/default/CMakeLists.txt +++ b/zephyr/test/drivers/default/CMakeLists.txt @@ -20,6 +20,7 @@ target_sources(app PRIVATE src/console_cmd/accelrange.c src/console_cmd/accelread.c src/console_cmd/accelres.c + src/console_cmd/crash.c src/console_cmd/cutoff.c src/console_cmd/gpio.c src/console_cmd/i2c_portmap.c diff --git a/zephyr/test/drivers/default/src/console_cmd/crash.c b/zephyr/test/drivers/default/src/console_cmd/crash.c new file mode 100644 index 0000000000..9c65c25ddb --- /dev/null +++ b/zephyr/test/drivers/default/src/console_cmd/crash.c @@ -0,0 +1,34 @@ +/* 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/shell/shell.h> +#include <zephyr/ztest.h> + +#include "builtin/assert.h" +#include "console.h" +#include "test/drivers/test_mocks.h" +#include "test/drivers/test_state.h" + +ZTEST_SUITE(console_cmd_crash, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); + +ZTEST_USER(console_cmd_crash, test_wrong_num_args) +{ + int rv = shell_execute_cmd(get_ec_shell(), "crash"); + + zassert_equal(EC_ERROR_PARAM1, rv, "Expected %d, but got %d", + EC_ERROR_PARAM1, rv); +} + +ZTEST_USER(console_cmd_crash, test_assert) +{ + int rv; + + RESET_FAKE(assert_post_action); + rv = shell_execute_cmd(get_ec_shell(), "crash assert"); + + zassert_equal(EC_ERROR_UNKNOWN, rv, NULL); + zassert_equal(1, assert_post_action_fake.call_count, NULL); +} diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index 4ba842b933..308a42027d 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -13,6 +13,7 @@ CONFIG_ZTEST_NEW_API=y CONFIG_ZTEST_PARAMETER_COUNT=24 CONFIG_TEST=y CONFIG_ASSERT=y +CONFIG_ASSERT_TEST=y CONFIG_SHELL_VT100_COMMANDS=n # Print logs from Zephyr LOG_MODULE to stdout |