blob: 2ec2d82eaf964428bb2df62f312020c6a2c4dccf [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
18# Pythonify the list of packages
19function pythonify_test_list() {
Zdenek Behan31315b32010-08-05 16:34:39 -070020 AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}"
21 AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}"
22
Zdenek Behan12ad1c52010-08-03 16:34:37 -070023 local result
Zdenek Behan12ad1c52010-08-03 16:34:37 -070024 # NOTE: shell-like commenting of individual tests using grep
Zdenek Behan31315b32010-08-05 16:34:39 -070025 result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done)
26 echo ${result}
Zdenek Behan12ad1c52010-08-03 16:34:37 -070027}
28
29# Create python package init files for top level test case dirs.
30function touch_init_py() {
31 local dirs=${1}
32 for base_dir in $dirs
33 do
34 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
35 for sub_dir in ${sub_dirs}
36 do
37 touch ${sub_dir}/__init__.py
38 done
39 touch ${base_dir}/__init__.py
40 done
41}
42
43function setup_cross_toolchain() {
44 if tc-is-cross-compiler ; then
45 tc-export CC CXX AR RANLIB LD NM STRIP
46 export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/"
47 export CCFLAGS="$CFLAGS"
48 fi
49
50 # TODO(fes): Check for /etc/hardened for now instead of the hardened
51 # use flag because we aren't enabling hardened on the target board.
52 # Rather, right now we're using hardened only during toolchain compile.
53 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
54 # using the hardened compiler
55 if use x86 ; then
56 if use hardened ; then
57 #CC="${CC} -nopie"
58 append-flags -nopie
59 fi
60 fi
61}
62
63function create_autotest_workdir() {
64 local dst=${1}
65
66 # create a working enviroment for pre-building
Zdenek Behan99bf5842010-08-04 17:23:38 -070067 ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/
68
Zdenek Behan12ad1c52010-08-03 16:34:37 -070069 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
70 # to make sure the binaries are real, because they do the path magic
71 local root_path base_path
72 for base_path in client client/bin; do
73 root_path="${SYSROOT}/usr/local/autotest/${base_path}"
74 mkdir -p "${dst}/${base_path}"
75
Zdenek Behan451e07f2010-08-06 11:25:37 -070076 # Skip bin, because it is processed separately, and test-provided dirs
77 # Also don't symlink to packages, because that kills the build
78 for entry in $(ls "${root_path}" |grep -v "\(bin\|tests\|site_tests\|deps\|profilers\|config\|packages\)$"); do
Zdenek Behan12ad1c52010-08-03 16:34:37 -070079 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
80 done
81 done
82 # replace the important binaries with real copies
83 for base_path in autotest autotest_client; do
84 root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}"
85 rm "${dst}/client/bin/${base_path}"
86 cp -f ${root_path} "${dst}/client/bin/${base_path}"
87 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -070088}
89
90function print_test_dirs() {
91 local testroot="${1}"
92
93 pushd "${testroot}" 1> /dev/null
94 for test in *; do
95 if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then
96 echo "${test}"
97 fi
98 done
99 popd 1> /dev/null
100}
101
Zdenek Behan99bf5842010-08-04 17:23:38 -0700102function autotest_src_prepare() {
103 # pull in all the tests from this package
104 mkdir -p "${AUTOTEST_WORKDIR}"/client
Zdenek Behanc02fc472010-08-13 12:55:07 -0700105 mkdir -p "${AUTOTEST_WORKDIR}"/client/tests
106 mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests
Zdenek Behan99bf5842010-08-04 17:23:38 -0700107 mkdir -p "${AUTOTEST_WORKDIR}"/server
Zdenek Behanc02fc472010-08-13 12:55:07 -0700108 mkdir -p "${AUTOTEST_WORKDIR}"/server/tests
109 mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700110
Zdenek Behanc02fc472010-08-13 12:55:07 -0700111 for dir in "${WORKDIR}/${P}"/client/{config,deps,profilers}; do
112 if [ -d "${dir}" ]; then
113 cp -fpru "${dir}" "${AUTOTEST_WORKDIR}"/client/ || die
114 fi
115 done
Zdenek Behan31315b32010-08-05 16:34:39 -0700116
117 for l1 in client server; do
118 for l2 in site_tests tests; do
Zdenek Behanc02fc472010-08-13 12:55:07 -0700119 if [ -d "${WORKDIR}/${P}/${l1}/${l2}" ]; then # test does have this directory
Zdenek Behan31315b32010-08-05 16:34:39 -0700120 mkdir -p "${AUTOTEST_WORKDIR}/${l1}/${l2}"
121 pushd "${WORKDIR}/${P}/${l1}/${l2}" 1> /dev/null
122 for test in *; do
123 if use tests_${test} &> /dev/null; then
124 cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
125 fi
126 done
127 popd 1> /dev/null
Zdenek Behanc02fc472010-08-13 12:55:07 -0700128 fi
Zdenek Behan31315b32010-08-05 16:34:39 -0700129 done
130 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700131
132 create_autotest_workdir "${AUTOTEST_WORKDIR}"
133}
134
135function autotest_src_configure() {
Zdenek Behanc02fc472010-08-13 12:55:07 -0700136 cd "${AUTOTEST_WORKDIR}"
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700137 for dir in client/tests/* client/site_tests/*; do
138 [ -d "${dir}" ] || continue
139
140 touch_init_py ${dir}
141 done
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700142
143 # Cleanup checked-in binaries that don't support the target architecture
144 [[ ${E_MACHINE} == "" ]] && return 0;
145 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
146}
147
148function autotest_src_compile() {
Zdenek Behan31315b32010-08-05 16:34:39 -0700149 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700150
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700151 setup_cross_toolchain
152
153 if use opengles ; then
154 graphics_backend=OPENGLES
155 else
156 graphics_backend=OPENGL
157 fi
158
159 TESTS=$(pythonify_test_list)
160 einfo "Tests enabled: ${TESTS}"
161
162 # Do not use sudo, it'll unset all your environment
163 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
164 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
165 || ! use buildcheck || die "Tests failed to build."
166
167 # Cleanup some temp files after compiling
168 find . -name '*.[ado]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700169
170 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700171}
172
173function autotest_src_install() {
Zdenek Behan1ec164a2010-08-17 19:06:31 -0700174 local instdirs="
175 client/tests
176 client/site_tests
177 client/deps
178 client/profilers
179 client/config
180 server/tests
181 server/site_tests"
182
183 for dir in ${instdirs}; do
184 [ -d "${dir}" ] || continue
185
186 insinto /usr/local/autotest/$(dirname ${dir})
187 doins -r "${AUTOTEST_WORKDIR}/${dir}"
188 done
189
190 # TODO: Not all needs to be executable, but it's hard to pick selectively.
191 # The source repo should already contain stuff with the right permissions.
192 chmod -R a+x "${D}"/usr/local/autotest/*
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700193}
194
Zdenek Behan99bf5842010-08-04 17:23:38 -0700195EXPORT_FUNCTIONS src_configure src_compile src_prepare src_install