summaryrefslogtreecommitdiff
path: root/test/power_button.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-09 07:44:36 +0800
committerChromeBot <chrome-bot@google.com>2013-05-08 18:11:01 -0700
commitd2ca284bc6da637aabb0dbfd4a4d67451646f23a (patch)
tree842d6508167f568b32b7c524167c093aa7a71b85 /test/power_button.c
parente71f008388b3c69cf01a534c5084d7e3a441149b (diff)
downloadchrome-ec-d2ca284bc6da637aabb0dbfd4a4d67451646f23a.tar.gz
Add power button test
This tests power button notification and debouncing. BUG=chrome-os-partner:19236 TEST=Pass all tests BRANCH=None Change-Id: Ief8bc24a8725e01734d84e76ab4b6ae0506b811f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50524 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test/power_button.c')
-rw-r--r--test/power_button.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/power_button.c b/test/power_button.c
new file mode 100644
index 0000000000..7ed2211cc6
--- /dev/null
+++ b/test/power_button.c
@@ -0,0 +1,104 @@
+/* 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 "power_button.h"
+#include "test_util.h"
+#include "timer.h"
+#include "util.h"
+
+static int mock_power_button = 1;
+static int mock_lid = 1;
+static int pb_hook_count;
+
+int gpio_get_level(enum gpio_signal signal)
+{
+ if (signal == GPIO_POWER_BUTTON_L)
+ return mock_power_button;
+ return 0;
+}
+
+int lid_is_open(void)
+{
+ return mock_lid;
+}
+
+static void pb_change_hook(void)
+{
+ pb_hook_count++;
+}
+DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, pb_change_hook, HOOK_PRIO_DEFAULT);
+
+static int test_hook(void)
+{
+ /* Release power button for testing */
+ mock_power_button = 1;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(100);
+ pb_hook_count = 0;
+ host_clear_events(0xffffffff);
+
+ mock_power_button = 0;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(50);
+ TEST_ASSERT(pb_hook_count == 1);
+ TEST_ASSERT(power_button_is_pressed());
+ TEST_ASSERT(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON));
+ host_clear_events(0xffffffff);
+
+ mock_power_button = 1;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(50);
+ TEST_ASSERT(pb_hook_count == 2);
+ TEST_ASSERT(!power_button_is_pressed());
+ TEST_ASSERT(!(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
+
+ return EC_SUCCESS;
+}
+
+static int test_debounce(void)
+{
+ /* Release power button for testing */
+ mock_power_button = 1;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(100);
+ pb_hook_count = 0;
+ host_clear_events(0xffffffff);
+
+ mock_power_button = 0;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(20);
+ TEST_ASSERT(pb_hook_count == 0);
+ TEST_ASSERT(!power_button_is_pressed());
+ TEST_ASSERT(!(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
+
+ mock_power_button = 1;
+ power_button_interrupt(GPIO_POWER_BUTTON_L);
+ msleep(50);
+ TEST_ASSERT(pb_hook_count == 0);
+ TEST_ASSERT(!power_button_is_pressed());
+ TEST_ASSERT(!(host_get_events() &
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON)));
+
+ return EC_SUCCESS;
+}
+
+void run_test(void)
+{
+ test_reset();
+
+ RUN_TEST(test_hook);
+ RUN_TEST(test_debounce);
+
+ test_print_result();
+}