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

Side by Side Diff: bin/cros_run_vm_test

Issue 5174009: Add support for saving VM state when a test fails. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Fix nit 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | image_to_vm.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # Runs a given test case under a VM. 7 # Runs a given test case under a VM.
8 8
9 . "$(dirname $0)/../common.sh" 9 . "$(dirname $0)/../common.sh"
10 . "$(dirname $0)/../lib/cros_vm_lib.sh" 10 . "$(dirname $0)/../lib/cros_vm_lib.sh"
11 . "$(dirname "$0")/../lib/cros_vm_constants.sh" 11 . "$(dirname "$0")/../lib/cros_vm_constants.sh"
12 12
13 MAX_RETRIES=3 13 MAX_RETRIES=3
14 14
15 get_default_board 15 get_default_board
16 16
17 DEFINE_string board "$DEFAULT_BOARD" \ 17 DEFINE_string board "$DEFAULT_BOARD" \
18 "The board for which you built autotest." b 18 "The board for which you built autotest." b
19 DEFINE_string image_path "" "Full path of the VM image" 19 DEFINE_string image_path "" "Full path of the VM image"
20 DEFINE_string results_dir_root "" "alternate root results directory" 20 DEFINE_string results_dir_root "" "alternate root results directory"
21 DEFINE_boolean save_vm_state ${FLAGS_FALSE} \
22 "Save the state of the VM when a test fails"
23 DEFINE_string save_vm_state_file ${DEFAULT_QEMU_COW_IMAGE} \
24 "Name of file to save VM state into if test fails"
21 DEFINE_string test_case "" "Name of the test case to run" 25 DEFINE_string test_case "" "Name of the test case to run"
22 DEFINE_boolean use_emerged ${FLAGS_FALSE} \ 26 DEFINE_boolean use_emerged ${FLAGS_FALSE} \
23 "Force use of emerged autotest packages" 27 "Force use of emerged autotest packages"
24 DEFINE_string verify_chrome_version "" \ 28 DEFINE_string verify_chrome_version "" \
25 "Verify that this chrome version matches that on vm." 29 "Verify that this chrome version matches that on vm."
26 30
27 set -e 31 set -e
28 32
29 # Returns normally if the given $1 is a valid chrome version. 33 # Returns normally if the given $1 is a valid chrome version.
30 chrome_version_is_valid() { 34 chrome_version_is_valid() {
(...skipping 16 matching lines...) Expand all
47 51
48 if [ -n "${FLAGS_test_case}" ]; then 52 if [ -n "${FLAGS_test_case}" ]; then
49 warn "Use of --test_case=<test> is being deprecated. Just pass test names \ 53 warn "Use of --test_case=<test> is being deprecated. Just pass test names \
50 as separate command line arguments." 54 as separate command line arguments."
51 fi 55 fi
52 56
53 if [ -z "${FLAGS_test_case}" ] && [ -z "${FLAGS_ARGV}" ]; then 57 if [ -z "${FLAGS_test_case}" ] && [ -z "${FLAGS_ARGV}" ]; then
54 die "You must specify a test case." 58 die "You must specify a test case."
55 fi 59 fi
56 60
61 if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ] &&
62 [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then
63 die "You cannot set both --snapshot and --save_vm_state."
64 fi
65
66 if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ] &&
67 [ -z ${FLAGS_save_vm_state_file} ]; then
68 die "You must specify a save_vm_state_file."
69 fi
70
57 USE_EMERGED= 71 USE_EMERGED=
58 if [[ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]]; then 72 if [[ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]]; then
59 USE_EMERGED="--use_emerged" 73 USE_EMERGED="--use_emerged"
60 fi 74 fi
61 75
62 tests=( ) 76 tests=( )
63 [ -n "${FLAGS_test_case}" ] && tests=( "${FLAGS_test_case}" ) 77 [ -n "${FLAGS_test_case}" ] && tests=( "${FLAGS_test_case}" )
64 for test in ${FLAGS_ARGV}; do 78 for test in ${FLAGS_ARGV}; do
65 tests=( "${tests[@]}" "$(remove_quotes "${test}")" ) 79 tests=( "${tests[@]}" "$(remove_quotes "${test}")" )
66 done 80 done
67 81
82 # Create a copy-on-write qcow2 file that is based off the default QEMU image
83 # so that we can save state information into it.
84 if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ]; then
85 QEMU_COW_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh \
86 --board=${FLAGS_board})/${FLAGS_save_vm_state_file}"
87 qemu-img create -f qcow2 -b ${LATEST_IMAGE} ${QEMU_COW_IMAGE}
88 FLAGS_image_path=${QEMU_COW_IMAGE}
89 fi
90
68 trap stop_kvm EXIT 91 trap stop_kvm EXIT
69 start_kvm "${FLAGS_image_path}" 92 start_kvm "${FLAGS_image_path}"
70 info "Checking for ssh access to virtual machine." 93 info "Checking for ssh access to virtual machine."
71 retry_until_ssh ${MAX_RETRIES} 94 retry_until_ssh ${MAX_RETRIES}
72 95
73 if [ -n "${FLAGS_verify_chrome_version}" ]; then 96 if [ -n "${FLAGS_verify_chrome_version}" ]; then
74 info "Verifying version of Chrome matches what we expect." 97 info "Verifying version of Chrome matches what we expect."
75 if chrome_version_is_valid "${FLAGS_verify_chrome_version}"; then 98 if chrome_version_is_valid "${FLAGS_verify_chrome_version}"; then
76 chrome_version_on_vm=$("$(dirname $0)/cros_get_chrome_version" \ 99 chrome_version_on_vm=$("$(dirname $0)/cros_get_chrome_version" \
77 --remote=127.0.0.1 \ 100 --remote=127.0.0.1 \
78 --ssh_port=${FLAGS_ssh_port}) 101 --ssh_port=${FLAGS_ssh_port})
79 [[ ${chrome_version_on_vm} == ${FLAGS_verify_chrome_version} ]] || \ 102 [[ ${chrome_version_on_vm} == ${FLAGS_verify_chrome_version} ]] || \
80 die "Chrome version mismatch. VM reported ${chrome_version_on_vm}" 103 die "Chrome version mismatch. VM reported ${chrome_version_on_vm}"
81 else 104 else
82 warn "${FLAGS_verify_chrome_version} is not a valid Chrome version" 105 warn "${FLAGS_verify_chrome_version} is not a valid Chrome version"
83 fi 106 fi
84 fi 107 fi
85 108
86 "$(dirname $0)"/../run_remote_tests.sh \ 109 "$(dirname $0)"/../run_remote_tests.sh \
87 --board=${FLAGS_board} \ 110 --board=${FLAGS_board} \
88 --ssh_port=${FLAGS_ssh_port} \ 111 --ssh_port=${FLAGS_ssh_port} \
89 --remote=127.0.0.1 \ 112 --remote=127.0.0.1 \
90 --results_dir_root="${FLAGS_results_dir_root}" \ 113 --results_dir_root="${FLAGS_results_dir_root}" \
91 ${USE_EMERGED} \ 114 ${USE_EMERGED} \
92 "${tests[@]}" 115 "${tests[@]}"
OLDNEW
« no previous file with comments | « no previous file | image_to_vm.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698