blob: fb9e715246ed61008ac2b0333760a45ebb44e7ae [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 Behan12ad1c52010-08-03 16:34:37 -0700137 touch_init_py client/tests client/site_tests
138 touch __init__.py
139
140 # Cleanup checked-in binaries that don't support the target architecture
141 [[ ${E_MACHINE} == "" ]] && return 0;
142 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
143}
144
145function autotest_src_compile() {
Zdenek Behan31315b32010-08-05 16:34:39 -0700146 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700147
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700148 setup_cross_toolchain
149
150 if use opengles ; then
151 graphics_backend=OPENGLES
152 else
153 graphics_backend=OPENGL
154 fi
155
156 TESTS=$(pythonify_test_list)
157 einfo "Tests enabled: ${TESTS}"
158
159 # Do not use sudo, it'll unset all your environment
160 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
161 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
162 || ! use buildcheck || die "Tests failed to build."
163
164 # Cleanup some temp files after compiling
165 find . -name '*.[ado]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700166
167 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700168}
169
170function autotest_src_install() {
171 insinto /usr/local/autotest/client/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700172 doins -r "${AUTOTEST_WORKDIR}"/client/{tests,site_tests,deps,profilers,config}
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700173 insinto /usr/local/autotest/server/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700174 doins -r "${AUTOTEST_WORKDIR}"/server/{tests,site_tests}
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700175}
176
Zdenek Behan99bf5842010-08-04 17:23:38 -0700177EXPORT_FUNCTIONS src_configure src_compile src_prepare src_install