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 | |
| 9 | RDEPEND=">=chromeos-base/autotest-0.0.2" |
| 10 | DEPEND="${RDEPEND}" |
| 11 | |
| 12 | IUSE="buildcheck" |
| 13 | |
| 14 | # Ensure the configures run by autotest pick up the right config.site |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 15 | export CONFIG_SITE="/usr/share/config.site" |
| 16 | export AUTOTEST_WORKDIR="${WORKDIR}/autotest-work" |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 17 | |
| 18 | # Pythonify the list of packages |
| 19 | function pythonify_test_list() { |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 20 | AUTOTEST_TESTS="${IUSE_TESTS//[+-]tests_/}" |
| 21 | AUTOTEST_TESTS="${AUTOTEST_TESTS//tests_/}" |
| 22 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 23 | local result |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 24 | # NOTE: shell-like commenting of individual tests using grep |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 25 | result=$(for test in ${AUTOTEST_TESTS}; do use tests_${test} && echo -n "${test},"; done) |
| 26 | echo ${result} |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | # Create python package init files for top level test case dirs. |
| 30 | function 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 | |
| 43 | function 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 | |
| 63 | function create_autotest_workdir() { |
| 64 | local dst=${1} |
| 65 | |
| 66 | # create a working enviroment for pre-building |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 67 | ln -sf "${SYSROOT}"/usr/local/autotest/{conmux,tko,utils,global_config.ini,shadow_config.ini} "${dst}"/ |
| 68 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 69 | # 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 Behan | 451e07f | 2010-08-06 11:25:37 -0700 | [diff] [blame] | 76 | # 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 Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 79 | 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 Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | function 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 Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 102 | function 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 Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 106 | |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 107 | 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 Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 121 | |
| 122 | create_autotest_workdir "${AUTOTEST_WORKDIR}" |
| 123 | } |
| 124 | |
| 125 | function autotest_src_configure() { |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 126 | 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 | |
| 134 | function autotest_src_compile() { |
Zdenek Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 135 | pushd "${AUTOTEST_WORKDIR}" 1> /dev/null |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 136 | |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 137 | 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 Behan | 31315b3 | 2010-08-05 16:34:39 -0700 | [diff] [blame] | 155 | |
| 156 | popd 1> /dev/null |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | function autotest_src_install() { |
| 160 | insinto /usr/local/autotest/client/ |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 161 | doins -r "${AUTOTEST_WORKDIR}"/client/{tests,site_tests,deps,profilers,config} |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 162 | insinto /usr/local/autotest/server/ |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 163 | doins -r "${AUTOTEST_WORKDIR}"/server/{tests,site_tests} |
Zdenek Behan | 12ad1c5 | 2010-08-03 16:34:37 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Zdenek Behan | 99bf584 | 2010-08-04 17:23:38 -0700 | [diff] [blame] | 166 | EXPORT_FUNCTIONS src_configure src_compile src_prepare src_install |