diff options
author | Vic Yang <victoryang@chromium.org> | 2012-06-17 15:51:00 +0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-25 07:15:52 -0700 |
commit | 7eabcb4e69aa5e19d92a8ab84806bc92377a82aa (patch) | |
tree | 95e03ad9edacaa8390f2c5a6b085843387206624 /test | |
parent | 7ae80c05522afb393eac816e5e4e9f3993e1b1ed (diff) | |
download | chrome-ec-7eabcb4e69aa5e19d92a8ab84806bc92377a82aa.tar.gz |
Add a test of checking power button handling
This test checks power button is correctly debounced, and also check
power button press of different length are handled correctly.
BUG=chrome-os-partner:10273
TEST=Test passed
Change-Id: I18595c60896255d36326731d28bab55e64c6bca2
Reviewed-on: https://gerrit.chromium.org/gerrit/25505
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 7 | ||||
-rw-r--r-- | test/power_button.py | 174 | ||||
-rw-r--r-- | test/power_button.tasklist | 24 |
3 files changed, 205 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 2ad8df6c4f..e4ca8341c2 100644 --- a/test/build.mk +++ b/test/build.mk @@ -7,6 +7,7 @@ # test-list=hello pingpong timer_calib timer_dos timer_jump mutex thermal +test-list+=power_button #disable: powerdemo pingpong-y=pingpong.o @@ -20,3 +21,9 @@ chip-mock-thermal-lpc.o=mock_lpc.o chip-mock-thermal-pwm.o=mock_pwm.o common-mock-thermal-x86_power.o=mock_x86_power.o common-mock-thermal-temp_sensor.o=mock_temp_sensor.o + +# Mock modules for 'power_button' +chip-mock-power_button-gpio.o=mock_gpio.o +chip-mock-power_button-pwm.o=mock_pwm.o +common-mock-power_button-x86_power.o=mock_x86_power.o +common-mock-power_button-i8042.o=mock_i8042.o diff --git a/test/power_button.py b/test/power_button.py new file mode 100644 index 0000000000..7f5c3b9fb0 --- /dev/null +++ b/test/power_button.py @@ -0,0 +1,174 @@ +# 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 check_no_output(helper, reg_ex): + success = False + try: + helper.wait_output(reg_ex, use_re=True, timeout=1) + except: + success = True + return success + +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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "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 check_no_output(helper, "pwrbtn=LOW"): + return False + + return True # PASS ! diff --git a/test/power_button.tasklist b/test/power_button.tasklist new file mode 100644 index 0000000000..293d200041 --- /dev/null +++ b/test/power_button.tasklist @@ -0,0 +1,24 @@ +/* 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. + */ + +/** + * List of enabled tasks in the priority order + * + * The first one has the lowest priority. + * + * For each task, use the macro TASK(n, r, d) where : + * 'n' in the name of the task + * 'r' in the main routine of the task + * 'd' in an opaque parameter passed to the routine at startup + */ +#define CONFIG_TASK_LIST \ + TASK(WATCHDOG, watchdog_task, NULL) \ + TASK(PWM, pwm_task, NULL) \ + TASK(TYPEMATIC, keyboard_typematic_task, NULL) \ + TASK(X86POWER, x86_power_task, NULL) \ + TASK(I8042CMD, i8042_command_task, NULL) \ + TASK(POWERBTN, power_button_task, NULL) \ + TASK(KEYSCAN, keyboard_scan_task, NULL) \ + TASK(CONSOLE, console_task, NULL) |