aboutsummaryrefslogtreecommitdiff
path: root/client/site_tests/touch_WakeupSource/touch_WakeupSource.py
blob: 2a8eb3fa2efe8437b22506ac1c0cee39aee83368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright (c) 2014 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.

import logging
import os

from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib.cros import cros_config
from autotest_lib.client.cros import touch_playback_test_base


class touch_WakeupSource(touch_playback_test_base.touch_playback_test_base):
    """Check that touchpad/touchscreen are set/not set as wake sources."""
    version = 1

    # Devices whose touchpads should not be a wake source.
    #
    # Note, starting with octopus platform, convertibles should enable touchpad
    # wake.  If you  wish to enable on previous devices, see furquan@ doc
    # go/cros-trackpad-wake and/or consult chromeos-platform-power@ for more
    # details.
    _NO_TOUCHPAD_WAKE = [
            'caroline', 'clapper', 'elm', 'glimmer', 'hana', 'kevin', 'kukui',
            'pyro', 'veyron_minnie'
    ]
    _TOUCHPAD_WAKE_SET_BY_CROS_CONFIG = ['coral', 'nami']

    # Devices with Synaptics touchpads that do not report wake source,
    # or reference platforms like Rambi which are broken but do not ship,
    # or devices like Cyan which don't report this way: crosbug.com/p/46019.
    _INVALID_TOUCHPADS = ['x86-alex', 'x86-alex_he', 'x86-zgb', 'x86-zgb_he',
                          'x86-mario', 'stout', 'rambi', 'cyan']
    _INVALID_TOUCHSCREENS = ['cyan', 'nocturne', 'sumo', 'ultima']

    def _touchpad_should_be_wake_source(self):
        base_platform = self._platform.replace('-kernelnext', '')
        if base_platform in self._NO_TOUCHPAD_WAKE:
            return False
        if (base_platform in self._TOUCHPAD_WAKE_SET_BY_CROS_CONFIG
                    and cros_config.call_cros_config_get_output(
                            '/power touchpad-wakeup', utils.run) == '0'):
            return False
        return True

    def _find_wakeup_file(self, input_type):
        """Return path to wakeup file or None.

        If the file does not exist, check the parent bus for wakeup rules
        as well, as is the setup for some devices.

        @param input_type: e.g. 'touchpad' or 'mouse'. See parent class for
                all options.

        @raises: TestError if input_type lacks required information.

        """
        device_dir = self.player.devices[input_type].device_dir
        if not device_dir:
            raise error.TestError('No device directory for %s!' % input_type)

        filename = os.path.join(device_dir, 'power', 'wakeup')
        if not os.path.isfile(filename):
            logging.info('%s not found for %s', filename, input_type)

            # Look for wakeup file on parent bus instead.
            event = self.player.devices[input_type].node.split('/')[-1]

            parent = None
            i2c_devices_dir = os.path.join('/', 'sys', 'bus', 'i2c', 'devices')
            for device_dir in os.listdir(i2c_devices_dir):
                event_search = os.path.join(i2c_devices_dir, device_dir, '*',
                                            'input', 'input*', event)
                match_count = utils.run('ls %s 2>/dev/null | wc -l' % (
                        event_search)).stdout.strip()
                if int(match_count) > 0:
                    parent = os.path.join(i2c_devices_dir, device_dir)
                    break
            if parent is None:
                logging.info('Could not find parent bus for %s.', input_type)
                return None

            logging.info('Parent bus of %s is %s.', input_type, parent)
            filename = os.path.join(parent, 'power', 'wakeup')
            if not os.path.isfile(filename):
                logging.info('%s not found either.', filename)
                return None

        return filename

    def _is_wake_source(self, input_type):
        """Return True if the given device is a wake source, else False.

        If the file does not exist, return False.

        @param input_type: e.g. 'touchpad' or 'mouse'. See parent class for
                all options.

        @raises: TestError if test cannot interpret the file contents.

        """
        filename = self._find_wakeup_file(input_type)
        if filename is None:
            return False

        result = utils.run('cat %s' % filename).stdout.strip()
        if result == 'enabled':
            logging.info('Found that %s is a wake source.', input_type)
            return True
        elif result == 'disabled':
            logging.info('Found that %s is not a wake source.', input_type)
            return False
        raise error.TestError('Wakeup file for %s said "%s".' %
                              (input_type, result))

    def run_once(self, source):
        """Entry point of this test."""

        # Check that touchpad is a wake source for all but the excepted boards.
        if source == 'touchpad':
            if (self._has_touchpad and
                self._platform not in self._INVALID_TOUCHPADS):
                if self._touchpad_should_be_wake_source():
                    if not self._is_wake_source('touchpad'):
                        raise error.TestFail('Touchpad is not a wake source!')
                else:
                    if self._is_wake_source('touchpad'):
                        raise error.TestFail('Touchpad is a wake source!')

        # Check that touchscreen is not a wake source (if present).
        # Devices without a touchpad should have touchscreen as wake source.
        if source == 'touchscreen':
            if (self._has_touchscreen and
                self._platform not in self._INVALID_TOUCHSCREENS):
                touchscreen_wake = self._is_wake_source('touchscreen')
                if self._has_touchpad and touchscreen_wake:
                    raise error.TestFail('Touchscreen is a wake source!')
                if not self._has_touchpad and not touchscreen_wake:
                    raise error.TestFail('Touchscreen is not a wake source!')