| Index: client/common_lib/utils.py
|
| diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
|
| index 47f3cb4c2e11d32a7331f6d12fbc448a6ee09b7f..caba7a8a32f2fab18d1a08a2711262b2152f7f71 100644
|
| --- a/client/common_lib/utils.py
|
| +++ b/client/common_lib/utils.py
|
| @@ -2,7 +2,7 @@
|
| # Copyright 2008 Google Inc. Released under the GPL v2
|
|
|
| import os, pickle, random, re, resource, select, shutil, signal, StringIO
|
| -import socket, struct, subprocess, sys, time, textwrap, urlparse
|
| +import socket, struct, subprocess, sys, time, textwrap, urlparse, platform
|
| import warnings, smtplib, logging, urllib2
|
| from threading import Thread, Event
|
| try:
|
| @@ -1708,3 +1708,26 @@ def get_unused_port():
|
| # Check if this port is unused on the other protocol.
|
| if port and try_bind(port, socket.SOCK_DGRAM, socket.IPPROTO_UDP):
|
| return port
|
| +
|
| +
|
| +def save_vm_state(checkpoint):
|
| + """Saves the current state of the virtual machine
|
| +
|
| + This function is a NOOP if the test is not running under a virtual machine
|
| + with the USB serial port redirected.
|
| +
|
| + Arguments:
|
| + checkpoint - Name used to identify this state
|
| +
|
| + Returns:
|
| + None
|
| + """
|
| + # The QEMU monitor has been redirected to the guest serial port located at
|
| + # /dev/ttyUSB0. To save the state of the VM, we just send the 'savevm'
|
| + # command to the serial port.
|
| + proc = platform.processor()
|
| + if proc.find('QEMU') >= 0 and os.path.exists('/dev/ttyUSB0'):
|
| + logging.info('Saving VM state "%s"' % checkpoint)
|
| + serial = open('/dev/ttyUSB0', 'w')
|
| + serial.write("savevm %s\r\n" % checkpoint)
|
| + logging.info('Done saving VM state "%s"' % checkpoint)
|
|
|