Skip to content

Commit 26ca5c9

Browse files
author
OpenShift Bot
authored
Merge pull request #14027 from jhadvig/junit
Merged by openshift-bot
2 parents e895aca + 5029094 commit 26ca5c9

File tree

3 files changed

+62
-13
lines changed

3 files changed

+62
-13
lines changed

hack/lib/test/junit.sh

+38-3
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,47 @@ function os::test::junit::generate_oscmd_report() {
170170
os::test::junit::check_test_counters
171171

172172
# use the junitreport tool to generate us a report
173-
os::util::ensure::built_binary_exists 'junitreport'
173+
os::test::junit::generate_report "oscmd"
174+
175+
junitreport summarize <"${ARTIFACT_DIR}/report.xml"
176+
}
174177

175-
junitreport --type oscmd \
178+
# os::test::junit::generate_gotest_report generats an XML jUnit report
179+
# for the `go test` suite from the raw test output.
180+
#
181+
# Globals:
182+
# - JUNIT_REPORT_OUTPUT
183+
# - ARTIFACT_DIR
184+
# Arguments:
185+
# None
186+
# Returns:
187+
# None
188+
function os::test::junit::generate_gotest_report() {
189+
if [[ -z "${JUNIT_REPORT_OUTPUT:-}" ||
190+
-n "${JUNIT_REPORT_OUTPUT:-}" && ! -s "${JUNIT_REPORT_OUTPUT:-}" ]]; then
191+
# we can't generate a report
192+
return
193+
fi
194+
os::test::junit::generate_report "gotest"
195+
196+
os::log::info "Full output from \`go test\` logged at ${JUNIT_REPORT_OUTPUT}"
197+
os::log::info "jUnit XML report placed at ${ARTIFACT_DIR}/report.xml"
198+
}
199+
200+
# os::test::junit::generate_report generats an XML jUnit report
201+
# for either `os::cmd` or `go test`, based on the passed argument.
202+
# If the `junitreport` binary is not present, it will be built.
203+
#
204+
# Globals:
205+
# - JUNIT_REPORT_OUTPUT
206+
# - ARTIFACT_DIR
207+
# Arguments:
208+
# - 1: specify which type of tests command output should junitreport read
209+
function os::test::junit::generate_report() {
210+
os::util::ensure::built_binary_exists 'junitreport'
211+
junitreport --type "${1}" \
176212
--suites nested \
177213
--roots github.com/openshift/origin \
178214
--output "${ARTIFACT_DIR}/report.xml" \
179215
<"${JUNIT_REPORT_OUTPUT}"
180-
junitreport summarize <"${ARTIFACT_DIR}/report.xml"
181216
}

hack/test-go.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,9 @@ if [[ -n "${junit_report}" ]]; then
186186
set +o pipefail
187187

188188
go test -i ${gotest_flags} ${test_packages}
189-
go test ${gotest_flags} ${test_packages} 2>"${test_error_file}" \
190-
| tee "${test_output_file}" \
191-
| junitreport --type gotest \
192-
--suites nested \
193-
--roots github.com/openshift/origin \
194-
--stream \
195-
--output "${junit_report_file}"
189+
go test ${gotest_flags} ${test_packages} 2>"${test_error_file}" | tee "${test_output_file}"
190+
191+
JUNIT_REPORT_OUTPUT="${test_output_file}" os::test::junit::generate_gotest_report
196192

197193
test_return_code="${PIPESTATUS[0]}"
198194

@@ -225,8 +221,6 @@ if [[ -n "${junit_report}" ]]; then
225221
fi
226222
fi
227223

228-
os::log::info "Full output from \`go test\` logged at ${test_output_file}"
229-
os::log::info "jUnit XML report placed at ${junit_report_file}"
230224
exit "${test_return_code}"
231225

232226
elif [[ -n "${coverage_output_dir}" ]]; then

hack/test-integration.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ package="${OS_TEST_PACKAGE:-test/integration}"
2929
name="$(basename ${package})"
3030
dlv_debug="${DLV_DEBUG:-}"
3131
verbose="${VERBOSE:-}"
32+
junit_report="${JUNIT_REPORT:-}"
33+
34+
if [[ -n "${JUNIT_REPORT:-}" ]]; then
35+
export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
36+
rm -rf "${JUNIT_REPORT_OUTPUT}"
37+
fi
3238

3339
# CGO must be disabled in order to debug
3440
if [[ -n "${dlv_debug}" ]]; then
@@ -61,6 +67,10 @@ function exectest() {
6167
# run tests with extra verbosity
6268
out=$("${testexec}" -vmodule=*=5 -test.v -test.timeout=4m -test.run="^$1$" "${@:2}" 2>&1)
6369
result=$?
70+
elif [[ -n "${junit_report}" ]]; then
71+
# run tests and generate jUnit xml
72+
out=$("${testexec}" -test.v -test.timeout=4m -test.run="^$1$" "${@:2}" 2>/dev/null | tee -a "${JUNIT_REPORT_OUTPUT}" )
73+
result=$?
6474
else
6575
# run tests normally
6676
out=$("${testexec}" -test.timeout=4m -test.run="^$1$" "${@:2}" 2>&1)
@@ -96,16 +106,26 @@ loop="${TIMES:-1}"
96106
# hack/test-integration.sh Template*
97107
# hack/test-integration.sh "(WatchBuilds|Template)"
98108
tests=( $(go run "${OS_ROOT}/hack/listtests.go" -prefix="${OS_GO_PACKAGE}/${package}.Test" "${testexec}" | grep -E "${1-Test}") )
109+
99110
# run each test as its own process
100111
ret=0
112+
test_result="ok"
101113
pushd "${OS_ROOT}/${package}" &>/dev/null
114+
test_start_time=$(date +%s%3N)
102115
for test in "${tests[@]}"; do
103116
for((i=0;i<${loop};i+=1)); do
104117
if ! (exectest "${test}" ${@:2}); then
105118
ret=1
119+
test_result="FAIL"
106120
fi
107121
done
108122
done
123+
test_end_time=$(date +%s%3N)
124+
test_duration=$((test_end_time - test_start_time))
125+
126+
echo "${test_result} github.com/openshift/origin/test/integration $((test_duration / 1000)).$((test_duration % 1000))s" >> "${JUNIT_REPORT_OUTPUT:-/dev/null}"
127+
os::test::junit::generate_gotest_report
128+
109129
popd &>/dev/null
110130

111-
ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret"
131+
ENDTIME=$(date +%s); echo "$0 took $((ENDTIME - STARTTIME)) seconds"; exit "$ret"

0 commit comments

Comments
 (0)