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

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
112 info \ 94 AUTOTEST_DIR="/build/${FLAGS_board}/usr/local/autotest"
113 "As requested, using emerged autotests already installed in your sysroot."
114 FLAGS_build=${FLAGS_FALSE} 95 FLAGS_build=${FLAGS_FALSE}
115 return 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 else
kmixter1 2010/11/24 23:31:21 please switch to fi.
ericli 2010/11/25 02:23:07 Done.
101 info \
102 "As requested, using emerged autotests already installed at ${AUTOTEST_DIR}."
103 return
104 fi
105 elif [ ${FLAGS_build} -eq ${FLAGS_FALSE} ] && \
kmixter1 2010/11/24 23:31:21 Please switch to: ... return fi if [ ${FLAGS_
ericli 2010/11/25 02:23:07 Done.
ericli 2010/11/25 02:23:07 Done.
106 $(dirname $0)/cros_workon --board=${FLAGS_board} list |
107 grep -q autotest; then
108 AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files"
109 FLAGS_build=${FLAGS_TRUE}
110 if [ ! -d "${AUTOTEST_DIR}" ]; then
111 die \
112 "Detected cros_workon autotest but ${AUTOTEST_DIR} does not exist. Run \
113 repo sync autotest."
114 else
kmixter1 2010/11/24 23:31:21 Please switch to fi as it shows the code following
115 info \
116 "Detected cros_workon autotests, Build and run autotests from ${AUTOTEST_DIR}. \
kmixter1 2010/11/24 19:50:13 Some clean up: Detected cros_workon autotests. B
ericli 2010/11/24 20:47:54 changed, but I kept emerged autotest instead of in
kmixter1 2010/11/24 23:31:21 OK.
117 To use emerged autotest, pass --use_emerged."
118 return
119 fi
116 fi 120 fi
117 if ${ENTER_CHROOT} ./cros_workon --board=${FLAGS_board} list | \ 121
118 grep -q autotest; then 122 # flag use_emerged should be false once the code reaches here.
kmixter1 2010/11/24 19:50:13 I'm not seeing how that's correct when it enters t
ericli 2010/11/24 20:47:54 if you enter this function with flag used_emerged
kmixter1 2010/11/24 23:31:21 I see that now, but it's not clear. I think some
119 info \ 123 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
120 "Detected cros_workon autotests, building your sources instead of emerged \ 124 AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files"
121 autotest. To use installed autotest, pass --use_emerged." 125 if [ ! -d "${AUTOTEST_DIR}" ]; then
122 FLAGS_build=${FLAGS_TRUE} 126 die \
127 "build flag was turned on but ${AUTOTEST_DIR} is not found. Run cros_workon \
kmixter1 2010/11/24 19:50:13 Capitalize
kmixter1 2010/11/24 23:31:21 Sorry if it wasn't clear: I'm requesting to capita
ericli 2010/11/25 02:23:07 I dont fully understand, why? On 2010/11/24 23:31
128 start autotest to continue."
129 else
kmixter1 2010/11/24 23:31:21 Please switch to fi as above.
ericli 2010/11/25 02:23:07 Done.
130 info "Build and run autotests from ${AUTOTEST_DIR}."
131 fi
123 else 132 else
kmixter1 2010/11/24 23:31:21 Suggest switching to fi, and returning above this.
ericli 2010/11/25 02:23:07 Done.
124 info \ 133 AUTOTEST_DIR="/build/${FLAGS_board}/usr/local/autotest"
125 "Using emerged autotests already installed in your sysroot. To build \ 134 if [ ! -d "${AUTOTEST_DIR}" ]; then
126 autotests directly from your source directory instead, pass --build." 135 die \
127 FLAGS_build=${FLAGS_FALSE} 136 "Autotest was not emerged, either emerge-${FLAGS_board} autotest \
137 autotest-tests or cros_workon start autotest to continue."
138 else
kmixter1 2010/11/24 23:31:21 Please switch to fi, as above.
ericli 2010/11/25 02:23:07 Done.
139 info "Using emerged autotests already installed at ${AUTOTEST_DIR}."
140 fi
128 fi 141 fi
129 } 142 }
130 143
131 function main() { 144 function main() {
132 cd $(dirname "$0") 145 cd $(dirname "$0")
133 146
134 FLAGS "$@" || exit 1 147 FLAGS "$@" || exit 1
135 148
136 if [[ -z "${FLAGS_ARGV}" ]]; then 149 if [[ -z "${FLAGS_ARGV}" ]]; then
137 echo "Usage: $0 --remote=[hostname] [regexp...]:" 150 echo "Usage: $0 --remote=[hostname] [regexp...]:"
(...skipping 15 matching lines...) Expand all
153 166
154 set -e 167 set -e
155 168
156 create_tmp 169 create_tmp
157 170
158 trap cleanup EXIT 171 trap cleanup EXIT
159 172
160 remote_access_init 173 remote_access_init
161 174
162 learn_board 175 learn_board
163 autotest_dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local/autotest" 176 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 177
182 local control_files_to_run="" 178 local control_files_to_run=""
183 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files " 179 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files "
184 # Now search for tests which unambiguously include the given identifier 180 # Now search for tests which unambiguously include the given identifier
185 local search_path=$(echo {client,server}/{tests,site_tests}) 181 local search_path=$(echo {client,server}/{tests,site_tests})
186 # Include chrome autotest in the search path 182 # Include chrome autotest in the search path
187 if [ -n "${CHROME_ROOT}" ]; then 183 if [ -n "${CHROME_ROOT}" ]; then
188 search_path="${search_path} ${chrome_autotests}/client/site_tests" 184 search_path="${search_path} ${chrome_autotests}/client/site_tests"
189 fi 185 fi
190 pushd ${autotest_dir} > /dev/null 186
187 pushd ${AUTOTEST_DIR} > /dev/null
191 for test_request in $FLAGS_ARGV; do 188 for test_request in $FLAGS_ARGV; do
192 test_request=$(remove_quotes "${test_request}") 189 test_request=$(remove_quotes "${test_request}")
193 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ 190 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \
194 -name control \) | egrep -v "~$" | egrep "${test_request}") 191 -name control \) | egrep -v "~$" | egrep "${test_request}")
195 if [[ -z "${finds}" ]]; then 192 if [[ -z "${finds}" ]]; then
196 die "Cannot find match for \"${test_request}\"" 193 die "Cannot find match for \"${test_request}\""
197 fi 194 fi
198 local matches=$(echo "${finds}" | wc -l) 195 local matches=$(echo "${finds}" | wc -l)
199 if [[ ${matches} -gt 1 ]]; then 196 if [[ ${matches} -gt 1 ]]; then
200 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \ 197 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \
201 "passing one of these patterns instead:" 198 "passing one of these patterns instead:"
202 for FIND in ${finds}; do 199 for FIND in ${finds}; do
203 echo " ^${FIND}\$" 200 echo " ^${FIND}\$"
204 done 201 done
205 exit 1 202 exit 1
206 fi 203 fi
207 for i in $(seq 1 $FLAGS_iterations); do 204 for i in $(seq 1 $FLAGS_iterations); do
208 control_files_to_run="${control_files_to_run} '${finds}'" 205 control_files_to_run="${control_files_to_run} '${finds}'"
209 done 206 done
210 done 207 done
211 popd > /dev/null
212 208
213 echo "" 209 echo ""
214 210
215 if [[ -z "${control_files_to_run}" ]]; then 211 if [[ -z "${control_files_to_run}" ]]; then
216 die "Found no control files" 212 die "Found no control files"
217 fi 213 fi
218 214
219 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && prepare_build_dir "${autotest_dir}" 215 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && prepare_build_env
220 216
221 info "Running the following control files:" 217 info "Running the following control files:"
222 for CONTROL_FILE in ${control_files_to_run}; do 218 for control_file in ${control_files_to_run}; do
223 info " * ${CONTROL_FILE}" 219 info " * ${control_file}"
224 done 220 done
225 221
226 for control_file in ${control_files_to_run}; do 222 for control_file in ${control_files_to_run}; do
227 # Assume a line starts with TEST_TYPE = 223 # Assume a line starts with TEST_TYPE =
228 control_file=$(remove_quotes "${control_file}") 224 control_file=$(remove_quotes "${control_file}")
229 local type=$(read_test_type "${autotest_dir}/${control_file}") 225 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) 226 # Check if the control file is an absolute path (i.e. chrome autotests case)
231 if [[ ${control_file:0:1} == "/" ]]; then 227 if [[ ${control_file:0:1} == "/" ]]; then
232 type=$(read_test_type "${control_file}") 228 test_type=$(read_test_type "${control_file}")
233 fi 229 fi
234 local option 230 local option
235 if [[ "${type}" == "client" ]]; then 231 if [[ "${test_type}" == "client" ]]; then
236 option="-c" 232 option="-c"
237 else 233 else
238 option="-s" 234 option="-s"
239 fi 235 fi
240 echo "" 236 echo ""
241 info "Running ${type} test ${control_file}" 237 info "Running ${test_type} test ${control_file}"
242 local control_file_name=$(basename "${control_file}") 238 local control_file_name=$(basename "${control_file}")
243 local short_name=$(basename $(dirname "${control_file}")) 239 local short_name=$(basename $(dirname "${control_file}"))
244 240
245 # testName/control --> testName 241 # testName/control --> testName
246 # testName/control.bvt --> testName.bvt 242 # testName/control.bvt --> testName.bvt
247 # testName/control.regression --> testName.regression 243 # testName/control.regression --> testName.regression
248 # testName/some_control --> testName.some_control 244 # testName/some_control --> testName.some_control
249 if [[ "${control_file_name}" != control ]]; then 245 if [[ "${control_file_name}" != control ]]; then
250 if [[ "${control_file_name}" == control.* ]]; then 246 if [[ "${control_file_name}" == control.* ]]; then
251 short_name=${short_name}.${control_file_name/control./} 247 short_name=${short_name}.${control_file_name/control./}
252 else 248 else
253 short_name=${short_name}.${control_file_name} 249 short_name=${short_name}.${control_file_name}
254 fi 250 fi
255 fi 251 fi
256 252
257 local results_dir_name="${short_name}" 253 local results_dir_name="${short_name}"
258 local results_dir="${TMP_INSIDE_CHROOT}/${results_dir_name}" 254 local results_dir="${TMP}/${results_dir_name}"
259 rm -rf "${results_dir}" 255 rm -rf "${results_dir}"
260 local verbose="" 256 local verbose=""
261 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then 257 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then
262 verbose="--verbose" 258 verbose="--verbose"
263 fi 259 fi
264 260
265 RAN_ANY_TESTS=${FLAGS_TRUE} 261 RAN_ANY_TESTS=${FLAGS_TRUE}
266 262
267 # Remove chrome autotest location prefix from control_file if needed 263 # Remove chrome autotest location prefix from control_file if needed
268 if [[ ${control_file:0:${#chrome_autotests}} == \ 264 if [[ ${control_file:0:${#chrome_autotests}} == \
269 "${chrome_autotests}" ]]; then 265 "${chrome_autotests}" ]]; then
270 control_file="${control_file:${#chrome_autotests}+1}" 266 control_file="${control_file:${#chrome_autotests}+1}"
271 info "Running chrome autotest ${control_file}" 267 info "Running chrome autotest ${control_file}"
272 fi 268 fi
273 269
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} \ 270 local autoserv_args="-m ${FLAGS_remote} --ssh-port ${FLAGS_ssh_port} \
279 ${option} ${control_file} -r ${results_dir} ${verbose}" 271 ${option} ${control_file} -r ${results_dir} ${verbose}"
280 if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ]; then 272 if [ -n "${FLAGS_args}" ]; then
281 cat > "${TMP}/run_test.sh" <<EOF 273 autoserv_args="${autoserv_args} -a \""${FLAGS_args}"\""
282 cd /build/${FLAGS_board}/usr/local/autotest 274 fi
283 sudo chmod a+w ./server/{tests,site_tests} 275
284 echo ./server/autoserv ${autoserv_args} ${autoserv_test_args} 276 sudo chmod a+w ./server/{tests,site_tests}
285 ./server/autoserv ${autoserv_args} ${autoserv_test_args} 277 echo ./server/autoserv ${autoserv_args}
286 EOF 278
287 chmod a+rx "${TMP}/run_test.sh" 279 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
288 ${ENTER_CHROOT} ${TMP_INSIDE_CHROOT}/run_test.sh >&2 280 # run autoserv in subshell
281 export autoserv_args
282 bash -c \
283 '. ${BUILD_ENV};tc-export CC CXX PKG_CONFIG;./server/autoserv ${autoserv_args}'
kmixter1 2010/11/24 19:50:13 nit: Amperands may make this easier to diagnose if
ericli 2010/11/24 20:47:54 Done.
289 else 284 else
290 cp "${BUILD_DIR}/environment" "${TMP}/run_test.sh" 285 ./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 286 fi
306 done 287 done
288 popd > /dev/null
307 289
308 echo "" 290 echo ""
309 info "Test results:" 291 info "Test results:"
310 ./generate_test_report "${TMP}" --strip="${TMP}/" 292 ./generate_test_report "${TMP}" --strip="${TMP}/"
311 293
312 print_time_elapsed 294 print_time_elapsed
313 } 295 }
314 296
297 restart_in_chroot_if_needed $*
315 main "$@" 298 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