blob: 465dff32d75493459246b3e20e78e91015f2b4ec [file] [log] [blame]
Craig Harrison2b6c6fc2011-06-23 10:34:02 -07001# Copyright (c) 2011 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 subprocess
6
7from autotest_lib.server import test, autotest
8import autotest_lib.server.cros.servo
9
10class ServoTest(test.test):
11 """AutoTest test class that creates and destroys a servo object.
12
13 Servo-based server side AutoTests can inherit from this object.
14 """
15 version = 1
16 servo = None
17 _ip = None
18
19
Todd Broch5fd6bc02011-07-20 15:53:37 -070020 def initialize(self, host, servo_port, xml_config='servo.xml',
21 servo_vid=None, servo_pid=None, servo_serial=None):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070022 """Create a Servo object."""
23 self.servo = autotest_lib.server.cros.servo.Servo(servo_port,
Todd Broch5fd6bc02011-07-20 15:53:37 -070024 xml_config,
25 servo_vid,
26 servo_pid,
27 servo_serial)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070028 self._ip = host.ip
29
30
31 def assert_ping(self):
32 """Ping to assert that the device is up."""
33 assert self.ping_test(self._ip)
34
35
36 def assert_pingfail(self):
37 """Ping to assert that the device is down."""
38 assert not self.ping_test(self._ip)
39
40
41 def ping_test(self, hostname, timeout=5):
42 """Verify whether a host responds to a ping.
43
44 Args:
45 hostname: Hostname to ping.
46 timeout: Time in seconds to wait for a response.
47 """
48 return subprocess.call(['ping', '-c', '1', '-W',
49 str(timeout), hostname]) == 0
50
51
52 def cleanup(self):
53 """Delete the Servo object."""
54 del self.servo