blob: 934ec6bc381e6dc59e5c81c35959345c17a606ce [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
Zdenek Behan9e98f322010-08-26 18:56:54 -07009RDEPEND="( autotest? ( >=chromeos-base/autotest-0.0.1-r3 ) )"
Zdenek Behan14ae4892010-08-26 15:25:30 -070010# HACK: all packages should get autotest-deps for now
11if ! [ "${PN}" = "autotest-deps" ]; then
12 RDEPEND="${RDEPEND} ( autotest? ( chromeos-base/autotest-deps ) )"
13fi
Zdenek Behan12ad1c52010-08-03 16:34:37 -070014DEPEND="${RDEPEND}"
15
Zdenek Behan14ae4892010-08-26 15:25:30 -070016IUSE="buildcheck autotest"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070017
18# Ensure the configures run by autotest pick up the right config.site
Zdenek Behan99bf5842010-08-04 17:23:38 -070019export CONFIG_SITE="/usr/share/config.site"
20export AUTOTEST_WORKDIR="${WORKDIR}/autotest-work"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070021
Zdenek Behancd997a32010-08-20 12:55:44 -070022# @ECLASS-VARIABLE: AUTOTEST_CLIENT_*
23# @DESCRIPTION:
24# Location of the appropriate test directory inside ${S}
25: ${AUTOTEST_CLIENT_TESTS:=client/tests}
26: ${AUTOTEST_CLIENT_SITE_TESTS:=client/site_tests}
27: ${AUTOTEST_SERVER_TESTS:=server/tests}
28: ${AUTOTEST_SERVER_SITE_TESTS:=server/site_tests}
Zdenek Behan41463c92010-08-23 12:12:31 -070029: ${AUTOTEST_CONFIG:=client/config}
30: ${AUTOTEST_DEPS:=client/deps}
31: ${AUTOTEST_PROFILERS:=client/profilers}
32
33# @ECLASS-VARIABLE: AUTOTEST_*_LIST
34# @DESCRIPTION:
35# The list of deps/configs/profilers provided with this package
36: ${AUTOTEST_CONFIG_LIST:=*}
37: ${AUTOTEST_DEPS_LIST:=*}
38: ${AUTOTEST_PROFILERS_LIST:=*}
Zdenek Behancd997a32010-08-20 12:55:44 -070039
Zdenek Behan12ad1c52010-08-03 16:34:37 -070040# Pythonify the list of packages
41function pythonify_test_list() {
Zdenek Behan31315b32010-08-05 16:34:39 -070042 AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}"
43 AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}"
44
Zdenek Behan12ad1c52010-08-03 16:34:37 -070045 local result
Zdenek Behan12ad1c52010-08-03 16:34:37 -070046 # NOTE: shell-like commenting of individual tests using grep
Zdenek Behan31315b32010-08-05 16:34:39 -070047 result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done)
48 echo ${result}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070049}
50
51# Create python package init files for top level test case dirs.
52function touch_init_py() {
53 local dirs=${1}
54 for base_dir in $dirs
55 do
56 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
57 for sub_dir in ${sub_dirs}
58 do
59 touch ${sub_dir}/__init__.py
60 done
61 touch ${base_dir}/__init__.py
62 done
63}
64
65function setup_cross_toolchain() {
66 if tc-is-cross-compiler ; then
67 tc-export CC CXX AR RANLIB LD NM STRIP
68 export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/"
69 export CCFLAGS="$CFLAGS"
70 fi
71
72 # TODO(fes): Check for /etc/hardened for now instead of the hardened
73 # use flag because we aren't enabling hardened on the target board.
74 # Rather, right now we're using hardened only during toolchain compile.
75 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
76 # using the hardened compiler
77 if use x86 ; then
78 if use hardened ; then
79 #CC="${CC} -nopie"
80 append-flags -nopie
81 fi
82 fi
83}
84
85function create_autotest_workdir() {
86 local dst=${1}
87
88 # create a working enviroment for pre-building
Zdenek Behan99bf5842010-08-04 17:23:38 -070089 ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/
90
Zdenek Behan12ad1c52010-08-03 16:34:37 -070091 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
92 # to make sure the binaries are real, because they do the path magic
93 local root_path base_path
94 for base_path in client client/bin; do
95 root_path="${SYSROOT}/usr/local/autotest/${base_path}"
96 mkdir -p "${dst}/${base_path}"
97
Zdenek Behan451e07f2010-08-06 11:25:37 -070098 # Skip bin, because it is processed separately, and test-provided dirs
99 # Also don't symlink to packages, because that kills the build
Zdenek Behan41463c92010-08-23 12:12:31 -0700100 for entry in $(ls "${root_path}" | \
101 grep -v "\(bin\|tests\|site_tests\|config\|deps\|profilers\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700102 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
103 done
104 done
105 # replace the important binaries with real copies
106 for base_path in autotest autotest_client; do
107 root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}"
108 rm "${dst}/client/bin/${base_path}"
109 cp -f ${root_path} "${dst}/client/bin/${base_path}"
110 done
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700111
112 # Selectively pull in deps that are not provided by the current test package
113 for base_path in config deps profilers; do
114 for dir in "${SYSROOT}/usr/local/autotest/client/${base_path}"/*; do
115 if [ -d "${dir}" ] && \
116 ! [ -d "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" ]; then
117 # directory does not exist, create a symlink
118 ln -sf "${dir}" "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})"
119 fi
120 done
121 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700122}
123
124function print_test_dirs() {
125 local testroot="${1}"
126
127 pushd "${testroot}" 1> /dev/null
128 for test in *; do
129 if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then
130 echo "${test}"
131 fi
132 done
133 popd 1> /dev/null
134}
135
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700136# checks IUSE_TESTS and sees if at least one of these is enabled
137function are_we_used() {
Zdenek Behan14ae4892010-08-26 15:25:30 -0700138 if ! use autotest; then
139 # unused
140 return 1
141 fi
142
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700143 for test in ${IUSE_TESTS}; do
144 # careful, tests may be prefixed with a +
145 if use ${test/+/}; then
146 return 0
147 fi
148 done
149
150 # unused
151 return 1
152}
153
Zdenek Behan99bf5842010-08-04 17:23:38 -0700154function autotest_src_prepare() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700155 are_we_used || return 0
156 einfo "Preparing tests"
157
158 # FIXME: These directories are needed, autotest quietly dies if
159 # they don't even exist. They may, however, stay empty.
Zdenek Behanc02fc472010-08-13 12:55:07 -0700160 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
161 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behan41463c92010-08-23 12:12:31 -0700162 mkdir -p "${AUTOTEST_WORKDIR}"/client/config
163 mkdir -p "${AUTOTEST_WORKDIR}"/client/deps
164 mkdir -p "${AUTOTEST_WORKDIR}"/client/profilers
Zdenek Behanc02fc472010-08-13 12:55:07 -0700165 mkdir -p "${AUTOTEST_WORKDIR}"/server/tests
166 mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700167
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700168 # Pull in the individual test cases.
Zdenek Behan31315b32010-08-05 16:34:39 -0700169 for l1 in client server; do
170 for l2 in site_tests tests; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700171 # pick up the indicated location of test sources
172 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}}
173
174 if [ -d "${srcdir}" ]; then # test does have this directory
Zdenek Behancd997a32010-08-20 12:55:44 -0700175 pushd "${srcdir}" 1> /dev/null
176 for test in *; do
177 if use tests_${test} &> /dev/null; then
178 cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
179 fi
180 done
181 popd 1> /dev/null
182 fi
Zdenek Behan31315b32010-08-05 16:34:39 -0700183 done
184 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700185
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700186 # Pull in all the deps provided by this package, selectively.
Zdenek Behan41463c92010-08-23 12:12:31 -0700187 for l2 in config deps profilers; do
188 # pick up the indicated location of test sources
189 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l2^^*}}
190
191 if [ -d "${srcdir}" ]; then # test does have this directory
192 pushd "${srcdir}" 1> /dev/null
193 eval deplist=\${AUTOTEST_${l2^^*}_LIST}
194
195 if [ "${deplist}" = "*" ]; then
196 cp -fpru * "${AUTOTEST_WORKDIR}/client/${l2}"
197 else
198 for dir in ${deplist}; do
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700199 cp -fpru "${dir}" "${AUTOTEST_WORKDIR}/client/${l2}"/ || die
Zdenek Behan41463c92010-08-23 12:12:31 -0700200 done
201 fi
202 popd 1> /dev/null
203 fi
204 done
205
Zdenek Behan474fbae2010-08-20 21:13:22 -0700206 # FIXME: We'd like if this were not necessary, and autotest supported out-of-tree build
Zdenek Behan99bf5842010-08-04 17:23:38 -0700207 create_autotest_workdir "${AUTOTEST_WORKDIR}"
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700208
Zdenek Behanc02fc472010-08-13 12:55:07 -0700209 cd "${AUTOTEST_WORKDIR}"
Zdenek Behan474fbae2010-08-20 21:13:22 -0700210 for dir in client/tests/* client/site_tests/* server/tests/* server/site_tests/*; do
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700211 [ -d "${dir}" ] || continue
212
213 touch_init_py ${dir}
214 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700215
216 # Cleanup checked-in binaries that don't support the target architecture
217 [[ ${E_MACHINE} == "" ]] && return 0;
218 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
219}
220
221function autotest_src_compile() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700222 are_we_used || return 0
223 einfo "Compiling tests"
224
Zdenek Behan31315b32010-08-05 16:34:39 -0700225 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700226
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700227 setup_cross_toolchain
228
229 if use opengles ; then
230 graphics_backend=OPENGLES
231 else
232 graphics_backend=OPENGL
233 fi
234
235 TESTS=$(pythonify_test_list)
236 einfo "Tests enabled: ${TESTS}"
237
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700238 # Call autotest to prebuild all test cases.
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700239 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
240 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
241 || ! use buildcheck || die "Tests failed to build."
242
243 # Cleanup some temp files after compiling
Zdenek Behan9f6fb9a2010-08-25 13:17:59 -0700244 find . -name '*.[do]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700245
246 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700247}
248
249function autotest_src_install() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700250 are_we_used || return 0
251 einfo "Installing tests"
252
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700253 # Install all test cases, after setup has been called on them.
254 # We install everything, because nothing else is copied into the
255 # testcase directories besides what this package provides.
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700256 local instdirs="
257 client/tests
258 client/site_tests
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700259 server/tests
260 server/site_tests"
261
262 for dir in ${instdirs}; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700263 [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700264
265 insinto /usr/local/autotest/$(dirname ${dir})
266 doins -r "${AUTOTEST_WORKDIR}/${dir}"
267 done
268
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700269 # Install the deps, configs, profilers.
270 # Difference from above is, we don't install the whole thing, just
271 # the stuff provided by this package, by looking at AUTOTEST_*_LIST.
272 instdirs="
273 config
274 deps
275 profilers"
276
277 for dir in ${instdirs}; do
278 [ -d "${AUTOTEST_WORKDIR}/client/${dir}" ] || continue
279
280 insinto /usr/local/autotest/client/${dir}
281
282 eval provided=\${AUTOTEST_${dir^^*}_LIST}
283 # * means provided all, figure out the list from ${S}
284 if [ "${provided}" = "*" ]; then
285 if eval pushd "${WORKDIR}/${P}/\${AUTOTEST_${dir^^*}}" &> /dev/null; then
286 provided=$(ls)
287 popd 1> /dev/null
288 else
289 provided=""
290 fi
291 fi
292
293 for item in ${provided}; do
294 doins -r "${AUTOTEST_WORKDIR}/client/${dir}/${item}"
295 done
296 done
297
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700298 # TODO: Not all needs to be executable, but it's hard to pick selectively.
299 # The source repo should already contain stuff with the right permissions.
300 chmod -R a+x "${D}"/usr/local/autotest/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700301}
302
Zdenek Behan474fbae2010-08-20 21:13:22 -0700303EXPORT_FUNCTIONS src_compile src_prepare src_install