blob: 914e5dcd344375e96b26d3206e4463133bf152ad [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
15export CONFIG_SITE=/usr/share/config.site
16
17# Pythonify the list of packages
18function pythonify_test_list() {
19 local result
20
21 # NOTE: shell-like commenting of individual tests using grep
22 result=$(for test in ${AUTOTEST_TEST_LIST}; do echo "${test},"|grep -v "^#"; done)
23
24 echo ${result}|sed -e 's/ //g'
25}
26
27# Create python package init files for top level test case dirs.
28function touch_init_py() {
29 local dirs=${1}
30 for base_dir in $dirs
31 do
32 local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)"
33 for sub_dir in ${sub_dirs}
34 do
35 touch ${sub_dir}/__init__.py
36 done
37 touch ${base_dir}/__init__.py
38 done
39}
40
41function setup_cross_toolchain() {
42 if tc-is-cross-compiler ; then
43 tc-export CC CXX AR RANLIB LD NM STRIP
44 export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/"
45 export CCFLAGS="$CFLAGS"
46 fi
47
48 # TODO(fes): Check for /etc/hardened for now instead of the hardened
49 # use flag because we aren't enabling hardened on the target board.
50 # Rather, right now we're using hardened only during toolchain compile.
51 # Various tests/etc. use %ebx in here, so we have to turn off PIE when
52 # using the hardened compiler
53 if use x86 ; then
54 if use hardened ; then
55 #CC="${CC} -nopie"
56 append-flags -nopie
57 fi
58 fi
59}
60
61function create_autotest_workdir() {
62 local dst=${1}
63
64 # create a working enviroment for pre-building
65 ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils} "${dst}"/
66 # NOTE: in order to make autotest not notice it's running from /usr/local/, we need
67 # to make sure the binaries are real, because they do the path magic
68 local root_path base_path
69 for base_path in client client/bin; do
70 root_path="${SYSROOT}/usr/local/autotest/${base_path}"
71 mkdir -p "${dst}/${base_path}"
72
73 # skip bin, because it is processed separately, and test-provided dirs
74 for entry in $(ls "${root_path}" |grep -v "\(bin\|tests\|site_tests\|deps\|profilers\|config\)$"); do
75 ln -sf "${root_path}/${entry}" "${dst}/${base_path}/"
76 done
77 done
78 # replace the important binaries with real copies
79 for base_path in autotest autotest_client; do
80 root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}"
81 rm "${dst}/client/bin/${base_path}"
82 cp -f ${root_path} "${dst}/client/bin/${base_path}"
83 done
84
85}
86
87function print_test_dirs() {
88 local testroot="${1}"
89
90 pushd "${testroot}" 1> /dev/null
91 for test in *; do
92 if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then
93 echo "${test}"
94 fi
95 done
96 popd 1> /dev/null
97}
98
99function autotest_src_configure() {
100 sed "/^enable_server_prebuild/d" "${AUTOTEST_SRC}/global_config.ini" > \
101 "${S}/global_config.ini"
102
103 touch_init_py client/tests client/site_tests
104 touch __init__.py
105
106 # Cleanup checked-in binaries that don't support the target architecture
107 [[ ${E_MACHINE} == "" ]] && return 0;
108 rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} )
109}
110
111function autotest_src_compile() {
112 setup_cross_toolchain
113
114 if use opengles ; then
115 graphics_backend=OPENGLES
116 else
117 graphics_backend=OPENGL
118 fi
119
120 TESTS=$(pythonify_test_list)
121 einfo "Tests enabled: ${TESTS}"
122
123 # Do not use sudo, it'll unset all your environment
124 GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \
125 client/bin/autotest_client --quiet --client_test_setup=${TESTS} \
126 || ! use buildcheck || die "Tests failed to build."
127
128 # Cleanup some temp files after compiling
129 find . -name '*.[ado]' -delete
130}
131
132function autotest_src_install() {
133 insinto /usr/local/autotest/client/
134 doins -r "${S}"/client/{tests,site_tests,deps,profilers,config}
135 insinto /usr/local/autotest/server/
136 doins -r "${S}"/server/{tests,site_tests}
137}
138
139EXPORT_FUNCTIONS src_configure src_compile src_install