blob: 373505db40759be4d6d286905c3ffaca2fe0f5b3 [file] [log] [blame]
Zdenek Behan12ad1c52010-08-03 16:34:37 -07001# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2# Distributed under the terms of the GNU General Public License v2
3
4#
5# Original Author: The Chromium OS Authors <chromium-os-dev@chromium.org>
6# Purpose: Eclass for handling autotest test packages
7#
8
Aviv Keshet4144c8d2013-07-22 10:52:53 -07009inherit cros-constants
10
Zdenek Behan9e98f322010-08-26 18:56:54 -070011RDEPEND="( autotest? ( >=chromeos-base/autotest-0.0.1-r3 ) )"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070012
Zdenek Behan302e7482011-02-01 21:58:52 +010013IUSE="+buildcheck autotest opengles"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070014
15# Ensure the configures run by autotest pick up the right config.site
Zdenek Behan99bf5842010-08-04 17:23:38 -070016export CONFIG_SITE="/usr/share/config.site"
17export AUTOTEST_WORKDIR="${WORKDIR}/autotest-work"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070018
Zdenek Behancd997a32010-08-20 12:55:44 -070019# @ECLASS-VARIABLE: AUTOTEST_CLIENT_*
20# @DESCRIPTION:
21# Location of the appropriate test directory inside ${S}
22: ${AUTOTEST_CLIENT_TESTS:=client/tests}
23: ${AUTOTEST_CLIENT_SITE_TESTS:=client/site_tests}
Alex Miller01855e42014-04-06 22:43:36 -070024: ${AUTOTEST_SERVER_TESTS:=server/tests}
25: ${AUTOTEST_SERVER_SITE_TESTS:=server/site_tests}
Zdenek Behan41463c92010-08-23 12:12:31 -070026: ${AUTOTEST_CONFIG:=client/config}
27: ${AUTOTEST_DEPS:=client/deps}
28: ${AUTOTEST_PROFILERS:=client/profilers}
29
30# @ECLASS-VARIABLE: AUTOTEST_*_LIST
31# @DESCRIPTION:
32# The list of deps/configs/profilers provided with this package
Chris Sosa6bde1602012-03-15 23:19:57 -070033: ${AUTOTEST_CONFIG_LIST:=}
34: ${AUTOTEST_DEPS_LIST:=}
35: ${AUTOTEST_PROFILERS_LIST:=}
Zdenek Behancd997a32010-08-20 12:55:44 -070036
Zdenek Behand012b762010-09-01 21:22:26 -070037# @ECLASS-VARIABLE: AUTOTEST_FORCE_LIST
38# @DESCRIPTION:
39# Sometimes we just want to forget about useflags and build what's inside
40: ${AUTOTEST_FORCE_TEST_LIST:=}
41
Zdenek Behanb1f7c892010-09-22 12:25:38 -070042# @ECLASS-VARIABLE: AUTOTEST_FILE_MASK
43# @DESCRIPTION:
44# The list of 'find' expressions to find in the resulting image and delete
45: ${AUTOTEST_FILE_MASK:=}
46
Chris Sosa6bde1602012-03-15 23:19:57 -070047fast_cp() {
Zdenek Behan7922d132010-09-24 14:18:05 -070048 cp -l "$@" || cp "$@"
49}
50
Chris Sosa6bde1602012-03-15 23:19:57 -070051get_test_list() {
Zdenek Behand012b762010-09-01 21:22:26 -070052 if [ -n "${AUTOTEST_FORCE_TEST_LIST}" ]; then
53 # list forced
54 echo "${AUTOTEST_FORCE_TEST_LIST}"
55 return
56 fi
57
58 # we cache the result of this operation in AUTOTEST_TESTS,
59 # because it's expensive and does not change over the course of one ebuild run
Albert Chaulk85eeef52014-01-08 15:26:33 -033060 local tests=$(portageq use_reduce "${IUSE_TESTS[*]}")
61 local result="${tests//[+-]tests_/}"
Zdenek Behand012b762010-09-01 21:22:26 -070062 result="${result//tests_/}"
63
64 result=$(for test in ${result}; do use tests_${test} && echo -n "${test} "; done)
65 echo "${result}"
66}
67
Chris Sosa6bde1602012-03-15 23:19:57 -070068# Pythonify the list of packages by doing the equivalent of ','.join(args)
69pythonify_test_list() {
70 local result=$(printf '%s,' "$@")
71 echo ${result%,}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070072}
73
74# Create python package init files for top level test case dirs.
Chris Sosa6bde1602012-03-15 23:19:57 -070075touch_init_py() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -070076 local dirs=${1}
77 for base_dir in $dirs
78 do
79 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
80 for sub_dir in ${sub_dirs}
81 do
82 touch ${sub_dir}/__init__.py
83 done
84 touch ${base_dir}/__init__.py
85 done
86}
87
Zdenek Behan361d8142012-03-19 04:30:45 +010088# Exports a CROS_WORKON_SUBDIRS_TO_COPY variable to ensure that only the
89# necessary files will be copied. This cannot be applied globally, as some
90# ebuilds may not have tests only.
91autotest_restrict_workon_subdirs() {
92 CROS_WORKON_SUBDIRS_TO_COPY=()
93 local var
94 for var in AUTOTEST_{CLIENT,SERVER}_{TESTS,SITE_TESTS} \
95 AUTOTEST_{CONFIG,DEPS,PROFILERS}; do
96 CROS_WORKON_SUBDIRS_TO_COPY+=( ${!var} )
97 done
98}
99
Chris Sosa6bde1602012-03-15 23:19:57 -0700100setup_cross_toolchain() {
Mike Frysingerb1eda9e2012-03-08 14:56:18 -0500101 tc-export CC CXX AR RANLIB LD NM STRIP PKG_CONFIG
102 export CCFLAGS="$CFLAGS"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700103}
104
Chris Sosa6bde1602012-03-15 23:19:57 -0700105create_autotest_workdir() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700106 local dst=${1}
107
108 # create a working enviroment for pre-building
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700109 ln -sf "${SYSROOT}"${AUTOTEST_BASE}/{conmux,tko,global_config.ini,shadow_config.ini} "${dst}"/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700110
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700111 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
112 # to make sure the binaries are real, because they do the path magic
113 local root_path base_path
Chris Masone21512432010-11-15 16:18:57 -0800114 for base_path in utils server; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700115 root_path="${SYSROOT}${AUTOTEST_BASE}/${base_path}"
Chris Masone21512432010-11-15 16:18:57 -0800116 mkdir -p "${dst}/${base_path}"
117 for entry in $(ls "${root_path}"); do
Zdenek Behan7e9e32f2012-02-28 03:15:46 +0100118 # Take all important binaries from SYSROOT install, make a copy.
119 if [ -d "${root_path}/${entry}" ]; then
120 # Ignore anything that has already been put in place by
121 # something else. This will typically be server/{site_tests,tests}.
122 if ! [ -e "${dst}/${base_path}/${entry}" ]; then
123 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
124 fi
Chris Masone21512432010-11-15 16:18:57 -0800125 else
126 cp -f ${root_path}/${entry} ${dst}/${base_path}/
127 fi
128 done
129 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700130 for base_path in client client/bin; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700131 root_path="${SYSROOT}${AUTOTEST_BASE}/${base_path}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700132 mkdir -p "${dst}/${base_path}"
133
Zdenek Behan451e07f2010-08-06 11:25:37 -0700134 # Skip bin, because it is processed separately, and test-provided dirs
135 # Also don't symlink to packages, because that kills the build
Zdenek Behan41463c92010-08-23 12:12:31 -0700136 for entry in $(ls "${root_path}" | \
137 grep -v "\(bin\|tests\|site_tests\|config\|deps\|profilers\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700138 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
139 done
140 done
141 # replace the important binaries with real copies
142 for base_path in autotest autotest_client; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700143 root_path="${SYSROOT}${AUTOTEST_BASE}/client/bin/${base_path}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700144 rm "${dst}/client/bin/${base_path}"
145 cp -f ${root_path} "${dst}/client/bin/${base_path}"
146 done
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700147
148 # Selectively pull in deps that are not provided by the current test package
149 for base_path in config deps profilers; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700150 for dir in "${SYSROOT}${AUTOTEST_BASE}/client/${base_path}"/*; do
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700151 if [ -d "${dir}" ] && \
152 ! [ -d "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" ]; then
153 # directory does not exist, create a symlink
154 ln -sf "${dir}" "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})"
155 fi
156 done
157 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700158}
159
Chris Sosa6bde1602012-03-15 23:19:57 -0700160print_test_dirs() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700161 local testroot="${1}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700162 local ignore_test_contents="${2}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700163
164 pushd "${testroot}" 1> /dev/null
165 for test in *; do
Chris Sosa6bde1602012-03-15 23:19:57 -0700166 if [ -d "${test}" ] && [ -n "${ignore_test_contents}" -o \
167 -f "${test}/${test}".py ]; then
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700168 echo "${test}"
169 fi
170 done
171 popd 1> /dev/null
172}
173
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700174# checks IUSE_TESTS and sees if at least one of these is enabled
Chris Sosa6bde1602012-03-15 23:19:57 -0700175are_we_used() {
Zdenek Behan14ae4892010-08-26 15:25:30 -0700176 if ! use autotest; then
177 # unused
178 return 1
179 fi
180
Zdenek Behand012b762010-09-01 21:22:26 -0700181 [ -n "$(get_test_list)" ] && return 0
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700182
183 # unused
184 return 1
185}
186
Chris Sosa6bde1602012-03-15 23:19:57 -0700187autotest_src_prepare() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700188 are_we_used || return 0
189 einfo "Preparing tests"
190
191 # FIXME: These directories are needed, autotest quietly dies if
192 # they don't even exist. They may, however, stay empty.
Zdenek Behanc02fc472010-08-13 12:55:07 -0700193 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
194 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behan41463c92010-08-23 12:12:31 -0700195 mkdir -p "${AUTOTEST_WORKDIR}"/client/config
196 mkdir -p "${AUTOTEST_WORKDIR}"/client/deps
197 mkdir -p "${AUTOTEST_WORKDIR}"/client/profilers
Alex Miller01855e42014-04-06 22:43:36 -0700198 mkdir -p "${AUTOTEST_WORKDIR}"/server/tests
199 mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700200
Zdenek Behand012b762010-09-01 21:22:26 -0700201 TEST_LIST=$(get_test_list)
202
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700203 # Pull in the individual test cases.
Zdenek Behan31315b32010-08-05 16:34:39 -0700204 for l1 in client server; do
205 for l2 in site_tests tests; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700206 # pick up the indicated location of test sources
207 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}}
208
Zdenek Behand012b762010-09-01 21:22:26 -0700209 # test does have this directory
210 for test in ${TEST_LIST}; do
211 if [ -d "${srcdir}/${test}" ]; then
Zdenek Behan7922d132010-09-24 14:18:05 -0700212 fast_cp -fpr "${srcdir}/${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
Zdenek Behand012b762010-09-01 21:22:26 -0700213 fi
214 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700215 done
216 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700217
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700218 # Pull in all the deps provided by this package, selectively.
Zdenek Behan41463c92010-08-23 12:12:31 -0700219 for l2 in config deps profilers; do
220 # pick up the indicated location of test sources
221 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l2^^*}}
222
223 if [ -d "${srcdir}" ]; then # test does have this directory
224 pushd "${srcdir}" 1> /dev/null
225 eval deplist=\${AUTOTEST_${l2^^*}_LIST}
226
227 if [ "${deplist}" = "*" ]; then
Zdenek Behan7922d132010-09-24 14:18:05 -0700228 fast_cp -fpr * "${AUTOTEST_WORKDIR}/client/${l2}"
Zdenek Behan41463c92010-08-23 12:12:31 -0700229 else
230 for dir in ${deplist}; do
Zdenek Behan7922d132010-09-24 14:18:05 -0700231 fast_cp -fpr "${dir}" "${AUTOTEST_WORKDIR}/client/${l2}"/ || die
Zdenek Behan41463c92010-08-23 12:12:31 -0700232 done
233 fi
234 popd 1> /dev/null
235 fi
236 done
237
Zdenek Behan474fbae2010-08-20 21:13:22 -0700238 # FIXME: We'd like if this were not necessary, and autotest supported out-of-tree build
Zdenek Behan99bf5842010-08-04 17:23:38 -0700239 create_autotest_workdir "${AUTOTEST_WORKDIR}"
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700240
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700241 # Each test directory needs to be visited and have an __init__.py created.
242 # However, that only applies to the directories which have a main .py file.
Zdenek Behanedb527a2010-09-22 12:24:14 -0700243 pushd "${AUTOTEST_WORKDIR}" > /dev/null || die "AUTOTEST_WORKDIR does not exist?!"
Alex Miller01855e42014-04-06 22:43:36 -0700244 for dir in client/tests client/site_tests server/tests server/site_tests; do
Zdenek Behanedb527a2010-09-22 12:24:14 -0700245 pushd "${dir}" > /dev/null || continue
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700246 for sub in *; do
247 [ -f "${sub}/${sub}.py" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700248
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700249 touch_init_py ${sub}
250 done
Zdenek Behanedb527a2010-09-22 12:24:14 -0700251 popd > /dev/null
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700252 done
Zdenek Behanedb527a2010-09-22 12:24:14 -0700253 popd > /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700254
255 # Cleanup checked-in binaries that don't support the target architecture
256 [[ ${E_MACHINE} == "" ]] && return 0;
Zdenek Behan092f4632010-09-21 19:34:01 -0700257 rm -fv $( scanelf -RmyBF%a "${AUTOTEST_WORKDIR}" | grep -v -e ^${E_MACHINE} )
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700258}
259
Chris Sosa6bde1602012-03-15 23:19:57 -0700260autotest_src_compile() {
Zdenek Behan48096a82010-09-23 19:39:26 -0700261 if ! are_we_used; then
262 ewarn "***************************************************************"
263 ewarn "* Not building any tests, because the requested list is empty *"
264 ewarn "***************************************************************"
265 return 0
266 fi
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700267 einfo "Compiling tests"
268
Zdenek Behan31315b32010-08-05 16:34:39 -0700269 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700270
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700271 setup_cross_toolchain
272
273 if use opengles ; then
274 graphics_backend=OPENGLES
275 else
276 graphics_backend=OPENGL
277 fi
278
Zdenek Behan9e979bb2010-09-23 17:32:05 -0700279 # HACK: Some of the autotests depend on SYSROOT being defined, and die
280 # a gruesome death if it isn't. But SYSROOT does not need to exist, for
281 # example on the host, it doesn't. Let's define a compatible variable
282 # here in case we have none.
283 export SYSROOT=${SYSROOT:-"/"}
284
Zdenek Behan8ad65252010-09-07 12:35:19 -0700285 # This only prints the tests that have the associated .py
286 # (and therefore a setup function)
287 local prebuild_test_dirs="
Chris Sosa1767b532012-11-09 15:13:15 -0800288 client/tests client/site_tests"
Zdenek Behan8ad65252010-09-07 12:35:19 -0700289 TESTS=$(\
290 for dir in ${prebuild_test_dirs}; do
291 print_test_dirs "${AUTOTEST_WORKDIR}/${dir}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700292 done | sort -u)
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100293 NR_TESTS=$(echo ${TESTS}|wc -w)
294 if ! [ "${NR_TESTS}" = "0" ]; then
295 einfo "Building tests (${NR_TESTS}):"
296 einfo "${TESTS}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700297
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100298 NORMAL=$(echo -e "\e[0m")
299 GREEN=$(echo -e "\e[1;32m")
300 RED=$(echo -e "\e[1;31m")
Zdenek Behan402fea02010-09-14 13:50:09 -0700301
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100302 # Call autotest to prebuild all test cases.
303 # Parse output through a colorifying sed script
304 ( GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
305 client/bin/autotest_client --quiet \
306 --client_test_setup=$(pythonify_test_list ${TESTS}) \
307 || ! use buildcheck || die "Tests failed to build."
308 ) | sed -e "s/\(INFO:root:setup\)/${GREEN}* \1${NORMAL}/" \
309 -e "s/\(ERROR:root:\[.*\]\)/${RED}\1${NORMAL}/"
310 else
311 einfo "No tests to prebuild, skipping"
312 fi
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700313
314 # Cleanup some temp files after compiling
Zdenek Behan7c162bb2012-05-14 18:42:15 +0200315 for mask in '*.[do]' '*.pyc' ${AUTOTEST_FILE_MASK}; do
Zdenek Behanb1f7c892010-09-22 12:25:38 -0700316 einfo "Purging ${mask}"
317 find . -name "${mask}" -delete
318 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700319
320 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700321}
322
Chris Sosa6bde1602012-03-15 23:19:57 -0700323autotest_src_install() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700324 are_we_used || return 0
325 einfo "Installing tests"
326
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700327 # Install all test cases, after setup has been called on them.
328 # We install everything, because nothing else is copied into the
329 # testcase directories besides what this package provides.
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700330 local instdirs="
331 client/tests
Alex Miller01855e42014-04-06 22:43:36 -0700332 client/site_tests
333 server/tests
334 server/site_tests"
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700335
336 for dir in ${instdirs}; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700337 [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700338
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700339 insinto ${AUTOTEST_BASE}/$(dirname ${dir})
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700340 doins -r "${AUTOTEST_WORKDIR}/${dir}"
341 done
342
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700343 # Install the deps, configs, profilers.
344 # Difference from above is, we don't install the whole thing, just
345 # the stuff provided by this package, by looking at AUTOTEST_*_LIST.
346 instdirs="
347 config
348 deps
349 profilers"
350
351 for dir in ${instdirs}; do
352 [ -d "${AUTOTEST_WORKDIR}/client/${dir}" ] || continue
353
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700354 insinto ${AUTOTEST_BASE}/client/${dir}
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700355
Aviv Keshet605cfb12014-02-12 14:52:23 -0800356 # Capitalize the string dir (e.g. profilers -> PROFILERS)
357 # then pull out the value of e.g. AUTOTEST_PROFILERS_LIST
358 # into provided.
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700359 eval provided=\${AUTOTEST_${dir^^*}_LIST}
Aviv Keshet605cfb12014-02-12 14:52:23 -0800360
361 # If provided is *, we evaluate the wildcard outselves
362 # by running `ls` inside of the approriate subdirectory
363 # of the ebuild workdir.
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700364 if [ "${provided}" = "*" ]; then
365 if eval pushd "${WORKDIR}/${P}/\${AUTOTEST_${dir^^*}}" &> /dev/null; then
366 provided=$(ls)
367 popd 1> /dev/null
368 else
369 provided=""
370 fi
371 fi
372
373 for item in ${provided}; do
Aviv Keshet605cfb12014-02-12 14:52:23 -0800374 local item_path="${AUTOTEST_WORKDIR}/client/${dir}/${item}"
375 # Warn on files that do not exist, rather than failing. See
376 # crbug.com/342512 for context.
377 if [[ -e "${item_path}" ]]; then
378 doins -r "${item_path}"
379 else
380 ewarn "No file ${item_path}, skipping."
381 fi
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700382 done
383 done
384
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700385 # TODO: Not all needs to be executable, but it's hard to pick selectively.
386 # The source repo should already contain stuff with the right permissions.
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700387 chmod -R a+x "${D}"${AUTOTEST_BASE}/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700388}
389
Chris Sosa6bde1602012-03-15 23:19:57 -0700390autotest_pkg_postinst() {
Mandeep Singh Baines060c2db2012-12-07 17:12:31 -0800391 are_we_used || return 0
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700392 local root_autotest_dir="${ROOT}${AUTOTEST_BASE}"
393 local path_to_image="${D}${AUTOTEST_BASE}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700394 # Should only happen when running emerge on a DUT.
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700395 if [ ! -e "${root_autotest_dir}/utils/packager.py" ]; then
Chris Sosa6bde1602012-03-15 23:19:57 -0700396 einfo "Skipping packaging as no autotest installation detected."
397 return 0
398 fi
Chris Masone21512432010-11-15 16:18:57 -0800399
Chris Sosa6bde1602012-03-15 23:19:57 -0700400 # Gather the artifacts we want autotest to package.
401 local test_opt dep_opt prof_opt
Chris Sosaccb6c8b2012-03-09 10:47:32 -0800402
Chris Sosa6bde1602012-03-15 23:19:57 -0700403 # Only client tests can be packaged.
404 local tests_to_package_dirs="client/tests client/site_tests"
405 local client_tests=$(\
406 for dir in ${tests_to_package_dirs}; do
407 print_test_dirs "${path_to_image}/${dir}" yes
408 done | sort -u)
409
410 if [ -n "${client_tests}" ] && [ "${client_tests}" != "myfaketest" ]; then
Aviv Keshet28ecfa62013-09-03 17:42:16 -0700411 test_opt="--test=$(pythonify_test_list ${client_tests})"
Chris Sosa6bde1602012-03-15 23:19:57 -0700412 fi
413
Aviv Keshete90ff5d2013-09-10 15:55:06 -0700414 if [ -n "${AUTOTEST_DEPS_LIST}" ]; then
415 dep_opt="--dep=$(pythonify_test_list ${AUTOTEST_DEPS_LIST})"
416 fi
Chris Sosa6bde1602012-03-15 23:19:57 -0700417
Aviv Keshete90ff5d2013-09-10 15:55:06 -0700418 # For *, we must generate the list of profilers.
419 if [ "${AUTOTEST_PROFILERS_LIST}" = "*" ]; then
420 AUTOTEST_PROFILERS_LIST=$(\
421 print_test_dirs "${path_to_image}/client/profilers" yes | sort -u)
422 fi
423
424 if [ -n "${AUTOTEST_PROFILERS_LIST}" ]; then
425 prof_opt="--profiler=$(pythonify_test_list ${AUTOTEST_PROFILERS_LIST})"
Chris Sosa6bde1602012-03-15 23:19:57 -0700426 fi
427
428 if [ -n "${test_opt}" -o -n "${dep_opt}" -o -n "${prof_opt}" ]; then
429 einfo "Running packager with options ${test_opt} ${dep_opt} ${prof_opt}"
Aviv Keshetdfc4d922013-09-17 16:32:32 -0700430 local logfile=${root_autotest_dir}/packages/${CATEGORY}_${PN}.log
Chris Sosa6bde1602012-03-15 23:19:57 -0700431 flock "${root_autotest_dir}/packages" \
Zdenek Behan7c162bb2012-05-14 18:42:15 +0200432 -c "python -B ${root_autotest_dir}/utils/packager.py \
Chris Sosa6bde1602012-03-15 23:19:57 -0700433 -r ${root_autotest_dir}/packages \
Aviv Keshet1616e692013-09-11 18:19:13 -0700434 ${test_opt} ${dep_opt} ${prof_opt} upload && \
435 echo ${CATEGORY}/${PN} > ${logfile} && \
436 echo ${test_opt} ${dep_opt} ${prof_opt} >> ${logfile}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700437 else
438 einfo "Packager not run as nothing was found to package."
439 fi
Chris Masone21512432010-11-15 16:18:57 -0800440}
441
Zdenek Behan361d8142012-03-19 04:30:45 +0100442if [[ "${CROS_WORKON_PROJECT}" == "chromiumos/third_party/autotest" ]]; then
443 # Using main autotest repo. Automatically restricting checkout.
444 # Note that this does not happen if the inherit is done prior to setting
445 # CROS_WORKON_* variables.
446 autotest_restrict_workon_subdirs
447fi
448
Chris Sosaccb6c8b2012-03-09 10:47:32 -0800449EXPORT_FUNCTIONS src_compile src_prepare src_install pkg_postinst