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