diff options
author | Clayton Whitelaw <cawhitelaw@google.com> | 2022-11-16 18:44:53 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-20 08:36:29 +0000 |
commit | 2d85efd59b7dd76998c7063142d69aa9874bd514 (patch) | |
tree | 976e947fd67d849ff831206b52e4f75f81a4205e | |
parent | 1c5c179db16ce361a680f18006b80c1d6e173ec8 (diff) | |
download | chrome-ec-stabilize-15251.B-main.tar.gz |
tcpm_header: add test for set_vconn failurestabilize-15251.B-main
Create test file and suite "tcpm_header" to house this test.
BRANCH=none
BUG=none
TEST=twister
Signed-off-by: Clayton Whitelaw <cawhitelaw@google.com>
Change-Id: I3abd0cb47eb9d2fdf1196e525001429b7055fecc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4031969
Reviewed-by: Yuval Peress <peress@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Commit-Queue: Yuval Peress <peress@google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/test/drivers/default/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/default/src/tcpm_header.c | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt index d7396ad159..8f1c2ddf84 100644 --- a/zephyr/test/drivers/default/CMakeLists.txt +++ b/zephyr/test/drivers/default/CMakeLists.txt @@ -85,6 +85,7 @@ target_sources(app PRIVATE src/task.c src/tcpci.c src/tcpci_test_common.c + src/tcpm_header.c src/tcs3400.c src/temp_sensor.c src/thermistor.c diff --git a/zephyr/test/drivers/default/src/tcpm_header.c b/zephyr/test/drivers/default/src/tcpm_header.c new file mode 100644 index 0000000000..b4c3ece359 --- /dev/null +++ b/zephyr/test/drivers/default/src/tcpm_header.c @@ -0,0 +1,71 @@ +/* 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 "tcpm/tcpci.h" +#include "tcpm/tcpm.h" +#include "test/drivers/stubs.h" +#include "test/drivers/test_state.h" + +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> + +#define TCPM_TEST_PORT USBC_PORT_C0 + +FAKE_VALUE_FUNC(int, set_vconn, int, int); + +struct tcpm_header_fixture { + /* The original driver pointer that gets restored after the tests */ + const struct tcpm_drv *saved_driver_ptr; + /* Mock driver that gets substituted */ + struct tcpm_drv mock_driver; + /* Saved tcpc config flags that get restored after the tests */ + uint32_t saved_tcpc_flags; +}; + +ZTEST_F(tcpm_header, test_tcpm_header_drv_set_vconn_failure) +{ + int res; + + tcpc_config[TCPM_TEST_PORT].flags = TCPC_FLAGS_CONTROL_VCONN; + + fixture->mock_driver.set_vconn = set_vconn; + set_vconn_fake.return_val = -1; + + res = tcpm_set_vconn(TCPM_TEST_PORT, true); + + zassert_true(set_vconn_fake.call_count > 0); + zassert_equal(-1, res); +} + +static void *tcpm_header_setup(void) +{ + static struct tcpm_header_fixture fixture; + + return &fixture; +} + +static void tcpm_header_before(void *state) +{ + struct tcpm_header_fixture *fixture = state; + + RESET_FAKE(set_vconn); + + fixture->mock_driver = (struct tcpm_drv){ 0 }; + fixture->saved_driver_ptr = tcpc_config[TCPM_TEST_PORT].drv; + tcpc_config[TCPM_TEST_PORT].drv = &fixture->mock_driver; + + fixture->saved_tcpc_flags = tcpc_config[TCPM_TEST_PORT].flags; +} + +static void tcpm_header_after(void *state) +{ + struct tcpm_header_fixture *fixture = state; + + tcpc_config[TCPM_TEST_PORT].drv = fixture->saved_driver_ptr; + tcpc_config[TCPM_TEST_PORT].flags = fixture->saved_tcpc_flags; +} + +ZTEST_SUITE(tcpm_header, drivers_predicate_pre_main, tcpm_header_setup, + tcpm_header_before, tcpm_header_after, NULL); |