Chromium Code Reviews| 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 "" \ | 24 DEFINE_string chroot_dir "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c |
| 25 "Directory to place individual autoserv results files (default to TMP)" | |
| 26 | 25 |
| 27 function cleanup() { | 26 function cleanup() { |
| 28 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then | 27 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then |
| 29 rm -rf "${TMP}" | 28 rm -rf "${TMP}" |
| 30 else | 29 else |
| 31 echo "Left temporary files at ${TMP}" | 30 echo "Left temporary files at ${TMP}" |
| 32 fi | 31 fi |
| 32 if [[ -n "${SSH_AGENT_PID}" ]] | |
| 33 then | |
| 34 kill ${SSH_AGENT_PID} 2>/dev/null | |
| 35 fi | |
| 33 } | 36 } |
| 34 | 37 |
| 35 # Returns an error if the test_result_file has text which indicates | 38 # Returns an error if the test_result_file has text which indicates |
| 36 # the test was not run successfully. | 39 # the test was not run successfully. |
| 37 # Arguments: | 40 # Arguments: |
| 38 # $1 - file name of autotest status for to check for success | 41 # $1 - file name of autotest status for to check for success |
| 39 # Returns: | 42 # Returns: |
| 40 # None | 43 # None |
| 41 function is_successful_test() { | 44 function is_successful_test() { |
| 42 local file="$1" | 45 local file="$1" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 98 |
| 96 local parse_cmd="$(dirname $0)/../third_party/autotest/files/tko/parse.py" | 99 local parse_cmd="$(dirname $0)/../third_party/autotest/files/tko/parse.py" |
| 97 | 100 |
| 98 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then | 101 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then |
| 99 echo "Cannot find parser ${parse_cmd}" | 102 echo "Cannot find parser ${parse_cmd}" |
| 100 exit 1 | 103 exit 1 |
| 101 fi | 104 fi |
| 102 | 105 |
| 103 set -e | 106 set -e |
| 104 | 107 |
| 108 AUTOTEST_INSTALL_DIR="${DEFAULT_CHROOT_DIR}/usr/local/autotest" | |
| 109 | |
| 105 # Set global TMP for remote_access.sh's sake | 110 # Set global TMP for remote_access.sh's sake |
| 106 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) | 111 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) |
| 107 | 112 |
| 108 if [[ -z "${FLAGS_results_dir_root}" ]]; then | |
| 109 FLAGS_results_dir_root="${TMP}" | |
| 110 fi | |
| 111 | |
| 112 rm -f "${FLAGS_output_file}" | 113 rm -f "${FLAGS_output_file}" |
| 113 | 114 |
| 114 trap cleanup EXIT | 115 trap cleanup EXIT |
| 115 | 116 |
| 116 cp -r "${SRC_ROOT}/third_party/autotest/files" "${TMP}/autotest" | 117 # Check for installed autotest. |
| 117 | 118 local autoserv="${AUTOTEST_INSTALL_DIR}/server/autoserv" |
| 119 if [[ ! -f "${autoserv}" ]]; then | |
| 120 echo "Cannot find autotest in build dir. Run build_autotest.sh" | |
| 121 exit 1 | |
| 122 fi | |
| 123 | |
| 118 local control_files_to_run="" | 124 local control_files_to_run="" |
| 119 local any_failures=0 | |
| 120 | 125 |
| 121 # Now search for tests which unambiguously include the given identifier | 126 # Now search for tests which unambiguously include the given identifier |
| 122 local search_path=$(echo ${TMP}/autotest/{client,server}/{tests,site_tests}) | 127 local search_path=$(echo ${AUTOTEST_INSTALL_DIR}/{client,server}/{tests,site_t ests}) |
|
petkov
2010/01/27 17:12:06
80 chars
seano
2010/01/27 19:51:47
Done.
| |
| 123 for test_request in $FLAGS_ARGV; do | 128 for test_request in $FLAGS_ARGV; do |
| 124 test_request=$(remove_quotes "${test_request}") | 129 test_request=$(remove_quotes "${test_request}") |
| 125 ! finds=$(find ${search_path} -type f -name control | \ | 130 ! finds=$(find ${search_path} -type f -name control | \ |
| 126 egrep "${test_request}") | 131 egrep "${test_request}") |
| 127 if [[ -z "${finds}" ]]; then | 132 if [[ -z "${finds}" ]]; then |
| 128 echo "Can not find match for ${test_request}" | 133 echo "Can not find match for ${test_request}" |
| 129 any_failures=1 | 134 exit 1 |
| 130 continue | |
| 131 fi | 135 fi |
| 132 local matches=$(echo "${finds}" | wc -l) | 136 local matches=$(echo "${finds}" | wc -l) |
| 133 if [[ ${matches} -gt 1 ]]; then | 137 if [[ ${matches} -gt 1 ]]; then |
| 134 echo "${test_request} is ambiguous:" | 138 echo "${test_request} is ambiguous:" |
| 135 echo "${finds}" | 139 echo "${finds}" |
| 136 any_failures=1 | 140 exit 1 |
| 137 continue | |
| 138 fi | 141 fi |
| 139 for i in $(seq 1 $FLAGS_iterations); do | 142 for i in $(seq 1 $FLAGS_iterations); do |
| 140 control_files_to_run="${control_files_to_run} '${finds}'" | 143 control_files_to_run="${control_files_to_run} '${finds}'" |
| 141 done | 144 done |
| 142 done | 145 done |
| 143 | 146 |
| 144 echo "Running the following control files: ${control_files_to_run}" | 147 echo "Running the following control files: ${control_files_to_run}" |
| 145 | 148 |
| 146 remote_access_init | 149 remote_access_init |
| 147 | 150 |
| 148 # Set the default machine description to the machine's IP | 151 # Set the default machine description to the machine's IP |
| 149 if [[ -z "${FLAGS_machine_desc}" ]]; then | 152 if [[ -z "${FLAGS_machine_desc}" ]]; then |
| 150 FLAGS_machine_desc="${FLAGS_remote}" | 153 FLAGS_machine_desc="${FLAGS_remote}" |
| 151 fi | 154 fi |
| 152 | |
| 153 local autoserv="${TMP}/autotest/server/autoserv" | |
| 154 | 155 |
| 155 for control_file in ${control_files_to_run}; do | 156 for control_file in ${control_files_to_run}; do |
| 156 # Assume a line starts with TEST_TYPE = | 157 # Assume a line starts with TEST_TYPE = |
| 157 control_file=$(remove_quotes "${control_file}") | 158 control_file=$(remove_quotes "${control_file}") |
| 158 local type=$(egrep '^\s*TEST_TYPE\s*=' "${control_file}" | head -1) | 159 local type=$(egrep '^\s*TEST_TYPE\s*=' "${control_file}" | head -1) |
| 159 type=$(python -c "${type}; print TEST_TYPE.lower()") | 160 type=$(python -c "${type}; print TEST_TYPE.lower()") |
| 160 local option | 161 local option |
| 161 if [ "${type}" == "client" ]; then | 162 if [ "${type}" == "client" ]; then |
| 162 option="-c" | 163 option="-c" |
| 163 elif [ "${type}" == "server" ]; then | 164 elif [ "${type}" == "server" ]; then |
| 164 option="-s" | 165 option="-s" |
| 165 else | 166 else |
| 166 echo "Unknown type of test (${type}) in ${control_file}" | 167 echo "Unknown type of test (${type}) in ${control_file}" |
| 167 exit 1 | 168 exit 1 |
| 168 fi | 169 fi |
| 169 echo "Running ${type} test ${control_file}" | 170 echo "Running ${type} test ${control_file}" |
| 170 local short_name=$(basename $(dirname "${control_file}")) | 171 local short_name=$(basename $(dirname "${control_file}")) |
| 171 local start_time=$(date '+%s') | 172 local start_time=$(date '+%s') |
| 172 local results_dir_name="${short_name},${FLAGS_machine_desc},${start_time}" | 173 local results_dir="${TMP}/${short_name},${FLAGS_machine_desc},${start_time}" |
| 173 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" | |
| 174 rm -rf "${results_dir}" | 174 rm -rf "${results_dir}" |
| 175 local verbose="" | 175 local verbose="" |
| 176 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then | 176 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then |
| 177 verbose="--verbose" | 177 verbose="--verbose" |
| 178 fi | 178 fi |
| 179 if ! ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ | 179 TODO call from correct install dir |
|
petkov
2010/01/27 15:46:26
This needs to be a comment? Also, TODO(seano)...
seano
2010/01/27 19:51:47
Done.
| |
| 180 -r "${results_dir}" ${verbose}; then | 180 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ |
| 181 echo "Autoserv run of ${control_file} failed." | \ | 181 -r "${results_dir}" ${verbose} |
| 182 tee -a "${FLAGS_output_file}" | |
| 183 any_failures=1 | |
| 184 continue | |
| 185 fi | |
| 186 local test_status="${results_dir}/status" | 182 local test_status="${results_dir}/status" |
| 187 local test_result_dir="${results_dir}/${short_name}" | 183 local test_result_dir="${results_dir}/${short_name}" |
| 188 local keyval_file="${test_result_dir}/results/keyval" | 184 local keyval_file="${test_result_dir}/results/keyval" |
| 189 if is_successful_test "${test_status}"; then | 185 if is_successful_test "${test_status}"; then |
| 190 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" | 186 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" |
| 191 if [[ -f "${keyval_file}" ]]; then | 187 if [[ -f "${keyval_file}" ]]; then |
| 192 echo "Keyval was:" | tee -a "${FLAGS_output_file}" | 188 echo "Keyval was:" | tee -a "${FLAGS_output_file}" |
| 193 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" | 189 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" |
| 194 fi | 190 fi |
| 195 else | 191 else |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 207 add_test_attribute "${results_dir}" server-start-time "${start_time}" | 203 add_test_attribute "${results_dir}" server-start-time "${start_time}" |
| 208 add_test_attribute "${results_dir}" server-end-time "${end_time}" | 204 add_test_attribute "${results_dir}" server-end-time "${end_time}" |
| 209 if ! "${parse_cmd}" -o "${results_dir}"; then | 205 if ! "${parse_cmd}" -o "${results_dir}"; then |
| 210 echo "Parse failed." | tee -a "${FLAGS_output_file}" | 206 echo "Parse failed." | tee -a "${FLAGS_output_file}" |
| 211 FLAGS_cleanup=${FLAGS_FALSE} | 207 FLAGS_cleanup=${FLAGS_FALSE} |
| 212 fi | 208 fi |
| 213 fi | 209 fi |
| 214 done | 210 done |
| 215 | 211 |
| 216 echo "Output stored to ${FLAGS_output_file}" | 212 echo "Output stored to ${FLAGS_output_file}" |
| 217 | |
| 218 return ${any_failures} | |
| 219 } | 213 } |
| 220 | 214 |
| 221 main $@ | 215 main $@ |
| OLD | NEW |