HBASE-4480 Testing script to simplify local testing

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1196939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-11-03 04:11:46 +00:00
parent 0c07e905a2
commit 09225cf9b6
1 changed files with 167 additions and 0 deletions

167
src/test/bin/test-util.sh Executable file
View File

@ -0,0 +1,167 @@
#!/usr/bin/env bash
#
#/**
# * Copyright 2007 The Apache Software Foundation
# *
# * Licensed to the Apache Software Foundation (ASF) under one
# * or more contributor license agreements. See the NOTICE file
# * distributed with this work for additional information
# * regarding copyright ownership. The ASF licenses this file
# * to you under the Apache License, Version 2.0 (the
# * "License"); you may not use this file except in compliance
# * with the License. You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# */
usage()
{
cat << EOF
usage: $0 [options] [test-name...]
Run a set of hbase tests. Individual tests may be specified on the
command line or in a file using -f, with one test per line. Runs all
tests by default. Each specified tests should include the fully
qualified package name.
options:
-h Show this message
-c Run 'mvn clean' before running the tests
-f FILE Run the additional tests listed in the FILE
-u Only run unit tests. Default is to run
unit and integration tests
-n N Run each test N times. Default = 1.
-s N Print N slowest tests
-H Print which tests are hanging (if any)
EOF
}
testFile=
doClean=""
testType=verify
numIters=1
showSlowest=
showHanging=
# normalize path refs for surefire
if [[ "$0" != /* ]]; then
# relative path
scriptDir=`pwd`/$(dirname $0)
else
# absolute path
scriptDir=$(dirname $0)
fi
testDir=$scriptDir/../../../target/surefire-reports
while getopts "hcHun:s:f:" OPTION
do
case $OPTION in
h)
usage
exit 0
;;
c)
doClean="clean"
;;
H)
showHanging=1
;;
u)
testType=test
;;
n)
numIters=$OPTARG
;;
s)
showSlowest=$OPTARG
;;
f)
testFile=$OPTARG
;;
?)
usage
exit 1
esac
done
testIdx=0
# add tests specified in a file
if [ ! -z $testFile ]; then
exec 3<$testFile
while read <&3 line ; do
if [ ! -z "$line" ]; then
test[$testIdx]="$line"
fi
testIdx=$(($testIdx+1))
done
fi
# add tests specified on cmd line
if [ ! -z $BASH_ARGC ]; then
shift $(($OPTIND - 1))
for (( i = $OPTIND; i <= $BASH_ARGC; i++ ))
do
test[$testIdx]=$1;
testIdx=$(($testIdx+1))
shift
done
fi
echo "Running tests..."
numTests=${#test[@]}
for (( i = 1 ; i <= $numIters; i++ ))
do
if [[ $numTests > 0 ]]; then
#Now loop through each test
for (( j = 0; j < $numTests; j++ ))
do
nice -10 mvn $doClean $testType -Dtest=${test[$j]}
if [ $? -ne 0 ]; then
echo "${test[$j]} failed, iteration: $i"
exit 1
fi
done
else
echo "EXECUTING ALL TESTS"
nice -10 mvn $doClean $testType
fi
done
# Print a report of the slowest running tests
if [ ! -z $showSlowest ]; then
testNameIdx=0
for (( i = 0; i < ${#test[@]}; i++ ))
do
testNames[$i]=$testDir/'TEST-'${test[$i]}'.xml'
done
echo "Slowest $showSlowest tests:"
awk '/<testsuite/ { \
gsub(/\"/,""); \
gsub(/>/,""); \
split($7,testname,"="); \
split($3,time,"="); \
print testname[2]"\t"time[2]}' \
${testNames[@]} \
| sort -k2,2rn \
| head -n $showSlowest
fi
# Print a report of tests that hung
if [ ! -z $showHanging ]; then
echo "Hanging tests:"
find $testDir -type f -name *.xml -size 0k \
| xargs basename \
| cut -d"." -f -1
fi