diff options
author | Tristan Honscheid <honscheid@google.com> | 2022-11-21 10:48:11 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-30 23:10:44 +0000 |
commit | b6e76ee80d897db61684668978450207a7184367 (patch) | |
tree | 8d6132c5e6c2660b8c2025cca8c9663c68454e44 | |
parent | aa40b859b3a73e5a205bc561c1a29eff38485461 (diff) | |
download | chrome-ec-b6e76ee80d897db61684668978450207a7184367.tar.gz |
zephyr: test: Make get_panic_data_write mockable
The version of get_panic_data_write() that currently gets compiled in is
controlled by an `#ifdef CONFIG_BOARD_NATIVE_POSIX` block, which means
that the actual implementation used in device builds (over 30 SLOCs) is
unreachable in testing, in favor of a stub that directly returns the
pdata_ptr pointer.
This CL removes the stub native posix version of the function and makes the
real version test_mockable. Then, all test binaries that were relying on
the removed stub definition are supplied with a mocked version of
get_panic_data_write() that behaves the same way the stub did by
returning pdata_ptr directly. This frees a new test binary to test the
actual implementation.
BRANCH=None
BUG=None
TEST=./twister
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: I8228acb0147b3b3843d302c272d8715d925fddd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4052121
Commit-Queue: Aaron Massey <aaronmassey@google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: Tristan Honscheid <honscheid@google.com>
Auto-Submit: Tristan Honscheid <honscheid@google.com>
-rw-r--r-- | common/panic_output.c | 10 | ||||
-rw-r--r-- | include/panic.h | 9 | ||||
-rw-r--r-- | zephyr/test/drivers/default/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/host_cmd/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/mock_panic_output/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/mock_panic_output/src/test_get_panic_data_write.c | 18 |
6 files changed, 47 insertions, 6 deletions
diff --git a/common/panic_output.c b/common/panic_output.c index 55d551f548..fd163b21f5 100644 --- a/common/panic_output.c +++ b/common/panic_output.c @@ -196,13 +196,13 @@ static uint32_t get_panic_data_size(void) * should be used when we are sure that we don't need it. */ #ifdef CONFIG_BOARD_NATIVE_POSIX -struct panic_data *get_panic_data_write(void) +struct panic_data *test_get_panic_data_pointer(void) { return pdata_ptr; } -#else -/* LCOV_EXCL_START - Can't cover non posix lines (yet) */ -struct panic_data *get_panic_data_write(void) +#endif + +test_mockable struct panic_data *get_panic_data_write(void) { /* * Pointer to panic_data structure. It may not point to @@ -295,8 +295,6 @@ struct panic_data *get_panic_data_write(void) return pdata_ptr; } -/* LCOV_EXCL_STOP */ -#endif /* CONFIG_BOARD_NATIVE_POSIX */ static void panic_init(void) { diff --git a/include/panic.h b/include/panic.h index 25829017ea..efd3e4d86b 100644 --- a/include/panic.h +++ b/include/panic.h @@ -292,6 +292,15 @@ struct panic_data *panic_get_data(void); */ uintptr_t get_panic_data_start(void); +#ifdef CONFIG_BOARD_NATIVE_POSIX +/** + * @brief Test-only function for accessing the pdata_ptr object. + * + * @return struct panic_data* pdata_ptr + */ +struct panic_data *test_get_panic_data_pointer(void); +#endif + /* * Return a pointer to panic_data structure that can be safely written. * Please note that this function can move jump data and jump tags. diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt index 07688db4f2..08d5caa04b 100644 --- a/zephyr/test/drivers/default/CMakeLists.txt +++ b/zephyr/test/drivers/default/CMakeLists.txt @@ -97,6 +97,11 @@ target_sources(app PRIVATE src/watchdog.c ) +add_subdirectory( + ${PLATFORM_EC}/zephyr/test/drivers/mock_panic_output + mock_panic_output +) + # This test does not work when power functions are mocked, so only run it for # the plain `drivers.default` test case. zephyr_library_sources_ifndef(CONFIG_POWER_SEQUENCE_MOCK src/chipset.c) diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt index 14733253c3..6e6cf0f48a 100644 --- a/zephyr/test/drivers/host_cmd/CMakeLists.txt +++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt @@ -25,3 +25,8 @@ target_sources(app PRIVATE src/usb_pd_control.c src/usb_pd_host_cmd.c ) + +add_subdirectory( + ${PLATFORM_EC}/zephyr/test/drivers/mock_panic_output + mock_panic_output +) diff --git a/zephyr/test/drivers/mock_panic_output/CMakeLists.txt b/zephyr/test/drivers/mock_panic_output/CMakeLists.txt new file mode 100644 index 0000000000..2e3b959805 --- /dev/null +++ b/zephyr/test/drivers/mock_panic_output/CMakeLists.txt @@ -0,0 +1,6 @@ +# 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. + +# Add source files +target_sources(app PRIVATE src/test_get_panic_data_write.c) diff --git a/zephyr/test/drivers/mock_panic_output/src/test_get_panic_data_write.c b/zephyr/test/drivers/mock_panic_output/src/test_get_panic_data_write.c new file mode 100644 index 0000000000..5d7bcf9010 --- /dev/null +++ b/zephyr/test/drivers/mock_panic_output/src/test_get_panic_data_write.c @@ -0,0 +1,18 @@ +/* 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 "panic.h" + +/** + * @brief Override for testing. This method simply returns `pdata_ptr` and + * bypasses the usual logic in `common/panic_output.c` + * + * @return struct panic_data* Pointer to the pdata_ptr object + */ +struct panic_data *get_panic_data_write(void) +{ + /* Test-only helper method to access `pdata_ptr` in `panic_output.c` */ + return test_get_panic_data_pointer(); +} |