diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/test/BUILD | 6 | ||||
-rw-r--r-- | tools/test/generate-xml.sh | 55 | ||||
-rwxr-xr-x | tools/test/test-setup.sh | 21 |
3 files changed, 78 insertions, 4 deletions
diff --git a/tools/test/BUILD b/tools/test/BUILD index 4a4e56b284..c6a8311033 100644 --- a/tools/test/BUILD +++ b/tools/test/BUILD @@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"]) # Members of this filegroup shouldn't have duplicate basenames, otherwise # TestRunnerAction#getRuntimeArtifact() will get confused. +# Deprecated, do not use. filegroup( name = "runtime", srcs = ["test-setup.sh"], @@ -13,6 +14,11 @@ filegroup( ) filegroup( + name = "test_xml_generator", + srcs = ["generate-xml.sh"], +) + +filegroup( name = "collect_coverage", srcs = ["collect_coverage.sh"], ) diff --git a/tools/test/generate-xml.sh b/tools/test/generate-xml.sh new file mode 100644 index 0000000000..730b131f38 --- /dev/null +++ b/tools/test/generate-xml.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# 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. + +TEST_LOG="$1" +XML_OUTPUT_FILE="$2" +DURATION_IN_SECONDS="$3" +EXIT_CODE="$4" + +# Keep this in sync with test-setup.sh! +function encode_output_file { + if [[ -f "$1" ]]; then + # Replace invalid XML characters and invalid sequence in CDATA + # cf. https://stackoverflow.com/a/7774512/4717701 + perl -CSDA -pe's/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]+/?/g;' "$1" \ + | sed 's|]]>|]]>]]<![CDATA[>|g' + fi +} + +test_name="${TEST_BINARY#./}" +errors=0 +error_msg="" +if (( $EXIT_CODE != 0 )); then + errors=1 + error_msg="<error message=\"exited with error code $EXIT_CODE\"></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_IN_SECONDS}" time="${DURATION_IN_SECONDS}">${error_msg}</testcase> + <system-out><![CDATA[$(encode_output_file "${TEST_LOG}")]]></system-out> +</testsuite> +</testsuites> +EOF + diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index d8f2a47b67..d7bb931b5f 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -152,6 +152,7 @@ if [[ -z "$no_echo" ]]; then echo "-----------------------------------------------------------------------------" fi +# Unused if EXPERIMENTAL_SPLIT_XML_GENERATION is set. function encode_output_file { if [ -f "$1" ]; then # Replace invalid XML characters and invalid sequence in CDATA @@ -161,6 +162,8 @@ function encode_output_file { fi } +# Unused if EXPERIMENTAL_SPLIT_XML_GENERATION is set. +# Keep this in sync with generate-xml.sh! function write_xml_output_file { local duration=$(expr $(date +%s) - $start) local errors=0 @@ -268,17 +271,27 @@ if [ "$has_tail" == true ] && [ -z "$no_echo" ]; then wait $pid exitCode=$? else - if [ -z "$COVERAGE_DIR" ]; then - "${TEST_PATH}" "$@" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + if [[ "${EXPERIMENTAL_SPLIT_XML_GENERATION}" == "1" ]]; then + if [ -z "$COVERAGE_DIR" ]; then + "${TEST_PATH}" "$@" 2>&1 || exitCode=$? + else + "$1" "$TEST_PATH" "${@:3}" 2>&1 || exitCode=$? + fi else - "$1" "$TEST_PATH" "${@:3}" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + if [ -z "$COVERAGE_DIR" ]; then + "${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}" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + fi fi fi for signal in $signals; do trap - ${signal} done -write_xml_output_file +if [[ "${EXPERIMENTAL_SPLIT_XML_GENERATION}" != "1" ]]; then + write_xml_output_file +fi # Add all of the files from the undeclared outputs directory to the manifest. if [[ -n "$TEST_UNDECLARED_OUTPUTS_DIR" && -n "$TEST_UNDECLARED_OUTPUTS_MANIFEST" ]]; then |