diff options
author | Yuval Peress <peress@google.com> | 2022-07-24 21:31:52 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-25 20:51:37 +0000 |
commit | c16f255ef203b67eb31cb727a98f96e3fbce1d4b (patch) | |
tree | 7f6b5f11e5221b9588795cd56dfd6db8dad90cc9 /zephyr/test/drivers/default/src/charge_manager.c | |
parent | 3524a1f7eb23533a4a6cffd4c69bd07cf1b43129 (diff) | |
download | chrome-ec-c16f255ef203b67eb31cb727a98f96e3fbce1d4b.tar.gz |
zephyr: test: migrate drivers test to twister
1. Move the common test logic to drivers/common with its own
CMakeLists.txt
2. Move the drivers test suites to drivers/default with its own
CMakeLists.txt
3. Add a Kconfig for each suite that can enable it, use Zephyr's
add_subdirectory_ifdef to control which suites get added to the
biary and verify that at least 1 suite was added.
4. Add a check for ZMAKE_PROJECT_NAME to still allow zmake commands
5. Add testcase.yaml which runs all the tests
BRANCH=none
BUG=b:240093007
TEST=./twister --coverage -p native_posix -T zephyr/test/drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: Ib9d4ea4a8431539391cc5349a7a8fd7a7d21f120
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3784043
Reviewed-by: Tristan Honscheid <honscheid@google.com>
Commit-Queue: Tristan Honscheid <honscheid@google.com>
Diffstat (limited to 'zephyr/test/drivers/default/src/charge_manager.c')
-rw-r--r-- | zephyr/test/drivers/default/src/charge_manager.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/charge_manager.c b/zephyr/test/drivers/default/src/charge_manager.c new file mode 100644 index 0000000000..13668924fd --- /dev/null +++ b/zephyr/test/drivers/default/src/charge_manager.c @@ -0,0 +1,58 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <ztest.h> + +#include "charge_manager.h" +#include "ec_commands.h" +#include "test/drivers/test_state.h" + +ZTEST_SUITE(charge_manager, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); + +/** + * Test the default implementation of board_fill_source_power_info(). The fill + * function should reset all the power info values. If the test binary overrides + * board_fill_source_power_info(), then this test can be removed. + */ +ZTEST_USER(charge_manager, test_default_fill_power_info) +{ + struct ec_response_usb_pd_power_info info = { + .meas = { + .voltage_now = 10, + .voltage_max = 10, + .current_max = 10, + .current_lim = 10, + }, + .max_power = 10, + }; + + board_fill_source_power_info(0, &info); + zassert_equal(info.meas.voltage_now, 0, NULL); + zassert_equal(info.meas.voltage_max, 0, NULL); + zassert_equal(info.meas.current_max, 0, NULL); + zassert_equal(info.meas.current_lim, 0, NULL); + zassert_equal(info.max_power, 0, NULL); +} + +/** + * Test the default implementation of board_charge_port_is_connected(). This + * function should always return 1 regardless of input. + */ +ZTEST_USER(charge_manager, test_default_charge_port_is_connected) +{ + zassert_true(board_charge_port_is_connected(-1), NULL); + zassert_true(board_charge_port_is_connected(0), NULL); + zassert_true(board_charge_port_is_connected(1), NULL); + zassert_true(board_charge_port_is_connected(500), NULL); +} + +ZTEST_USER(charge_manager, test_default_charge_port_is_sink) +{ + zassert_true(board_charge_port_is_sink(-1), NULL); + zassert_true(board_charge_port_is_sink(0), NULL); + zassert_true(board_charge_port_is_sink(1), NULL); + zassert_true(board_charge_port_is_sink(500), NULL); +} |