summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bernacki <bernacki@google.com>2023-02-28 13:20:51 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-13 21:48:09 +0000
commit72a40fac54a35536366038866bd91606a368a320 (patch)
treedb5f608aeae88bea05f64670596a3d3ca3f4bb7a
parentfc95c65a4d0fb63d5ba5219e3243cd9d2817e925 (diff)
downloadchrome-ec-72a40fac54a35536366038866bd91606a368a320.tar.gz
skyrim: Add clamshell & convertible tests.
BRANCH=none BUG=b:269234224 TEST=Ran tests Change-Id: I8d0d889cbc7d508854e35ab45bb13d1b2a4af360 Signed-off-by: Grzegorz Bernacki <bernacki@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4296798 Reviewed-by: Robert Zieba <robertzieba@google.com>
-rw-r--r--zephyr/program/skyrim/skyrim/src/form_factor.c2
-rw-r--r--zephyr/test/skyrim/Kconfig9
-rw-r--r--zephyr/test/skyrim/boards/native_posix.overlay54
-rw-r--r--zephyr/test/skyrim/boards/skyrim/skyrim.dtsi30
-rw-r--r--zephyr/test/skyrim/testcase.yaml7
-rw-r--r--zephyr/test/skyrim/tests/skyrim/CMakeLists.txt2
-rw-r--r--zephyr/test/skyrim/tests/skyrim/src/form_factor.c164
7 files changed, 266 insertions, 2 deletions
diff --git a/zephyr/program/skyrim/skyrim/src/form_factor.c b/zephyr/program/skyrim/skyrim/src/form_factor.c
index afeacb4c1e..7a240a3447 100644
--- a/zephyr/program/skyrim/skyrim/src/form_factor.c
+++ b/zephyr/program/skyrim/skyrim/src/form_factor.c
@@ -40,7 +40,7 @@ static void form_factor_init(void)
}
DECLARE_HOOK(HOOK_INIT, form_factor_init, HOOK_PRIO_POST_I2C);
-static void clamshell_init(void)
+test_export_static void clamshell_init(void)
{
int ret;
uint32_t val;
diff --git a/zephyr/test/skyrim/Kconfig b/zephyr/test/skyrim/Kconfig
index e489379062..c75d199114 100644
--- a/zephyr/test/skyrim/Kconfig
+++ b/zephyr/test/skyrim/Kconfig
@@ -62,6 +62,15 @@ config TEST_BOARD_FAN_CUSTOM
bool "ENable fan tests with a variant-specific test file"
select TEST_BOARD_FAN
+config TEST_BOARD_FORM_FACTOR
+ select PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT
+ select PLATFORM_EC_GMR_TABLET_MODE
+ select PLATFORM_EC_TABLET_MODE
+ bool "Run the tests intended for form factor testing"
+ help
+ Include tests which checks accelerometer
+ interrupt and tablet mode.
+
config TEST_BOARD_USB_PD_POLICY
bool "Enable USB PD policy specific tests"
select TEST_ENABLE_USB_PD_HOST_CMD
diff --git a/zephyr/test/skyrim/boards/native_posix.overlay b/zephyr/test/skyrim/boards/native_posix.overlay
index cbf687b743..279f5e954b 100644
--- a/zephyr/test/skyrim/boards/native_posix.overlay
+++ b/zephyr/test/skyrim/boards/native_posix.overlay
@@ -54,11 +54,48 @@
gpios = <&gpio0 8 GPIO_OUTPUT_LOW>;
enum-name = "IOEX_USB_C0_SBU_FLIP";
};
+
+ gpio_accel_gyro_int_l: accel_gyro_int_l {
+ gpios = <&gpio0 9 GPIO_INPUT>;
+ };
+
+ tablet_mode_l: tablet_mode_l {
+ gpios = <&gpio0 11 GPIO_INPUT>;
+ enum-name = "GPIO_TABLET_MODE_L";
+ };
+ };
+
+ gpio-interrupts {
+ compatible = "cros-ec,gpio-interrupts";
+
+ int_accel_gyro: accel_gyro {
+ irq-pin = <&gpio_accel_gyro_int_l>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "bmi3xx_interrupt";
+ };
};
skyrim-fw-config {
compatible = "cros-ec,cbi-fw-config";
+ form-factor {
+ enum-name = "FW_FORM_FACTOR";
+ start = <0>;
+ size = <1>;
+
+ ff-clamshell {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "FW_FF_CLAMSHELL";
+ value = <0>;
+ };
+ ff-convertible {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "FW_FF_CONVERTIBLE";
+ value = <1>;
+ default;
+ };
+ };
+
io-db {
enum-name = "FW_IO_DB";
start = <6>;
@@ -117,8 +154,23 @@
};
};
};
+
+ named-i2c-ports {
+ compatible = "named-i2c-ports";
+
+ eeprom {
+ i2c-port = <&i2c0>;
+ enum-names = "I2C_PORT_EEPROM";
+ };
+
+ i2c_sensor: sensor {
+ i2c-port = <&i2c0>;
+ enum-names = "I2C_PORT_SENSOR";
+ };
+
+ };
};
&gpio0 {
ngpios = <23>;
-}; \ No newline at end of file
+};
diff --git a/zephyr/test/skyrim/boards/skyrim/skyrim.dtsi b/zephyr/test/skyrim/boards/skyrim/skyrim.dtsi
new file mode 100644
index 0000000000..e5f846c3ce
--- /dev/null
+++ b/zephyr/test/skyrim/boards/skyrim/skyrim.dtsi
@@ -0,0 +1,30 @@
+/* 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 "../native_posix.overlay"
+#include "../../../../program/skyrim/skyrim/motionsense.dtsi"
+
+/ {
+ /* Rotation matrices for motion sensors. */
+ motionsense-rotation-ref {
+ compatible = "cros-ec,motionsense-rotation-ref";
+ lid_rot_ref: lid-rotation-ref {
+ mat33 = <0 (-1) 0
+ 1 0 0
+ 0 0 1>;
+ };
+
+ lid_rot_ref1: lid-rotation-ref1 {
+ mat33 = <0 1 0
+ (-1) 0 0
+ 0 0 1>;
+ };
+
+ base_rot_ref: base-rotation-ref {
+ mat33 = <0 1 0
+ (-1) 0 0
+ 0 0 1>;
+ };
+ };
+};
diff --git a/zephyr/test/skyrim/testcase.yaml b/zephyr/test/skyrim/testcase.yaml
index a940d45eae..a59ba79371 100644
--- a/zephyr/test/skyrim/testcase.yaml
+++ b/zephyr/test/skyrim/testcase.yaml
@@ -86,6 +86,13 @@ tests:
- CONFIG_TEST_BOARD_SKYRIM=y
- CONFIG_TEST_BOARD_PPC_CONFIG=y
+ skyrim.skyrim.form_factor:
+ extra_args:
+ DTC_OVERLAY_FILE="./boards/skyrim/skyrim.dtsi;"
+ extra_configs:
+ - CONFIG_TEST_BOARD_SKYRIM=y
+ - CONFIG_TEST_BOARD_FORM_FACTOR=y
+
# Winterhold tests
skyrim.winterhold:
extra_configs:
diff --git a/zephyr/test/skyrim/tests/skyrim/CMakeLists.txt b/zephyr/test/skyrim/tests/skyrim/CMakeLists.txt
index e78711fed2..48ebbf074b 100644
--- a/zephyr/test/skyrim/tests/skyrim/CMakeLists.txt
+++ b/zephyr/test/skyrim/tests/skyrim/CMakeLists.txt
@@ -3,3 +3,5 @@
# found in the LICENSE file.
target_sources(app PRIVATE src/common.c)
+target_sources_ifdef(CONFIG_TEST_BOARD_FORM_FACTOR app PRIVATE
+ src/form_factor.c ${PLATFORM_EC_PROGRAM_DIR}/skyrim/${CONFIG_TEST_BOARD_NAME}/src/form_factor.c)
diff --git a/zephyr/test/skyrim/tests/skyrim/src/form_factor.c b/zephyr/test/skyrim/tests/skyrim/src/form_factor.c
new file mode 100644
index 0000000000..af71a61be6
--- /dev/null
+++ b/zephyr/test/skyrim/tests/skyrim/src/form_factor.c
@@ -0,0 +1,164 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "tablet_mode.h"
+#include "zephyr/kernel.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/ztest.h>
+
+void clamshell_init(void);
+
+FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config, enum cbi_fw_config_field_id,
+ uint32_t *);
+
+static bool clamshell_mode;
+static int interrupt_count;
+
+void bmi3xx_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+static int cros_cbi_get_fw_config_mock(enum cbi_fw_config_field_id field_id,
+ uint32_t *value)
+{
+ if (field_id != FW_FORM_FACTOR)
+ return -EINVAL;
+
+ *value = clamshell_mode ? FW_FF_CLAMSHELL : FW_FF_CONVERTIBLE;
+ return 0;
+}
+
+static void *form_factor_setup(void)
+{
+ const struct device *tablet_mode_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(tablet_mode_l), gpios));
+ const gpio_port_pins_t tablet_mode_pin =
+ DT_GPIO_PIN(DT_NODELABEL(tablet_mode_l), gpios);
+
+ /* Set default value of TABLET_MODE_L */
+ gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 1);
+
+ clamshell_mode = 0;
+
+ RESET_FAKE(cros_cbi_get_fw_config);
+ cros_cbi_get_fw_config_fake.custom_fake = cros_cbi_get_fw_config_mock;
+
+ hook_notify(HOOK_INIT);
+
+ return NULL;
+}
+
+ZTEST_SUITE(skyrim_form_factor, NULL, form_factor_setup, NULL, NULL, NULL);
+
+ZTEST(skyrim_form_factor, test_03_clamshell_gmr_tablet_switch_disabled)
+{
+ const struct device *tablet_mode_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(tablet_mode_l), gpios));
+ const gpio_port_pins_t tablet_mode_pin =
+ DT_GPIO_PIN(DT_NODELABEL(tablet_mode_l), gpios);
+
+ clamshell_mode = 1;
+ clamshell_init();
+
+ /* Verify gmr_tablet_switch is disabled, by checking the side effects
+ * of calling tablet_set_mode, and setting gpio_tablet_mode_l.
+ */
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 1),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(0, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+}
+
+ZTEST(skyrim_form_factor, test_04_clamshell_base_imu_irq_disabled)
+{
+ const struct device *base_imu_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_accel_gyro_int_l), gpios));
+ const gpio_port_pins_t base_imu_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_accel_gyro_int_l), gpios);
+
+ clamshell_mode = 1;
+ clamshell_init();
+
+ /* Verify base_imu_irq is disabled. */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 1), NULL);
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 0, "interrupt_count=%d",
+ interrupt_count);
+}
+
+ZTEST(skyrim_form_factor, test_01_convertible_gmr_tablet_switch_enabled)
+{
+ const struct device *tablet_mode_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(tablet_mode_l), gpios));
+ const gpio_port_pins_t tablet_mode_pin =
+ DT_GPIO_PIN(DT_NODELABEL(tablet_mode_l), gpios);
+
+ clamshell_mode = 0;
+ clamshell_init();
+
+ /* Verify gmr_tablet_switch is enabled, by checking the side effects
+ * of calling tablet_set_mode, and setting gpio_tablet_mode_l.
+ */
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(1, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 1),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(0, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(1, tablet_get_mode(), NULL);
+}
+
+ZTEST(skyrim_form_factor, test_02_convertible_base_imu_irq_enabled)
+{
+ const struct device *base_imu_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_accel_gyro_int_l), gpios));
+ const gpio_port_pins_t base_imu_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_accel_gyro_int_l), gpios);
+
+ clamshell_mode = 0;
+ clamshell_init();
+
+ /* Verify base_imu_irq is enabled. Interrupt is configured
+ * GPIO_INT_EDGE_FALLING, so set high, then set low.
+ */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 1), NULL);
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 1, "interrupt_count=%d",
+ interrupt_count);
+}