Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: src/scripts/run_remote_tests.sh

Issue 1090005: Enable run_remote_tests to run in chroot and clean up output (Closed)
Patch Set: Make colors more obvious Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 DEFAULT_OUTPUT_FILE=test-output-$(date '+%Y%m%d.%H%M%S')
17
18 DEFINE_string build_desc "" "Build description used in database"
19 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c 16 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c
20 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory" 17 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory"
21 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
22 DEFINE_string machine_desc "" "Machine description used in database"
23 DEFINE_string output_file "${DEFAULT_OUTPUT_FILE}" "Test run output" o
24 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir" 19 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir"
25 DEFINE_string results_dir_root "" "alternate root results directory" 20 DEFINE_string results_dir_root "" "alternate root results directory"
26 DEFINE_boolean update_db ${FLAGS_FALSE} "Put results in autotest database" u
27 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v 21 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v
28 22
23 # Check if our stdout is a tty
24 function is_a_tty() {
25 local stdout=$(readlink /proc/$$/fd/1)
26 [[ "${stdout#/dev/tty}" != "${stdout}" ]] && return 0
27 [[ "${stdout#/dev/pts}" != "${stdout}" ]] && return 0
28 return 1
29 }
30
31 # Writes out text in specified color if stdout is a tty
32 # Arguments:
33 # $1 - color
34 # $2 - text to color
35 # $3 - text following colored text (default colored)
36 # Returns:
37 # None
38 function echo_color() {
39 local color=0
40 [[ "$1" == "red" ]] && color=31
41 [[ "$1" == "green" ]] && color=32
42 [[ "$1" == "yellow" ]] && color=33
43 if is_a_tty; then
44 echo -e "\033[1;${color}m$2\033[0m$3"
45 else
46 echo "$2$3"
47 fi
48 }
49
29 function cleanup() { 50 function cleanup() {
30 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then 51 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then
31 rm -rf "${TMP}" 52 rm -rf "${TMP}"
32 else 53 else
33 echo "Left temporary files at ${TMP}" 54 echo ">>> Details stored under ${TMP}"
34 fi 55 fi
35 cleanup_remote_access 56 cleanup_remote_access
36 } 57 }
37 58
38 # Returns an error if the test_result_file has text which indicates 59 # Returns an error if the test_result_file has text which indicates
39 # the test was not run successfully. 60 # the test was not run successfully.
40 # Arguments: 61 # Arguments:
41 # $1 - file name of autotest status for to check for success 62 # $1 - file name of autotest status for to check for success
42 # Returns: 63 # Returns:
43 # None 64 # None
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release 113 remote_sh grep CHROMEOS_RELEASE_BOARD /etc/lsb-release
93 FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d= -f2) 114 FLAGS_board=$(echo "${REMOTE_OUT}" | cut -d= -f2)
94 if [[ -z "${FLAGS_board}" ]]; then 115 if [[ -z "${FLAGS_board}" ]]; then
95 check_board 116 check_board
96 fi 117 fi
97 echo "Target reports board is ${FLAGS_board}" 118 echo "Target reports board is ${FLAGS_board}"
98 } 119 }
99 120
100 121
101 function main() { 122 function main() {
102 assert_outside_chroot
103
104 cd $(dirname "$0") 123 cd $(dirname "$0")
105 124
106 FLAGS "$@" || exit 1 125 FLAGS "$@" || exit 1
107 126
108 if [[ -z "${FLAGS_ARGV}" ]]; then 127 if [[ -z "${FLAGS_ARGV}" ]]; then
109 echo "Please specify tests to run, like:" 128 echo "Please specify tests to run. For example:"
110 echo " $0 --remote=MyMachine SystemBootPerf" 129 echo " $0 --remote=MyMachine BootPerfServer"
111 exit 1 130 exit 1
112 fi 131 fi
113 132
114 set -e 133 set -e
115 134
116 # Set global TMP for remote_access.sh's sake 135 # Set global TMP for remote_access.sh's sake
117 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) 136 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX)
118 137
119 rm -f "${FLAGS_output_file}"
120
121 trap cleanup EXIT 138 trap cleanup EXIT
122 139
123 remote_access_init 140 remote_access_init
124 141
125 local autotest_dir="" 142 local autotest_dir=""
126 if [[ -z "${FLAGS_prepackaged_autotest}" ]]; then 143 if [[ -z "${FLAGS_prepackaged_autotest}" ]]; then
127 learn_board 144 learn_board
128 # Always copy into installed autotest directory. This way if a user 145 # Always copy into installed autotest directory. This way if a user
129 # is just modifying scripts, they take effect without having to wait 146 # is just modifying scripts, they take effect without having to wait
130 # for the laborious build_autotest.sh command. 147 # for the laborious build_autotest.sh command.
131 local original="${GCLIENT_ROOT}/src/third_party/autotest/files" 148 local original="${GCLIENT_ROOT}/src/third_party/autotest/files"
132 autotest_dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local/autotest" 149 autotest_dir="/build/${FLAGS_board}/usr/local/autotest"
150 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then
151 autotest_dir="${FLAGS_chroot}/${autotest_dir}"
152 fi
133 update_chroot_autotest "${original}" "${autotest_dir}" 153 update_chroot_autotest "${original}" "${autotest_dir}"
134 else 154 else
135 autotest_dir="${FLAGS_prepackaged_autotest}" 155 autotest_dir="${FLAGS_prepackaged_autotest}"
136 fi 156 fi
137 157
138 local parse_cmd="${autotest_dir}/tko/parse.py"
139
140 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then
141 echo "Cannot find parser ${parse_cmd}"
142 exit 1
143 fi
144
145 local autoserv="${autotest_dir}/server/autoserv" 158 local autoserv="${autotest_dir}/server/autoserv"
146 159
147 local control_files_to_run="" 160 local control_files_to_run=""
148 161
149 # Now search for tests which unambiguously include the given identifier 162 # Now search for tests which unambiguously include the given identifier
150 local search_path=$(echo ${autotest_dir}/{client,server}/{tests,site_tests}) 163 local search_path=$(echo ${autotest_dir}/{client,server}/{tests,site_tests})
151 for test_request in $FLAGS_ARGV; do 164 for test_request in $FLAGS_ARGV; do
152 test_request=$(remove_quotes "${test_request}") 165 test_request=$(remove_quotes "${test_request}")
153 ! finds=$(find ${search_path} -maxdepth 2 -type f -name control\* | \ 166 ! finds=$(find ${search_path} -maxdepth 2 -type f -name control\* | \
154 egrep "${test_request}") 167 egrep "${test_request}")
155 if [[ -z "${finds}" ]]; then 168 if [[ -z "${finds}" ]]; then
156 echo "Can not find match for ${test_request}" 169 echo_color "red" ">>> Cannot find match for \"${test_request}\""
170 FLAGS_cleanup=${FLAGS_TRUE}
157 exit 1 171 exit 1
158 fi 172 fi
159 local matches=$(echo "${finds}" | wc -l) 173 local matches=$(echo "${finds}" | wc -l)
160 if [[ ${matches} -gt 1 ]]; then 174 if [[ ${matches} -gt 1 ]]; then
161 echo "${test_request} is ambiguous:" 175 echo ""
162 echo "${finds}" 176 echo_color "red" \
177 ">>> \"${test_request}\" is ambiguous. These control file paths match:"
178 for FIND in ${finds}; do
179 echo_color "red" " * " "${FIND}"
180 done
181 echo ""
182 echo ">>> Disambiguate by copy-and-pasting the whole path above" \
183 "instead of passing \"${test_request}\"."
184 FLAGS_cleanup=${FLAGS_TRUE}
163 exit 1 185 exit 1
164 fi 186 fi
165 for i in $(seq 1 $FLAGS_iterations); do 187 for i in $(seq 1 $FLAGS_iterations); do
166 control_files_to_run="${control_files_to_run} '${finds}'" 188 control_files_to_run="${control_files_to_run} '${finds}'"
167 done 189 done
168 done 190 done
169 191
170 echo "Running the following control files: ${control_files_to_run}" 192 echo ""
171 193 echo_color "yellow" ">>> Running the following control files:"
172 # Set the default machine description to the machine's IP 194 for CONTROL_FILE in ${control_files_to_run}; do
173 if [[ -z "${FLAGS_machine_desc}" ]]; then 195 echo_color "yellow" " * " "${CONTROL_FILE}"
174 FLAGS_machine_desc="${FLAGS_remote}" 196 done
175 fi
176 197
177 if [[ -z "${FLAGS_results_dir_root}" ]]; then 198 if [[ -z "${FLAGS_results_dir_root}" ]]; then
178 FLAGS_results_dir_root="${TMP}" 199 FLAGS_results_dir_root="${TMP}"
179 fi 200 fi
180 201
181 mkdir -p "${FLAGS_results_dir_root}" 202 mkdir -p "${FLAGS_results_dir_root}"
182 203
183 for control_file in ${control_files_to_run}; do 204 for control_file in ${control_files_to_run}; do
184 # Assume a line starts with TEST_TYPE = 205 # Assume a line starts with TEST_TYPE =
185 control_file=$(remove_quotes "${control_file}") 206 control_file=$(remove_quotes "${control_file}")
186 local type=$(egrep '^\s*TEST_TYPE\s*=' "${control_file}" | head -1) 207 local type=$(egrep '^[[:space:]]*TEST_TYPE[[:space:]]*=' "${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
187 type=$(python -c "${type}; print TEST_TYPE.lower()") 213 type=$(python -c "${type}; print TEST_TYPE.lower()")
188 local option 214 local option
189 if [ "${type}" == "client" ]; then 215 if [ "${type}" == "client" ]; then
190 option="-c" 216 option="-c"
191 elif [ "${type}" == "server" ]; then 217 elif [ "${type}" == "server" ]; then
192 option="-s" 218 option="-s"
193 else 219 else
194 echo "Unknown type of test (${type}) in ${control_file}" 220 echo_color "red" ">>> Unknown type of test (${type}) in ${control_file}"
195 exit 1 221 exit 1
196 fi 222 fi
197 echo "Running ${type} test ${control_file}" 223 echo ""
224 echo_color "yellow" ">>> Running ${type} test " ${control_file}
198 local short_name=$(basename $(dirname "${control_file}")) 225 local short_name=$(basename $(dirname "${control_file}"))
199 local start_time=$(date '+%s') 226 local results_dir_name="${short_name}"
200 local results_dir_name="${short_name},${FLAGS_machine_desc},${start_time}"
201 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" 227 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}"
202 rm -rf "${results_dir}" 228 rm -rf "${results_dir}"
203 local verbose="" 229 local verbose=""
204 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then 230 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then
205 verbose="--verbose" 231 verbose="--verbose"
206 fi 232 fi
207 233
208 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ 234 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \
209 -r "${results_dir}" ${verbose} 235 -r "${results_dir}" ${verbose}
210 local test_status="${results_dir}/status.log" 236 local test_status="${results_dir}/status.log"
211 local test_result_dir="${results_dir}/${short_name}" 237 local test_result_dir="${results_dir}/${short_name}"
212 local keyval_file="${test_result_dir}/results/keyval" 238 local keyval_file="${test_result_dir}/results/keyval"
239 echo ""
213 if is_successful_test "${test_status}"; then 240 if is_successful_test "${test_status}"; then
214 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}" 241 echo_color "green" ">>> SUCCESS: ${control_file}"
215 if [[ -f "${keyval_file}" ]]; then 242 if [[ -f "${keyval_file}" ]]; then
216 echo "Keyval was:" | tee -a "${FLAGS_output_file}" 243 echo ">>> Keyval was:"
217 cat "${keyval_file}" | tee -a "${FLAGS_output_file}" 244 cat "${keyval_file}"
218 fi 245 fi
219 else 246 else
220 echo "${control_file} failed:" | tee -a "${FLAGS_output_file}" 247 echo_color "red" ">>> FAILED: ${control_file}"
221 cat "${test_status}" | tee -a "${FLAGS_output_file}" 248 cat "${test_status}"
222 # Leave around output directory if the test failed.
223 FLAGS_cleanup=${FLAGS_FALSE}
224 fi 249 fi
225 local end_time=$(date '+%s') 250 local end_time=$(date '+%s')
226
227 # Update the database with results.
228 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} ]]; then
229 add_test_attribute "${results_dir}" machine-desc "${FLAGS_machine_desc}"
230 add_test_attribute "${results_dir}" build-desc "${FLAGS_build_desc}"
231 add_test_attribute "${results_dir}" server-start-time "${start_time}"
232 add_test_attribute "${results_dir}" server-end-time "${end_time}"
233 if ! "${parse_cmd}" -o "${results_dir}"; then
234 echo "Parse failed." | tee -a "${FLAGS_output_file}"
235 FLAGS_cleanup=${FLAGS_FALSE}
236 fi
237 fi
238 done 251 done
239
240 echo "Output stored to ${FLAGS_output_file}"
241 } 252 }
242 253
243 main $@ 254 main $@
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698