blob: 4d4f94b8ce9b30e23a78bb3cb206fc335b54369e [file] [log] [blame]
# Copyright (c) 2011 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.
# This test isn't really HW specific. It's testing /dev/watchdog API
# to make sure it works as expected. The most robust implementations is
# based on real HW but it doesn't have to be.
import logging, os
# http://docs.python.org/2/library/errno.html
import errno
from autotest_lib.client.common_lib import error
from autotest_lib.server import test
class platform_HWwatchdog(test.test):
version = 1
def _stop_watchdog(self, wd_dev):
# HW watchdog is open and closed "properly".
try:
self.client.run('echo "V" > %s' % wd_dev);
except error.AutoservRunError, e:
raise error.TestError('write to %s failed (%s)' %
(wd_dev, errno.errorcode[e.errno]))
def _trig_watchdog(self, wd_dev):
# Test the machine will reboot if HW watchdog is open but NOT pet.
try:
self.client.run('echo "z" > %s' % wd_dev);
except error.AutoservRunError, e:
raise error.TestError('write to %s failed (%s)' %
(wd_dev, errno.errorcode[e.errno]))
logging.info("KernelHWpath: tickled watchdog on %s" %
self.client.hostname)
# machine should became unpingable after lockup
if not self.client.wait_down(timeout=30):
raise error.TestError('machine should be unpingable'
'within 30 seconds')
# make sure the machine comes back,
# DHCP can take up to 45 seconds in odd cases.
if not self.client.wait_up(timeout=60):
raise error.TestError('machine did not reboot/ping within'
'60 seconds of HW reset')
def _exists_on_client(self, wd_dev):
return self.client.run('test -c "%s"' % wd_dev,
ignore_status=True).exit_status == 0
# If daisydog is running, stop it so we can use /dev/watchdog
def _stop_daemon(self):
"""If running, stop daisydog so we can use /dev/watchdog."""
self.client.run('stop daisydog', ignore_status=True)
def _start_daemon(self):
self.client.run('start daisydog', ignore_status=True)
def run_once(self, host=None):
self.client = host
wd_dev = '/dev/watchdog'
# If watchdog not present, just skip this test
if not self._exists_on_client(wd_dev):
logging.info("INFO: %s not present. Skipping test." % wd_dev)
return
self._stop_daemon()
self._stop_watchdog(wd_dev)
self._trig_watchdog(wd_dev)
self._start_daemon()