1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6import os 7 8from autotest_lib.client.bin import utils 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.cros import touch_playback_test_base 11 12 13class touch_WakeupSource(touch_playback_test_base.touch_playback_test_base): 14 """Check that touchpad/touchscreen are set/not set as wake sources.""" 15 version = 1 16 17 # Devices whose touchpads should not be a wake source. 18 # 19 # Note, starting with octopus platform, convertibles should enable touchpad 20 # wake. If you wish to enable on previous devices, see furquan@ doc 21 # go/cros-trackpad-wake and/or consult chromeos-platform-power@ for more 22 # details. 23 _NO_TOUCHPAD_WAKE = ['clapper', 'glimmer', 'veyron_minnie', 'caroline', 24 'eve', 'kevin', 'pyro'] 25 26 # Devices with Synaptics touchpads that do not report wake source, 27 # or reference platforms like Rambi which are broken but do not ship, 28 # or devices like Cyan which don't report this way: crosbug.com/p/46019. 29 _INVALID_TOUCHPADS = ['x86-alex', 'x86-alex_he', 'x86-zgb', 'x86-zgb_he', 30 'x86-mario', 'stout', 'rambi', 'cyan'] 31 _INVALID_TOUCHSCREENS = ['cyan', 'sumo', 'ultima'] 32 33 def _find_wakeup_file(self, input_type): 34 """Return path to wakeup file or None. 35 36 If the file does not exist, check the parent bus for wakeup rules 37 as well, as is the setup for some devices. 38 39 @param input_type: e.g. 'touchpad' or 'mouse'. See parent class for 40 all options. 41 42 @raises: TestError if input_type lacks required information. 43 44 """ 45 device_dir = self.player.devices[input_type].device_dir 46 if not device_dir: 47 raise error.TestError('No device directory for %s!' % input_type) 48 49 filename = os.path.join(device_dir, 'power', 'wakeup') 50 if not os.path.isfile(filename): 51 logging.info('%s not found for %s', filename, input_type) 52 53 # Look for wakeup file on parent bus instead. 54 event = self.player.devices[input_type].node.split('/')[-1] 55 56 parent = None 57 i2c_devices_dir = os.path.join('/', 'sys', 'bus', 'i2c', 'devices') 58 for device_dir in os.listdir(i2c_devices_dir): 59 event_search = os.path.join(i2c_devices_dir, device_dir, '*', 60 'input', 'input*', event) 61 match_count = utils.run('ls %s 2>/dev/null | wc -l' % ( 62 event_search)).stdout.strip() 63 if int(match_count) > 0: 64 parent = os.path.join(i2c_devices_dir, device_dir) 65 break 66 if parent is None: 67 logging.info('Could not find parent bus for %s.', input_type) 68 return None 69 70 logging.info('Parent bus of %s is %s.', input_type, parent) 71 filename = os.path.join(parent, 'power', 'wakeup') 72 if not os.path.isfile(filename): 73 logging.info('%s not found either.', filename) 74 return None 75 76 return filename 77 78 def _is_wake_source(self, input_type): 79 """Return True if the given device is a wake source, else False. 80 81 If the file does not exist, return False. 82 83 @param input_type: e.g. 'touchpad' or 'mouse'. See parent class for 84 all options. 85 86 @raises: TestError if test cannot interpret the file contents. 87 88 """ 89 filename = self._find_wakeup_file(input_type) 90 if filename is None: 91 return False 92 93 result = utils.run('cat %s' % filename).stdout.strip() 94 if result == 'enabled': 95 logging.info('Found that %s is a wake source.', input_type) 96 return True 97 elif result == 'disabled': 98 logging.info('Found that %s is not a wake source.', input_type) 99 return False 100 raise error.TestError('Wakeup file for %s said "%s".' % 101 (input_type, result)) 102 103 def run_once(self): 104 """Entry point of this test.""" 105 # Check that touchpad is a wake source for all but the excepted boards. 106 if (self._has_touchpad and 107 self._platform not in self._INVALID_TOUCHPADS): 108 if self._platform in self._NO_TOUCHPAD_WAKE: 109 if self._is_wake_source('touchpad'): 110 raise error.TestFail('Touchpad is a wake source!') 111 else: 112 if not self._is_wake_source('touchpad'): 113 raise error.TestFail('Touchpad is not a wake source!') 114 115 # Check that touchscreen is not a wake source (if present). 116 # Devices without a touchpad should have touchscreen as wake source. 117 if (self._has_touchscreen and 118 self._platform not in self._INVALID_TOUCHSCREENS): 119 touchscreen_wake = self._is_wake_source('touchscreen') 120 if self._has_touchpad and touchscreen_wake: 121 raise error.TestFail('Touchscreen is a wake source!') 122 if not self._has_touchpad and not touchscreen_wake: 123 raise error.TestFail('Touchscreen is not a wake source!') 124 125