diff options
author | Damien Martin-Guillerez <dmarting@google.com> | 2017-07-19 14:27:33 +0200 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2017-07-19 16:49:35 +0200 |
commit | b8514f533d4546d3bfbec3700012f2bbeffd1c37 (patch) | |
tree | d5057c9dc417ba1ea5a7bc5549312486e19ccde8 /tools/test | |
parent | 29dc6f8e114420e7664b6882a65d237854750e7e (diff) |
Add stdout to default XML file and generate XML file on timeout
This should fix #1027 and get better error result on Jenkins.
Change-Id: I5ce30b64f634e01dd350af10748c4a9455a6bea8
PiperOrigin-RevId: 162474168
Diffstat (limited to 'tools/test')
-rwxr-xr-x | tools/test/test-setup.sh | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 058c459cc1..c43d5ee9c1 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -140,6 +140,42 @@ if [[ -z "$no_echo" ]]; then echo "-----------------------------------------------------------------------------" fi +function write_xml_output_file { + local duration=$(expr $(date +%s) - $start) + local errors=0 + local error_msg= + local signal="${1-}" + if [ -n "${XML_OUTPUT_FILE-}" -a ! -f "${XML_OUTPUT_FILE-}" ]; then + # Create a default XML output file if the test runner hasn't generated it + if [ -n "${signal}" ]; then + errors=1 + if [ "${signal}" = "SIGTERM" ]; then + error_msg="<error message=\"Timed out\"></error>" + else + error_msg="<error message=\"Terminated by signal ${signal}\"></error>" + fi + elif (( $exitCode != 0 )); then + errors=1 + error_msg="<error message=\"exited with error code $exitCode\"></error>" + fi + # Ensure that test shards have unique names in the xml output. + if [[ -n "${TEST_TOTAL_SHARDS+x}" ]] && ((TEST_TOTAL_SHARDS != 0)); then + ((shard_num=TEST_SHARD_INDEX+1)) + TEST_NAME="$TEST_NAME"_shard_"$shard_num"/"$TEST_TOTAL_SHARDS" + fi + cat <<EOF >${XML_OUTPUT_FILE} +<?xml version="1.0" encoding="UTF-8"?> +<testsuites> + <testsuite name="$TEST_NAME" tests="1" failures="0" errors="${errors}"> + <testcase name="$TEST_NAME" status="run" duration="${duration}">${error_msg}</testcase> + <system-out>$(<"${XML_OUTPUT_FILE}.log")</system-out> + </testsuite> +</testsuites> +EOF + fi + rm -f "${XML_OUTPUT_FILE}.log" +} + # The path of this command-line is usually relative to the exec-root, # but when using --run_under it can be a "/bin/bash -c" command-line. @@ -161,37 +197,21 @@ fi [[ -n "$RUNTEST_PRESERVE_CWD" ]] && EXE="${TEST_NAME}" exitCode=0 +signals="$(trap -l | sed -E 's/[0-9]+\)//g')" +for signal in $signals; do + trap "write_xml_output_file ${signal}" ${signal} +done start=$(date +%s) + if [ -z "$COVERAGE_DIR" ]; then - "${TEST_PATH}" "$@" || exitCode=$? + "${TEST_PATH}" "$@" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? else - "$1" "$TEST_PATH" "${@:3}" || exitCode=$? + "$1" "$TEST_PATH" "${@:3}" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? fi -duration=$(expr $(date +%s) - $start) - -if [ -n "${XML_OUTPUT_FILE-}" -a ! -f "${XML_OUTPUT_FILE-}" ]; then - # Create a default XML output file if the test runner hasn't generated it - if (( $exitCode != 0 )); then - errors=1 - error_msg="<error message=\"exited with error code $exitCode\"></error>" - else - errors=0 - error_msg= - fi - # Ensure that test shards have unique names in the xml output. - if [[ -n "${TEST_TOTAL_SHARDS+x}" ]] && ((TEST_TOTAL_SHARDS != 0)); then - ((shard_num=TEST_SHARD_INDEX+1)) - TEST_NAME="$TEST_NAME"_shard_"$shard_num"/"$TEST_TOTAL_SHARDS" - fi - cat <<EOF >${XML_OUTPUT_FILE} -<?xml version="1.0" encoding="UTF-8"?> -<testsuites> - <testsuite name="$TEST_NAME" tests="1" failures="0" errors="$errors"> - <testcase name="$TEST_NAME" status="run" duration="$duration">$error_msg</testcase> - </testsuite> -</testsuites> -EOF -fi +for signal in $signals; do + trap - ${signal} +done +write_xml_output_file exit $exitCode |