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)/autotest_lib.sh" | 13 . "$(dirname $0)/autotest_lib.sh" |
| 14 . "$(dirname $0)/remote_access.sh" | 14 . "$(dirname $0)/remote_access.sh" |
| 15 | 15 |
| 16 DEFINE_boolean build ${FLAGS_FALSE} "Build tests as well as running them" b | |
| 16 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c | 17 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c |
| 17 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory" | 18 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory" |
| 18 DEFINE_integer iterations 1 "Iterations to run every top level test" i | 19 DEFINE_integer iterations 1 "Iterations to run every top level test" i |
| 19 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir" | 20 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir" |
| 20 DEFINE_string results_dir_root "" "alternate root results directory" | 21 DEFINE_string results_dir_root "" "alternate root results directory" |
| 21 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v | 22 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v |
| 22 | 23 |
| 24 RAN_ANY_TESTS=${FLAGS_FALSE} | |
| 25 | |
| 23 # Check if our stdout is a tty | 26 # Check if our stdout is a tty |
| 24 function is_a_tty() { | 27 function is_a_tty() { |
| 25 local stdout=$(readlink /proc/$$/fd/1) | 28 local stdout=$(readlink /proc/$$/fd/1) |
| 26 [[ "${stdout#/dev/tty}" != "${stdout}" ]] && return 0 | 29 [[ "${stdout#/dev/tty}" != "${stdout}" ]] && return 0 |
| 27 [[ "${stdout#/dev/pts}" != "${stdout}" ]] && return 0 | 30 [[ "${stdout#/dev/pts}" != "${stdout}" ]] && return 0 |
| 28 return 1 | 31 return 1 |
| 29 } | 32 } |
| 30 | 33 |
| 31 # Writes out text in specified color if stdout is a tty | 34 # Writes out text in specified color if stdout is a tty |
| 32 # Arguments: | 35 # Arguments: |
| 33 # $1 - color | 36 # $1 - color |
| 34 # $2 - text to color | 37 # $2 - text to color |
| 35 # $3 - text following colored text (default colored) | 38 # $3 - text following colored text (default colored) |
| 36 # Returns: | 39 # Returns: |
| 37 # None | 40 # None |
| 38 function echo_color() { | 41 function echo_color() { |
| 39 local color=0 | 42 local color=0 |
| 40 [[ "$1" == "red" ]] && color=31 | 43 [[ "$1" == "red" ]] && color=31 |
| 41 [[ "$1" == "green" ]] && color=32 | 44 [[ "$1" == "green" ]] && color=32 |
| 42 [[ "$1" == "yellow" ]] && color=33 | 45 [[ "$1" == "yellow" ]] && color=33 |
| 43 if is_a_tty; then | 46 if is_a_tty; then |
| 44 echo -e "\033[1;${color}m$2\033[0m$3" | 47 echo -e "\033[1;${color}m$2\033[0m$3" |
| 45 else | 48 else |
| 46 echo "$2$3" | 49 echo "$2$3" |
| 47 fi | 50 fi |
| 48 } | 51 } |
| 49 | 52 |
| 50 function cleanup() { | 53 function cleanup() { |
| 51 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then | 54 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]] || \ |
| 55 [[ ${RAN_ANY_TESTS} -eq ${FLAGS_FALSE} ]]; then | |
| 52 rm -rf "${TMP}" | 56 rm -rf "${TMP}" |
| 53 else | 57 else |
| 54 echo ">>> Details stored under ${TMP}" | 58 echo ">>> Details stored under ${TMP}" |
| 55 fi | 59 fi |
| 56 cleanup_remote_access | 60 cleanup_remote_access |
| 57 } | 61 } |
| 58 | 62 |
| 59 # Returns an error if the test_result_file has text which indicates | 63 # Returns an error if the test_result_file has text which indicates |
| 60 # the test was not run successfully. | 64 # the test was not run successfully. |
| 61 # Arguments: | 65 # Arguments: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 fi | 116 fi |
| 113 remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release | 117 remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release |
| 114 FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d= -f2) | 118 FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d= -f2) |
| 115 if [[ -z "${FLAGS_board}" ]]; then | 119 if [[ -z "${FLAGS_board}" ]]; then |
| 116 check_board | 120 check_board |
| 117 fi | 121 fi |
| 118 echo "Target reports board is ${FLAGS_board}" | 122 echo "Target reports board is ${FLAGS_board}" |
| 119 } | 123 } |
| 120 | 124 |
| 121 | 125 |
| 126 # Determine if a control is for a client or server test. Echos | |
| 127 # either "server" or "client". | |
| 128 # Arguments: | |
| 129 # $1 - control file path | |
| 130 function read_test_type() { | |
| 131 local control_file=$1 | |
| 132 # Assume a line starts with TEST_TYPE = | |
| 133 local type=$(egrep '^[[:space:]]*TEST_TYPE[[:space:]]*=' "${control_file}" \ | |
|
petkov
2010/03/29 21:37:38
You could use egrep -m1 instead of piping through
| |
| 134 | head -1) | |
| 135 if [[ -z "${type}" ]]; then | |
| 136 echo_color "red" ">>> Unable to find TEST_TYPE line in ${control_file}" | |
| 137 exit 1 | |
| 138 fi | |
| 139 type=$(python -c "${type}; print TEST_TYPE.lower()") | |
| 140 if [[ "${type}" != "client" ]] && [[ "${type}" != "server" ]]; then | |
| 141 echo_color "red" ">>> Unknown type of test (${type}) in ${control_file}" | |
|
petkov
2010/03/29 21:37:38
Consider using die, warn, etc. from common.sh inst
| |
| 142 exit 1 | |
| 143 fi | |
| 144 echo ${type} | |
| 145 } | |
| 146 | |
| 122 function main() { | 147 function main() { |
| 123 cd $(dirname "$0") | 148 cd $(dirname "$0") |
| 124 | 149 |
| 125 FLAGS "$@" || exit 1 | 150 FLAGS "$@" || exit 1 |
| 126 | 151 |
| 127 if [[ -z "${FLAGS_ARGV}" ]]; then | 152 if [[ -z "${FLAGS_ARGV}" ]]; then |
| 128 echo "Please specify tests to run. For example:" | 153 echo "Please specify tests to run. For example:" |
| 129 echo " $0 --remote=MyMachine BootPerfServer" | 154 echo " $0 --remote=MyMachine BootPerfServer" |
| 130 exit 1 | 155 exit 1 |
| 131 fi | 156 fi |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 160 local control_files_to_run="" | 185 local control_files_to_run="" |
| 161 | 186 |
| 162 # Now search for tests which unambiguously include the given identifier | 187 # Now search for tests which unambiguously include the given identifier |
| 163 local search_path=$(echo ${autotest_dir}/{client,server}/{tests,site_tests}) | 188 local search_path=$(echo ${autotest_dir}/{client,server}/{tests,site_tests}) |
| 164 for test_request in $FLAGS_ARGV; do | 189 for test_request in $FLAGS_ARGV; do |
| 165 test_request=$(remove_quotes "${test_request}") | 190 test_request=$(remove_quotes "${test_request}") |
| 166 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ | 191 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ |
| 167 -name control \) | egrep -v "~$" | egrep "${test_request}") | 192 -name control \) | egrep -v "~$" | egrep "${test_request}") |
| 168 if [[ -z "${finds}" ]]; then | 193 if [[ -z "${finds}" ]]; then |
| 169 echo_color "red" ">>> Cannot find match for \"${test_request}\"" | 194 echo_color "red" ">>> Cannot find match for \"${test_request}\"" |
| 170 FLAGS_cleanup=${FLAGS_TRUE} | |
| 171 exit 1 | 195 exit 1 |
| 172 fi | 196 fi |
| 173 local matches=$(echo "${finds}" | wc -l) | 197 local matches=$(echo "${finds}" | wc -l) |
| 174 if [[ ${matches} -gt 1 ]]; then | 198 if [[ ${matches} -gt 1 ]]; then |
| 175 echo "" | 199 echo "" |
| 176 echo_color "red" \ | 200 echo_color "red" \ |
| 177 ">>> \"${test_request}\" is ambiguous. These control file paths match:" | 201 ">>> \"${test_request}\" is ambiguous. These control file paths match:" |
| 178 for FIND in ${finds}; do | 202 for FIND in ${finds}; do |
| 179 echo_color "red" " * " "${FIND}" | 203 echo_color "red" " * " "${FIND}" |
| 180 done | 204 done |
| 181 echo "" | 205 echo "" |
| 182 echo ">>> Disambiguate by copy-and-pasting the whole path above" \ | 206 echo ">>> Disambiguate by copy-and-pasting the whole path above" \ |
| 183 "instead of passing \"${test_request}\"." | 207 "instead of passing \"${test_request}\"." |
| 184 FLAGS_cleanup=${FLAGS_TRUE} | |
| 185 exit 1 | 208 exit 1 |
| 186 fi | 209 fi |
| 187 for i in $(seq 1 $FLAGS_iterations); do | 210 for i in $(seq 1 $FLAGS_iterations); do |
| 188 control_files_to_run="${control_files_to_run} '${finds}'" | 211 control_files_to_run="${control_files_to_run} '${finds}'" |
| 189 done | 212 done |
| 190 done | 213 done |
| 191 | 214 |
| 192 echo "" | 215 echo "" |
| 216 | |
| 217 if [[ -z "${control_files_to_run}" ]]; then | |
| 218 echo_color "red" ">>> Found no control files" | |
| 219 exit 1 | |
| 220 fi | |
| 221 | |
| 193 echo_color "yellow" ">>> Running the following control files:" | 222 echo_color "yellow" ">>> Running the following control files:" |
| 194 for CONTROL_FILE in ${control_files_to_run}; do | 223 for CONTROL_FILE in ${control_files_to_run}; do |
| 195 echo_color "yellow" " * " "${CONTROL_FILE}" | 224 echo_color "yellow" " * " "${CONTROL_FILE}" |
| 196 done | 225 done |
| 197 | 226 |
| 198 if [[ -z "${FLAGS_results_dir_root}" ]]; then | 227 if [[ -z "${FLAGS_results_dir_root}" ]]; then |
| 199 FLAGS_results_dir_root="${TMP}" | 228 FLAGS_results_dir_root="${TMP}" |
| 200 fi | 229 fi |
| 201 | 230 |
| 202 mkdir -p "${FLAGS_results_dir_root}" | 231 mkdir -p "${FLAGS_results_dir_root}" |
| 203 | 232 |
| 233 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | |
| 234 # Create a list of files to build based on all the client tests | |
| 235 # the user has specified. If they have specified at least one | |
| 236 # that is a server test, offer to build all client tests since | |
| 237 # it's quite hard to know what client tests a server test might | |
| 238 # use. | |
| 239 local build_param="" | |
| 240 for control_file in ${control_files_to_run}; do | |
| 241 control_file=$(remove_quotes "${control_file}") | |
| 242 local type=$(read_test_type "${control_file}") | |
| 243 if [[ "${type}" == "server" ]]; then | |
| 244 build_param="" | |
| 245 break | |
| 246 fi | |
| 247 if [[ -n "${build_param}" ]]; then | |
| 248 build_param="${build_param}," | |
| 249 fi | |
| 250 local simple_path=$(basename $(dirname $control_file)) | |
| 251 build_param="${build_param}${simple_path}" | |
|
ericli
2010/03/29 21:33:22
I think it needs to be seperated by comma, if ther
| |
| 252 done | |
| 253 local enter_chroot="" | |
| 254 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then | |
| 255 enter_chroot="./enter_chroot.sh --" | |
| 256 fi | |
| 257 if [[ -n "${build_param}" ]]; then | |
| 258 build_param="--build=${build_param}" | |
| 259 fi | |
| 260 echo "" | |
| 261 echo_color "yellow" ">>> Building autotest: " \ | |
| 262 "./build_autotest.sh --board=${FLAGS_board} ${build_param}" | |
| 263 ${enter_chroot} ./build_autotest.sh --board=${FLAGS_board} ${build_param} | |
| 264 fi | |
| 265 | |
| 204 for control_file in ${control_files_to_run}; do | 266 for control_file in ${control_files_to_run}; do |
| 205 # Assume a line starts with TEST_TYPE = | 267 # Assume a line starts with TEST_TYPE = |
| 206 control_file=$(remove_quotes "${control_file}") | 268 control_file=$(remove_quotes "${control_file}") |
| 207 local type=$(egrep '^[[:space:]]*TEST_TYPE[[:space:]]*=' "${control_file}" \ | 269 local type=$(read_test_type "${control_file}") |
| 208 | head -1) | |
| 209 if [[ -z "${type}" ]]; then | |
| 210 echo_color "red" ">>> Unable to find TEST_TYPE line in ${control_file}" | |
| 211 exit 1 | |
| 212 fi | |
| 213 type=$(python -c "${type}; print TEST_TYPE.lower()") | |
| 214 local option | 270 local option |
| 215 if [ "${type}" == "client" ]; then | 271 if [[ "${type}" == "client" ]]; then |
| 216 option="-c" | 272 option="-c" |
| 217 elif [ "${type}" == "server" ]; then | 273 elif [[ "${type}" == "server" ]]; then |
| 218 option="-s" | 274 option="-s" |
| 219 else | 275 else |
| 220 echo_color "red" ">>> Unknown type of test (${type}) in ${control_file}" | 276 echo_color "red" ">>> Unknown type of test (${type}) in ${control_file}" |
| 221 exit 1 | 277 exit 1 |
| 222 fi | 278 fi |
| 223 echo "" | 279 echo "" |
| 224 echo_color "yellow" ">>> Running ${type} test " ${control_file} | 280 echo_color "yellow" ">>> Running ${type} test " ${control_file} |
| 225 local short_name=$(basename $(dirname "${control_file}")) | 281 local short_name=$(basename $(dirname "${control_file}")) |
| 226 local results_dir_name="${short_name}" | 282 local results_dir_name="${short_name}" |
| 227 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" | 283 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" |
| 228 rm -rf "${results_dir}" | 284 rm -rf "${results_dir}" |
| 229 local verbose="" | 285 local verbose="" |
| 230 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then | 286 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then |
| 231 verbose="--verbose" | 287 verbose="--verbose" |
| 232 fi | 288 fi |
| 233 | 289 |
| 290 RAN_ANY_TESTS=${FLAGS_TRUE} | |
| 234 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ | 291 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ |
| 235 -r "${results_dir}" ${verbose} | 292 -r "${results_dir}" ${verbose} |
| 236 local test_status="${results_dir}/status.log" | 293 local test_status="${results_dir}/status.log" |
| 237 local test_result_dir="${results_dir}/${short_name}" | 294 local test_result_dir="${results_dir}/${short_name}" |
| 238 local keyval_file="${test_result_dir}/results/keyval" | 295 local keyval_file="${test_result_dir}/results/keyval" |
| 239 echo "" | 296 echo "" |
| 240 if is_successful_test "${test_status}"; then | 297 if is_successful_test "${test_status}"; then |
| 241 echo_color "green" ">>> SUCCESS: ${control_file}" | 298 echo_color "green" ">>> SUCCESS: ${control_file}" |
| 242 if [[ -f "${keyval_file}" ]]; then | 299 if [[ -f "${keyval_file}" ]]; then |
| 243 echo ">>> Keyval was:" | 300 echo ">>> Keyval was:" |
| 244 cat "${keyval_file}" | 301 cat "${keyval_file}" |
| 245 fi | 302 fi |
| 246 else | 303 else |
| 247 echo_color "red" ">>> FAILED: ${control_file}" | 304 echo_color "red" ">>> FAILED: ${control_file}" |
| 248 cat "${test_status}" | 305 cat "${test_status}" |
| 249 fi | 306 fi |
| 250 local end_time=$(date '+%s') | 307 local end_time=$(date '+%s') |
| 251 done | 308 done |
| 252 } | 309 } |
| 253 | 310 |
| 254 main $@ | 311 main $@ |
| OLD | NEW |