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

Side by Side Diff: src/scripts/run_remote_tests.sh

Issue 519041: Simple way to run client/server autotest(s) from server (Closed)
Patch Set: No longer necessary to graft Created 10 years, 11 months 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
« no previous file with comments | « src/scripts/remote_access.sh ('k') | 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
(Empty)
1 #!/bin/bash
2
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
5 # found in the LICENSE file.
6
7 # Script to run client or server tests on a live remote image.
8
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.
11
12 . "$(dirname $0)/common.sh"
13 . "$(dirname $0)/remote_access.sh"
14
15 DEFAULT_OUTPUT_FILE=test-output-$(date '+%Y%m%d.%H%M%S')
16
17 DEFINE_boolean cleanup ${FLAGS_TRUE} "Clean up temp directory"
18 DEFINE_integer iterations 1 "Iterations to run every top level test" i
19 DEFINE_string output_file "${DEFAULT_OUTPUT_FILE}" "Test run output" o
20 DEFINE_boolean verbose ${FLAGS_FALSE} "Show verbose autoserv output" v
21 DEFINE_boolean update_db ${FLAGS_FALSE} "Put results in autotest database" u
22 DEFINE_string machine_desc "" "Machine description used in database"
23
24 function cleanup() {
25 if [[ $FLAGS_cleanup -eq ${FLAGS_TRUE} ]]; then
26 rm -rf "${TMP}"
27 else
28 echo "Left temporary files at ${TMP}"
29 fi
30 }
31
32 # Returns an error if the test_result_file has text which indicates
33 # the test was not run successfully.
34 # Arguments:
35 # $1 - file name of autotest status for to check for success
36 # Returns:
37 # None
38 function is_successful_test() {
39 local file="$1"
40 # To be successful, must not have FAIL or BAD in the file.
41 if egrep -q "(BAD|FAIL)" "${file}"; then
42 return 1
43 fi
44 # To be successful, must have GOOD in the file.
45 if ! grep -q GOOD "${file}"; then
46 return 1
47 fi
48 return 0
49 }
50
51 # Removes single quotes around parameter
52 # Arguments:
53 # $1 - string which optionally has surrounding quotes
54 # Returns:
55 # None, but prints the string without quotes.
56 function remove_quotes() {
57 echo "$1" | sed -e "s/^'//; s/'$//"
58 }
59
60 function main() {
61 assert_outside_chroot
62
63 cd $(dirname "$0")
64
65 FLAGS "$@" || exit 1
66
67 if [[ -z "${FLAGS_ARGV}" ]]; then
68 echo "Please specify tests to run, like:"
69 echo " $0 --remote=MyMachine SystemBootPerf"
70 exit 1
71 fi
72
73 local parse_cmd="$(dirname $0)/../third_party/autotest/files/tko/parse.py"
74
75 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} && ! -x "${parse_cmd}" ]]; then
76 echo "Cannot find parser ${parse_cmd}"
77 exit 1
78 fi
79
80 set -e
81
82 # Set global TMP for remote_access.sh's sake
83 TMP=$(mktemp -d /tmp/run_remote_tests.XXXX)
84
85 rm -f "${FLAGS_output_file}"
86
87 trap cleanup EXIT
88
89 cp -r "${SRC_ROOT}/third_party/autotest/files" "${TMP}/autotest"
90
91 local control_files_to_run=""
92
93 # Now search for tests which unambiguously include the given identifier
94 local search_path=$(echo ${TMP}/autotest/{client,server}/{tests,site_tests})
95 for test_request in $FLAGS_ARGV; do
96 test_request=$(remove_quotes "${test_request}")
97 ! finds=$(find ${search_path} -type f -name control | \
98 egrep "${test_request}")
99 if [[ -z "${finds}" ]]; then
100 echo "Can not find match for ${test_request}"
101 exit 1
102 fi
103 local matches=$(echo "${finds}" | wc -l)
104 if [[ ${matches} -gt 1 ]]; then
105 echo "${test_request} is ambiguous:"
106 echo "${finds}"
107 exit 1
108 fi
109 for i in $(seq 1 $FLAGS_iterations); do
110 control_files_to_run="${control_files_to_run} '${finds}'"
111 done
112 done
113
114 echo "Running the following control files: ${control_files_to_run}"
115
116 remote_access_init
117
118 # Set the default machine description to the machine's IP
119 if [[ -z "${FLAGS_machine_desc}" ]]; then
120 FLAGS_machine_desc="${FLAGS_remote}"
121 fi
122
123 local autoserv="${TMP}/autotest/server/autoserv"
124
125 for control_file in ${control_files_to_run}; do
126 # Assume a line starts with TEST_TYPE =
127 control_file=$(remove_quotes "${control_file}")
128 local type=$(egrep '^\s*TEST_TYPE\s*=' "${control_file}" | head -1)
129 type=$(python -c "${type}; print TEST_TYPE.lower()")
130 local option
131 if [ "${type}" == "client" ]; then
132 option="-c"
133 elif [ "${type}" == "server" ]; then
134 option="-s"
135 else
136 echo "Unknown type of test (${type}) in ${control_file}"
137 exit 1
138 fi
139 echo "Running ${type} test ${control_file}"
140 local short_name=$(basename $(dirname "${control_file}"))
141 local timestamp=$(date '+%s')
142 local results_dir="${TMP}/${short_name},${FLAGS_machine_desc},${timestamp}"
143 rm -rf "${results_dir}"
144 local verbose=""
145 if [[ ${FLAGS_verbose} -eq $FLAGS_TRUE ]]; then
146 verbose="--verbose"
147 fi
148 ${autoserv} -m "${FLAGS_remote}" "${option}" "${control_file}" \
149 -r "${results_dir}" ${verbose}
150 local test_status="${results_dir}/status"
151 local test_result_dir="${results_dir}/${short_name}"
152 local keyval_file="${test_result_dir}/results/keyval"
153 if is_successful_test "${test_status}"; then
154 echo "${control_file} succeeded." | tee -a "${FLAGS_output_file}"
155 if [[ -f "${keyval_file}" ]]; then
156 echo "Keyval was:" | tee -a "${FLAGS_output_file}"
157 cat "${keyval_file}" | tee -a "${FLAGS_output_file}"
158 fi
159 else
160 echo "${control_file} failed:" | tee -a "${FLAGS_output_file}"
161 cat "${test_status}" | tee -a "${FLAGS_output_file}"
162 # Leave around output directory if the test failed.
163 FLAGS_cleanup=${FLAGS_FALSE}
164 fi
165
166 # Update the database with results.
167 if [[ ${FLAGS_update_db} -eq ${FLAGS_TRUE} ]]; then
168 if ! "${parse_cmd}" -o "${results_dir}"; then
169 echo "Parse failed." | tee -a "${FLAGS_output_file}"
170 FLAGS_cleanup=${FLAGS_FALSE}
171 fi
172 fi
173 done
174
175 echo "Output stored to ${FLAGS_output_file}"
176 }
177
178 main $@
OLDNEW
« no previous file with comments | « src/scripts/remote_access.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698