HBASE-22518 yetus personality is treating branch-1.4 like earlier branches for hadoop...
[hbase.git] / dev-support / adhoc_run_tests / adhoc_run_tests.sh
blob1dedcb1c45f8810cf747026e00fa93d7c4bd13ef
1 #!/usr/bin/env bash
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
19 set -e
20 function usage {
21 echo "Usage: ${0} [options] TestSomeTestName [TestOtherTest...]"
22 echo ""
23 echo " --repeat times number of times to repeat if successful"
24 echo " --force-timeout seconds Seconds to wait before killing a given test run."
25 echo " --maven-local-repo /path/to/use Path for maven artifacts while building"
26 echo " --surefire-fork-count set the fork-count. only useful if multiple " \
27 "tests running (default 0.5C)"
28 echo " --log-output /path/to/use path to directory to hold attempt log"
29 exit 1
31 # Get arguments
32 declare -i force_timeout=7200
33 declare fork_count="0.5C"
34 declare -i attempts=1
35 declare maven_repo="${HOME}/.m2/repository"
36 declare output="."
37 while [ $# -gt 0 ]
39 case "$1" in
40 --force-timeout) shift; force_timeout=$1; shift;;
41 --maven-local-repo) shift; maven_repo=$1; shift;;
42 --repeat) shift; attempts=$1; shift;;
43 --log-output) shift; output=$1; shift;;
44 --surefire-fork-count) shift; fork_count=$1; shift;;
45 --) shift; break;;
46 -*) usage ;;
47 *) break;; # terminate while loop
48 esac
49 done
51 if [ "$#" -lt 1 ]; then
52 usage
55 function find_modules
57 declare testmaybepattern=$1
58 declare path
59 while IFS= read -r -d $'\0' path; do
60 while [ -n "${path}" ]; do
61 path=$(dirname "${path}")
62 if [ -f "${path}/pom.xml" ]; then
63 echo "${path}"
64 break
66 done
67 done < <(find . -name "${testmaybepattern}.java" -a -type f -a -not -path '*/target/*' -print0)
70 function echo_run_redirect
72 declare log=$1
73 shift
74 echo "${*}" >"${log}"
75 "${@}" >>"${log}" 2>&1
78 declare -a modules
80 for test in "${@}"; do
81 for module in $(find_modules "${test}"); do
82 if [[ ! "${modules[*]}" =~ ${module} ]]; then
83 echo "adding module '${module}' to set."
84 modules+=(${module})
86 done
87 done
89 declare -a mvn_module_arg
91 for module in "${modules[@]}"; do
92 mvn_module_arg+=(-pl "${module}")
93 done
94 declare tests="${*}"
95 for attempt in $(seq "${attempts}"); do
96 echo "Attempt ${attempt}" >&2
97 echo_run_redirect "${output}/mvn_test.log" mvn --batch-mode -Dmaven.repo.local="${maven_repo}" \
98 -Dtest="${tests// /,}" \
99 -Dsurefire.rerunFailingTestsCount=0 -Dsurefire.parallel.forcedTimeout="${force_timeout}" \
100 -Dsurefire.shutdown=kill -DtrimStackTrace=false -am "${mvn_module_arg[@]}" \
101 -DforkCount="${fork_count}" package
102 done