1# Copyright (c) 2009 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
5from __future__ import print_function
6
7import logging
8from autotest_lib.client.common_lib import error
9from autotest_lib.server import test, autotest
10
11
12class platform_TrackpadStressServer(test.test):
13    """
14    Make sure the trackpad continues to operate after a kernel panic.
15    """
16    version = 1
17
18    def _run_client_test(self, client_at, verify_only=False):
19        self.job.set_state('client_passed', None)
20        client_at.run_test(self.client_test)
21        return self.job.get_state('client_passed')
22
23    def run_once(self, host=None):
24        self.client = host
25        self.client_test = 'platform_TrackpadStress'
26
27        logging.info('TrackpadStressServer: start client test')
28        client_at = autotest.Autotest(self.client)
29        if not self._run_client_test(client_at):
30            raise error.TestFail('Client test failed precheck state')
31
32        # Configure the client to reboot on a kernel panic
33        self.client.run('sysctl kernel.panic|grep "kernel.panic = -1"')
34        self.client.run('sysctl kernel.panic_on_oops|'
35                        'grep "kernel.panic_on_oops = 1"')
36
37        boot_id = self.client.get_boot_id()
38
39        # Make it rain
40        command  = 'echo BUG > /sys/kernel/debug/provoke-crash/DIRECT'
41        command += '|| echo bug > /proc/breakme'
42        logging.info('TrackpadStressServer: executing "%s" on %s',
43                     command, self.client.hostname)
44        try:
45            # Simply writing to the crash interface resets the target
46            # immediately, leaving files unsaved to disk and the master ssh
47            # connection wedged for a long time.
48            self.client.run(
49                'sh -c "sync; sleep 1; %s" >/dev/null 2>&1 &' % command)
50        except error.AutoservRunError as e:
51            # It is expected that this will cause a non-zero exit status.
52            pass
53
54        self.client.wait_for_restart(
55                    down_timeout=60,
56                    down_warning=60,
57                    old_boot_id=boot_id,
58                    # Extend the default reboot timeout as some targets take
59                    # longer than normal before ssh is available again.
60                    timeout=self.client.DEFAULT_REBOOT_TIMEOUT * 4)
61
62        # Check that the trackpad is running
63        # Todo, need an additional client test.
64        if not self._run_client_test(client_at, verify_only=True):
65            raise error.TestFail('Client test failed final state verification.'
66                                 'The trackpad is not running after kernel '
67                                 'panic.')
68
69
70