Skip to content

Commit

Permalink
Merge pull request #14027 from jhadvig/junit
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored May 6, 2017
2 parents e895aca + 5029094 commit 26ca5c9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
41 changes: 38 additions & 3 deletions hack/lib/test/junit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,47 @@ function os::test::junit::generate_oscmd_report() {
os::test::junit::check_test_counters

# use the junitreport tool to generate us a report
os::util::ensure::built_binary_exists 'junitreport'
os::test::junit::generate_report "oscmd"

junitreport summarize <"${ARTIFACT_DIR}/report.xml"
}

junitreport --type oscmd \
# os::test::junit::generate_gotest_report generats an XML jUnit report
# for the `go test` suite from the raw test output.
#
# Globals:
# - JUNIT_REPORT_OUTPUT
# - ARTIFACT_DIR
# Arguments:
# None
# Returns:
# None
function os::test::junit::generate_gotest_report() {
if [[ -z "${JUNIT_REPORT_OUTPUT:-}" ||
-n "${JUNIT_REPORT_OUTPUT:-}" && ! -s "${JUNIT_REPORT_OUTPUT:-}" ]]; then
# we can't generate a report
return
fi
os::test::junit::generate_report "gotest"

os::log::info "Full output from \`go test\` logged at ${JUNIT_REPORT_OUTPUT}"
os::log::info "jUnit XML report placed at ${ARTIFACT_DIR}/report.xml"
}

# os::test::junit::generate_report generats an XML jUnit report
# for either `os::cmd` or `go test`, based on the passed argument.
# If the `junitreport` binary is not present, it will be built.
#
# Globals:
# - JUNIT_REPORT_OUTPUT
# - ARTIFACT_DIR
# Arguments:
# - 1: specify which type of tests command output should junitreport read
function os::test::junit::generate_report() {
os::util::ensure::built_binary_exists 'junitreport'
junitreport --type "${1}" \
--suites nested \
--roots github.com/openshift/origin \
--output "${ARTIFACT_DIR}/report.xml" \
<"${JUNIT_REPORT_OUTPUT}"
junitreport summarize <"${ARTIFACT_DIR}/report.xml"
}
12 changes: 3 additions & 9 deletions hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,9 @@ if [[ -n "${junit_report}" ]]; then
set +o pipefail

go test -i ${gotest_flags} ${test_packages}
go test ${gotest_flags} ${test_packages} 2>"${test_error_file}" \
| tee "${test_output_file}" \
| junitreport --type gotest \
--suites nested \
--roots github.com/openshift/origin \
--stream \
--output "${junit_report_file}"
go test ${gotest_flags} ${test_packages} 2>"${test_error_file}" | tee "${test_output_file}"

JUNIT_REPORT_OUTPUT="${test_output_file}" os::test::junit::generate_gotest_report

test_return_code="${PIPESTATUS[0]}"

Expand Down Expand Up @@ -225,8 +221,6 @@ if [[ -n "${junit_report}" ]]; then
fi
fi

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

elif [[ -n "${coverage_output_dir}" ]]; then
Expand Down
22 changes: 21 additions & 1 deletion hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ package="${OS_TEST_PACKAGE:-test/integration}"
name="$(basename ${package})"
dlv_debug="${DLV_DEBUG:-}"
verbose="${VERBOSE:-}"
junit_report="${JUNIT_REPORT:-}"

if [[ -n "${JUNIT_REPORT:-}" ]]; then
export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
rm -rf "${JUNIT_REPORT_OUTPUT}"
fi

# CGO must be disabled in order to debug
if [[ -n "${dlv_debug}" ]]; then
Expand Down Expand Up @@ -61,6 +67,10 @@ function exectest() {
# run tests with extra verbosity
out=$("${testexec}" -vmodule=*=5 -test.v -test.timeout=4m -test.run="^$1$" "${@:2}" 2>&1)
result=$?
elif [[ -n "${junit_report}" ]]; then
# run tests and generate jUnit xml
out=$("${testexec}" -test.v -test.timeout=4m -test.run="^$1$" "${@:2}" 2>/dev/null | tee -a "${JUNIT_REPORT_OUTPUT}" )
result=$?
else
# run tests normally
out=$("${testexec}" -test.timeout=4m -test.run="^$1$" "${@:2}" 2>&1)
Expand Down Expand Up @@ -96,16 +106,26 @@ loop="${TIMES:-1}"
# hack/test-integration.sh Template*
# hack/test-integration.sh "(WatchBuilds|Template)"
tests=( $(go run "${OS_ROOT}/hack/listtests.go" -prefix="${OS_GO_PACKAGE}/${package}.Test" "${testexec}" | grep -E "${1-Test}") )

# run each test as its own process
ret=0
test_result="ok"
pushd "${OS_ROOT}/${package}" &>/dev/null
test_start_time=$(date +%s%3N)
for test in "${tests[@]}"; do
for((i=0;i<${loop};i+=1)); do
if ! (exectest "${test}" ${@:2}); then
ret=1
test_result="FAIL"
fi
done
done
test_end_time=$(date +%s%3N)
test_duration=$((test_end_time - test_start_time))

echo "${test_result} github.com/openshift/origin/test/integration $((test_duration / 1000)).$((test_duration % 1000))s" >> "${JUNIT_REPORT_OUTPUT:-/dev/null}"
os::test::junit::generate_gotest_report

popd &>/dev/null

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

0 comments on commit 26ca5c9

Please sign in to comment.