summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-08-31 02:05:03 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-01 00:04:13 +0000
commit2aaee77c3797d5b7fcf4876f9306f33e4b15a640 (patch)
tree9458aa75ee2014e262ca9dbaa724ae64ba1271af
parentb2a302b1bef67dd322762feb8e344d45987c30f2 (diff)
downloadchrome-ec-2aaee77c3797d5b7fcf4876f9306f33e4b15a640.tar.gz
test: Add tests for lid_angle.c cover the basic code paths
Test the basic code paths of setting/getting the wake angle as well as having the lid at 45 while the wake angle is at either the min/max. BRANCH=none BUG=b:244402830 TEST=twister -T zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I076f00fe7f572ac3358a9471a51b6408ee082b92 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3867250 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
-rw-r--r--zephyr/test/drivers/common/include/test/drivers/test_mocks.h3
-rw-r--r--zephyr/test/drivers/common/src/test_mocks.c4
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/default/src/lid_angle.c70
-rw-r--r--zephyr/test/drivers/testcase.yaml2
5 files changed, 80 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h
index f77eb6fc10..eb6325903f 100644
--- a/zephyr/test/drivers/common/include/test/drivers/test_mocks.h
+++ b/zephyr/test/drivers/common/include/test/drivers/test_mocks.h
@@ -108,3 +108,6 @@ DECLARE_FAKE_VALUE_FUNC(int, system_jumped_late);
DECLARE_FAKE_VOID_FUNC(system_reset, int);
DECLARE_FAKE_VOID_FUNC(software_panic, uint32_t, uint32_t);
DECLARE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int);
+
+/* Mocks for common/lid_angle.c */
+DECLARE_FAKE_VOID_FUNC(lid_angle_peripheral_enable, int);
diff --git a/zephyr/test/drivers/common/src/test_mocks.c b/zephyr/test/drivers/common/src/test_mocks.c
index 6c8db5c27a..d2e4770f9b 100644
--- a/zephyr/test/drivers/common/src/test_mocks.c
+++ b/zephyr/test/drivers/common/src/test_mocks.c
@@ -20,6 +20,9 @@ DEFINE_FAKE_VOID_FUNC(system_reset, int);
DEFINE_FAKE_VOID_FUNC(software_panic, uint32_t, uint32_t);
DEFINE_FAKE_VOID_FUNC(assert_post_action, const char *, unsigned int);
+/* Mocks for common/lid_angle.c */
+DEFINE_FAKE_VOID_FUNC(lid_angle_peripheral_enable, int);
+
/**
* @brief Reset all the fakes before each test.
*/
@@ -36,6 +39,7 @@ static void fff_reset_rule_before(const struct ztest_unit_test *test,
RESET_FAKE(system_reset);
RESET_FAKE(software_panic);
RESET_FAKE(assert_post_action);
+ RESET_FAKE(lid_angle_peripheral_enable);
}
ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL);
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index 5e5cd31c95..57687787d1 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -52,6 +52,7 @@ target_sources(app PRIVATE
src/isl923x.c
src/keyboard_scan.c
src/led.c
+ src/lid_angle.c
src/lid_switch.c
src/lis2dw12.c
src/ln9310.c
diff --git a/zephyr/test/drivers/default/src/lid_angle.c b/zephyr/test/drivers/default/src/lid_angle.c
new file mode 100644
index 0000000000..0289261cda
--- /dev/null
+++ b/zephyr/test/drivers/default/src/lid_angle.c
@@ -0,0 +1,70 @@
+/* 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 "ec_commands.h"
+#include "lid_angle.h"
+#include "test/drivers/test_mocks.h"
+#include "test/drivers/test_state.h"
+
+#define LID_ANGLE_MIN_LARGE_ANGLE 0
+#define LID_ANGLE_MAX_LARGE_ANGLE 360
+
+static void lid_angle_after(void *f)
+{
+ ARG_UNUSED(f);
+ /* Reset the wake angle */
+ lid_angle_set_wake_angle(180);
+ /* Flush the buffer */
+ lid_angle_update(LID_ANGLE_UNRELIABLE);
+ lid_angle_update(LID_ANGLE_UNRELIABLE);
+ lid_angle_update(LID_ANGLE_UNRELIABLE);
+ lid_angle_update(LID_ANGLE_UNRELIABLE);
+}
+
+ZTEST_SUITE(lid_angle, drivers_predicate_post_main, NULL, NULL, lid_angle_after,
+ NULL);
+
+ZTEST(lid_angle, test_get_set_wake_angle)
+{
+ lid_angle_set_wake_angle(LID_ANGLE_MIN_LARGE_ANGLE - 1);
+ zassert_equal(LID_ANGLE_MIN_LARGE_ANGLE, lid_angle_get_wake_angle(),
+ NULL);
+
+ lid_angle_set_wake_angle(LID_ANGLE_MAX_LARGE_ANGLE + 1);
+ zassert_equal(LID_ANGLE_MAX_LARGE_ANGLE, lid_angle_get_wake_angle(),
+ NULL);
+
+ lid_angle_set_wake_angle(
+ (LID_ANGLE_MIN_LARGE_ANGLE + LID_ANGLE_MAX_LARGE_ANGLE) / 2);
+ zassert_equal((LID_ANGLE_MIN_LARGE_ANGLE + LID_ANGLE_MAX_LARGE_ANGLE) /
+ 2,
+ lid_angle_get_wake_angle(), NULL);
+}
+
+ZTEST(lid_angle, test_no_wake_min_large_angle)
+{
+ lid_angle_set_wake_angle(LID_ANGLE_MIN_LARGE_ANGLE);
+ lid_angle_update(45);
+ lid_angle_update(45);
+ lid_angle_update(45);
+ lid_angle_update(45);
+
+ zassert_equal(1, lid_angle_peripheral_enable_fake.call_count, NULL);
+ zassert_equal(0, lid_angle_peripheral_enable_fake.arg0_val, NULL);
+}
+
+ZTEST(lid_angle, test_wake_max_large_angle)
+{
+ lid_angle_set_wake_angle(LID_ANGLE_MAX_LARGE_ANGLE);
+ lid_angle_update(45);
+ lid_angle_update(45);
+ lid_angle_update(45);
+ lid_angle_update(45);
+
+ zassert_equal(1, lid_angle_peripheral_enable_fake.call_count, NULL);
+ zassert_equal(1, lid_angle_peripheral_enable_fake.arg0_val, NULL);
+}
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index eb88b14a54..a8d88d4346 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -8,6 +8,7 @@ tests:
- CONFIG_LINK_TEST_SUITE_DEFAULT=y
- CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK=y
- CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y
+ - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y
drivers.default.mock_power:
timeout: 240
extra_args: CONF_FILE="prj.conf;default/prj.conf"
@@ -15,6 +16,7 @@ tests:
- CONFIG_LINK_TEST_SUITE_DEFAULT=y
- CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK=y
- CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y
+ - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y
- CONFIG_POWER_SEQUENCE_MOCK=y
drivers.host_cmd:
extra_configs: