Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5406)

Unified Diff: client/common_lib/utils.py

Issue 5303005: Add support for saving VM state after test failure (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« client/common_lib/test.py ('K') | « client/common_lib/test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« client/common_lib/test.py ('K') | « client/common_lib/test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698