summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNehemiah Dureus <ndureus@chromium.org>2022-08-29 13:07:42 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-02 23:56:04 +0000
commit02b7a40359ad90b19997a229589ce81bbb94a756 (patch)
treef768a2534382366ed54f05321889daafde06548d
parent155f25935a1ba0e3d105c7c98c7e5ac587e10a80 (diff)
downloadchrome-ec-firmware-ti50-mp-15090.B-main.tar.gz
test: Add tests for the powerbtn commandfirmware-ti50-mp-15090.B-main
As part of ensuring the test passes, the powerbtn command now errors on negative millisecond inputs. BRANCH=none BUG=b:236074627 TEST=zmake test test-drivers Signed-off-by: Nehemiah Dureus <ndureus@chromium.org> Change-Id: Ib257b101a2c909064b350a905006b25d2c85e0f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3860409 Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--common/power_button.c4
-rw-r--r--include/power_button.h2
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/default/src/console_cmd/power_button.c34
4 files changed, 38 insertions, 3 deletions
diff --git a/common/power_button.c b/common/power_button.c
index 6aaa293631..42b165ec8f 100644
--- a/common/power_button.c
+++ b/common/power_button.c
@@ -200,7 +200,7 @@ void power_button_interrupt(enum gpio_signal signal)
power_button.debounce_us);
}
-void power_button_simulate_press(int duration)
+void power_button_simulate_press(unsigned int duration)
{
ccprintf("Simulating %d ms %s press.\n", duration, power_button.name);
simulate_power_pressed = 1;
@@ -226,7 +226,7 @@ static int command_powerbtn(int argc, const char **argv)
if (argc > 1) {
ms = strtoi(argv[1], &e, 0);
- if (*e)
+ if (*e || ms < 0)
return EC_ERROR_PARAM1;
}
diff --git a/include/power_button.h b/include/power_button.h
index 3c2eabf13e..eecc65e948 100644
--- a/include/power_button.h
+++ b/include/power_button.h
@@ -74,6 +74,6 @@ void board_pwrbtn_to_pch(int level);
*
* @param duration Simulated power button press duration in ms.
*/
-void power_button_simulate_press(int duration);
+void power_button_simulate_press(unsigned int duration);
#endif /* __CROS_EC_POWER_BUTTON_H */
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index 3f0e6ec0ec..3725c27ebd 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -31,6 +31,7 @@ target_sources(app PRIVATE
src/console_cmd/panic_output.c
src/console_cmd/port80.c
src/console_cmd/powerindebug.c
+ src/console_cmd/power_button.c
src/console_cmd/rw.c
src/console_cmd/sleeptimeout.c
src/console_cmd/tcpci_dump.c
diff --git a/zephyr/test/drivers/default/src/console_cmd/power_button.c b/zephyr/test/drivers/default/src/console_cmd/power_button.c
new file mode 100644
index 0000000000..713b3c4966
--- /dev/null
+++ b/zephyr/test/drivers/default/src/console_cmd/power_button.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/ztest.h>
+#include <console.h>
+
+ZTEST_SUITE(console_cmd_power_button, NULL, NULL, NULL, NULL, NULL);
+
+ZTEST_USER(console_cmd_power_button, test_return_ok)
+{
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "powerbtn"), NULL);
+}
+
+ZTEST_USER(console_cmd_power_button, test_negative_delay)
+{
+ int rv;
+
+ rv = shell_execute_cmd(get_ec_shell(), "powerbtn -1");
+
+ zassert_not_equal(rv, EC_SUCCESS,
+ "Command should error on negative delay");
+}
+
+ZTEST_USER(console_cmd_power_button, test_invalid_arg)
+{
+ int rv;
+
+ rv = shell_execute_cmd(get_ec_shell(), "powerbtn foo");
+
+ zassert_equal(rv, EC_ERROR_PARAM1, "Expected %d, but got %d",
+ EC_ERROR_PARAM1, rv);
+}