OLD | NEW |
---|---|
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_string test_case "" "Name of the test case to run" | 21 DEFINE_string test_case "" "Name of the test case to run" |
22 DEFINE_boolean use_emerged ${FLAGS_FALSE} \ | 22 DEFINE_boolean use_emerged ${FLAGS_FALSE} \ |
23 "Force use of emerged autotest packages" | 23 "Force use of emerged autotest packages" |
24 DEFINE_string verify_chrome_version "" \ | 24 DEFINE_string verify_chrome_version "" \ |
25 "Verify that this chrome version matches that on vm." | 25 "Verify that this chrome version matches that on vm." |
26 DEFINE_boolean save_vm_state ${FLAGS_FALSE} \ | |
sosa
2010/11/20 08:55:08
Sort in alphabetical order
thieule
2010/11/24 00:51:34
Done.
| |
27 "Save the state of the VM when a test fails" | |
28 DEFINE_string save_vm_state_file ${DEFAULT_QEMU_COW_IMAGE} \ | |
29 "Name of file to save VM state into if test fails" | |
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() { |
31 local chrome_version="$1" | 35 local chrome_version="$1" |
32 echo ${chrome_version} | egrep '^[0-9]+.[0-9]+.[0-9]+.[0-9]+$' &> /dev/null | 36 echo ${chrome_version} | egrep '^[0-9]+.[0-9]+.[0-9]+.[0-9]+$' &> /dev/null |
33 } | 37 } |
34 | 38 |
35 # Parse command line. | 39 # Parse command line. |
(...skipping 11 matching lines...) Expand all Loading... | |
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[@]}" |
OLD | NEW |