/
test-patch-20-tests
executable file
·197 lines (177 loc) · 5.36 KB
/
test-patch-20-tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
#
# Licensed 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.
if [ "${TESTPATCHDEBUG}" == "true" ] ; then
set -x
fi
TASKNAME="TESTS"
OP=""
TEMPDIR=""
REPORTDIR=""
SUMMARYFILE=""
SUMMARYFILEFULL=""
STDOUT="/dev/null"
MVNPASSTHRU=""
FLAKY_LIMIT=10
###############################################################################
cleanupAndExit() {
exit "$1"
}
printUsage() {
echo "Usage: $0 --taskname | (--op=pre|post|report --tempdir=<TEMP DIR> --reportdir=<REPORT DIR> --summaryfile=<SUMMARY FILE> --summaryfile-full=<FULL SUMMARY FILE>) [--verbose] [-D<VALUE>...] [-P<VALUE>...]"
echo
}
parseArgs() {
for i in "$@"
do
case $i in
--taskname)
echo ${TASKNAME}
exit 0
;;
--op=*)
OP=${i#*=}
;;
--tempdir=*)
TEMPDIR=${i#*=}
;;
--reportdir=*)
REPORTDIR=${i#*=}
;;
--summaryfile=*)
SUMMARYFILE=${i#*=}
;;
--summaryfile-full=*)
SUMMARYFILEFULL=${i#*=}
;;
--verbose)
STDOUT="/dev/stdout"
;;
-D*)
MVNPASSTHRU="${MVNPASSTHRU} $i"
;;
-P*)
MVNPASSTHRU="${MVNPASSTHRU} $i"
;;
esac
done
if [[ "${TASKNAME}" == "" || "${OP}" == "" || "${TEMPDIR}" == "" || "${REPORTDIR}" == "" || "${SUMMARYFILE}" == "" ]] ; then
echo "Missing options"
echo
printUsage
cleanupAndExit 1
fi
if [[ "${OP}" != "pre" && "${OP}" != "post" && "${OP}" != "report" ]] ; then
echo "Invalid operation"
echo
printUsage
cleanupAndExit 1
fi
}
count_test_result_type() {
local type=$1
find . -name "TEST-*.xml" -exec sh -c 'xmllint --xpath "string(//testsuite/@'"${type}"')" $1; echo' _ {} \; \
| awk 'BEGIN {count=0} {count=count+$1} END {print count}';
}
run_tests() {
export MAVEN_OPTS="${MVNPASSTHRU} \
-Dmaven.test.failure.ignore=true \
-Doozie.test.waitfor.ratio=3 \
-Dtest.timeout=7200 \
-Dsurefire.rerunFailingTestsCount=1 \
${MAVEN_OPTS}"
mvn test -fae | tee "${TEMPDIR}/${TASKNAME}.out" >> "$STDOUT"
local exitCode=${PIPESTATUS[0]}
grep -b1 -e "Run .: PASS" "${TEMPDIR}/${TASKNAME}.out" | grep Test | cut -d':' -f2 \
| awk '{print $1}' > "${TEMPDIR}/${TASKNAME}.flakies.out"
if [ "${PIPESTATUS[0]}" -eq "0" ]; then
isTestsFlaky=1
sed -i -e "s/\./#/g" "${TEMPDIR}/${TASKNAME}.flakies.out"
else
isTestsFlaky=0
fi
if [ "${isTestsFlaky}" -eq "1" ]; then
echo "There are flaky tests."
else
rm "${TEMPDIR}/${TASKNAME}.flakies.out"
if [ "${exitCode}" -eq 0 ]; then
echo "All tests passed."
else
echo "Tests failed."
fi
fi
echo "$exitCode" > "${TEMPDIR}/${TASKNAME}.exitCode"
}
print_flakies() {
if [ -f "${TEMPDIR}/${TASKNAME}.flakies.out" ]; then
echo ". {color:orange}Tests failed at first run:{color}"
local limit="${1}"
if [ -n "${limit}" ]; then
cat "${TEMPDIR}/${TASKNAME}.flakies.out" | head -"${limit}"
echo ". For the complete list of flaky tests, see TEST-SUMMARY-FULL files."
else
cat "${TEMPDIR}/${TASKNAME}.flakies.out"
fi
fi
}
print_flakies_short() {
print_flakies "${FLAKY_LIMIT}"
}
print_flakies_full() {
print_flakies
}
generate_report() {
failedTests=$(find . -name '*\.txt' | grep target/surefire-reports | xargs grep "<<< FAILURE" | grep -v "Tests run:" | sed 's/.*\.txt\://' | sed 's/ .*//')
testsWithError=$(find . -name '*\.txt' | grep target/surefire-reports | xargs grep "<<< ERROR" | grep -v "Tests run:" | sed 's/.*\.txt\://' | sed 's/ .*//')
testsRun=$(grep "Tests run:" "${TEMPDIR}/${TASKNAME}.out" | grep -v " Time elapsed:" | awk '{print $4}' | sed 's/,//' | awk 'BEGIN {count=0} {count=count+$1} END {print count}')
testsFailed=$(count_test_result_type failures)
testsErrors=$(count_test_result_type errors)
hasFailures=$((testsFailed + testsErrors))
testsExitCode=$(cat "${TEMPDIR}/${TASKNAME}.exitCode")
if [[ ${hasFailures} != 0 ]] ; then
echo "{color:red}-1 ${TASKNAME}{color}"
echo ". Tests run: $testsRun"
echo ". Tests failed: $testsFailed"
echo ". Tests errors: $testsErrors"
echo ""
echo ". The patch failed the following testcases:"
echo ""
echo "${failedTests//#/. /}"
echo ""
echo ". Tests failing with errors:"
echo "${testsWithError//#/. /}"
echo ""
else
if [[ "${testsExitCode}" != "0" ]] ; then
echo "{color:red}-1 ${TASKNAME}{color} - patch does not compile, cannot run testcases"
else
echo "{color:green}+1 ${TASKNAME}{color}"
echo ". Tests run: $testsRun"
fi
fi
}
###############################################################################
parseArgs "$@"
case $OP in
pre)
;;
post)
run_tests
;;
report)
generate_report >> "${SUMMARYFILE}"
print_flakies_short >> "${SUMMARYFILE}"
print_flakies_full >> "${SUMMARYFILEFULL}"
;;
esac
exit 0