OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 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 # Script to run client or server tests on a live remote image. | 7 # Script to run client or server tests on a live remote image. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
11 | 11 |
12 . "$(dirname $0)/common.sh" | 12 . "$(dirname $0)/common.sh" |
13 . "$(dirname $0)/remote_access.sh" | 13 . "$(dirname $0)/remote_access.sh" |
14 | 14 |
15 DEFAULT_OUTPUT_FILE=test-output-$(date '+%Y%m%d.%H%M%S') | 15 DEFAULT_OUTPUT_FILE=test-output-$(date '+%Y%m%d.%H%M%S') |
16 | 16 |
17 DEFINE_boolean cleanup ${FLAGS_TRUE} "Clean up temp directory" | 17 DEFINE_boolean cleanup ${FLAGS_TRUE} "Clean up temp directory" |
18 DEFINE_integer iterations 1 "Iterations to run every top level test" i | 18 DEFINE_integer iterations 1 "Iterations to run every top level test" i |
19 DEFINE_string output_file "${DEFAULT_OUTPUT_FILE}" "Test run output" o | 19 DEFINE_string output_file "${DEFAULT_OUTPUT_FILE}" "Test run output" o |
20 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v | 20 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v |
21 DEFINE_boolean update_db ${FLAGS_FALSE} "Put results in autotest database" u | 21 DEFINE_boolean update_db ${FLAGS_FALSE} "Put results in autotest database" u |
22 DEFINE_string machine_desc "" "Machine description used in database" | 22 DEFINE_string machine_desc "" "Machine description used in database" |
| 23 DEFINE_string build_desc "" "Build description used in database" |
23 | 24 |
24 function cleanup() { | 25 function cleanup() { |
25 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then | 26 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then |
26 rm -rf "${TMP}" | 27 rm -rf "${TMP}" |
27 else | 28 else |
28 echo "Left temporary files at ${TMP}" | 29 echo "Left temporary files at ${TMP}" |
29 fi | 30 fi |
30 } | 31 } |
31 | 32 |
32 # Returns an error if the test_result_file has text which indicates | 33 # Returns an error if the test_result_file has text which indicates |
(...skipping 17 matching lines...) Expand all Loading... |
50 | 51 |
51 # Removes single quotes around parameter | 52 # Removes single quotes around parameter |
52 # Arguments: | 53 # Arguments: |
53 # $1 - string which optionally has surrounding quotes | 54 # $1 - string which optionally has surrounding quotes |
54 # Returns: | 55 # Returns: |
55 # None, but prints the string without quotes. | 56 # None, but prints the string without quotes. |
56 function remove_quotes() { | 57 function remove_quotes() { |
57 echo "$1" | sed -e "s/^'//; s/'$//" | 58 echo "$1" | sed -e "s/^'//; s/'$//" |
58 } | 59 } |
59 | 60 |
| 61 # Adds attributes to all tests run |
| 62 # Arguments: |
| 63 # $1 - results directory |
| 64 # $2 - attribute name (key) |
| 65 # $3 - attribute value (value) |
| 66 function add_test_attribute() { |
| 67 local results_dir="$1" |
| 68 local attribute_name="$2" |
| 69 local attribute_value="$3" |
| 70 if [[ -z "$attribute_value" ]]; then |
| 71 return; |
| 72 fi |
| 73 |
| 74 for status_file in $(echo "${results_dir}"/*/status); do |
| 75 local keyval_file=$(dirname $status_file)/keyval |
| 76 echo "Updating ${keyval_file}" |
| 77 echo "${attribute_name}=${attribute_value}" >> "${keyval_file}" |
| 78 done |
| 79 } |
| 80 |
60 function main() { | 81 function main() { |
61 assert_outside_chroot | 82 assert_outside_chroot |
62 | 83 |
63 cd $(dirname "$0") | 84 cd $(dirname "$0") |
64 | 85 |
65 FLAGS "$@" || exit 1 | 86 FLAGS "$@" || exit 1 |
66 | 87 |
67 if [[ -z "${FLAGS_ARGV}" ]]; then | 88 if [[ -z "${FLAGS_ARGV}" ]]; then |
68 echo "Please specify tests to run, like:" | 89 echo "Please specify tests to run, like:" |
69 echo " $0 --remote=MyMachine SystemBootPerf" | 90 echo " $0 --remote=MyMachine SystemBootPerf" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if [ "${type}" == "client" ]; then | 152 if [ "${type}" == "client" ]; then |
132 option="-c" | 153 option="-c" |
133 elif [ "${type}" == "server" ]; then | 154 elif [ "${type}" == "server" ]; then |
134 option="-s" | 155 option="-s" |
135 else | 156 else |
136 echo "Unknown type of test (${type}) in ${control_file}" | 157 echo "Unknown type of test (${type}) in ${control_file}" |
137 exit 1 | 158 exit 1 |
138 fi | 159 fi |
139 echo "Running ${type} test ${control_file}" | 160 echo "Running ${type} test ${control_file}" |
140 local short_name=$(basename $(dirname "${control_file}")) | 161 local short_name=$(basename $(dirname "${control_file}")) |
141 local timestamp=$(date '+%s') | 162 local start_time=$(date '+%s') |
142 local results_dir="${TMP}/${short_name},${FLAGS_machine_desc},${timestamp}" | 163 local results_dir="${TMP}/${short_name},${FLAGS_machine_desc},${start_time}" |
143 rm -rf "${results_dir}" | 164 rm -rf "${results_dir}" |
144 local verbose="" | 165 local verbose="" |
145 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then | 166 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then |
146 verbose="--verbose" | 167 verbose="--verbose" |
147 fi | 168 fi |
148 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ | 169 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ |
149 -r "${results_dir}" ${verbose} | 170 -r "${results_dir}" ${verbose} |
150 local test_status="${results_dir}/status" | 171 local test_status="${results_dir}/status" |
151 local test_result_dir="${results_dir}/${short_name}" | 172 local test_result_dir="${results_dir}/${short_name}" |
152 local keyval_file="${test_result_dir}/results/keyval" | 173 local keyval_file="${test_result_dir}/results/keyval" |
153 if is_successful_test "${test_status}"; then | 174 if is_successful_test "${test_status}"; then |
154 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" | 175 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" |
155 if [[ -f "${keyval_file}" ]]; then | 176 if [[ -f "${keyval_file}" ]]; then |
156 echo "Keyval was:" | tee -a "${FLAGS_output_file}" | 177 echo "Keyval was:" | tee -a "${FLAGS_output_file}" |
157 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" | 178 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" |
158 fi | 179 fi |
159 else | 180 else |
160 echo "${control_file} failed:" | tee -a "${FLAGS_output_file}" | 181 echo "${control_file} failed:" | tee -a "${FLAGS_output_file}" |
161 cat "${test_status}" | tee -a "${FLAGS_output_file}" | 182 cat "${test_status}" | tee -a "${FLAGS_output_file}" |
162 # Leave around output directory if the test failed. | 183 # Leave around output directory if the test failed. |
163 FLAGS_cleanup=${FLAGS_FALSE} | 184 FLAGS_cleanup=${FLAGS_FALSE} |
164 fi | 185 fi |
| 186 local end_time=$(date '+%s') |
165 | 187 |
166 # Update the database with results. | 188 # Update the database with results. |
167 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} ]]; then | 189 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} ]]; then |
| 190 add_test_attribute "${results_dir}" machine-desc "${FLAGS_machine_desc}" |
| 191 add_test_attribute "${results_dir}" build-desc "${FLAGS_build_desc}" |
| 192 add_test_attribute "${results_dir}" server-start-time "${start_time}" |
| 193 add_test_attribute "${results_dir}" server-end-time "${end_time}" |
168 if ! "${parse_cmd}" -o "${results_dir}"; then | 194 if ! "${parse_cmd}" -o "${results_dir}"; then |
169 echo "Parse failed." | tee -a "${FLAGS_output_file}" | 195 echo "Parse failed." | tee -a "${FLAGS_output_file}" |
170 FLAGS_cleanup=${FLAGS_FALSE} | 196 FLAGS_cleanup=${FLAGS_FALSE} |
171 fi | 197 fi |
172 fi | 198 fi |
173 done | 199 done |
174 | 200 |
175 echo "Output stored to ${FLAGS_output_file}" | 201 echo "Output stored to ${FLAGS_output_file}" |
176 } | 202 } |
177 | 203 |
178 main $@ | 204 main $@ |
OLD | NEW |