summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-05-25 06:24:38 (GMT)
committerGerrit <chrome-bot@google.com>2012-05-28 08:10:02 (GMT)
commitc816085154b735e8706deb417bede13a051ee32d (patch)
tree8e6116acf32f548facb4b5ef102c010022153b9d
parentd4fcefa67bb727ee71934dd478dec36d88a265bc (diff)
downloadautotest-c816085154b735e8706deb417bede13a051ee32d.tar.gz
autotest-c816085154b735e8706deb417bede13a051ee32d.tar.xz
Add a test of EC lid switch handling
This test includes: - Check lid open wakes DUT from G3 and S5 - Check lid open/close doesn't send power button keycode - Check lid open/close controls keyboard backlight accordingly BUG=chrome-os-partner:9188 TEST=Test passed. Change-Id: I07e72dc8679d406abb2db47780139ee1b07c82cd Reviewed-on: https://gerrit.chromium.org/gerrit/23628 Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org> Commit-Ready: Vic Yang <victoryang@chromium.org>
-rw-r--r--server/site_tests/firmware_ECLidSwitch/control28
-rw-r--r--server/site_tests/firmware_ECLidSwitch/firmware_ECLidSwitch.py201
2 files changed, 229 insertions, 0 deletions
diff --git a/server/site_tests/firmware_ECLidSwitch/control b/server/site_tests/firmware_ECLidSwitch/control
new file mode 100644
index 0000000..1a8048e
--- /dev/null
+++ b/server/site_tests/firmware_ECLidSwitch/control
@@ -0,0 +1,28 @@
+# Copyright (c) 2012 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.
+
+AUTHOR = "Chrome OS Team"
+NAME = "firmware_ECLidSwitch"
+PURPOSE = "Servo based EC lid switch functional test"
+CRITERIA = "This test will fail if EC lid switch misbehalved."
+TIME = "LONG"
+TEST_CATEGORY = "Functional"
+TEST_CLASS = "firmware"
+TEST_TYPE = "server"
+
+DOC = """
+This test check the functionality of EC lid switch handling. This includes:
+ - Wake system from G3 (shutdown for more than 10 sec)
+ - Wake system from S5 (shutdown for less than 10 sec)
+ - Check no power button keycode is sent in S0 when lid close
+ - Check keyboard backlight is switched off when lid close in S0
+ - Check keyboard backlight is switched on when lid open in S0
+"""
+
+def run_eclidswitch(machine):
+ host = hosts.create_host(machine)
+ job.run_test("firmware_ECLidSwitch", host=host, cmdline_args=args,
+ use_faft=True, disable_sysinfo=True)
+
+parallel_simple(run_eclidswitch, machines)
diff --git a/server/site_tests/firmware_ECLidSwitch/firmware_ECLidSwitch.py b/server/site_tests/firmware_ECLidSwitch/firmware_ECLidSwitch.py
new file mode 100644
index 0000000..26ebd13
--- /dev/null
+++ b/server/site_tests/firmware_ECLidSwitch/firmware_ECLidSwitch.py
@@ -0,0 +1,201 @@
+# Copyright (c) 2012 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.
+
+from threading import Timer
+import re
+import time
+
+from autotest_lib.client.common_lib import error
+from autotest_lib.server.cros.faftsequence import FAFTSequence
+
+def delayed(seconds):
+ def decorator(f):
+ def wrapper(*args, **kargs):
+ t = Timer(seconds, f, args, kargs)
+ t.start()
+ return wrapper
+ return decorator
+
+
+class firmware_ECLidSwitch(FAFTSequence):
+ """
+ Servo based EC lid switch test.
+ """
+ version = 1
+
+
+ # Delay between closing and opening the lid
+ LID_DELAY = 1
+
+ # Delay to allow FAFT client receive command
+ RPC_DELAY = 2
+
+ # Delay between shutdown and wake by lid switch including kernel
+ # shutdown time
+ LONG_WAKE_DELAY = 25
+ SHORT_WAKE_DELAY = 15
+
+
+ def _open_lid(self):
+ """Open lid by servo."""
+ self.servo.set('lid_open', 'yes')
+
+
+ def _close_lid(self):
+ """Close lid by servo."""
+ self.servo.set('lid_open', 'no')
+
+
+ @delayed(RPC_DELAY)
+ def delayed_open_lid(self):
+ """Delay by RPC_DELAY and then open lid by servo."""
+ self._open_lid()
+
+
+ @delayed(RPC_DELAY)
+ def delayed_close_lid(self):
+ """Delay by RPC_DELAY and then close lid by servo."""
+ self._close_lid()
+
+
+ def _wake_by_lid_switch(self):
+ """Wake DUT with lid switch."""
+ self._close_lid()
+ time.sleep(self.LID_DELAY)
+ self._open_lid()
+
+
+ @delayed(LONG_WAKE_DELAY)
+ def long_delayed_wake(self):
+ """Delay for LONG_WAKE_DELAY and then wake DUT with lid switch."""
+ self._wake_by_lid_switch()
+
+
+ @delayed(SHORT_WAKE_DELAY)
+ def short_delayed_wake(self):
+ """Delay for SHORT_WAKE_DELAY and then wake DUT with lid switch."""
+ self._wake_by_lid_switch()
+
+
+ def shutdown_and_wake(self, wake_func):
+ """Software shutdown and delay. Then wake by lid switch.
+
+ Args:
+ wake_func: Delayed function to wake DUT.
+ """
+ self.faft_client.run_shell_command('shutdown -P now')
+ wake_func()
+
+
+ def _get_keyboard_backlight(self):
+ """Get keyboard backlight brightness.
+
+ Returns:
+ Backlight brightness percentage 0~100. If it is disabled, 0 is
+ returned.
+ """
+ cmd = 'ectool pwmgetkblight'
+ pattern_percent = re.compile(
+ 'Current keyboard backlight percent: (\d*)')
+ pattern_disable = re.compile('Keyboard backlight disabled.')
+ lines = self.faft_client.run_shell_command_get_output(cmd)
+ for line in lines:
+ matched_percent = pattern_percent.match(line)
+ if matched_percent is not None:
+ return int(matched_percent.group(1))
+ matched_disable = pattern_disable.match(line)
+ if matched_disable is not None:
+ return 0
+ raise error.TestError('Cannot get keyboard backlight status.')
+
+
+ def _set_keyboard_backlight(self, value):
+ """Set keyboard backlight brightness.
+
+ Args:
+ value: Backlight brightness percentage 0~100.
+ """
+ cmd = 'ectool pwmsetkblight %d' % value
+ self.faft_client.run_shell_command(cmd)
+
+
+ def check_keycode(self):
+ """Check if lid open/close send power button keycode.
+
+ Returns:
+ True if no power button keycode is captured. Otherwise, False.
+ """
+ cmd = 'showkey | grep "keycode 116" | wc -l'
+
+ self._open_lid()
+ self.delayed_close_lid()
+ lines = self.faft_client.run_shell_command_get_output(cmd)
+ if int(lines[0].strip()) != 0:
+ logging.error("Captured power button keycode on lid close.")
+ self._open_lid()
+ return False
+ self.delayed_open_lid()
+ lines = self.faft_client.run_shell_command_get_output(cmd)
+ if int(lines[0].strip()) != 0:
+ logging.error("Captured power button keycode on lid close.")
+ return False
+ return True
+
+
+ def check_backlight(self):
+ """Check if lid open/close controls keyboard backlight as expected.
+
+ Returns:
+ True if keyboard backlight is turned off when lid close and on when
+ lid open.
+ """
+ ok = True
+ original_value = self._get_keyboard_backlight()
+ self._set_keyboard_backlight(100)
+
+ self._close_lid()
+ if self._get_keyboard_backlight() != 0:
+ logging.error("Keyboard backlight still on when lid close.")
+ ok = False
+ self._open_lid()
+ if self._get_keyboard_backlight() == 0:
+ logging.error("Keyboard backlight still off when lid open.")
+ ok = False
+
+ self._set_keyboard_backlight(original_value)
+ return ok
+
+
+ def check_keycode_and_backlight(self):
+ """
+ Disable powerd to prevent DUT shutting down dutring test. Then check
+ if lid switch event controls keycode and backlight as we expected.
+ """
+ ok = True
+ self.faft_client.run_shell_command('stop powerd')
+ if not self.check_keycode():
+ logging.error("check_keycode failed.")
+ ok = False
+ if not self.check_backlight():
+ logging.error("check_backlight failed.")
+ ok = False
+ self.faft_client.run_shell_command('start powerd')
+ return ok
+
+
+ def run_once(self, host=None):
+ self.register_faft_sequence((
+ { # Step 1, shutdown and long delayed wake
+ 'reboot_action': (self.shutdown_and_wake,
+ self.long_delayed_wake),
+ },
+ { # Step 2, shutdown and short delayed wake
+ 'reboot_action': (self.shutdown_and_wake,
+ self.short_delayed_wake),
+ },
+ { # Step 3, check keycode and backlight
+ 'state_checker': self.check_keycode_and_backlight
+ }
+ ))
+ self.run_faft_sequence()