1#!/bin/bash 2 3# Copyright 2014 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17readonly PREFIX="#####" 18readonly RETRIES=2 19 20function maybePlural() { 21 # $1 = integer to use for plural check 22 # $2 = singular string 23 # $3 = plural string 24 if [ $1 -ne 1 ]; then 25 echo "$3" 26 else 27 echo "$2" 28 fi 29} 30 31 32function runTest() { 33 local cmd="$1" 34 35 if $cmd; then 36 return 0 37 fi 38 39 for iteration in $(seq $RETRIES); do 40 if ! $cmd; then 41 echo >&2 "'$cmd' failed more than once, giving up" 42 return 1 43 fi 44 done 45 46 echo >&2 "Warning: '$cmd' FLAKY, passed $RETRIES/$((RETRIES + 1))" 47} 48 49 50readonly tests=$(find . -name '*_test.py' -type f -executable) 51readonly count=$(echo $tests | wc -w) 52echo "$PREFIX Found $count $(maybePlural $count test tests)." 53 54exit_code=0 55 56i=0 57for test in $tests; do 58 i=$((i + 1)) 59 echo "" 60 echo "$PREFIX $test ($i/$count)" 61 echo "" 62 runTest $test || exit_code=$(( exit_code + 1 )) 63 echo "" 64done 65 66echo "$PREFIX $exit_code failed $(maybePlural $exit_code test tests)." 67exit $exit_code 68