blob: d2558a216add316f54f06ae7de39f22002f553c4 [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
9RDEPEND=">=chromeos-base/autotest-0.0.2"
10DEPEND="${RDEPEND}"
11
12IUSE="buildcheck"
13
14# Ensure the configures run by autotest pick up the right config.site
Zdenek Behan99bf5842010-08-04 17:23:38 -070015export CONFIG_SITE="/usr/share/config.site"
16export AUTOTEST_WORKDIR="${WORKDIR}/autotest-work"
Zdenek Behan12ad1c52010-08-03 16:34:37 -070017
Zdenek Behancd997a32010-08-20 12:55:44 -070018# @ECLASS-VARIABLE: AUTOTEST_CLIENT_*
19# @DESCRIPTION:
20# Location of the appropriate test directory inside ${S}
21: ${AUTOTEST_CLIENT_TESTS:=client/tests}
22: ${AUTOTEST_CLIENT_SITE_TESTS:=client/site_tests}
23: ${AUTOTEST_SERVER_TESTS:=server/tests}
24: ${AUTOTEST_SERVER_SITE_TESTS:=server/site_tests}
Zdenek Behan41463c92010-08-23 12:12:31 -070025: ${AUTOTEST_CONFIG:=client/config}
26: ${AUTOTEST_DEPS:=client/deps}
27: ${AUTOTEST_PROFILERS:=client/profilers}
28
29# @ECLASS-VARIABLE: AUTOTEST_*_LIST
30# @DESCRIPTION:
31# The list of deps/configs/profilers provided with this package
32: ${AUTOTEST_CONFIG_LIST:=*}
33: ${AUTOTEST_DEPS_LIST:=*}
34: ${AUTOTEST_PROFILERS_LIST:=*}
Zdenek Behancd997a32010-08-20 12:55:44 -070035
Zdenek Behan12ad1c52010-08-03 16:34:37 -070036# Pythonify the list of packages
37function pythonify_test_list() {
Zdenek Behan31315b32010-08-05 16:34:39 -070038 AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}"
39 AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}"
40
Zdenek Behan12ad1c52010-08-03 16:34:37 -070041 local result
Zdenek Behan12ad1c52010-08-03 16:34:37 -070042 # NOTE: shell-like commenting of individual tests using grep
Zdenek Behan31315b32010-08-05 16:34:39 -070043 result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done)
44 echo ${result}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070045}
46
47# Create python package init files for top level test case dirs.
48function touch_init_py() {
49 local dirs=${1}
50 for base_dir in $dirs
51 do
52 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
53 for sub_dir in ${sub_dirs}
54 do
55 touch ${sub_dir}/__init__.py
56 done
57 touch ${base_dir}/__init__.py
58 done
59}
60
61function setup_cross_toolchain() {
62 if tc-is-cross-compiler ; then
63 tc-export CC CXX AR RANLIB LD NM STRIP
64 export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/"
65 export CCFLAGS="$CFLAGS"
66 fi
67
68 # TODO(fes): Check for /etc/hardened for now instead of the hardened
69 # use flag because we aren't enabling hardened on the target board.
70 # Rather, right now we're using hardened only during toolchain compile.
71 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
72 # using the hardened compiler
73 if use x86 ; then
74 if use hardened ; then
75 #CC="${CC} -nopie"
76 append-flags -nopie
77 fi
78 fi
79}
80
81function create_autotest_workdir() {
82 local dst=${1}
83
84 # create a working enviroment for pre-building
Zdenek Behan99bf5842010-08-04 17:23:38 -070085 ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/
86
Zdenek Behan12ad1c52010-08-03 16:34:37 -070087 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
88 # to make sure the binaries are real, because they do the path magic
89 local root_path base_path
90 for base_path in client client/bin; do
91 root_path="${SYSROOT}/usr/local/autotest/${base_path}"
92 mkdir -p "${dst}/${base_path}"
93
Zdenek Behan451e07f2010-08-06 11:25:37 -070094 # Skip bin, because it is processed separately, and test-provided dirs
95 # Also don't symlink to packages, because that kills the build
Zdenek Behan41463c92010-08-23 12:12:31 -070096 for entry in $(ls "${root_path}" | \
97 grep -v "\(bin\|tests\|site_tests\|config\|deps\|profilers\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -070098 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
99 done
100 done
101 # replace the important binaries with real copies
102 for base_path in autotest autotest_client; do
103 root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}"
104 rm "${dst}/client/bin/${base_path}"
105 cp -f ${root_path} "${dst}/client/bin/${base_path}"
106 done
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700107
108 # Selectively pull in deps that are not provided by the current test package
109 for base_path in config deps profilers; do
110 for dir in "${SYSROOT}/usr/local/autotest/client/${base_path}"/*; do
111 if [ -d "${dir}" ] && \
112 ! [ -d "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" ]; then
113 # directory does not exist, create a symlink
114 ln -sf "${dir}" "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})"
115 fi
116 done
117 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700118}
119
120function print_test_dirs() {
121 local testroot="${1}"
122
123 pushd "${testroot}" 1> /dev/null
124 for test in *; do
125 if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then
126 echo "${test}"
127 fi
128 done
129 popd 1> /dev/null
130}
131
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700132# checks IUSE_TESTS and sees if at least one of these is enabled
133function are_we_used() {
134 for test in ${IUSE_TESTS}; do
135 # careful, tests may be prefixed with a +
136 if use ${test/+/}; then
137 return 0
138 fi
139 done
140
141 # unused
142 return 1
143}
144
Zdenek Behan99bf5842010-08-04 17:23:38 -0700145function autotest_src_prepare() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700146 are_we_used || return 0
147 einfo "Preparing tests"
148
149 # FIXME: These directories are needed, autotest quietly dies if
150 # they don't even exist. They may, however, stay empty.
Zdenek Behanc02fc472010-08-13 12:55:07 -0700151 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
152 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behan41463c92010-08-23 12:12:31 -0700153 mkdir -p "${AUTOTEST_WORKDIR}"/client/config
154 mkdir -p "${AUTOTEST_WORKDIR}"/client/deps
155 mkdir -p "${AUTOTEST_WORKDIR}"/client/profilers
Zdenek Behanc02fc472010-08-13 12:55:07 -0700156 mkdir -p "${AUTOTEST_WORKDIR}"/server/tests
157 mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700158
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700159 # Pull in the individual test cases.
Zdenek Behan31315b32010-08-05 16:34:39 -0700160 for l1 in client server; do
161 for l2 in site_tests tests; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700162 # pick up the indicated location of test sources
163 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}}
164
165 if [ -d "${srcdir}" ]; then # test does have this directory
Zdenek Behancd997a32010-08-20 12:55:44 -0700166 pushd "${srcdir}" 1> /dev/null
167 for test in *; do
168 if use tests_${test} &> /dev/null; then
169 cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
170 fi
171 done
172 popd 1> /dev/null
173 fi
Zdenek Behan31315b32010-08-05 16:34:39 -0700174 done
175 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700176
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700177 # Pull in all the deps provided by this package, selectively.
Zdenek Behan41463c92010-08-23 12:12:31 -0700178 for l2 in config deps profilers; do
179 # pick up the indicated location of test sources
180 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l2^^*}}
181
182 if [ -d "${srcdir}" ]; then # test does have this directory
183 pushd "${srcdir}" 1> /dev/null
184 eval deplist=\${AUTOTEST_${l2^^*}_LIST}
185
186 if [ "${deplist}" = "*" ]; then
187 cp -fpru * "${AUTOTEST_WORKDIR}/client/${l2}"
188 else
189 for dir in ${deplist}; do
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700190 cp -fpru "${dir}" "${AUTOTEST_WORKDIR}/client/${l2}"/ || die
Zdenek Behan41463c92010-08-23 12:12:31 -0700191 done
192 fi
193 popd 1> /dev/null
194 fi
195 done
196
Zdenek Behan474fbae2010-08-20 21:13:22 -0700197 # FIXME: We'd like if this were not necessary, and autotest supported out-of-tree build
Zdenek Behan99bf5842010-08-04 17:23:38 -0700198 create_autotest_workdir "${AUTOTEST_WORKDIR}"
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700199
Zdenek Behanc02fc472010-08-13 12:55:07 -0700200 cd "${AUTOTEST_WORKDIR}"
Zdenek Behan474fbae2010-08-20 21:13:22 -0700201 for dir in client/tests/* client/site_tests/* server/tests/* server/site_tests/*; do
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700202 [ -d "${dir}" ] || continue
203
204 touch_init_py ${dir}
205 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700206
207 # Cleanup checked-in binaries that don't support the target architecture
208 [[ ${E_MACHINE} == "" ]] && return 0;
209 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
210}
211
212function autotest_src_compile() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700213 are_we_used || return 0
214 einfo "Compiling tests"
215
Zdenek Behan31315b32010-08-05 16:34:39 -0700216 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700217
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700218 setup_cross_toolchain
219
220 if use opengles ; then
221 graphics_backend=OPENGLES
222 else
223 graphics_backend=OPENGL
224 fi
225
226 TESTS=$(pythonify_test_list)
227 einfo "Tests enabled: ${TESTS}"
228
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700229 # Call autotest to prebuild all test cases.
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700230 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
231 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
232 || ! use buildcheck || die "Tests failed to build."
233
234 # Cleanup some temp files after compiling
235 find . -name '*.[ado]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700236
237 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700238}
239
240function autotest_src_install() {
Zdenek Behaneee7bc22010-08-20 18:33:13 -0700241 are_we_used || return 0
242 einfo "Installing tests"
243
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700244 # Install all test cases, after setup has been called on them.
245 # We install everything, because nothing else is copied into the
246 # testcase directories besides what this package provides.
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700247 local instdirs="
248 client/tests
249 client/site_tests
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700250 server/tests
251 server/site_tests"
252
253 for dir in ${instdirs}; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700254 [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700255
256 insinto /usr/local/autotest/$(dirname ${dir})
257 doins -r "${AUTOTEST_WORKDIR}/${dir}"
258 done
259
Zdenek Behan448ddaa2010-08-24 11:18:50 -0700260 # Install the deps, configs, profilers.
261 # Difference from above is, we don't install the whole thing, just
262 # the stuff provided by this package, by looking at AUTOTEST_*_LIST.
263 instdirs="
264 config
265 deps
266 profilers"
267
268 for dir in ${instdirs}; do
269 [ -d "${AUTOTEST_WORKDIR}/client/${dir}" ] || continue
270
271 insinto /usr/local/autotest/client/${dir}
272
273 eval provided=\${AUTOTEST_${dir^^*}_LIST}
274 # * means provided all, figure out the list from ${S}
275 if [ "${provided}" = "*" ]; then
276 if eval pushd "${WORKDIR}/${P}/\${AUTOTEST_${dir^^*}}" &> /dev/null; then
277 provided=$(ls)
278 popd 1> /dev/null
279 else
280 provided=""
281 fi
282 fi
283
284 for item in ${provided}; do
285 doins -r "${AUTOTEST_WORKDIR}/client/${dir}/${item}"
286 done
287 done
288
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700289 # TODO: Not all needs to be executable, but it's hard to pick selectively.
290 # The source repo should already contain stuff with the right permissions.
291 chmod -R a+x "${D}"/usr/local/autotest/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700292}
293
Zdenek Behan474fbae2010-08-20 21:13:22 -0700294EXPORT_FUNCTIONS src_compile src_prepare src_install