Index: bin/cros_run_vm_test |
diff --git a/bin/cros_run_vm_test b/bin/cros_run_vm_test |
index d62a2b98524fadc489971677df2df893e1be18bc..d6aa81a1303d37de2e475ff68e23786e01e3627d 100755 |
--- a/bin/cros_run_vm_test |
+++ b/bin/cros_run_vm_test |
@@ -18,6 +18,10 @@ DEFINE_string board "$DEFAULT_BOARD" \ |
"The board for which you built autotest." b |
DEFINE_string image_path "" "Full path of the VM image" |
DEFINE_string results_dir_root "" "alternate root results directory" |
+DEFINE_boolean save_vm_state ${FLAGS_FALSE} \ |
+ "Save the state of the VM when a test fails" |
+DEFINE_string save_vm_state_file ${DEFAULT_QEMU_COW_IMAGE} \ |
+ "Name of file to save VM state into if test fails" |
DEFINE_string test_case "" "Name of the test case to run" |
DEFINE_boolean use_emerged ${FLAGS_FALSE} \ |
"Force use of emerged autotest packages" |
@@ -54,6 +58,16 @@ if [ -z "${FLAGS_test_case}" ] && [ -z "${FLAGS_ARGV}" ]; then |
die "You must specify a test case." |
fi |
+if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ] && |
+ [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then |
+ die "You cannot set both --snapshot and --save_vm_state." |
+fi |
+ |
+if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ] && |
+ [ -z ${FLAGS_save_vm_state_file} ]; then |
+ die "You must specify a save_vm_state_file." |
+fi |
+ |
USE_EMERGED= |
if [[ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]]; then |
USE_EMERGED="--use_emerged" |
@@ -65,6 +79,15 @@ for test in ${FLAGS_ARGV}; do |
tests=( "${tests[@]}" "$(remove_quotes "${test}")" ) |
done |
+# Create a copy-on-write qcow2 file that is based off the default QEMU image |
+# so that we can save state information into it. |
+if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ]; then |
+ QEMU_COW_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh \ |
+ --board=${FLAGS_board})/${FLAGS_save_vm_state_file}" |
+ qemu-img create -f qcow2 -b ${LATEST_IMAGE} ${QEMU_COW_IMAGE} |
+ FLAGS_image_path=${QEMU_COW_IMAGE} |
+fi |
+ |
trap stop_kvm EXIT |
start_kvm "${FLAGS_image_path}" |
info "Checking for ssh access to virtual machine." |