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

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: patchwq Created 10 years, 1 month 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 setup_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}" "${ebuild_dir}/${E_only}" clean unpack 2>&1 \
104 clean unpack 2>&1 > /dev/null 86 > /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 . "${P_tmp}/${E_dir}/temp/environment"
90 tc-export CC CXX PKG_CONFIG
108 } 91 }
109 92
110 function autodetect_build() { 93 function autodetect_build() {
jrbarnette 2010/11/23 00:11:29 In this function, if FLAGS_use_emerged is false, a
ericli 2010/11/23 18:49:29 Hi Richard, Thanks to push me think more about the
111 if [ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]; then 94 if [ ${FLAGS_use_emerged} -eq ${FLAGS_TRUE} ]; then
112 info \
113 "As requested, using emerged autotests already installed in your sysroot."
114 FLAGS_build=${FLAGS_FALSE} 95 FLAGS_build=${FLAGS_FALSE}
96 AUTOTEST_DIR="/build/${FLAGS_board}/usr/local/autotest"
97 if [ -d "${AUTOTEST_DIR}" ] ; then
98 info \
99 "As requested, using emerged autotests already installed at ${AUTOTEST_DIR}."
100 else
101 die \
102 "Could not find pre-installed autotest, you need to emerge-${FLAGS_board} \
103 autotest-tests (or use --build)."
104 fi
115 return 105 return
116 fi 106 fi
117 if ${ENTER_CHROOT} ./cros_workon --board=${FLAGS_board} list | \ 107 if $(dirname $0)/cros_workon --board=${FLAGS_board} list | \
118 grep -q autotest; then 108 grep -q autotest; then
109 FLAGS_build=${FLAGS_TRUE}
119 info \ 110 info \
120 "Detected cros_workon autotests, building your sources instead of emerged \ 111 "Detected cros_workon autotests, building your sources instead of emerged \
121 autotest. To use installed autotest, pass --use_emerged." 112 autotest. To use installed autotest, pass --use_emerged."
122 FLAGS_build=${FLAGS_TRUE} 113 fi
123 else 114 if [ ${FLAGS_build} -eq ${FLAGS_TRUE} ]; then
124 info \ 115 AUTOTEST_DIR="${SRC_ROOT}/third_party/autotest/files"
125 "Using emerged autotests already installed in your sysroot. To build \ 116 if [ -d "${AUTOTEST_DIR}" ] ; then
126 autotests directly from your source directory instead, pass --build." 117 info "Use autotest src from ${AUTOTEST_DIR}."
127 FLAGS_build=${FLAGS_FALSE} 118 else
119 die \
120 "build flag was turned on but ${AUTOTEST_DIR} is not found. Run cros_workon \
121 start autotest first."
122 fi
128 fi 123 fi
129 } 124 }
130 125
131 function main() { 126 function main() {
132 cd $(dirname "$0") 127 cd $(dirname "$0")
133 128
134 FLAGS "$@" || exit 1 129 FLAGS "$@" || exit 1
135 130
136 if [[ -z "${FLAGS_ARGV}" ]]; then 131 if [[ -z "${FLAGS_ARGV}" ]]; then
137 echo "Usage: $0 --remote=[hostname] [regexp...]:" 132 echo "Usage: $0 --remote=[hostname] [regexp...]:"
(...skipping 15 matching lines...) Expand all
153 148
154 set -e 149 set -e
155 150
156 create_tmp 151 create_tmp
157 152
158 trap cleanup EXIT 153 trap cleanup EXIT
159 154
160 remote_access_init 155 remote_access_init
161 156
162 learn_board 157 learn_board
163 autotest_dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local/autotest" 158 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 159
182 local control_files_to_run="" 160 local control_files_to_run=""
183 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files " 161 local chrome_autotests="${CHROME_ROOT}/src/chrome/test/chromeos/autotest/files "
184 # Now search for tests which unambiguously include the given identifier 162 # Now search for tests which unambiguously include the given identifier
185 local search_path=$(echo {client,server}/{tests,site_tests}) 163 local search_path=$(echo {client,server}/{tests,site_tests})
186 # Include chrome autotest in the search path 164 # Include chrome autotest in the search path
187 if [ -n "${CHROME_ROOT}" ]; then 165 if [ -n "${CHROME_ROOT}" ]; then
188 search_path="${search_path} ${chrome_autotests}/client/site_tests" 166 search_path="${search_path} ${chrome_autotests}/client/site_tests"
189 fi 167 fi
190 pushd ${autotest_dir} > /dev/null 168
169 pushd ${AUTOTEST_DIR} > /dev/null
191 for test_request in $FLAGS_ARGV; do 170 for test_request in $FLAGS_ARGV; do
192 test_request=$(remove_quotes "${test_request}") 171 test_request=$(remove_quotes "${test_request}")
193 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \ 172 ! finds=$(find ${search_path} -maxdepth 2 -type f \( -name control.\* -or \
194 -name control \) | egrep -v "~$" | egrep "${test_request}") 173 -name control \) | egrep -v "~$" | egrep "${test_request}")
195 if [[ -z "${finds}" ]]; then 174 if [[ -z "${finds}" ]]; then
196 die "Cannot find match for \"${test_request}\"" 175 die "Cannot find match for \"${test_request}\""
197 fi 176 fi
198 local matches=$(echo "${finds}" | wc -l) 177 local matches=$(echo "${finds}" | wc -l)
199 if [[ ${matches} -gt 1 ]]; then 178 if [[ ${matches} -gt 1 ]]; then
200 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \ 179 echo ">>> \"${test_request}\" is an ambiguous pattern. Disambiguate by" \
201 "passing one of these patterns instead:" 180 "passing one of these patterns instead:"
202 for FIND in ${finds}; do 181 for FIND in ${finds}; do
203 echo " ^${FIND}\$" 182 echo " ^${FIND}\$"
204 done 183 done
205 exit 1 184 exit 1
206 fi 185 fi
207 for i in $(seq 1 $FLAGS_iterations); do 186 for i in $(seq 1 $FLAGS_iterations); do
208 control_files_to_run="${control_files_to_run} '${finds}'" 187 control_files_to_run="${control_files_to_run} '${finds}'"
209 done 188 done
210 done 189 done
211 popd > /dev/null
212 190
213 echo "" 191 echo ""
214 192
215 if [[ -z "${control_files_to_run}" ]]; then 193 if [[ -z "${control_files_to_run}" ]]; then
216 die "Found no control files" 194 die "Found no control files"
217 fi 195 fi
218 196
219 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && prepare_build_dir "${autotest_dir}" 197 [ ${FLAGS_build} -eq ${FLAGS_TRUE} ] && setup_build_env
220 198
221 info "Running the following control files:" 199 info "Running the following control files:"
222 for CONTROL_FILE in ${control_files_to_run}; do 200 for control_file in ${control_files_to_run}; do
223 info " * ${CONTROL_FILE}" 201 info " * ${control_file}"
224 done 202 done
225 203
226 for control_file in ${control_files_to_run}; do 204 for control_file in ${control_files_to_run}; do
227 # Assume a line starts with TEST_TYPE = 205 # Assume a line starts with TEST_TYPE =
228 control_file=$(remove_quotes "${control_file}") 206 control_file=$(remove_quotes "${control_file}")
229 local type=$(read_test_type "${autotest_dir}/${control_file}") 207 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) 208 # Check if the control file is an absolute path (i.e. chrome autotests case)
231 if [[ ${control_file:0:1} == "/" ]]; then 209 if [[ ${control_file:0:1} == "/" ]]; then
232 type=$(read_test_type "${control_file}") 210 test_type=$(read_test_type "${control_file}")
233 fi 211 fi
234 local option 212 local option
235 if [[ "${type}" == "client" ]]; then 213 if [[ "${test_type}" == "client" ]]; then
236 option="-c" 214 option="-c"
237 else 215 else
238 option="-s" 216 option="-s"
239 fi 217 fi
240 echo "" 218 echo ""
241 info "Running ${type} test ${control_file}" 219 info "Running ${test_type} test ${control_file}"
242 local control_file_name=$(basename "${control_file}") 220 local control_file_name=$(basename "${control_file}")
243 local short_name=$(basename $(dirname "${control_file}")) 221 local short_name=$(basename $(dirname "${control_file}"))
244 222
245 # testName/control --> testName 223 # testName/control --> testName
246 # testName/control.bvt --> testName.bvt 224 # testName/control.bvt --> testName.bvt
247 # testName/control.regression --> testName.regression 225 # testName/control.regression --> testName.regression
248 # testName/some_control --> testName.some_control 226 # testName/some_control --> testName.some_control
249 if [[ "${control_file_name}" != control ]]; then 227 if [[ "${control_file_name}" != control ]]; then
250 if [[ "${control_file_name}" == control.* ]]; then 228 if [[ "${control_file_name}" == control.* ]]; then
251 short_name=${short_name}.${control_file_name/control./} 229 short_name=${short_name}.${control_file_name/control./}
252 else 230 else
253 short_name=${short_name}.${control_file_name} 231 short_name=${short_name}.${control_file_name}
254 fi 232 fi
255 fi 233 fi
256 234
257 local results_dir_name="${short_name}" 235 local results_dir_name="${short_name}"
258 local results_dir="${TMP_INSIDE_CHROOT}/${results_dir_name}" 236 local results_dir="${TMP}/${results_dir_name}"
259 rm -rf "${results_dir}" 237 rm -rf "${results_dir}"
260 local verbose="" 238 local verbose=""
261 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then 239 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then
262 verbose="--verbose" 240 verbose="--verbose"
263 fi 241 fi
264 242
265 RAN_ANY_TESTS=${FLAGS_TRUE} 243 RAN_ANY_TESTS=${FLAGS_TRUE}
266 244
267 # Remove chrome autotest location prefix from control_file if needed 245 # Remove chrome autotest location prefix from control_file if needed
268 if [[ ${control_file:0:${#chrome_autotests}} == \ 246 if [[ ${control_file:0:${#chrome_autotests}} == \
269 "${chrome_autotests}" ]]; then 247 "${chrome_autotests}" ]]; then
270 control_file="${control_file:${#chrome_autotests}+1}" 248 control_file="${control_file:${#chrome_autotests}+1}"
271 info "Running chrome autotest ${control_file}" 249 info "Running chrome autotest ${control_file}"
272 fi 250 fi
273 251
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} \ 252 local autoserv_args="-m ${FLAGS_remote} --ssh-port ${FLAGS_ssh_port} \
279 ${option} ${control_file} -r ${results_dir} ${verbose}" 253 ${option} ${control_file} -r ${results_dir} ${verbose}"
280 if [ ${FLAGS_build} -eq ${FLAGS_FALSE} ]; then 254 if [ -n "${FLAGS_args}" ]; then
281 cat > "${TMP}/run_test.sh" <<EOF 255 autoserv_args="${autoserv_args} -a \""${FLAGS_args}"\""
282 cd /build/${FLAGS_board}/usr/local/autotest
283 sudo chmod a+w ./server/{tests,site_tests}
284 echo ./server/autoserv ${autoserv_args} ${autoserv_test_args}
285 ./server/autoserv ${autoserv_args} ${autoserv_test_args}
286 EOF
287 chmod a+rx "${TMP}/run_test.sh"
288 ${ENTER_CHROOT} ${TMP_INSIDE_CHROOT}/run_test.sh >&2
289 else
290 cp "${BUILD_DIR}/environment" "${TMP}/run_test.sh"
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 256 fi
257
258 sudo chmod a+w ./server/{tests,site_tests}
259 echo ./server/autoserv ${autoserv_args}
260 ./server/autoserv ${autoserv_args}
306 done 261 done
262 popd > /dev/null
307 263
308 echo "" 264 echo ""
309 info "Test results:" 265 info "Test results:"
310 ./generate_test_report "${TMP}" --strip="${TMP}/" 266 ./generate_test_report "${TMP}" --strip="${TMP}/"
311 267
312 print_time_elapsed 268 print_time_elapsed
313 } 269 }
314 270
271 restart_in_chroot_if_needed $*
315 main "$@" 272 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