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

Side by Side Diff: run_remote_tests.sh

Issue 5176009: Continue to refactor run_remote_tests script. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: patch Created 10 years 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 | Annotate | Revision Log
« 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.
(...skipping 30 matching lines...) Expand all
41 cleanup_remote_access 41 cleanup_remote_access
42 } 42 }
43 43
44 # Determine if a control is for a client or server test. Echos 44 # Determine if a control is for a client or server test. Echos
45 # either "server" or "client". 45 # either "server" or "client".
46 # Arguments: 46 # Arguments:
47 # $1 - control file path 47 # $1 - control file path
48 function read_test_type() { 48 function read_test_type() {
49 local control_file=$1 49 local control_file=$1
50 # Assume a line starts with TEST_TYPE = 50 # Assume a line starts with TEST_TYPE =
51 local type=$(egrep -m1 \ 51 local test_type=$(egrep -m1 \
52 '^[[:space:]]*TEST_TYPE[[:space:]]*=' "${control_file}") 52 '^[[:space:]]*TEST_TYPE[[:space:]]*=' "${control_file}")
53 if [[ -z "${type}" ]]; then 53 if [[ -z "${test_type}" ]]; then
54 die "Unable to find TEST_TYPE line in ${control_file}" 54 die "Unable to find TEST_TYPE line in ${control_file}"
55 fi 55 fi
56 type=$(python -c "${type}; print TEST_TYPE.lower()") 56 test_type=$(python -c "${test_type}; print TEST_TYPE.lower()")
57 if [[ "${type}" != "client" ]] && [[ "${type}" != "server" ]]; then 57 if [[ "${test_type}" != "client" ]] && [[ "${test_type}" != "server" ]]; then
58 die "Unknown type of test (${type}) in ${control_file}" 58 die "Unknown type of test (${test_type}) in ${control_file}"
59 fi 59 fi
60 echo ${type} 60 echo ${test_type}
61 } 61 }
62 62
63 function create_tmp() { 63 function create_tmp() {
64 # Set global TMP for remote_access.sh's sake 64 # Set global TMP for remote_access.sh's sake
65 # and if --results_dir_root is specified, 65 # and if --results_dir_root is specified,
66 # set TMP and create dir appropriately 66 # set TMP and create dir appropriately
67 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then 67 if [[ -n "${FLAGS_results_dir_root}" ]]; then
68 if [[ -n "${FLAGS_results_dir_root}" ]]; then 68 TMP=${FLAGS_results_dir_root}
69 TMP=${FLAGS_chroot}${FLAGS_results_dir_root} 69 mkdir -p -m 777 ${TMP}
70 mkdir -p -m 777 ${TMP}
71 else
72 TMP=$(mktemp -d ${FLAGS_chroot}/tmp/run_remote_tests.XXXX)
73 fi
74 TMP_INSIDE_CHROOT=$(echo ${TMP#${FLAGS_chroot}})
75 else 70 else
76 if [[ -n "${FLAGS_results_dir_root}" ]]; then 71 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX)
77 TMP=${FLAGS_results_dir_root}
78 mkdir -p -m 777 ${TMP}
79 else
80 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX)
81 fi
82 TMP_INSIDE_CHROOT=${TMP}
83 fi 72 fi
84 } 73 }
85 74
86 function prepare_build_dir() { 75 function prepare_build_env() {
87 local autotest_dir="$1"
88 INSIDE_BUILD_DIR="${TMP_INSIDE_CHROOT}/build"
89 BUILD_DIR="${TMP}/build"
90 info "Copying autotest tree into ${BUILD_DIR}."
91 sudo mkdir -p "${BUILD_DIR}"
92 sudo rsync -rl --chmod=ugo=rwx "${autotest_dir}"/ "${BUILD_DIR}"
93 info "Pilfering toolchain shell environment from Portage." 76 info "Pilfering toolchain shell environment from Portage."
94 local outside_ebuild_dir="${TMP}/chromeos-base/autotest-build" 77 local ebuild_dir="${TMP}/chromeos-base/autotest-build"
95 local inside_ebuild_dir="${TMP_INSIDE_CHROOT}/chromeos-base/autotest-build" 78 mkdir -p "${ebuild_dir}"
96 mkdir -p "${outside_ebuild_dir}"
97 local E_only="autotest-build-9999.ebuild" 79 local E_only="autotest-build-9999.ebuild"
98 cat > "${outside_ebuild_dir}/${E_only}" <<EOF 80 cat > "${ebuild_dir}/${E_only}" <<EOF
99 inherit toolchain-funcs 81 inherit toolchain-funcs
100 SLOT="0" 82 SLOT="0"
101 EOF 83 EOF
102 local E="chromeos-base/autotest-build/${E_only}" 84 local E="chromeos-base/autotest-build/${E_only}"
103 ${ENTER_CHROOT} "ebuild-${FLAGS_board}" "${inside_ebuild_dir}/${E_only}" \ 85 "ebuild-${FLAGS_board}" --skip-manifest "${ebuild_dir}/${E_only}" \
104 clean unpack 2>&1 > /dev/null 86 clean unpack 2>&1 > /dev/null
105 local P_tmp="${FLAGS_chroot}/build/${FLAGS_board}/tmp/portage/" 87 local P_tmp="/build/${FLAGS_board}/tmp/portage/"
106 local E_dir="${E%%/*}/${E_only%.*}" 88 local E_dir="${E%%/*}/${E_only%.*}"
107 sudo cp "${P_tmp}/${E_dir}/temp/environment" "${BUILD_DIR}" 89 export BUILD_ENV="${P_tmp}/${E_dir}/temp/environment"
108 } 90 }
109 91
110 function autodetect_build() { 92 function autodetect_build() {
111 if [ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]; then 93 if [ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]; then
94 AUTOTEST_DIR="/build/${FLAGS_board}/usr/local/autotest"
95 FLAGS_build=${FLAGS_FALSE}
96 if [ ! -d "${AUTOTEST_DIR}" ]; then
97 die \
98 "Could not find pre-installed autotest, you need to emerge-${FLAGS_board} \
99 autotest autotest-tests (or use --build)."
100 fi
112 info \ 101 info \
113 "As requested, using emerged autotests already installed in your sysroot." 102 "As requested, using emerged autotests already installed at ${AUTOTEST_DIR}."
114 FLAGS_build=${FLAGS_FALSE}
115 return 103 return
116 fi 104 fi
117 if ${ENTER_CHROOT} ./cros_workon --board=${FLAGS_board} list | \ 105
118 grep -q autotest; then 106 if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ] &&
107 $(dirname $0)/cros_workon --board=${FLAGS_board} list |
108 grep -q autotest; then
109 AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files"
110 FLAGS_build=${FLAGS_TRUE}
111 if [ ! -d "${AUTOTEST_DIR}" ]; then
112 die \
113 "Detected cros_workon autotest but ${AUTOTEST_DIR} does not exist. Run \
114 repo sync autotest."
115 fi
119 info \ 116 info \
120 "Detected cros_workon autotests, building your sources instead of emerged \ 117 "Detected cros_workon autotests. Building and running your autotests from \
121 autotest. To use installed autotest, pass --use_emerged." 118 ${AUTOTEST_DIR}. To use emerged autotest, pass --use_emerged."
122 FLAGS_build=${FLAGS_TRUE} 119 return
120 fi
121
122 # flag use_emerged should be false once the code reaches here.
123 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
124 AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files"
125 if [ ! -d "${AUTOTEST_DIR}" ]; then
126 die \
127 "Build flag was turned on but ${AUTOTEST_DIR} is not found. Run cros_workon \
128 start autotest to continue."
kmixter1 2010/11/29 22:04:36 Isn't it also necessary to repo sync in this case?
ericli 2010/11/29 22:12:37 Yes, true. But this reflect what it had before thi
129 fi
130 info "Build and run autotests from ${AUTOTEST_DIR}."
123 else 131 else
124 info \ 132 AUTOTEST_DIR="/build/${FLAGS_board}/usr/local/autotest"
125 "Using emerged autotests already installed in your sysroot. To build \ 133 if [ ! -d "${AUTOTEST_DIR}" ]; then
126 autotests directly from your source directory instead, pass --build." 134 die \
127 FLAGS_build=${FLAGS_FALSE} 135 "Autotest was not emerged, either emerge-${FLAGS_board} autotest \
136 autotest-tests or cros_workon start autotest to continue."
kmixter1 2010/11/29 22:04:36 If you cros_workon you probably need to repo sync
ericli 2010/11/29 22:12:37 OK. On 2010/11/29 22:04:36, kmixter1 wrote:
137 fi
138 info "Using emerged autotests already installed at ${AUTOTEST_DIR}."
128 fi 139 fi
129 } 140 }
130 141
131 function main() { 142 function main() {
132 cd $(dirname "$0") 143 cd $(dirname "$0")
133 144
134 FLAGS "$@" || exit 1 145 FLAGS "$@" || exit 1
135 146
136 if [[ -z "${FLAGS_ARGV}" ]]; then 147 if [[ -z "${FLAGS_ARGV}" ]]; then
137 echo "Usage: $0 --remote=[hostname] [regexp...]:" 148 echo "Usage: $0 --remote=[hostname] [regexp...]:"
(...skipping 15 matching lines...) Expand all
153 164
154 set -e 165 set -e
155 166
156 create_tmp 167 create_tmp
157 168
158 trap cleanup EXIT 169 trap cleanup EXIT
159 170
160 remote_access_init 171 remote_access_init
161 172
162 learn_board 173 learn_board
163 autotest_dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local/autotest" 174 autodetect_build
164
165 ENTER_CHROOT=""
166 if [[ ${INSIDE_CHROOT} -eq 0 ]]; then
167 ENTER_CHROOT="./enter_chroot.sh --chroot ${FLAGS_chroot} --"
168 fi
169
170 if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ]; then
171 autodetect_build
172 fi
173
174 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
175 autotest_dir="${SRC_ROOT}/third_party/autotest/files"
176 else
177 if [ ! -d "${autotest_dir}" ]; then
178 die "You need to emerge autotest-tests (or use --build)"
179 fi
180 fi
181 175
182 local control_files_to_run="" 176 local control_files_to_run=""
183 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files " 177 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files "
184 # Now search for tests which unambiguously include the given identifier 178 # Now search for tests which unambiguously include the given identifier
185 local search_path=$(echo {client,server}/{tests,site_tests}) 179 local search_path=$(echo {client,server}/{tests,site_tests})
186 # Include chrome autotest in the search path 180 # Include chrome autotest in the search path
187 if [ -n "${CHROME_ROOT}" ]; then 181 if [ -n "${CHROME_ROOT}" ]; then
188 search_path="${search_path} ${chrome_autotests}/client/site_tests" 182 search_path="${search_path} ${chrome_autotests}/client/site_tests"
189 fi 183 fi
190 pushd ${autotest_dir} > /dev/null 184
185 pushd ${AUTOTEST_DIR} > /dev/null
191 for test_request in $FLAGS_ARGV; do 186 for test_request in $FLAGS_ARGV; do
192 test_request=$(remove_quotes "${test_request}") 187 test_request=$(remove_quotes "${test_request}")
193 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ 188 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \
194 -name control \) | egrep -v "~$" | egrep "${test_request}") 189 -name control \) | egrep -v "~$" | egrep "${test_request}")
195 if [[ -z "${finds}" ]]; then 190 if [[ -z "${finds}" ]]; then
196 die "Cannot find match for \"${test_request}\"" 191 die "Cannot find match for \"${test_request}\""
197 fi 192 fi
198 local matches=$(echo "${finds}" | wc -l) 193 local matches=$(echo "${finds}" | wc -l)
199 if [[ ${matches} -gt 1 ]]; then 194 if [[ ${matches} -gt 1 ]]; then
200 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \ 195 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \
201 "passing one of these patterns instead:" 196 "passing one of these patterns instead:"
202 for FIND in ${finds}; do 197 for FIND in ${finds}; do
203 echo " ^${FIND}\$" 198 echo " ^${FIND}\$"
204 done 199 done
205 exit 1 200 exit 1
206 fi 201 fi
207 for i in $(seq 1 $FLAGS_iterations); do 202 for i in $(seq 1 $FLAGS_iterations); do
208 control_files_to_run="${control_files_to_run} '${finds}'" 203 control_files_to_run="${control_files_to_run} '${finds}'"
209 done 204 done
210 done 205 done
211 popd > /dev/null
212 206
213 echo "" 207 echo ""
214 208
215 if [[ -z "${control_files_to_run}" ]]; then 209 if [[ -z "${control_files_to_run}" ]]; then
216 die "Found no control files" 210 die "Found no control files"
217 fi 211 fi
218 212
219 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && prepare_build_dir "${autotest_dir}" 213 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && prepare_build_env
220 214
221 info "Running the following control files:" 215 info "Running the following control files:"
222 for CONTROL_FILE in ${control_files_to_run}; do 216 for control_file in ${control_files_to_run}; do
223 info " * ${CONTROL_FILE}" 217 info " * ${control_file}"
224 done 218 done
225 219
226 for control_file in ${control_files_to_run}; do 220 for control_file in ${control_files_to_run}; do
227 # Assume a line starts with TEST_TYPE = 221 # Assume a line starts with TEST_TYPE =
228 control_file=$(remove_quotes "${control_file}") 222 control_file=$(remove_quotes "${control_file}")
229 local type=$(read_test_type "${autotest_dir}/${control_file}") 223 local test_type=$(read_test_type "${AUTOTEST_DIR}/${control_file}")
230 # Check if the control file is an absolute path (i.e. chrome autotests case) 224 # Check if the control file is an absolute path (i.e. chrome autotests case)
231 if [[ ${control_file:0:1} == "/" ]]; then 225 if [[ ${control_file:0:1} == "/" ]]; then
232 type=$(read_test_type "${control_file}") 226 test_type=$(read_test_type "${control_file}")
233 fi 227 fi
234 local option 228 local option
235 if [[ "${type}" == "client" ]]; then 229 if [[ "${test_type}" == "client" ]]; then
236 option="-c" 230 option="-c"
237 else 231 else
238 option="-s" 232 option="-s"
239 fi 233 fi
240 echo "" 234 echo ""
241 info "Running ${type} test ${control_file}" 235 info "Running ${test_type} test ${control_file}"
242 local control_file_name=$(basename "${control_file}") 236 local control_file_name=$(basename "${control_file}")
243 local short_name=$(basename $(dirname "${control_file}")) 237 local short_name=$(basename $(dirname "${control_file}"))
244 238
245 # testName/control --> testName 239 # testName/control --> testName
246 # testName/control.bvt --> testName.bvt 240 # testName/control.bvt --> testName.bvt
247 # testName/control.regression --> testName.regression 241 # testName/control.regression --> testName.regression
248 # testName/some_control --> testName.some_control 242 # testName/some_control --> testName.some_control
249 if [[ "${control_file_name}" != control ]]; then 243 if [[ "${control_file_name}" != control ]]; then
250 if [[ "${control_file_name}" == control.* ]]; then 244 if [[ "${control_file_name}" == control.* ]]; then
251 short_name=${short_name}.${control_file_name/control./} 245 short_name=${short_name}.${control_file_name/control./}
252 else 246 else
253 short_name=${short_name}.${control_file_name} 247 short_name=${short_name}.${control_file_name}
254 fi 248 fi
255 fi 249 fi
256 250
257 local results_dir_name="${short_name}" 251 local results_dir_name="${short_name}"
258 local results_dir="${TMP_INSIDE_CHROOT}/${results_dir_name}" 252 local results_dir="${TMP}/${results_dir_name}"
259 rm -rf "${results_dir}" 253 rm -rf "${results_dir}"
260 local verbose="" 254 local verbose=""
261 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then 255 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then
262 verbose="--verbose" 256 verbose="--verbose"
263 fi 257 fi
264 258
265 RAN_ANY_TESTS=${FLAGS_TRUE} 259 RAN_ANY_TESTS=${FLAGS_TRUE}
266 260
267 # Remove chrome autotest location prefix from control_file if needed 261 # Remove chrome autotest location prefix from control_file if needed
268 if [[ ${control_file:0:${#chrome_autotests}} == \ 262 if [[ ${control_file:0:${#chrome_autotests}} == \
269 "${chrome_autotests}" ]]; then 263 "${chrome_autotests}" ]]; then
270 control_file="${control_file:${#chrome_autotests}+1}" 264 control_file="${control_file:${#chrome_autotests}+1}"
271 info "Running chrome autotest ${control_file}" 265 info "Running chrome autotest ${control_file}"
272 fi 266 fi
273 267
274 local autoserv_test_args="${FLAGS_args}"
275 if [ -n "${autoserv_test_args}" ]; then
276 autoserv_test_args="-a \"${autoserv_test_args}\""
277 fi
278 local autoserv_args="-m ${FLAGS_remote} --ssh-port ${FLAGS_ssh_port} \ 268 local autoserv_args="-m ${FLAGS_remote} --ssh-port ${FLAGS_ssh_port} \
279 ${option} ${control_file} -r ${results_dir} ${verbose}" 269 ${option} ${control_file} -r ${results_dir} ${verbose}"
280 if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ]; then 270 if [ -n "${FLAGS_args}" ]; then
281 cat > "${TMP}/run_test.sh" <<EOF 271 autoserv_args="${autoserv_args} -a \""${FLAGS_args}"\""
282 cd /build/${FLAGS_board}/usr/local/autotest 272 fi
283 sudo chmod a+w ./server/{tests,site_tests} 273
284 echo ./server/autoserv ${autoserv_args} ${autoserv_test_args} 274 sudo chmod a+w ./server/{tests,site_tests}
285 ./server/autoserv ${autoserv_args} ${autoserv_test_args} 275 echo ./server/autoserv ${autoserv_args}
286 EOF 276
287 chmod a+rx "${TMP}/run_test.sh" 277 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
288 ${ENTER_CHROOT} ${TMP_INSIDE_CHROOT}/run_test.sh >&2 278 # run autoserv in subshell
279 (. ${BUILD_ENV} && tc-export CC CXX PKG_CONFIG &&
280 ./server/autoserv ${autoserv_args})
289 else 281 else
290 cp "${BUILD_DIR}/environment" "${TMP}/run_test.sh" 282 ./server/autoserv ${autoserv_args}
291 GRAPHICS_BACKEND=${GRAPHICS_BACKEND:-OPENGL}
292 cat >> "${TMP}/run_test.sh" <<EOF
293 export GCLIENT_ROOT=/home/${USER}/trunk
294 export GRAPHICS_BACKEND=${GRAPHICS_BACKEND}
295 export SSH_AUTH_SOCK=${SSH_AUTH_SOCK} TMPDIR=/tmp SSH_AGENT_PID=${SSH_AGENT_PID}
296 export SYSROOT=/build/${FLAGS_board}
297 tc-export CC CXX PKG_CONFIG
298 cd ${INSIDE_BUILD_DIR}
299 echo ./server/autoserv ${autoserv_args} ${autoserv_test_args}
300 ./server/autoserv ${autoserv_args} ${autoserv_test_args}
301 EOF
302 sudo cp "${TMP}/run_test.sh" "${BUILD_DIR}"
303 sudo chmod a+rx "${BUILD_DIR}/run_test.sh"
304 ${ENTER_CHROOT} sudo bash -c "${INSIDE_BUILD_DIR}/run_test.sh" >&2
305 fi 283 fi
306 done 284 done
285 popd > /dev/null
307 286
308 echo "" 287 echo ""
309 info "Test results:" 288 info "Test results:"
310 ./generate_test_report "${TMP}" --strip="${TMP}/" 289 ./generate_test_report "${TMP}" --strip="${TMP}/"
311 290
312 print_time_elapsed 291 print_time_elapsed
313 } 292 }
314 293
294 restart_in_chroot_if_needed $*
315 main "$@" 295 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