| #!/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 is a less lazy way to get all the unittests running at once, but |
| # took longer to write. |
| |
| IN_CHROOT=cros_sdk |
| OUTSIDE_CHROOT_BUILDBOT=$(dirname $0) |
| CHROOT_BUILDBOT=../../chromite/buildbot |
| |
| declare -a FAILED_TESTS |
| declare -a FAILED_LOGS |
| |
| set -eu |
| |
| # Helper function to add failed logs/tests to be printed out later. |
| # $1 test that failed. |
| # $2 log file where we stored the output of the failed test. |
| append_failed_test() { |
| echo "ERROR: $1 failed. Log will be output at end of run!!!" |
| FAILED_TESTS+=($1) |
| FAILED_LOGS+=($2) |
| } |
| |
| # Wrapper to run unittest. Hides output unless test fails. |
| # $1 test to run. Must be in chromite/buildbot. |
| # $2 If set, run inside the chroot. |
| run_test() { |
| local log_file=$(mktemp) |
| echo "Running unittest $1" |
| |
| if [ $# -gt 1 ]; then |
| ${IN_CHROOT} -- $CHROOT_BUILDBOT/$1 &> $log_file || |
| append_failed_test $1 $log_file |
| else |
| $OUTSIDE_CHROOT_BUILDBOT/$1 &> $log_file || |
| append_failed_test $1 $log_file |
| fi |
| } |
| |
| # For some versions of 'sudo' (notably, the 'sudo' in the chroot at |
| # the time of this writing), sudo -v will ask for a password whether |
| # or not it's needed. 'sudo true' will do what we want. |
| sudo true |
| |
| all_tests=( |
| portage_utilities_unittest.py |
| cbuildbot_unittest.py |
| cbuildbot_background_unittest.py |
| cbuildbot_config_unittest.py |
| cbuildbot_commands_unittest.py |
| cbuildbot_stages_unittest.py |
| gerrit_helper_unittest.py |
| lkgm_manager_unittest.py |
| manifest_version_unittest.py |
| patch_unittest.py |
| remote_try_unittest.py |
| repository_unittest.py |
| validation_pool_unittest.py |
| "../scripts/cros_mark_as_stable_unittest.py yes" |
| "../scripts/cros_mark_chrome_as_stable_unittest.py yes" |
| "../scripts/upload_prebuilts_unittest.py" |
| ) |
| if [ $# -eq 0 ]; then |
| set -- "${all_tests[@]}" |
| fi |
| |
| for test in "$@" ; do |
| run_test ${test} |
| done |
| |
| if [ ${#FAILED_TESTS[@]} -gt 0 ]; then |
| index=0 |
| for test in "${FAILED_TESTS[@]}"; do |
| |
| echo |
| echo "FAIL: Unittest $test failed output:" |
| echo |
| |
| cat ${FAILED_LOGS[$index]} |
| rm ${FAILED_LOGS[$index]} |
| index=$(( index + 1 )) |
| done |
| echo |
| echo "FAIL: The following tests failed ${FAILED_TESTS[@]}" |
| exit 1 |
| else |
| echo "All tests succeeded!" |
| fi |