summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/host/board.c1
-rw-r--r--board/host/board.h4
-rw-r--r--test/build.mk5
-rw-r--r--test/power_button.c104
-rw-r--r--test/power_button.py166
5 files changed, 111 insertions, 169 deletions
diff --git a/board/host/board.c b/board/host/board.c
index c646340534..5c1603767a 100644
--- a/board/host/board.c
+++ b/board/host/board.c
@@ -10,4 +10,5 @@
const struct gpio_info gpio_list[GPIO_COUNT] = {
{"EC_INT", 0, 0, 0, 0},
{"LID_OPEN", 0, 0, 0, 0},
+ {"POWER_BUTTON_L", 0, 0, 0, 0},
};
diff --git a/board/host/board.h b/board/host/board.h
index 1997a23a7e..154a49fa60 100644
--- a/board/host/board.h
+++ b/board/host/board.h
@@ -8,14 +8,16 @@
#ifndef __BOARD_H
#define __BOARD_H
-#define CONFIG_HOST_EMU
#define CONFIG_HOSTCMD
+#define CONFIG_HOST_EMU
#define CONFIG_KEYBOARD_PROTOCOL_MKBP
#define CONFIG_LID_SWITCH
+#define CONFIG_POWER_BUTTON
enum gpio_signal {
GPIO_EC_INT,
GPIO_LID_OPEN,
+ GPIO_POWER_BUTTON_L,
GPIO_COUNT
};
diff --git a/test/build.mk b/test/build.mk
index aa964a71fd..9121d03d1b 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -10,7 +10,7 @@ test-list-y=pingpong timer_calib timer_dos timer_jump mutex utils
#disable: powerdemo
# TODO(victoryang): Fix these tests:
-# thermal power_button scancode typematic charging
+# thermal scancode typematic charging
test-list-$(BOARD_bds)+=
test-list-$(BOARD_daisy)+=kb_scan flash stress
@@ -25,7 +25,7 @@ test-list-$(BOARD_link)=
test-list-$(BOARD_slippy)=
# Emulator tests
-test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw
+test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw power_button
flash-y=flash.o
kb_mkbp-y=kb_mkbp.o
@@ -33,6 +33,7 @@ kb_scan-y=kb_scan.o
lid_sw-y=lid_sw.o
mutex-y=mutex.o
pingpong-y=pingpong.o
+power_button-y=power_button.o
powerdemo-y=powerdemo.o
stress-y=stress.o
timer_calib-y=timer_calib.o
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();
+}
diff --git a/test/power_button.py b/test/power_button.py
deleted file mode 100644
index 0f5766ca96..0000000000
--- a/test/power_button.py
+++ /dev/null
@@ -1,166 +0,0 @@
-# Copyright (c) 2011 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.
-#
-# Power button debounce test
-#
-# Refer to section 1.3 Power Button of
-# https://sites.google.com/a/google.com/chromeos-partners/pages/
-# tech-docs/firmware/ec-specification-v119
-#
-
-import time
-
-SHORTER_THAN_T0 = 0.01
-LONGER_THAN_T0 = 0.05
-LONGER_THAN_T1 = 5
-
-def consume_output(helper, reg_ex):
- done = False
- while not done:
- try:
- helper.wait_output(reg_ex, use_re=True, timeout=1)
- except:
- done = True
-
-def test(helper):
- helper.wait_output("--- UART initialized")
- # Release power button, set to soft off, and enable keyboard
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.ec_command("powermock off")
- helper.ec_command("kbd enable")
- consume_output(helper, "PB released")
-
- helper.trace("Press power button for shorter than T0 and check this\n" +
- "event is ignored\n")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not helper.check_no_output("PB released"):
- return False
-
- helper.trace("Press power button for longer than T0 and check this\n" +
- "event is treated as a single press.")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("PB released", timeout=1)
- # Expect shown only once
- if not helper.check_no_output("PB released"):
- return False
-
- helper.trace("Press power button for two consecutive SHORTER_THAN_T0\n" +
- "period and check this event is ignored\n")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not helper.check_no_output("PB released"):
- return False
-
- helper.trace("Hold down power button for LONGER_THAN_T0 and check a\n" +
- "single press is sent out\n")
- consume_output(helper, "pwrbtn=")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("pwrbtn=LOW", timeout=1)
- helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not helper.check_no_output("pwrbtn=LOW"):
- return False
-
- helper.trace("Press power button for SHORTER_THAN_T0, release for\n" +
- "SHORTER_THAN_T0, and then press for LONGER_THAN_T0.\n" +
- "Check this is treated as a single press\n")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("pwrbtn=LOW", timeout=1)
- helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not helper.check_no_output("pwrbtn=LOW"):
- return False
-
- helper.trace("Hold down power button, wait for power button press\n" +
- "sent out. Then relase for SHORTER_THAN_T0, check power\n" +
- "button release is not sent out. Expect power button is\n" +
- "treated as hold (ignoring the relase bounce)\n")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- helper.wait_output("pwrbtn=LOW", timeout=1)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- time.sleep(SHORTER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- if not helper.check_no_output("PB released"):
- return False
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("PB released", timeout=1)
-
- helper.trace("When system is off, hold down power button for\n" +
- "LONGER_THAN_T0. Check the initial is stretched\n")
- consume_output(helper, "pwrbtn=")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- t_low = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=LOW\]",
- use_re=True)["t"]
- t_high = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=HIGH\]",
- use_re=True)["t"]
- if not helper.check_no_output("pwrbtn=LOW"):
- return False
- if float(t_high) - float(t_low) <= LONGER_THAN_T0 - 0.1:
- return False
-
- helper.trace("When system is off, hold down power button for\n" +
- "LONGER_THAN_T0. Check no scan code is send\n")
- consume_output(helper, "i8042 SEND")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- if not helper.check_no_output("i8042 SEND"):
- return False
-
- helper.trace("While powered on, hold down power button for\n" +
- "LONGER_THAN_T0. A single short pulse should be sent\n")
- consume_output(helper, "pwrbtn=")
- helper.ec_command("powermock on")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- t_low = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=LOW\]",
- use_re=True)["t"]
- t_high = helper.wait_output("\[(?P<t>[\d\.]+) PB PCH pwrbtn=HIGH\]",
- use_re=True)["t"]
- if not helper.check_no_output("pwrbtn=LOW"):
- return False
- if float(t_high) - float(t_low) >= 0.1:
- return False
-
- helper.trace("While powered on, hold down power button for\n" +
- "LONGER_THAN_T0. Scan code should be sent\n")
- consume_output(helper, "i8042 SEND")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- helper.wait_output("i8042 SEND", timeout=1) # Expect make code
- time.sleep(LONGER_THAN_T0)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("i8042 SEND", timeout=1) # Expect release code
-
- helper.trace("While powered on, hold down power button for\n" +
- "LONGER_THAN_T1 and check two presses are sent out\n")
- consume_output(helper, "pwrbtn=")
- helper.ec_command("gpiomock POWER_BUTTONn 0")
- time.sleep(LONGER_THAN_T1)
- helper.ec_command("gpiomock POWER_BUTTONn 1")
- helper.wait_output("pwrbtn=LOW", timeout=1)
- helper.wait_output("pwrbtn=HIGH", timeout=1)
- helper.wait_output("pwrbtn=LOW", timeout=1)
- helper.wait_output("pwrbtn=HIGH", timeout=1)
- if not helper.check_no_output("pwrbtn=LOW"):
- return False
-
- return True # PASS !