Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 1 | # 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 | |
Zdenek Behan | 9e98f32 | 2010-08-26 18:56:54 -0700 | [diff] [blame] | 9 | RDEPEND="( autotest? ( >=chromeos-base/autotest-0.0.1-r3 ) )" |
Zdenek Behan | 14ae489 | 2010-08-26 15:25:30 -0700 | [diff] [blame] | 10 | # HACK: all packages should get autotest-deps for now |
| 11 | if ! [ "${PN}" = "autotest-deps" ]; then |
| 12 | RDEPEND="${RDEPEND} ( autotest? ( chromeos-base/autotest-deps ) )" |
| 13 | fi |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 14 | DEPEND="${RDEPEND}" |
| 15 | |
Zdenek Behan | 14ae489 | 2010-08-26 15:25:30 -0700 | [diff] [blame] | 16 | IUSE="buildcheck autotest" |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 17 | |
| 18 | # Ensure the configures run by autotest pick up the right config.site |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 19 | export CONFIG_SITE="/usr/share/config.site" |
| 20 | export AUTOTEST_WORKDIR="${WORKDIR}/autotest-work" |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 21 | |
Zdenek Behan | cd997a3 | 2010-08-20 12:55:44 -0700 | [diff] [blame] | 22 | # @ECLASS-VARIABLE: AUTOTEST_CLIENT_* |
| 23 | # @DESCRIPTION: |
| 24 | # Location of the appropriate test directory inside ${S} |
| 25 | : ${AUTOTEST_CLIENT_TESTS:=client/tests} |
| 26 | : ${AUTOTEST_CLIENT_SITE_TESTS:=client/site_tests} |
| 27 | : ${AUTOTEST_SERVER_TESTS:=server/tests} |
| 28 | : ${AUTOTEST_SERVER_SITE_TESTS:=server/site_tests} |
Zdenek Behan | 41463c9 | 2010-08-23 12:12:31 -0700 | [diff] [blame] | 29 | : ${AUTOTEST_CONFIG:=client/config} |
| 30 | : ${AUTOTEST_DEPS:=client/deps} |
| 31 | : ${AUTOTEST_PROFILERS:=client/profilers} |
| 32 | |
| 33 | # @ECLASS-VARIABLE: AUTOTEST_*_LIST |
| 34 | # @DESCRIPTION: |
| 35 | # The list of deps/configs/profilers provided with this package |
| 36 | : ${AUTOTEST_CONFIG_LIST:=*} |
| 37 | : ${AUTOTEST_DEPS_LIST:=*} |
| 38 | : ${AUTOTEST_PROFILERS_LIST:=*} |
Zdenek Behan | cd997a3 | 2010-08-20 12:55:44 -0700 | [diff] [blame] | 39 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 40 | # Pythonify the list of packages |
| 41 | function pythonify_test_list() { |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 42 | AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}" |
| 43 | AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}" |
| 44 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 45 | local result |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 46 | # NOTE: shell-like commenting of individual tests using grep |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 47 | result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done) |
| 48 | echo ${result} |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | # Create python package init files for top level test case dirs. |
| 52 | function touch_init_py() { |
| 53 | local dirs=${1} |
| 54 | for base_dir in $dirs |
| 55 | do |
| 56 | local sub_dirs="$(find ${base_dir} -maxdepth 1 -type d)" |
| 57 | for sub_dir in ${sub_dirs} |
| 58 | do |
| 59 | touch ${sub_dir}/__init__.py |
| 60 | done |
| 61 | touch ${base_dir}/__init__.py |
| 62 | done |
| 63 | } |
| 64 | |
| 65 | function setup_cross_toolchain() { |
| 66 | if tc-is-cross-compiler ; then |
| 67 | tc-export CC CXX AR RANLIB LD NM STRIP |
| 68 | export PKG_CONFIG_PATH="${ROOT}/usr/lib/pkgconfig/" |
| 69 | export CCFLAGS="$CFLAGS" |
| 70 | fi |
| 71 | |
| 72 | # TODO(fes): Check for /etc/hardened for now instead of the hardened |
| 73 | # use flag because we aren't enabling hardened on the target board. |
| 74 | # Rather, right now we're using hardened only during toolchain compile. |
| 75 | # Various tests/etc. use %ebx in here, so we have to turn off PIE when |
| 76 | # using the hardened compiler |
| 77 | if use x86 ; then |
| 78 | if use hardened ; then |
| 79 | #CC="${CC} -nopie" |
| 80 | append-flags -nopie |
| 81 | fi |
| 82 | fi |
| 83 | } |
| 84 | |
| 85 | function create_autotest_workdir() { |
| 86 | local dst=${1} |
| 87 | |
| 88 | # create a working enviroment for pre-building |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 89 | ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/ |
| 90 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 91 | # NOTE: in order to make autotest not notice it's running from /usr/local/, we need |
| 92 | # to make sure the binaries are real, because they do the path magic |
| 93 | local root_path base_path |
| 94 | for base_path in client client/bin; do |
| 95 | root_path="${SYSROOT}/usr/local/autotest/${base_path}" |
| 96 | mkdir -p "${dst}/${base_path}" |
| 97 | |
Zdenek Behan | 451e07f | 2010-08-06 11:25:37 -0700 | [diff] [blame] | 98 | # Skip bin, because it is processed separately, and test-provided dirs |
| 99 | # Also don't symlink to packages, because that kills the build |
Zdenek Behan | 41463c9 | 2010-08-23 12:12:31 -0700 | [diff] [blame] | 100 | for entry in $(ls "${root_path}" | \ |
| 101 | grep -v "\(bin\|tests\|site_tests\|config\|deps\|profilers\|packages\)$"); do |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 102 | ln -sf "${root_path}/${entry}" "${dst}/${base_path}/" |
| 103 | done |
| 104 | done |
| 105 | # replace the important binaries with real copies |
| 106 | for base_path in autotest autotest_client; do |
| 107 | root_path="${SYSROOT}/usr/local/autotest/client/bin/${base_path}" |
| 108 | rm "${dst}/client/bin/${base_path}" |
| 109 | cp -f ${root_path} "${dst}/client/bin/${base_path}" |
| 110 | done |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 111 | |
| 112 | # Selectively pull in deps that are not provided by the current test package |
| 113 | for base_path in config deps profilers; do |
| 114 | for dir in "${SYSROOT}/usr/local/autotest/client/${base_path}"/*; do |
| 115 | if [ -d "${dir}" ] && \ |
| 116 | ! [ -d "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" ]; then |
| 117 | # directory does not exist, create a symlink |
| 118 | ln -sf "${dir}" "${AUTOTEST_WORKDIR}/client/${base_path}/$(basename ${dir})" |
| 119 | fi |
| 120 | done |
| 121 | done |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | function print_test_dirs() { |
| 125 | local testroot="${1}" |
| 126 | |
| 127 | pushd "${testroot}" 1> /dev/null |
| 128 | for test in *; do |
| 129 | if [ -d "${test}" ] && [ -f "${test}/${test}".py ]; then |
| 130 | echo "${test}" |
| 131 | fi |
| 132 | done |
| 133 | popd 1> /dev/null |
| 134 | } |
| 135 | |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 136 | # checks IUSE_TESTS and sees if at least one of these is enabled |
| 137 | function are_we_used() { |
Zdenek Behan | 14ae489 | 2010-08-26 15:25:30 -0700 | [diff] [blame] | 138 | if ! use autotest; then |
| 139 | # unused |
| 140 | return 1 |
| 141 | fi |
| 142 | |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 143 | for test in ${IUSE_TESTS}; do |
| 144 | # careful, tests may be prefixed with a + |
| 145 | if use ${test/+/}; then |
| 146 | return 0 |
| 147 | fi |
| 148 | done |
| 149 | |
| 150 | # unused |
| 151 | return 1 |
| 152 | } |
| 153 | |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 154 | function autotest_src_prepare() { |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 155 | are_we_used || return 0 |
| 156 | einfo "Preparing tests" |
| 157 | |
| 158 | # FIXME: These directories are needed, autotest quietly dies if |
| 159 | # they don't even exist. They may, however, stay empty. |
Zdenek Behan | c02fc47 | 2010-08-13 12:55:07 -0700 | [diff] [blame] | 160 | mkdir -p "${AUTOTEST_WORKDIR}"/client/tests |
| 161 | mkdir -p "${AUTOTEST_WORKDIR}"/client/site_tests |
Zdenek Behan | 41463c9 | 2010-08-23 12:12:31 -0700 | [diff] [blame] | 162 | mkdir -p "${AUTOTEST_WORKDIR}"/client/config |
| 163 | mkdir -p "${AUTOTEST_WORKDIR}"/client/deps |
| 164 | mkdir -p "${AUTOTEST_WORKDIR}"/client/profilers |
Zdenek Behan | c02fc47 | 2010-08-13 12:55:07 -0700 | [diff] [blame] | 165 | mkdir -p "${AUTOTEST_WORKDIR}"/server/tests |
| 166 | mkdir -p "${AUTOTEST_WORKDIR}"/server/site_tests |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 167 | |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 168 | # Pull in the individual test cases. |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 169 | for l1 in client server; do |
| 170 | for l2 in site_tests tests; do |
Zdenek Behan | cd997a3 | 2010-08-20 12:55:44 -0700 | [diff] [blame] | 171 | # pick up the indicated location of test sources |
| 172 | eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l1^^*}_${l2^^*}} |
| 173 | |
| 174 | if [ -d "${srcdir}" ]; then # test does have this directory |
Zdenek Behan | cd997a3 | 2010-08-20 12:55:44 -0700 | [diff] [blame] | 175 | pushd "${srcdir}" 1> /dev/null |
| 176 | for test in *; do |
| 177 | if use tests_${test} &> /dev/null; then |
| 178 | cp -fpru "${test}" "${AUTOTEST_WORKDIR}/${l1}/${l2}"/ || die |
| 179 | fi |
| 180 | done |
| 181 | popd 1> /dev/null |
| 182 | fi |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 183 | done |
| 184 | done |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 185 | |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 186 | # Pull in all the deps provided by this package, selectively. |
Zdenek Behan | 41463c9 | 2010-08-23 12:12:31 -0700 | [diff] [blame] | 187 | for l2 in config deps profilers; do |
| 188 | # pick up the indicated location of test sources |
| 189 | eval srcdir=${WORKDIR}/${P}/\${AUTOTEST_${l2^^*}} |
| 190 | |
| 191 | if [ -d "${srcdir}" ]; then # test does have this directory |
| 192 | pushd "${srcdir}" 1> /dev/null |
| 193 | eval deplist=\${AUTOTEST_${l2^^*}_LIST} |
| 194 | |
| 195 | if [ "${deplist}" = "*" ]; then |
| 196 | cp -fpru * "${AUTOTEST_WORKDIR}/client/${l2}" |
| 197 | else |
| 198 | for dir in ${deplist}; do |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 199 | cp -fpru "${dir}" "${AUTOTEST_WORKDIR}/client/${l2}"/ || die |
Zdenek Behan | 41463c9 | 2010-08-23 12:12:31 -0700 | [diff] [blame] | 200 | done |
| 201 | fi |
| 202 | popd 1> /dev/null |
| 203 | fi |
| 204 | done |
| 205 | |
Zdenek Behan | 474fbae | 2010-08-20 21:13:22 -0700 | [diff] [blame] | 206 | # FIXME: We'd like if this were not necessary, and autotest supported out-of-tree build |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 207 | create_autotest_workdir "${AUTOTEST_WORKDIR}" |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 208 | |
Zdenek Behan | c02fc47 | 2010-08-13 12:55:07 -0700 | [diff] [blame] | 209 | cd "${AUTOTEST_WORKDIR}" |
Zdenek Behan | 474fbae | 2010-08-20 21:13:22 -0700 | [diff] [blame] | 210 | for dir in client/tests/* client/site_tests/* server/tests/* server/site_tests/*; do |
Zdenek Behan | 1ec164a | 2010-08-17 19:06:31 -0700 | [diff] [blame] | 211 | [ -d "${dir}" ] || continue |
| 212 | |
| 213 | touch_init_py ${dir} |
| 214 | done |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 215 | |
| 216 | # Cleanup checked-in binaries that don't support the target architecture |
| 217 | [[ ${E_MACHINE} == "" ]] && return 0; |
| 218 | rm -fv $( scanelf -RmyBF%a . | grep -v -e ^${E_MACHINE} ) |
| 219 | } |
| 220 | |
| 221 | function autotest_src_compile() { |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 222 | are_we_used || return 0 |
| 223 | einfo "Compiling tests" |
| 224 | |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 225 | pushd "${AUTOTEST_WORKDIR}" 1> /dev/null |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 226 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 227 | setup_cross_toolchain |
| 228 | |
| 229 | if use opengles ; then |
| 230 | graphics_backend=OPENGLES |
| 231 | else |
| 232 | graphics_backend=OPENGL |
| 233 | fi |
| 234 | |
| 235 | TESTS=$(pythonify_test_list) |
| 236 | einfo "Tests enabled: ${TESTS}" |
| 237 | |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 238 | # Call autotest to prebuild all test cases. |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 239 | GRAPHICS_BACKEND="$graphics_backend" LOGNAME=${SUDO_USER} \ |
| 240 | client/bin/autotest_client --quiet --client_test_setup=${TESTS} \ |
| 241 | || ! use buildcheck || die "Tests failed to build." |
| 242 | |
| 243 | # Cleanup some temp files after compiling |
Zdenek Behan | 9f6fb9a | 2010-08-25 13:17:59 -0700 | [diff] [blame] | 244 | find . -name '*.[do]' -delete |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 245 | |
| 246 | popd 1> /dev/null |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | function autotest_src_install() { |
Zdenek Behan | eee7bc2 | 2010-08-20 18:33:13 -0700 | [diff] [blame] | 250 | are_we_used || return 0 |
| 251 | einfo "Installing tests" |
| 252 | |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 253 | # Install all test cases, after setup has been called on them. |
| 254 | # We install everything, because nothing else is copied into the |
| 255 | # testcase directories besides what this package provides. |
Zdenek Behan | 1ec164a | 2010-08-17 19:06:31 -0700 | [diff] [blame] | 256 | local instdirs=" |
| 257 | client/tests |
| 258 | client/site_tests |
Zdenek Behan | 1ec164a | 2010-08-17 19:06:31 -0700 | [diff] [blame] | 259 | server/tests |
| 260 | server/site_tests" |
| 261 | |
| 262 | for dir in ${instdirs}; do |
Zdenek Behan | cd997a3 | 2010-08-20 12:55:44 -0700 | [diff] [blame] | 263 | [ -d "${AUTOTEST_WORKDIR}/${dir}" ] || continue |
Zdenek Behan | 1ec164a | 2010-08-17 19:06:31 -0700 | [diff] [blame] | 264 | |
| 265 | insinto /usr/local/autotest/$(dirname ${dir}) |
| 266 | doins -r "${AUTOTEST_WORKDIR}/${dir}" |
| 267 | done |
| 268 | |
Zdenek Behan | 448ddaa | 2010-08-24 11:18:50 -0700 | [diff] [blame] | 269 | # Install the deps, configs, profilers. |
| 270 | # Difference from above is, we don't install the whole thing, just |
| 271 | # the stuff provided by this package, by looking at AUTOTEST_*_LIST. |
| 272 | instdirs=" |
| 273 | config |
| 274 | deps |
| 275 | profilers" |
| 276 | |
| 277 | for dir in ${instdirs}; do |
| 278 | [ -d "${AUTOTEST_WORKDIR}/client/${dir}" ] || continue |
| 279 | |
| 280 | insinto /usr/local/autotest/client/${dir} |
| 281 | |
| 282 | eval provided=\${AUTOTEST_${dir^^*}_LIST} |
| 283 | # * means provided all, figure out the list from ${S} |
| 284 | if [ "${provided}" = "*" ]; then |
| 285 | if eval pushd "${WORKDIR}/${P}/\${AUTOTEST_${dir^^*}}" &> /dev/null; then |
| 286 | provided=$(ls) |
| 287 | popd 1> /dev/null |
| 288 | else |
| 289 | provided="" |
| 290 | fi |
| 291 | fi |
| 292 | |
| 293 | for item in ${provided}; do |
| 294 | doins -r "${AUTOTEST_WORKDIR}/client/${dir}/${item}" |
| 295 | done |
| 296 | done |
| 297 | |
Zdenek Behan | 1ec164a | 2010-08-17 19:06:31 -0700 | [diff] [blame] | 298 | # TODO: Not all needs to be executable, but it's hard to pick selectively. |
| 299 | # The source repo should already contain stuff with the right permissions. |
| 300 | chmod -R a+x "${D}"/usr/local/autotest/* |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Zdenek Behan | 474fbae | 2010-08-20 21:13:22 -0700 | [diff] [blame] | 303 | EXPORT_FUNCTIONS src_compile src_prepare src_install |