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" | |
14 . "$(dirname $0)/remote_access.sh" | 13 . "$(dirname $0)/remote_access.sh" |
15 | 14 |
16 DEFINE_boolean build ${FLAGS_FALSE} "Build tests as well as running them" b | 15 get_default_board |
| 16 |
| 17 DEFINE_string board "$DEFAULT_BOARD" \ |
| 18 "The board for which you are building autotest" |
17 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c | 19 DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c |
18 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory" | 20 DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory" |
19 DEFINE_integer iterations 1 "Iterations to run every top level test" i | 21 DEFINE_integer iterations 1 "Iterations to run every top level test" i |
20 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir" | 22 DEFINE_string prepackaged_autotest "" "Use this prepackaged autotest dir" |
21 DEFINE_string results_dir_root "" "alternate root results directory" | 23 DEFINE_string results_dir_root "" "alternate root results directory" |
22 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v | 24 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v |
23 | 25 |
24 RAN_ANY_TESTS=${FLAGS_FALSE} | 26 RAN_ANY_TESTS=${FLAGS_FALSE} |
25 | 27 |
26 # Check if our stdout is a tty | 28 # Check if our stdout is a tty |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 144 |
143 if [[ -z "${FLAGS_ARGV}" ]]; then | 145 if [[ -z "${FLAGS_ARGV}" ]]; then |
144 echo "Please specify tests to run. For example:" | 146 echo "Please specify tests to run. For example:" |
145 echo " $0 --remote=MyMachine BootPerfServer" | 147 echo " $0 --remote=MyMachine BootPerfServer" |
146 exit 1 | 148 exit 1 |
147 fi | 149 fi |
148 | 150 |
149 set -e | 151 set -e |
150 | 152 |
151 # Set global TMP for remote_access.sh's sake | 153 # Set global TMP for remote_access.sh's sake |
152 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) | 154 if [[ ${INSIDE_CHROOT} -eq 0 ]] |
| 155 then |
| 156 TMP=$(mktemp -d ${FLAGS_chroot}/tmp/run_remote_tests.XXXX) |
| 157 TMP_INSIDE_CHROOT=$(echo ${TMP#${FLAGS_chroot}}) |
| 158 else |
| 159 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX) |
| 160 TMP_INSIDE_CHROOT=${TMP} |
| 161 fi |
153 | 162 |
154 trap cleanup EXIT | 163 trap cleanup EXIT |
155 | 164 |
156 remote_access_init | 165 remote_access_init |
157 | 166 |
158 local autotest_dir="" | 167 local autotest_dir="" |
159 if [[ -z "${FLAGS_prepackaged_autotest}" ]]; then | 168 if [[ -z "${FLAGS_prepackaged_autotest}" ]]; then |
160 learn_board | 169 learn_board |
161 # Always copy into installed autotest directory. This way if a user | 170 autotest_dir="${GCLIENT_ROOT}/src/third_party/autotest/files" |
162 # is just modifying scripts, they take effect without having to wait | |
163 # for the laborious build_autotest.sh command. | |
164 local original="${GCLIENT_ROOT}/src/third_party/autotest/files" | |
165 autotest_dir="/build/${FLAGS_board}/usr/local/autotest" | |
166 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then | |
167 autotest_dir="${FLAGS_chroot}/${autotest_dir}" | |
168 fi | |
169 update_chroot_autotest "${original}" "${autotest_dir}" | |
170 else | 171 else |
171 autotest_dir="${FLAGS_prepackaged_autotest}" | 172 autotest_dir="${FLAGS_prepackaged_autotest}" |
172 fi | 173 fi |
173 | 174 |
174 local autoserv="${autotest_dir}/server/autoserv" | |
175 | |
176 local control_files_to_run="" | 175 local control_files_to_run="" |
177 | 176 |
178 # Now search for tests which unambiguously include the given identifier | 177 # Now search for tests which unambiguously include the given identifier |
179 local search_path=$(echo ${autotest_dir}/{client,server}/{tests,site_tests}) | 178 local search_path=$(echo {client,server}/{tests,site_tests}) |
| 179 pushd ${autotest_dir} > /dev/null |
180 for test_request in $FLAGS_ARGV; do | 180 for test_request in $FLAGS_ARGV; do |
181 test_request=$(remove_quotes "${test_request}") | 181 test_request=$(remove_quotes "${test_request}") |
182 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ | 182 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ |
183 -name control \) | egrep -v "~$" | egrep "${test_request}") | 183 -name control \) | egrep -v "~$" | egrep "${test_request}") |
184 if [[ -z "${finds}" ]]; then | 184 if [[ -z "${finds}" ]]; then |
185 echo_color "red" ">>> Cannot find match for \"${test_request}\"" | 185 echo_color "red" ">>> Cannot find match for \"${test_request}\"" |
186 exit 1 | 186 exit 1 |
187 fi | 187 fi |
188 local matches=$(echo "${finds}" | wc -l) | 188 local matches=$(echo "${finds}" | wc -l) |
189 if [[ ${matches} -gt 1 ]]; then | 189 if [[ ${matches} -gt 1 ]]; then |
190 echo "" | 190 echo "" |
191 echo_color "red" \ | 191 echo_color "red" \ |
192 ">>> \"${test_request}\" is ambiguous. These control file paths match:" | 192 ">>> \"${test_request}\" is ambiguous. These control file paths match:" |
193 for FIND in ${finds}; do | 193 for FIND in ${finds}; do |
194 echo_color "red" " * " "${FIND}" | 194 echo_color "red" " * " "${FIND}" |
195 done | 195 done |
196 echo "" | 196 echo "" |
197 echo ">>> Disambiguate by copy-and-pasting the whole path above" \ | 197 echo ">>> Disambiguate by copy-and-pasting the whole path above" \ |
198 "instead of passing \"${test_request}\"." | 198 "instead of passing \"${test_request}\"." |
199 exit 1 | 199 exit 1 |
200 fi | 200 fi |
201 for i in $(seq 1 $FLAGS_iterations); do | 201 for i in $(seq 1 $FLAGS_iterations); do |
202 control_files_to_run="${control_files_to_run} '${finds}'" | 202 control_files_to_run="${control_files_to_run} '${finds}'" |
203 done | 203 done |
204 done | 204 done |
| 205 popd > /dev/null |
205 | 206 |
206 echo "" | 207 echo "" |
207 | 208 |
208 if [[ -z "${control_files_to_run}" ]]; then | 209 if [[ -z "${control_files_to_run}" ]]; then |
209 echo_color "red" ">>> Found no control files" | 210 echo_color "red" ">>> Found no control files" |
210 exit 1 | 211 exit 1 |
211 fi | 212 fi |
212 | 213 |
213 echo_color "yellow" ">>> Running the following control files:" | 214 echo_color "yellow" ">>> Running the following control files:" |
214 for CONTROL_FILE in ${control_files_to_run}; do | 215 for CONTROL_FILE in ${control_files_to_run}; do |
215 echo_color "yellow" " * " "${CONTROL_FILE}" | 216 echo_color "yellow" " * " "${CONTROL_FILE}" |
216 done | 217 done |
217 | 218 |
218 if [[ -z "${FLAGS_results_dir_root}" ]]; then | 219 if [[ -z "${FLAGS_results_dir_root}" ]]; then |
219 FLAGS_results_dir_root="${TMP}" | 220 FLAGS_results_dir_root="${TMP_INSIDE_CHROOT}" |
220 fi | 221 fi |
221 | 222 |
222 mkdir -p "${FLAGS_results_dir_root}" | 223 mkdir -p "${FLAGS_results_dir_root}" |
223 | 224 |
224 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | |
225 # Create a list of files to build based on all the client tests | |
226 # the user has specified. If they have specified at least one | |
227 # that is a server test, offer to build all client tests since | |
228 # it's quite hard to know what client tests a server test might | |
229 # use. | |
230 local build_param="" | |
231 for control_file in ${control_files_to_run}; do | |
232 control_file=$(remove_quotes "${control_file}") | |
233 local type=$(read_test_type "${control_file}") | |
234 if [[ "${type}" == "server" ]]; then | |
235 build_param="" | |
236 break | |
237 fi | |
238 if [[ -n "${build_param}" ]]; then | |
239 build_param="${build_param}," | |
240 fi | |
241 local simple_path=$(basename $(dirname $control_file)) | |
242 build_param="${build_param}${simple_path}" | |
243 done | |
244 local enter_chroot="" | |
245 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then | |
246 enter_chroot="./enter_chroot.sh --" | |
247 fi | |
248 if [[ -n "${build_param}" ]]; then | |
249 build_param="--build=${build_param}" | |
250 fi | |
251 echo "" | |
252 echo_color "yellow" ">>> Building " \ | |
253 "./build_autotest.sh --board=${FLAGS_board} ${build_param}" | |
254 ${enter_chroot} ./build_autotest.sh --board=${FLAGS_board} ${build_param} | |
255 fi | |
256 | |
257 for control_file in ${control_files_to_run}; do | 225 for control_file in ${control_files_to_run}; do |
258 # Assume a line starts with TEST_TYPE = | 226 # Assume a line starts with TEST_TYPE = |
259 control_file=$(remove_quotes "${control_file}") | 227 control_file=$(remove_quotes "${control_file}") |
260 local type=$(read_test_type "${control_file}") | 228 local type=$(read_test_type "${autotest_dir}/${control_file}") |
261 local option | 229 local option |
262 if [[ "${type}" == "client" ]]; then | 230 if [[ "${type}" == "client" ]]; then |
263 option="-c" | 231 option="-c" |
264 else | 232 else |
265 option="-s" | 233 option="-s" |
266 fi | 234 fi |
267 echo "" | 235 echo "" |
268 echo_color "yellow" ">>> Running ${type} test " ${control_file} | 236 echo_color "yellow" ">>> Running ${type} test " ${control_file} |
269 local short_name=$(basename $(dirname "${control_file}")) | 237 local short_name=$(basename $(dirname "${control_file}")) |
270 local results_dir_name="${short_name}" | 238 local results_dir_name="${short_name}" |
271 local results_dir="${FLAGS_results_dir_root}/${results_dir_name}" | 239 local results_dir="${TMP_INSIDE_CHROOT}/${results_dir_name}" |
272 rm -rf "${results_dir}" | 240 rm -rf "${results_dir}" |
273 local verbose="" | 241 local verbose="" |
274 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then | 242 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then |
275 verbose="--verbose" | 243 verbose="--verbose" |
276 fi | 244 fi |
277 | 245 |
278 RAN_ANY_TESTS=${FLAGS_TRUE} | 246 RAN_ANY_TESTS=${FLAGS_TRUE} |
279 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \ | 247 |
280 -r "${results_dir}" ${verbose} | 248 local enter_chroot="" |
| 249 local autotest="${GCLIENT_ROOT}/src/scripts/autotest" |
| 250 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then |
| 251 enter_chroot="./enter_chroot.sh --" |
| 252 autotest="./autotest" |
| 253 fi |
| 254 |
| 255 ${enter_chroot} ${autotest} --board "${FLAGS_board}" -m "${FLAGS_remote}" \ |
| 256 "${option}" "${control_file}" -r "${results_dir}" ${verbose} |
| 257 |
| 258 results_dir="${TMP}/${results_dir_name}" |
281 local test_status="${results_dir}/status.log" | 259 local test_status="${results_dir}/status.log" |
282 local test_result_dir="${results_dir}/${short_name}" | 260 local test_result_dir="${results_dir}/${short_name}" |
283 local keyval_file="${test_result_dir}/results/keyval" | 261 local keyval_file="${test_result_dir}/results/keyval" |
284 echo "" | 262 echo "" |
285 if is_successful_test "${test_status}"; then | 263 if is_successful_test "${test_status}"; then |
286 echo_color "green" ">>> SUCCESS: ${control_file}" | 264 echo_color "green" ">>> SUCCESS: ${control_file}" |
287 if [[ -f "${keyval_file}" ]]; then | 265 if [[ -f "${keyval_file}" ]]; then |
288 echo ">>> Keyval was:" | 266 echo ">>> Keyval was:" |
289 cat "${keyval_file}" | 267 cat "${keyval_file}" |
290 fi | 268 fi |
291 else | 269 else |
292 echo_color "red" ">>> FAILED: ${control_file}" | 270 echo_color "red" ">>> FAILED: ${control_file}" |
293 cat "${test_status}" | 271 cat "${test_status}" |
294 fi | 272 fi |
295 local end_time=$(date '+%s') | 273 local end_time=$(date '+%s') |
296 done | 274 done |
297 } | 275 } |
298 | 276 |
299 main $@ | 277 main $@ |
OLD | NEW |