OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import time | 5 import os, logging, platform, time |
petkov
2010/11/24 20:36:53
sort
thieule
2010/11/30 23:05:08
Done.
| |
6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
7 | 7 |
8 | 8 |
9 class TimeoutError(error.TestError): | 9 class TimeoutError(error.TestError): |
10 """Error raised when we time out when waiting on a condition.""" | 10 """Error raised when we time out when waiting on a condition.""" |
11 | 11 |
12 | 12 |
13 def poll_for_condition( | 13 def poll_for_condition( |
14 condition, exception=None, timeout=10, sleep_interval=0.1, desc=None): | 14 condition, exception=None, timeout=10, sleep_interval=0.1, desc=None): |
15 """Poll until a condition becomes true. | 15 """Poll until a condition becomes true. |
(...skipping 15 matching lines...) Expand all Loading... | |
31 if exception: | 31 if exception: |
32 raise exception | 32 raise exception |
33 | 33 |
34 if desc: | 34 if desc: |
35 desc = 'Timed out waiting for condition: %s' % desc | 35 desc = 'Timed out waiting for condition: %s' % desc |
36 else: | 36 else: |
37 desc = 'Timed out waiting for unnamed condition' | 37 desc = 'Timed out waiting for unnamed condition' |
38 raise TimeoutError, desc | 38 raise TimeoutError, desc |
39 | 39 |
40 time.sleep(sleep_interval) | 40 time.sleep(sleep_interval) |
41 | |
42 | |
43 def save_vm_state(checkpoint): | |
44 """Saves the current state of the virtual machine | |
petkov
2010/11/24 20:36:53
period
thieule
2010/11/30 23:05:08
Done.
| |
45 | |
46 This function is a NOOP if the test is not running under a virtual machine | |
47 with the USB serial port redirected. | |
48 | |
49 Arguments: | |
50 checkpoint - Name used to identify this state | |
51 | |
52 Returns: | |
53 None | |
54 """ | |
55 # The QEMU monitor has been redirected to the guest serial port located at | |
56 # /dev/ttyUSB0. To save the state of the VM, we just send the 'savevm' | |
57 # command to the serial port. | |
58 proc = platform.processor() | |
59 if proc.find('QEMU') >= 0 and os.path.exists('/dev/ttyUSB0'): | |
petkov
2010/11/24 20:36:53
'QEMU' in proc?
thieule
2010/11/30 23:05:08
I was a bit surprised myself as well to find pytho
| |
60 logging.info('Saving VM state "%s"' % checkpoint) | |
61 serial = open('/dev/ttyUSB0', 'w') | |
62 serial.write("savevm %s\r\n" % checkpoint) | |
63 logging.info('Done saving VM state "%s"' % checkpoint) | |
OLD | NEW |