blob: 6716ff94c2f1d1f86cd2849248fed6c5e3251b33 [file] [log] [blame]
#!/bin/bash
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script builds and runs Chromium OS unit tests. Note that this script
# utilizes the src_test stanza in chromeos-base packages. These stanzas
# should both build and run the unit tests.
# This script requires that you run build_packages first.
# Special because this can only run inside the chroot.
. "/usr/lib/crosutils/common.sh" 2> /dev/null ||
(echo "Must run within chroot" && false) ||
exit 1
# Flags
DEFINE_string board "${DEFAULT_BOARD}" \
"Target board of which tests were built"
DEFINE_string build_root "${DEFAULT_BUILD_ROOT}" \
"Root of build output"
DEFINE_boolean fast "${DEFAULT_FAST}" \
"Call many emerges in parallel."
DEFINE_string package_file "" \
"File with space-separated list of packages to run unit tests" f
DEFINE_string packages "" \
"Optional space-separated list of packages to run unit tests" p
DEFINE_boolean withdebug "${FLAGS_TRUE}" \
"Build debug versions of Chromium-OS-specific packages."
# List of packages with no unit tests.
NO_UNITTESTS=""
check_src_test() {
egrep '^src_test()' "${1}" > /dev/null
}
# Parse command line and die if unexpected parameters given.
FLAGS_HELP="usage: ${0} [flags]"
FLAGS "${@}" || exit 1
eval set -- "${FLAGS_ARGV}"
check_flags_only_and_allow_null_arg "${@}" && set --
set -e
[ -z "${FLAGS_board}" ] && die "--board required"
EMERGE_CMD="emerge"
EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
fi
# Create package list from package file and list of packages.
if [ -n "${FLAGS_package_file}" ]; then
if [ -f "${FLAGS_package_file}" ]; then
PACKAGE_LIST="$(cat ${FLAGS_package_file})"
else
warn "Missing package file."
fi
fi
[ -n "${FLAGS_packages}" ] && PACKAGE_LIST="${PACKAGE_LIST} ${FLAGS_packages}"
# If we didn't specify packages, find all packages.
if [ -z "${FLAGS_package_file}" -a -z "${FLAGS_packages}" ]; then
PACKAGE_LIST=$( /usr/lib/crosutils/get_package_list chromeos \
--board="${FLAGS_board}" |
egrep '^chromeos-base' )
fi
BLACK_LIST_FILE="/usr/share/crostestutils/unit_test_black_list.txt"
if [ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]; then
export USE="${USE} -cros-debug"
fi
TEST_PACKAGE_LIST=""
for package in ${PACKAGE_LIST}; do
if grep -xq "${package}" "${BLACK_LIST_FILE}"; then
warn "Skipping package ${package} since it is blacklisted."
continue
fi
EBUILD_PATH=$( equery-${FLAGS_board} which ${package} 2> /dev/null ) || \
warn "${package} not found"
if [ -n "${EBUILD_PATH}" ]; then
if check_src_test "${EBUILD_PATH}"; then
TEST_PACKAGE_LIST="${TEST_PACKAGE_LIST} ${package}"
else
NO_UNITTESTS="${NO_UNITTESTS} ${package}"
fi
fi
done
if [ -n "${NO_UNITTESTS}" ]; then
warn "The following packages have no unit tests:"
warn "${NO_UNITTESTS}"
fi
if [ -n "${TEST_PACKAGE_LIST}" ]; then
sudo -E PKGDIR="/build/${FLAGS_board}/test-packages" FEATURES="test" \
${EMERGE_BOARD_CMD} --nodeps --buildpkgonly ${TEST_PACKAGE_LIST}
fi
info "All unit tests passed."