summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-07 17:09:00 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-10 23:53:17 +0000
commit439186b7dade51b9255295afd9b62bde2221cb95 (patch)
treeee74b6081d282684ba535df56b794ab0140f44cf
parent5a0519d8018e9a3280d486a4ff3985b5492ee9e8 (diff)
downloadchrome-ec-439186b7dade51b9255295afd9b62bde2221cb95.tar.gz
test: pwm_hc.c EC_CMD_PWM_GET_DUTY
Add a new test binary that verifies the EC_CMD_PWM_GET_DUTY returns the raw up-to-date PWM value when invoked on a particular PWM. BRANCH=none BUG=b:236132469 TEST=twister --clobber -i -s zephyr/test/drivers/drivers.shim_pwm_hc Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: Ie6c5ec65f7e1caf7071fdc9b6c650e00aaaea68a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3939621 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/test/drivers/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/Kconfig3
-rw-r--r--zephyr/test/drivers/boards/native_posix.overlay12
-rw-r--r--zephyr/test/drivers/shim_pwm_hc/CMakeLists.txt6
-rw-r--r--zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c57
-rw-r--r--zephyr/test/drivers/testcase.yaml3
6 files changed, 82 insertions, 0 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index 8e8d08f9a2..c9f5f606d3 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -57,6 +57,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_KEYBOARD_SCAN keyboard_scan)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MKBP mkbp)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_RT9490 rt9490)
+add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC shim_pwm_hc)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_SHIM_RTC shim_rtc)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_TIMER timer)
add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK usb_malfunction_sink)
diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig
index f57d83b014..3cf356d2ab 100644
--- a/zephyr/test/drivers/Kconfig
+++ b/zephyr/test/drivers/Kconfig
@@ -35,6 +35,9 @@ config LINK_TEST_SUITE_LED_DRIVER
config LINK_TEST_SUITE_MKBP
bool "Link and test the mkbp tests"
+config LINK_TEST_SUITE_SHIM_PWM_HC
+ bool "Link and run the shim pwm_hc tests"
+
config LINK_TEST_SUITE_RT9490
bool "Link and test the rt9490 tests"
diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay
index 53ffca3219..6d9b74fc64 100644
--- a/zephyr/test/drivers/boards/native_posix.overlay
+++ b/zephyr/test/drivers/boards/native_posix.overlay
@@ -855,6 +855,12 @@
#pwm-cells = <3>;
status = "okay";
};
+ pwm_displight: pwm@5 {
+ compatible = "cros,pwm-mock";
+ reg = <5 1>;
+ #pwm-cells = <3>;
+ status = "okay";
+ };
};
pwmleds {
@@ -932,6 +938,12 @@
pwms = <&pwm_kblight 0 PWM_KHZ(10) PWM_POLARITY_NORMAL>;
generic-pwm-channel = <0>;
};
+
+ displight {
+ compatible = "cros-ec,displight";
+ pwms = <&pwm_kblight 0 PWM_KHZ(10) PWM_POLARITY_NORMAL>;
+ generic-pwm-channel = <1>;
+ };
};
&espi0 {
diff --git a/zephyr/test/drivers/shim_pwm_hc/CMakeLists.txt b/zephyr/test/drivers/shim_pwm_hc/CMakeLists.txt
new file mode 100644
index 0000000000..d20d965d2d
--- /dev/null
+++ b/zephyr/test/drivers/shim_pwm_hc/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_shim_pwm_hc.c)
diff --git a/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c
new file mode 100644
index 0000000000..5fc7344b75
--- /dev/null
+++ b/zephyr/test/drivers/shim_pwm_hc/src/test_shim_pwm_hc.c
@@ -0,0 +1,57 @@
+/* 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 <zephyr/drivers/emul.h>
+#include <zephyr/kernel.h>
+#include <zephyr/ztest_assert.h>
+#include <zephyr/drivers/i2c_emul.h>
+
+#include "drivers/cros_displight.h"
+#include "ec_commands.h"
+#include "host_command.h"
+#include "keyboard_backlight.h"
+#include "pwm.h"
+#include "test/drivers/test_state.h"
+
+ZTEST(shim_pwm_hc, test_pwm_get_duty_hc__kblight)
+{
+ struct ec_params_pwm_get_duty p = {
+ .index = DT_REG_ADDR(DT_NODELABEL(pwm_kblight)),
+ .pwm_type = EC_PWM_TYPE_KB_LIGHT,
+ };
+
+ struct ec_response_pwm_get_duty r;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND(EC_CMD_PWM_GET_DUTY, 0, r, p);
+
+ /* Set kblight percentage to arbitrary 56% */
+ kblight_set(56);
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(args.response_size, sizeof(r));
+ zassert_equal(r.duty, PWM_PERCENT_TO_RAW(56));
+}
+
+ZTEST(shim_pwm_hc, test_pwm_get_duty_hc__displight)
+{
+ struct ec_params_pwm_get_duty p = {
+ p.index = DT_REG_ADDR(DT_NODELABEL(pwm_displight)),
+ p.pwm_type = EC_PWM_TYPE_DISPLAY_LIGHT,
+ };
+
+ struct ec_response_pwm_get_duty r;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND(EC_CMD_PWM_GET_DUTY, 0, r, p);
+
+ /* Set displight percentage to arbitrary 72% */
+ displight_set(72);
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(args.response_size, sizeof(r));
+ zassert_equal(r.duty, PWM_PERCENT_TO_RAW(72));
+}
+
+ZTEST_SUITE(shim_pwm_hc, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index f8317d1cc9..6b822f2316 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -79,6 +79,9 @@ tests:
tags:
common
mkbp
+ drivers.shim_pwm_hc:
+ extra_configs:
+ - CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC=y
drivers.rt9490:
extra_args: CONF_FILE="prj.conf;rt9490/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./rt9490/charger.dts"
extra_configs: