blob: 3716e7176c9e7265c2ef0e1dcf697ed02f144596 [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
105 mkdir -p "${AUTOTEST_WORKDIR}"/server
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700106
Zdenek Behan31315b32010-08-05 16:34:39 -0700107 cp -fpru "${WORKDIR}/${P}"/client/{config,deps,profilers} "${AUTOTEST_WORKDIR}"/client/ || die
108
109 for l1 in client server; do
110 for l2 in site_tests tests; do
111 mkdir -p "${AUTOTEST_WORKDIR}/${l1}/${l2}"
112 pushd "${WORKDIR}/${P}/${l1}/${l2}" 1> /dev/null
113 for test in *; do
114 if use tests_${test} &> /dev/null; then
115 cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die
116 fi
117 done
118 popd 1> /dev/null
119 done
120 done
Zdenek Behan99bf5842010-08-04 17:23:38 -0700121
122 create_autotest_workdir "${AUTOTEST_WORKDIR}"
123}
124
125function autotest_src_configure() {
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700126 touch_init_py client/tests client/site_tests
127 touch __init__.py
128
129 # Cleanup checked-in binaries that don't support the target architecture
130 [[ ${E_MACHINE} == "" ]] && return 0;
131 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
132}
133
134function autotest_src_compile() {
Zdenek Behan31315b32010-08-05 16:34:39 -0700135 pushd "${AUTOTEST_WORKDIR}" 1> /dev/null
Zdenek Behan99bf5842010-08-04 17:23:38 -0700136
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700137 setup_cross_toolchain
138
139 if use opengles ; then
140 graphics_backend=OPENGLES
141 else
142 graphics_backend=OPENGL
143 fi
144
145 TESTS=$(pythonify_test_list)
146 einfo "Tests enabled: ${TESTS}"
147
148 # Do not use sudo, it'll unset all your environment
149 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
150 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
151 || ! use buildcheck || die "Tests failed to build."
152
153 # Cleanup some temp files after compiling
154 find . -name '*.[ado]' -delete
Zdenek Behan31315b32010-08-05 16:34:39 -0700155
156 popd 1> /dev/null
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700157}
158
159function autotest_src_install() {
160 insinto /usr/local/autotest/client/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700161 doins -r "${AUTOTEST_WORKDIR}"/client/{tests,site_tests,deps,profilers,config}
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700162 insinto /usr/local/autotest/server/
Zdenek Behan99bf5842010-08-04 17:23:38 -0700163 doins -r "${AUTOTEST_WORKDIR}"/server/{tests,site_tests}
Zdenek Behan12ad1c52010-08-03 16:34:37 -0700164}
165
Zdenek Behan99bf5842010-08-04 17:23:38 -0700166EXPORT_FUNCTIONS src_configure src_compile src_prepare src_install