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