HBASE-22518 yetus personality is treating branch-1.4 like earlier branches for hadoop...
[hbase.git] / dev-support / test-util.sh
blob9219bb96606c12b1503d2b5026c61b33b18e09e2
1 #!/usr/bin/env bash
3 #/**
4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
11 # *
12 # * http://www.apache.org/licenses/LICENSE-2.0
13 # *
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
19 # */
21 usage()
23 cat << EOF
24 usage: $0 [options] [test-name...]
26 Run a set of hbase tests. Individual tests may be specified on the
27 command line or in a file using -f, with one test per line. Runs all
28 tests by default. Each specified tests should include the fully
29 qualified package name.
31 options:
32 -h Show this message
33 -c Run 'mvn clean' before running the tests
34 -f FILE Run the additional tests listed in the FILE
35 -u Only run unit tests. Default is to run
36 unit and integration tests
37 -n N Run each test N times. Default = 1.
38 -s N Print N slowest tests
39 -H Print which tests are hanging (if any)
40 -e Echo the maven call before running. Default: not enabled
41 -r Runs remotely, on the build server. Default: not enabled
42 EOF
45 echoUsage=0
46 server=0
47 testFile=
48 doClean=""
49 testType=verify
50 numIters=1
51 showSlowest=
52 showHanging=
54 # normalize path refs for surefire
55 if [[ "$0" != /* ]]; then
56 # relative path
57 scriptDir=`pwd`/$(dirname $0)
58 else
59 # absolute path
60 scriptDir=$(dirname $0)
62 testDir=$scriptDir/../../../target/surefire-reports
64 while getopts "hcerHun:s:f:" OPTION
66 case $OPTION in
68 usage
69 exit 0
72 doClean="clean"
75 showHanging=1
78 testType=test
81 numIters=$OPTARG
84 showSlowest=$OPTARG
87 testFile=$OPTARG
90 echoUsage=1
93 server=1
95 ?)
96 usage
97 exit 1
98 esac
99 done
101 testIdx=0
103 # add tests specified in a file
104 if [ ! -z $testFile ]; then
105 exec 3<$testFile
107 while read <&3 line ; do
108 if [ ! -z "$line" ]; then
109 test[$testIdx]="$line"
111 testIdx=$(($testIdx+1))
112 done
115 # add tests specified on cmd line
116 if [ ! -z $BASH_ARGC ]; then
117 shift $(($OPTIND - 1))
118 for (( i = $OPTIND; i <= $BASH_ARGC; i++ ))
120 test[$testIdx]=$1;
121 testIdx=$(($testIdx+1))
122 shift
123 done
126 echo "Running tests..."
127 numTests=${#test[@]}
129 for (( i = 1 ; i <= $numIters; i++ ))
131 if [[ $numTests > 0 ]]; then
132 #Now loop through each test
133 for (( j = 0; j < $numTests; j++ ))
135 # Create the general command
136 cmd="nice -10 mvn $doClean $testType -Dtest=${test[$j]}"
138 # Add that is should run locally, if not on the server
139 if [ ${server} -eq 0 ]; then
140 cmd="${cmd} -P localTests"
143 # Print the command, if we should
144 if [ ${echoUsage} -eq 1 ]; then
145 echo "${cmd}"
148 # Run the command
149 $cmd
151 if [ $? -ne 0 ]; then
152 echo "${test[$j]} failed, iteration: $i"
153 exit 1
155 done
156 else
157 echo "EXECUTING ALL TESTS"
158 # Create the general command
159 cmd="nice -10 mvn $doClean $testType"
161 # Add that is should run locally, if not on the server
162 if [ ${server} -eq 0 ]; then
163 cmd="${cmd} -P localTests"
166 # Print the command, if we should
167 if [ ${echoUsage} -eq 1 ]; then
168 echo "${cmd}"
171 #now run the command
172 $cmd
174 done
176 # Print a report of the slowest running tests
177 if [ ! -z $showSlowest ]; then
179 testNameIdx=0
180 for (( i = 0; i < ${#test[@]}; i++ ))
182 testNames[$i]=$testDir/'TEST-'${test[$i]}'.xml'
183 done
185 echo "Slowest $showSlowest tests:"
187 awk '/<testsuite/ { \
188 gsub(/\"/,""); \
189 gsub(/>/,""); \
190 split($7,testname,"="); \
191 split($3,time,"="); \
192 print testname[2]"\t"time[2]}' \
193 ${testNames[@]} \
194 | sort -k2,2rn \
195 | head -n $showSlowest
198 # Print a report of tests that hung
199 if [ ! -z $showHanging ]; then
200 echo "Hanging tests:"
201 find $testDir -type f -name *.xml -size 0k \
202 | xargs basename \
203 | cut -d"." -f -1