blob: e1f32079d124fa74ba2b1f19f7a09d76cfa714af [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}
25
Zdenek Behan12ad1c52010-08-03 16:34:37 -070026# Pythonify the list of packages
27function pythonify_test_list() {
Zdenek Behan31315b32010-08-05 16:34:39 -070028 AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}"
29 AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}"
30
Zdenek Behan12ad1c52010-08-03 16:34:37 -070031 local result
Zdenek Behan12ad1c52010-08-03 16:34:37 -070032 # NOTE: shell-like commenting of individual tests using grep
Zdenek Behan31315b32010-08-05 16:34:39 -070033 result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done)
34 echo ${result}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070035}
36
37# Create python package init files for top level test case dirs.
38function touch_init_py() {
39 local dirs=${1}
40 for base_dir in $dirs
41 do
42 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
43 for sub_dir in ${sub_dirs}
44 do
45 touch ${sub_dir}/__init__.py
46 done
47 touch ${base_dir}/__init__.py
48 done
49}
50
51function setup_cross_toolchain() {
52 if tc-is-cross-compiler ; then
53 tc-export CC CXX AR RANLIB LD NM STRIP
54 export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/"
55 export CCFLAGS="$CFLAGS"
56 fi
57
58 # TODO(fes): Check for /etc/hardened for now instead of the hardened
59 # use flag because we aren't enabling hardened on the target board.
60 # Rather, right now we're using hardened only during toolchain compile.
61 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
62 # using the hardened compiler
63 if use x86 ; then
64 if use hardened ; then
65 #CC="${CC} -nopie"
66 append-flags -nopie
67 fi
68 fi
69}
70
71function create_autotest_workdir() {
72 local dst=${1}
73
74 # create a working enviroment for pre-building
Zdenek Behan99bf5842010-08-04 17:23:38 -070075 ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/
76
Zdenek Behan12ad1c52010-08-03 16:34:37 -070077 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
78 # to make sure the binaries are real, because they do the path magic
79 local root_path base_path
80 for base_path in client client/bin; do
81 root_path="${SYSROOT}/usr/local/autotest/${base_path}"
82 mkdir -p "${dst}/${base_path}"
83
Zdenek Behan451e07f2010-08-06 11:25:37 -070084 # Skip bin, because it is processed separately, and test-provided dirs
85 # Also don't symlink to packages, because that kills the build
86 for entry in $(ls "${root_path}" |grep -v "\(bin\|tests\|site_tests\|deps\|profilers\|config\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -070087 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
88 done
89 done
90 # replace the important binaries with real copies
91 for base_path in autotest autotest_client; do
92 root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}"
93 rm "${dst}/client/bin/${base_path}"
94 cp -f ${root_path} "${dst}/client/bin/${base_path}"
95 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -070096}
97
98function print_test_dirs() {
99 local testroot="${1}"
100
101 pushd "${testroot}" 1> /dev/null
102 for test in *; do
103 if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then
104 echo "${test}"
105 fi
106 done
107 popd 1> /dev/null
108}
109
Zdenek Behan99bf5842010-08-04 17:23:38 -0700110function autotest_src_prepare() {
111 # pull in all the tests from this package
Zdenek Behanc02fc472010-08-13 12:55:07 -0700112 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
113 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behanc02fc472010-08-13 12:55:07 -0700114 mkdir -p "${AUTOTEST_WORKDIR}"/server/tests
115 mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700116
Zdenek Behanc02fc472010-08-13 12:55:07 -0700117 for dir in "${WORKDIR}/${P}"/client/{config,deps,profilers}; do
118 if [ -d "${dir}" ]; then
119 cp -fpru "${dir}" "${AUTOTEST_WORKDIR}"/client/ || die
120 fi
121 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700122
123 for l1 in client server; do
124 for l2 in site_tests tests; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700125 # pick up the indicated location of test sources
126 eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}}
127
128 if [ -d "${srcdir}" ]; then # test does have this directory
129 mkdir -p "${AUTOTEST_WORKDIR}/${l1}/${l2}"
130 pushd "${srcdir}" 1> /dev/null
131 for test in *; do
132 if use tests_${test} &> /dev/null; then
133 cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
134 fi
135 done
136 popd 1> /dev/null
137 fi
Zdenek Behan31315b32010-08-05 16:34:39 -0700138 done
139 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700140
141 create_autotest_workdir "${AUTOTEST_WORKDIR}"
142}
143
144function autotest_src_configure() {
Zdenek Behanc02fc472010-08-13 12:55:07 -0700145 cd "${AUTOTEST_WORKDIR}"
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700146 for dir in client/tests/* client/site_tests/*; do
147 [ -d "${dir}" ] || continue
148
149 touch_init_py ${dir}
150 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700151
152 # Cleanup checked-in binaries that don't support the target architecture
153 [[ ${E_MACHINE} == "" ]] && return 0;
154 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
155}
156
157function autotest_src_compile() {
Zdenek Behan31315b32010-08-05 16:34:39 -0700158 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700159
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700160 setup_cross_toolchain
161
162 if use opengles ; then
163 graphics_backend=OPENGLES
164 else
165 graphics_backend=OPENGL
166 fi
167
168 TESTS=$(pythonify_test_list)
169 einfo "Tests enabled: ${TESTS}"
170
171 # Do not use sudo, it'll unset all your environment
172 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
173 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
174 || ! use buildcheck || die "Tests failed to build."
175
176 # Cleanup some temp files after compiling
177 find . -name '*.[ado]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700178
179 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700180}
181
182function autotest_src_install() {
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700183 local instdirs="
184 client/tests
185 client/site_tests
186 client/deps
187 client/profilers
188 client/config
189 server/tests
190 server/site_tests"
191
192 for dir in ${instdirs}; do
Zdenek Behancd997a32010-08-20 12:55:44 -0700193 [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700194
195 insinto /usr/local/autotest/$(dirname ${dir})
196 doins -r "${AUTOTEST_WORKDIR}/${dir}"
197 done
198
199 # TODO: Not all needs to be executable, but it's hard to pick selectively.
200 # The source repo should already contain stuff with the right permissions.
201 chmod -R a+x "${D}"/usr/local/autotest/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700202}
203
Zdenek Behan99bf5842010-08-04 17:23:38 -0700204EXPORT_FUNCTIONS src_configure src_compile src_prepare src_install