summaryrefslogtreecommitdiff
path: root/test/lid_sw.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-09 00:24:33 +0800
committerChromeBot <chrome-bot@google.com>2013-05-08 13:24:19 -0700
commita0bfc0c6698c01f722ed56bee8871f0620142db3 (patch)
tree23012995513931d68d5f358128eb9305cf8d333d /test/lid_sw.c
parentac3488cd0b41ade3dd38ec61c4b07db6489f2260 (diff)
downloadchrome-ec-a0bfc0c6698c01f722ed56bee8871f0620142db3.tar.gz
Add lid switch test and enable kb_mkbp test
BUG=chrome-os-partner:19236 TEST=Pass both tests BRANCH=None CQ-DEPEND=CL:50467 Change-Id: I59cc407c2d1bf7f549ff9c46226cf7fa60fe7157 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50466
Diffstat (limited to 'test/lid_sw.c')
-rw-r--r--test/lid_sw.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/test/lid_sw.c b/test/lid_sw.c
new file mode 100644
index 0000000000..4993147dcb
--- /dev/null
+++ b/test/lid_sw.c
@@ -0,0 +1,127 @@
+/* Copyright (c) 2013 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.
+ *
+ * Test lid switch.
+ */
+
+#include "common.h"
+#include "console.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "lid_switch.h"
+#include "timer.h"
+#include "util.h"
+
+static int error_count;
+
+static int mock_lid;
+static int lid_hook_count;
+
+#define RUN_TEST(n) \
+ do { \
+ ccprintf("Running %s...", #n); \
+ cflush(); \
+ if (n() == EC_SUCCESS) { \
+ ccputs("OK\n"); \
+ } else { \
+ ccputs("Fail\n"); \
+ error_count++; \
+ } \
+ } while (0)
+
+#define TEST_ASSERT(n) \
+ do { \
+ if (!(n)) \
+ return EC_ERROR_UNKNOWN; \
+ } while (0)
+
+int gpio_get_level(enum gpio_signal signal)
+{
+ if (signal == GPIO_LID_OPEN)
+ return mock_lid;
+ return 0;
+}
+
+static void lid_change_hook(void)
+{
+ lid_hook_count++;
+}
+DECLARE_HOOK(HOOK_LID_CHANGE, lid_change_hook, HOOK_PRIO_DEFAULT);
+
+static int test_hook(void)
+{
+ /* Close lid for testing */
+ mock_lid = 0;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(100);
+ lid_hook_count = 0;
+ host_clear_events(0xffffffff);
+
+ mock_lid = 1;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(50);
+ TEST_ASSERT(lid_hook_count == 1);
+ TEST_ASSERT(lid_is_open());
+ TEST_ASSERT(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN));
+
+ mock_lid = 0;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(50);
+ TEST_ASSERT(lid_hook_count == 2);
+ TEST_ASSERT(!lid_is_open());
+ TEST_ASSERT(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED));
+
+ return EC_SUCCESS;
+}
+
+static int test_debounce(void)
+{
+ /* Close lid for testing */
+ mock_lid = 0;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(100);
+ lid_hook_count = 0;
+ host_clear_events(0xffffffff);
+
+ mock_lid = 1;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(20);
+ TEST_ASSERT(lid_hook_count == 0);
+ TEST_ASSERT(!lid_is_open());
+ TEST_ASSERT(!(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)));
+
+ mock_lid = 0;
+ lid_interrupt(GPIO_LID_OPEN);
+ msleep(50);
+ TEST_ASSERT(lid_hook_count == 0);
+ TEST_ASSERT(!lid_is_open());
+ TEST_ASSERT(!(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)));
+
+ return EC_SUCCESS;
+}
+
+void run_test(void)
+{
+ error_count = 0;
+
+ RUN_TEST(test_hook);
+ RUN_TEST(test_debounce);
+
+ if (error_count)
+ ccprintf("Fail!\n", error_count);
+ else
+ ccprintf("Pass!\n");
+}
+
+static int command_run_test(int argc, char **argv)
+{
+ run_test();
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
+ NULL, NULL, NULL);