blob: a2e16198308d1d65816cafd59f803b315063b89d [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}
Zdenek Behan41463c92010-08-23 12:12:31 -070024: ${AUTOTEST_CONFIG:=client/config}
25: ${AUTOTEST_DEPS:=client/deps}
26: ${AUTOTEST_PROFILERS:=client/profilers}
27
28# @ECLASS-VARIABLE: AUTOTEST_*_LIST
29# @DESCRIPTION:
30# The list of deps/configs/profilers provided with this package
Chris Sosa6bde1602012-03-15 23:19:57 -070031: ${AUTOTEST_CONFIG_LIST:=}
32: ${AUTOTEST_DEPS_LIST:=}
33: ${AUTOTEST_PROFILERS_LIST:=}
Zdenek Behancd997a32010-08-20 12:55:44 -070034
Zdenek Behand012b762010-09-01 21:22:26 -070035# @ECLASS-VARIABLE: AUTOTEST_FORCE_LIST
36# @DESCRIPTION:
37# Sometimes we just want to forget about useflags and build what's inside
38: ${AUTOTEST_FORCE_TEST_LIST:=}
39
Zdenek Behanb1f7c892010-09-22 12:25:38 -070040# @ECLASS-VARIABLE: AUTOTEST_FILE_MASK
41# @DESCRIPTION:
42# The list of 'find' expressions to find in the resulting image and delete
43: ${AUTOTEST_FILE_MASK:=}
44
Chris Sosa6bde1602012-03-15 23:19:57 -070045fast_cp() {
Zdenek Behan7922d132010-09-24 14:18:05 -070046 cp -l "$@" || cp "$@"
47}
48
Chris Sosa6bde1602012-03-15 23:19:57 -070049get_test_list() {
Zdenek Behand012b762010-09-01 21:22:26 -070050 if [ -n "${AUTOTEST_FORCE_TEST_LIST}" ]; then
51 # list forced
52 echo "${AUTOTEST_FORCE_TEST_LIST}"
53 return
54 fi
55
56 # we cache the result of this operation in AUTOTEST_TESTS,
57 # because it's expensive and does not change over the course of one ebuild run
Albert Chaulk85eeef52014-01-08 15:26:33 -033058 local tests=$(portageq use_reduce "${IUSE_TESTS[*]}")
59 local result="${tests//[+-]tests_/}"
Zdenek Behand012b762010-09-01 21:22:26 -070060 result="${result//tests_/}"
61
62 result=$(for test in ${result}; do use tests_${test} && echo -n "${test} "; done)
63 echo "${result}"
64}
65
Chris Sosa6bde1602012-03-15 23:19:57 -070066# Pythonify the list of packages by doing the equivalent of ','.join(args)
67pythonify_test_list() {
68 local result=$(printf '%s,' "$@")
69 echo ${result%,}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070070}
71
72# Create python package init files for top level test case dirs.
Chris Sosa6bde1602012-03-15 23:19:57 -070073touch_init_py() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -070074 local dirs=${1}
75 for base_dir in $dirs
76 do
77 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
78 for sub_dir in ${sub_dirs}
79 do
80 touch ${sub_dir}/__init__.py
81 done
82 touch ${base_dir}/__init__.py
83 done
84}
85
Zdenek Behan361d8142012-03-19 04:30:45 +010086# Exports a CROS_WORKON_SUBDIRS_TO_COPY variable to ensure that only the
87# necessary files will be copied. This cannot be applied globally, as some
88# ebuilds may not have tests only.
89autotest_restrict_workon_subdirs() {
90 CROS_WORKON_SUBDIRS_TO_COPY=()
91 local var
92 for var in AUTOTEST_{CLIENT,SERVER}_{TESTS,SITE_TESTS} \
93 AUTOTEST_{CONFIG,DEPS,PROFILERS}; do
94 CROS_WORKON_SUBDIRS_TO_COPY+=( ${!var} )
95 done
96}
97
Chris Sosa6bde1602012-03-15 23:19:57 -070098setup_cross_toolchain() {
Mike Frysingerb1eda9e2012-03-08 14:56:18 -050099 tc-export CC CXX AR RANLIB LD NM STRIP PKG_CONFIG
100 export CCFLAGS="$CFLAGS"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700101
102 # TODO(fes): Check for /etc/hardened for now instead of the hardened
103 # use flag because we aren't enabling hardened on the target board.
104 # Rather, right now we're using hardened only during toolchain compile.
105 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
106 # using the hardened compiler
107 if use x86 ; then
108 if use hardened ; then
109 #CC="${CC} -nopie"
110 append-flags -nopie
111 fi
112 fi
113}
114
Chris Sosa6bde1602012-03-15 23:19:57 -0700115create_autotest_workdir() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700116 local dst=${1}
117
118 # create a working enviroment for pre-building
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700119 ln -sf "${SYSROOT}"${AUTOTEST_BASE}/{conmux,tko,global_config.ini,shadow_config.ini} "${dst}"/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700120
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700121 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
122 # to make sure the binaries are real, because they do the path magic
123 local root_path base_path
Chris Masone21512432010-11-15 16:18:57 -0800124 for base_path in utils server; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700125 root_path="${SYSROOT}${AUTOTEST_BASE}/${base_path}"
Chris Masone21512432010-11-15 16:18:57 -0800126 mkdir -p "${dst}/${base_path}"
127 for entry in $(ls "${root_path}"); do
Zdenek Behan7e9e32f2012-02-28 03:15:46 +0100128 # Take all important binaries from SYSROOT install, make a copy.
129 if [ -d "${root_path}/${entry}" ]; then
130 # Ignore anything that has already been put in place by
131 # something else. This will typically be server/{site_tests,tests}.
132 if ! [ -e "${dst}/${base_path}/${entry}" ]; then
133 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
134 fi
Chris Masone21512432010-11-15 16:18:57 -0800135 else
136 cp -f ${root_path}/${entry} ${dst}/${base_path}/
137 fi
138 done
139 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700140 for base_path in client client/bin; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700141 root_path="${SYSROOT}${AUTOTEST_BASE}/${base_path}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700142 mkdir -p "${dst}/${base_path}"
143
Zdenek Behan451e07f2010-08-06 11:25:37 -0700144 # Skip bin, because it is processed separately, and test-provided dirs
145 # Also don't symlink to packages, because that kills the build
Zdenek Behan41463c92010-08-23 12:12:31 -0700146 for entry in $(ls "${root_path}" | \
147 grep -v "\(bin\|tests\|site_tests\|config\|deps\|profilers\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700148 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
149 done
150 done
151 # replace the important binaries with real copies
152 for base_path in autotest autotest_client; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700153 root_path="${SYSROOT}${AUTOTEST_BASE}/client/bin/${base_path}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700154 rm "${dst}/client/bin/${base_path}"
155 cp -f ${root_path} "${dst}/client/bin/${base_path}"
156 done
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700157
158 # Selectively pull in deps that are not provided by the current test package
159 for base_path in config deps profilers; do
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700160 for dir in "${SYSROOT}${AUTOTEST_BASE}/client/${base_path}"/*; do
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700161 if [ -d "${dir}" ] && \
162 ! [ -d "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" ]; then
163 # directory does not exist, create a symlink
164 ln -sf "${dir}" "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})"
165 fi
166 done
167 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700168}
169
Chris Sosa6bde1602012-03-15 23:19:57 -0700170print_test_dirs() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700171 local testroot="${1}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700172 local ignore_test_contents="${2}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700173
174 pushd "${testroot}" 1> /dev/null
175 for test in *; do
Chris Sosa6bde1602012-03-15 23:19:57 -0700176 if [ -d "${test}" ] && [ -n "${ignore_test_contents}" -o \
177 -f "${test}/${test}".py ]; then
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700178 echo "${test}"
179 fi
180 done
181 popd 1> /dev/null
182}
183
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700184# checks IUSE_TESTS and sees if at least one of these is enabled
Chris Sosa6bde1602012-03-15 23:19:57 -0700185are_we_used() {
Zdenek Behan14ae4892010-08-26 15:25:30 -0700186 if ! use autotest; then
187 # unused
188 return 1
189 fi
190
Zdenek Behand012b762010-09-01 21:22:26 -0700191 [ -n "$(get_test_list)" ] && return 0
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700192
193 # unused
194 return 1
195}
196
Chris Sosa6bde1602012-03-15 23:19:57 -0700197autotest_src_prepare() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700198 are_we_used || return 0
199 einfo "Preparing tests"
200
201 # FIXME: These directories are needed, autotest quietly dies if
202 # they don't even exist. They may, however, stay empty.
Zdenek Behanc02fc472010-08-13 12:55:07 -0700203 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
204 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behan41463c92010-08-23 12:12:31 -0700205 mkdir -p "${AUTOTEST_WORKDIR}"/client/config
206 mkdir -p "${AUTOTEST_WORKDIR}"/client/deps
207 mkdir -p "${AUTOTEST_WORKDIR}"/client/profilers
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700208
Zdenek Behand012b762010-09-01 21:22:26 -0700209 TEST_LIST=$(get_test_list)
210
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700211 # Pull in the individual test cases.
Zdenek Behan31315b32010-08-05 16:34:39 -0700212 for l1 in client server; do
213 for l2 in site_tests tests; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700214 # pick up the indicated location of test sources
215 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}}
216
Zdenek Behand012b762010-09-01 21:22:26 -0700217 # test does have this directory
218 for test in ${TEST_LIST}; do
219 if [ -d "${srcdir}/${test}" ]; then
Zdenek Behan7922d132010-09-24 14:18:05 -0700220 fast_cp -fpr "${srcdir}/${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
Zdenek Behand012b762010-09-01 21:22:26 -0700221 fi
222 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700223 done
224 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700225
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700226 # Pull in all the deps provided by this package, selectively.
Zdenek Behan41463c92010-08-23 12:12:31 -0700227 for l2 in config deps profilers; do
228 # pick up the indicated location of test sources
229 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l2^^*}}
230
231 if [ -d "${srcdir}" ]; then # test does have this directory
232 pushd "${srcdir}" 1> /dev/null
233 eval deplist=\${AUTOTEST_${l2^^*}_LIST}
234
235 if [ "${deplist}" = "*" ]; then
Zdenek Behan7922d132010-09-24 14:18:05 -0700236 fast_cp -fpr * "${AUTOTEST_WORKDIR}/client/${l2}"
Zdenek Behan41463c92010-08-23 12:12:31 -0700237 else
238 for dir in ${deplist}; do
Zdenek Behan7922d132010-09-24 14:18:05 -0700239 fast_cp -fpr "${dir}" "${AUTOTEST_WORKDIR}/client/${l2}"/ || die
Zdenek Behan41463c92010-08-23 12:12:31 -0700240 done
241 fi
242 popd 1> /dev/null
243 fi
244 done
245
Zdenek Behan474fbae2010-08-20 21:13:22 -0700246 # FIXME: We'd like if this were not necessary, and autotest supported out-of-tree build
Zdenek Behan99bf5842010-08-04 17:23:38 -0700247 create_autotest_workdir "${AUTOTEST_WORKDIR}"
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700248
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700249 # Each test directory needs to be visited and have an __init__.py created.
250 # However, that only applies to the directories which have a main .py file.
Zdenek Behanedb527a2010-09-22 12:24:14 -0700251 pushd "${AUTOTEST_WORKDIR}" > /dev/null || die "AUTOTEST_WORKDIR does not exist?!"
Chris Sosa1767b532012-11-09 15:13:15 -0800252 for dir in client/tests client/site_tests; do
Zdenek Behanedb527a2010-09-22 12:24:14 -0700253 pushd "${dir}" > /dev/null || continue
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700254 for sub in *; do
255 [ -f "${sub}/${sub}.py" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700256
Zdenek Behanf93c208a2010-09-21 18:53:58 -0700257 touch_init_py ${sub}
258 done
Zdenek Behanedb527a2010-09-22 12:24:14 -0700259 popd > /dev/null
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700260 done
Zdenek Behanedb527a2010-09-22 12:24:14 -0700261 popd > /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700262
263 # Cleanup checked-in binaries that don't support the target architecture
264 [[ ${E_MACHINE} == "" ]] && return 0;
Zdenek Behan092f4632010-09-21 19:34:01 -0700265 rm -fv $( scanelf -RmyBF%a "${AUTOTEST_WORKDIR}" | grep -v -e ^${E_MACHINE} )
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700266}
267
Chris Sosa6bde1602012-03-15 23:19:57 -0700268autotest_src_compile() {
Zdenek Behan48096a82010-09-23 19:39:26 -0700269 if ! are_we_used; then
270 ewarn "***************************************************************"
271 ewarn "* Not building any tests, because the requested list is empty *"
272 ewarn "***************************************************************"
273 return 0
274 fi
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700275 einfo "Compiling tests"
276
Zdenek Behan31315b32010-08-05 16:34:39 -0700277 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700278
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700279 setup_cross_toolchain
280
281 if use opengles ; then
282 graphics_backend=OPENGLES
283 else
284 graphics_backend=OPENGL
285 fi
286
Zdenek Behan9e979bb2010-09-23 17:32:05 -0700287 # HACK: Some of the autotests depend on SYSROOT being defined, and die
288 # a gruesome death if it isn't. But SYSROOT does not need to exist, for
289 # example on the host, it doesn't. Let's define a compatible variable
290 # here in case we have none.
291 export SYSROOT=${SYSROOT:-"/"}
292
Zdenek Behan8ad65252010-09-07 12:35:19 -0700293 # This only prints the tests that have the associated .py
294 # (and therefore a setup function)
295 local prebuild_test_dirs="
Chris Sosa1767b532012-11-09 15:13:15 -0800296 client/tests client/site_tests"
Zdenek Behan8ad65252010-09-07 12:35:19 -0700297 TESTS=$(\
298 for dir in ${prebuild_test_dirs}; do
299 print_test_dirs "${AUTOTEST_WORKDIR}/${dir}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700300 done | sort -u)
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100301 NR_TESTS=$(echo ${TESTS}|wc -w)
302 if ! [ "${NR_TESTS}" = "0" ]; then
303 einfo "Building tests (${NR_TESTS}):"
304 einfo "${TESTS}"
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700305
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100306 NORMAL=$(echo -e "\e[0m")
307 GREEN=$(echo -e "\e[1;32m")
308 RED=$(echo -e "\e[1;31m")
Zdenek Behan402fea02010-09-14 13:50:09 -0700309
Zdenek Behan9afd0a32011-01-21 01:47:02 +0100310 # Call autotest to prebuild all test cases.
311 # Parse output through a colorifying sed script
312 ( GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
313 client/bin/autotest_client --quiet \
314 --client_test_setup=$(pythonify_test_list ${TESTS}) \
315 || ! use buildcheck || die "Tests failed to build."
316 ) | sed -e "s/\(INFO:root:setup\)/${GREEN}* \1${NORMAL}/" \
317 -e "s/\(ERROR:root:\[.*\]\)/${RED}\1${NORMAL}/"
318 else
319 einfo "No tests to prebuild, skipping"
320 fi
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700321
322 # Cleanup some temp files after compiling
Zdenek Behan7c162bb2012-05-14 18:42:15 +0200323 for mask in '*.[do]' '*.pyc' ${AUTOTEST_FILE_MASK}; do
Zdenek Behanb1f7c892010-09-22 12:25:38 -0700324 einfo "Purging ${mask}"
325 find . -name "${mask}" -delete
326 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700327
328 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700329}
330
Chris Sosa6bde1602012-03-15 23:19:57 -0700331autotest_src_install() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700332 are_we_used || return 0
333 einfo "Installing tests"
334
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700335 # Install all test cases, after setup has been called on them.
336 # We install everything, because nothing else is copied into the
337 # testcase directories besides what this package provides.
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700338 local instdirs="
339 client/tests
Chris Sosa1767b532012-11-09 15:13:15 -0800340 client/site_tests"
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700341
342 for dir in ${instdirs}; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700343 [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700344
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700345 insinto ${AUTOTEST_BASE}/$(dirname ${dir})
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700346 doins -r "${AUTOTEST_WORKDIR}/${dir}"
347 done
348
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700349 # Install the deps, configs, profilers.
350 # Difference from above is, we don't install the whole thing, just
351 # the stuff provided by this package, by looking at AUTOTEST_*_LIST.
352 instdirs="
353 config
354 deps
355 profilers"
356
357 for dir in ${instdirs}; do
358 [ -d "${AUTOTEST_WORKDIR}/client/${dir}" ] || continue
359
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700360 insinto ${AUTOTEST_BASE}/client/${dir}
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700361
362 eval provided=\${AUTOTEST_${dir^^*}_LIST}
363 # * means provided all, figure out the list from ${S}
364 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
374 doins -r "${AUTOTEST_WORKDIR}/client/${dir}/${item}"
375 done
376 done
377
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700378 # TODO: Not all needs to be executable, but it's hard to pick selectively.
379 # The source repo should already contain stuff with the right permissions.
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700380 chmod -R a+x "${D}"${AUTOTEST_BASE}/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700381}
382
Chris Sosa6bde1602012-03-15 23:19:57 -0700383autotest_pkg_postinst() {
Mandeep Singh Baines060c2db2012-12-07 17:12:31 -0800384 are_we_used || return 0
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700385 local root_autotest_dir="${ROOT}${AUTOTEST_BASE}"
386 local path_to_image="${D}${AUTOTEST_BASE}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700387 # Should only happen when running emerge on a DUT.
Aviv Keshet4144c8d2013-07-22 10:52:53 -0700388 if [ ! -e "${root_autotest_dir}/utils/packager.py" ]; then
Chris Sosa6bde1602012-03-15 23:19:57 -0700389 einfo "Skipping packaging as no autotest installation detected."
390 return 0
391 fi
Chris Masone21512432010-11-15 16:18:57 -0800392
Chris Sosa6bde1602012-03-15 23:19:57 -0700393 # Gather the artifacts we want autotest to package.
394 local test_opt dep_opt prof_opt
Chris Sosaccb6c8b2012-03-09 10:47:32 -0800395
Chris Sosa6bde1602012-03-15 23:19:57 -0700396 # Only client tests can be packaged.
397 local tests_to_package_dirs="client/tests client/site_tests"
398 local client_tests=$(\
399 for dir in ${tests_to_package_dirs}; do
400 print_test_dirs "${path_to_image}/${dir}" yes
401 done | sort -u)
402
403 if [ -n "${client_tests}" ] && [ "${client_tests}" != "myfaketest" ]; then
Aviv Keshet28ecfa62013-09-03 17:42:16 -0700404 test_opt="--test=$(pythonify_test_list ${client_tests})"
Chris Sosa6bde1602012-03-15 23:19:57 -0700405 fi
406
Aviv Keshete90ff5d2013-09-10 15:55:06 -0700407 if [ -n "${AUTOTEST_DEPS_LIST}" ]; then
408 dep_opt="--dep=$(pythonify_test_list ${AUTOTEST_DEPS_LIST})"
409 fi
Chris Sosa6bde1602012-03-15 23:19:57 -0700410
Aviv Keshete90ff5d2013-09-10 15:55:06 -0700411 # For *, we must generate the list of profilers.
412 if [ "${AUTOTEST_PROFILERS_LIST}" = "*" ]; then
413 AUTOTEST_PROFILERS_LIST=$(\
414 print_test_dirs "${path_to_image}/client/profilers" yes | sort -u)
415 fi
416
417 if [ -n "${AUTOTEST_PROFILERS_LIST}" ]; then
418 prof_opt="--profiler=$(pythonify_test_list ${AUTOTEST_PROFILERS_LIST})"
Chris Sosa6bde1602012-03-15 23:19:57 -0700419 fi
420
421 if [ -n "${test_opt}" -o -n "${dep_opt}" -o -n "${prof_opt}" ]; then
422 einfo "Running packager with options ${test_opt} ${dep_opt} ${prof_opt}"
Aviv Keshetdfc4d922013-09-17 16:32:32 -0700423 local logfile=${root_autotest_dir}/packages/${CATEGORY}_${PN}.log
Chris Sosa6bde1602012-03-15 23:19:57 -0700424 flock "${root_autotest_dir}/packages" \
Zdenek Behan7c162bb2012-05-14 18:42:15 +0200425 -c "python -B ${root_autotest_dir}/utils/packager.py \
Chris Sosa6bde1602012-03-15 23:19:57 -0700426 -r ${root_autotest_dir}/packages \
Aviv Keshet1616e692013-09-11 18:19:13 -0700427 ${test_opt} ${dep_opt} ${prof_opt} upload && \
428 echo ${CATEGORY}/${PN} > ${logfile} && \
429 echo ${test_opt} ${dep_opt} ${prof_opt} >> ${logfile}"
Chris Sosa6bde1602012-03-15 23:19:57 -0700430 else
431 einfo "Packager not run as nothing was found to package."
432 fi
Chris Masone21512432010-11-15 16:18:57 -0800433}
434
Zdenek Behan361d8142012-03-19 04:30:45 +0100435if [[ "${CROS_WORKON_PROJECT}" == "chromiumos/third_party/autotest" ]]; then
436 # Using main autotest repo. Automatically restricting checkout.
437 # Note that this does not happen if the inherit is done prior to setting
438 # CROS_WORKON_* variables.
439 autotest_restrict_workon_subdirs
440fi
441
Chris Sosaccb6c8b2012-03-09 10:47:32 -0800442EXPORT_FUNCTIONS src_compile src_prepare src_install pkg_postinst