3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script builds and runs Chromium OS unit tests. Note that this script
8 # utilizes the src_test stanza in chromeos-base packages. These stanzas
9 # should both build and run the unit tests.
11 # This script requires that you run build_packages first.
13 # Special because this can only run inside the chroot.
14 . "/usr/lib/crosutils/common.sh" 2> /dev/null ||
15 (echo "Must run within chroot" && false) ||
19 DEFINE_string board "${DEFAULT_BOARD}" \
20 "Target board of which tests were built"
21 DEFINE_string build_root "${DEFAULT_BUILD_ROOT}" \
22 "Root of build output"
23 DEFINE_boolean fast "${DEFAULT_FAST}" \
24 "Call many emerges in parallel."
25 DEFINE_string package_file "" \
26 "File with space-separated list of packages to run unit tests" f
27 DEFINE_string packages "" \
28 "Optional space-separated list of packages to run unit tests" p
29 DEFINE_string blacklist_packages "" \
30 "List of packages to blacklist from unit tests"
31 DEFINE_boolean withdebug "${FLAGS_TRUE}" \
32 "Build debug versions of Chromium-OS-specific packages."
34 # List of packages with no unit tests.
38 egrep '^src_test()' "${1}" > /dev/null
41 # Parse command line and die if unexpected parameters given.
42 FLAGS_HELP="usage: ${0} [flags]"
43 FLAGS "${@}" || exit 1
44 eval set -- "${FLAGS_ARGV}"
45 check_flags_only_and_allow_null_arg "${@}" && set --
49 [ -z "${FLAGS_board}" ] && die "--board required"
52 EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
53 if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
54 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
55 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
58 # Create package list from package file and list of packages.
59 if [ -n "${FLAGS_package_file}" ]; then
60 if [ -f "${FLAGS_package_file}" ]; then
61 PACKAGE_LIST="$(cat ${FLAGS_package_file})"
63 warn "Missing package file."
67 [ -n "${FLAGS_packages}" ] && PACKAGE_LIST="${PACKAGE_LIST} ${FLAGS_packages}"
69 # If we didn't specify packages, find all packages.
70 if [ -z "${FLAGS_package_file}" -a -z "${FLAGS_packages}" ]; then
71 PACKAGE_LIST=$( cd /usr/local/portage/chromiumos;
72 git grep -lE '^[[:space:]]*inherit.*\<cros-workon\>' | \
73 xargs git grep -lE '^src_test()' | \
74 xargs -n 1 dirname | grep '/' | sort -u )
77 BLACK_LIST_FILE="/usr/share/crostestutils/unit_test_black_list.txt"
78 BLACK_LIST_PACKAGES="${FLAGS_blacklist_packages}"
80 if [ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]; then
81 export USE="${USE} -cros-debug"
85 for package in ${PACKAGE_LIST}; do
86 if grep -xq "${package}" "${BLACK_LIST_FILE}" || \
87 [[ " ${BLACK_LIST_PACKAGES} " =~ " ${package} " ]]; then
88 warn "Skipping package ${package} since it is blacklisted."
91 EBUILD_PATH=$( equery-${FLAGS_board} which ${package} 2> /dev/null ) || \
92 warn "${package} not found"
93 if [ -n "${EBUILD_PATH}" ]; then
94 if check_src_test "${EBUILD_PATH}"; then
95 TEST_PACKAGE_LIST+=" ${package}"
97 NO_UNITTESTS+=" ${package}"
102 if [ -n "${NO_UNITTESTS}" ]; then
103 warn "The following packages have no unit tests:"
104 warn "${NO_UNITTESTS}"
107 if [ -n "${TEST_PACKAGE_LIST}" ]; then
108 sudo -E PKGDIR="/build/${FLAGS_board}/test-packages" FEATURES="test" \
109 ${EMERGE_BOARD_CMD} --nodeps --buildpkgonly ${TEST_PACKAGE_LIST}
112 info "All unit tests passed."