| 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 DEFINE_string build_desc "" "Build description used in database" |
| 24 DEFINE_string results_dir_root "" \ |
| 25 "Directory to place individual autoserv results files (default to TMP)" |
| 24 | 26 |
| 25 function cleanup() { | 27 function cleanup() { |
| 26 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then | 28 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then |
| 27 rm -rf "${TMP}" | 29 rm -rf "${TMP}" |
| 28 else | 30 else |
| 29 echo "Left temporary files at ${TMP}" | 31 echo "Left temporary files at ${TMP}" |
| 30 fi | 32 fi |
| 31 } | 33 } |
| 32 | 34 |
| 33 # Returns an error if the test_result_file has text which indicates | 35 # Returns an error if the test_result_file has text which indicates |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then | 98 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then |
| 97 echo "Cannot find parser ${parse_cmd}" | 99 echo "Cannot find parser ${parse_cmd}" |
| 98 exit 1 | 100 exit 1 |
| 99 fi | 101 fi |
| 100 | 102 |
| 101 set -e | 103 set -e |
| 102 | 104 |
| 103 # Set global TMP for remote_access.sh's sake | 105 # Set global TMP for remote_access.sh's sake |
| 104 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) | 106 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) |
| 105 | 107 |
| 108 if [[ -z "${FLAGS_results_dir_root}" ]]; then |
| 109 FLAGS_results_dir_root="${TMP}" |
| 110 fi |
| 111 |
| 106 rm -f "${FLAGS_output_file}" | 112 rm -f "${FLAGS_output_file}" |
| 107 | 113 |
| 108 trap cleanup EXIT | 114 trap cleanup EXIT |
| 109 | 115 |
| 110 cp -r "${SRC_ROOT}/third_party/autotest/files" "${TMP}/autotest" | 116 cp -r "${SRC_ROOT}/third_party/autotest/files" "${TMP}/autotest" |
| 111 | 117 |
| 112 local control_files_to_run="" | 118 local control_files_to_run="" |
| 119 local any_failures=0 |
| 113 | 120 |
| 114 # Now search for tests which unambiguously include the given identifier | 121 # Now search for tests which unambiguously include the given identifier |
| 115 local search_path=$(echo ${TMP}/autotest/{client,server}/{tests,site_tests}) | 122 local search_path=$(echo ${TMP}/autotest/{client,server}/{tests,site_tests}) |
| 116 for test_request in $FLAGS_ARGV; do | 123 for test_request in $FLAGS_ARGV; do |
| 117 test_request=$(remove_quotes "${test_request}") | 124 test_request=$(remove_quotes "${test_request}") |
| 118 ! finds=$(find ${search_path} -type f -name control | \ | 125 ! finds=$(find ${search_path} -type f -name control | \ |
| 119 egrep "${test_request}") | 126 egrep "${test_request}") |
| 120 if [[ -z "${finds}" ]]; then | 127 if [[ -z "${finds}" ]]; then |
| 121 echo "Can not find match for ${test_request}" | 128 echo "Can not find match for ${test_request}" |
| 122 exit 1 | 129 any_failures=1 |
| 130 continue |
| 123 fi | 131 fi |
| 124 local matches=$(echo "${finds}" | wc -l) | 132 local matches=$(echo "${finds}" | wc -l) |
| 125 if [[ ${matches} -gt 1 ]]; then | 133 if [[ ${matches} -gt 1 ]]; then |
| 126 echo "${test_request} is ambiguous:" | 134 echo "${test_request} is ambiguous:" |
| 127 echo "${finds}" | 135 echo "${finds}" |
| 128 exit 1 | 136 any_failures=1 |
| 137 continue |
| 129 fi | 138 fi |
| 130 for i in $(seq 1 $FLAGS_iterations); do | 139 for i in $(seq 1 $FLAGS_iterations); do |
| 131 control_files_to_run="${control_files_to_run} '${finds}'" | 140 control_files_to_run="${control_files_to_run} '${finds}'" |
| 132 done | 141 done |
| 133 done | 142 done |
| 134 | 143 |
| 135 echo "Running the following control files: ${control_files_to_run}" | 144 echo "Running the following control files: ${control_files_to_run}" |
| 136 | 145 |
| 137 remote_access_init | 146 remote_access_init |
| 138 | 147 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 option="-c" | 162 option="-c" |
| 154 elif [ "${type}" == "server" ]; then | 163 elif [ "${type}" == "server" ]; then |
| 155 option="-s" | 164 option="-s" |
| 156 else | 165 else |
| 157 echo "Unknown type of test (${type}) in ${control_file}" | 166 echo "Unknown type of test (${type}) in ${control_file}" |
| 158 exit 1 | 167 exit 1 |
| 159 fi | 168 fi |
| 160 echo "Running ${type} test ${control_file}" | 169 echo "Running ${type} test ${control_file}" |
| 161 local short_name=$(basename $(dirname "${control_file}")) | 170 local short_name=$(basename $(dirname "${control_file}")) |
| 162 local start_time=$(date '+%s') | 171 local start_time=$(date '+%s') |
| 163 local results_dir="${TMP}/${short_name},${FLAGS_machine_desc},${start_time}" | 172 local results_dir_name="${short_name},${FLAGS_machine_desc},${start_time}" |
| 173 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" |
| 164 rm -rf "${results_dir}" | 174 rm -rf "${results_dir}" |
| 165 local verbose="" | 175 local verbose="" |
| 166 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then | 176 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then |
| 167 verbose="--verbose" | 177 verbose="--verbose" |
| 168 fi | 178 fi |
| 169 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ | 179 if ! ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ |
| 170 -r "${results_dir}" ${verbose} | 180 -r "${results_dir}" ${verbose}; then |
| 181 echo "Autoserv run of ${control_file} failed." | \ |
| 182 tee -a "${FLAGS_output_file}" |
| 183 any_failures=1 |
| 184 continue |
| 185 fi |
| 171 local test_status="${results_dir}/status" | 186 local test_status="${results_dir}/status" |
| 172 local test_result_dir="${results_dir}/${short_name}" | 187 local test_result_dir="${results_dir}/${short_name}" |
| 173 local keyval_file="${test_result_dir}/results/keyval" | 188 local keyval_file="${test_result_dir}/results/keyval" |
| 174 if is_successful_test "${test_status}"; then | 189 if is_successful_test "${test_status}"; then |
| 175 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" | 190 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" |
| 176 if [[ -f "${keyval_file}" ]]; then | 191 if [[ -f "${keyval_file}" ]]; then |
| 177 echo "Keyval was:" | tee -a "${FLAGS_output_file}" | 192 echo "Keyval was:" | tee -a "${FLAGS_output_file}" |
| 178 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" | 193 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" |
| 179 fi | 194 fi |
| 180 else | 195 else |
| (...skipping 11 matching lines...) Expand all Loading... |
| 192 add_test_attribute "${results_dir}" server-start-time "${start_time}" | 207 add_test_attribute "${results_dir}" server-start-time "${start_time}" |
| 193 add_test_attribute "${results_dir}" server-end-time "${end_time}" | 208 add_test_attribute "${results_dir}" server-end-time "${end_time}" |
| 194 if ! "${parse_cmd}" -o "${results_dir}"; then | 209 if ! "${parse_cmd}" -o "${results_dir}"; then |
| 195 echo "Parse failed." | tee -a "${FLAGS_output_file}" | 210 echo "Parse failed." | tee -a "${FLAGS_output_file}" |
| 196 FLAGS_cleanup=${FLAGS_FALSE} | 211 FLAGS_cleanup=${FLAGS_FALSE} |
| 197 fi | 212 fi |
| 198 fi | 213 fi |
| 199 done | 214 done |
| 200 | 215 |
| 201 echo "Output stored to ${FLAGS_output_file}" | 216 echo "Output stored to ${FLAGS_output_file}" |
| 217 |
| 218 return ${any_failures} |
| 202 } | 219 } |
| 203 | 220 |
| 204 main $@ | 221 main $@ |
| OLD | NEW |