From dbb32786e08ca7cf654a7631dd525c9768d0d9b6 Mon Sep 17 00:00:00 2001 From: Robert Relyea Date: Thu, 15 Jul 2021 15:59:36 -0700 Subject: Bug 1720230 Gtest update changed the gtest reports, losing gtest details in all.sh reports. This patch includes the updated .sed script, and an experiment using bash instead to see how hard it would be to make a more robust parser. The robust parser generates identical output as sed, but takes about 30x longer, so instead of subsecond operations, it takes almost half a minute. With that result, I think we can stay with sed and continue to update when we get new versions of gtests. (sigh). time cat report.xml.0 | sed -f parsegtestreport.sed > r1 real 0m0.710s user 0m0.705s sys 0m0.008s time cat report.xml.0 | sh parsegtestreport.sh > r2 real 0m25.066s user 0m17.759s sys 0m9.506s [rrelyea@localhost common]$ diff r1 r2 updated: with review comments from Martin and move the report parsing to the common code so it can be shared with both ssl_gtests and gtests shell scripts. Differential Revision: https://phabricator.services.mozilla.com/D120028 --- tests/common/init.sh | 66 +++++++++++++++++++++++++++++++++++++++ tests/common/parsegtestreport.sed | 6 +++- tests/common/parsegtestreport.sh | 44 ++++++++++++++++++++++++++ tests/gtests/gtests.sh | 12 +------ tests/ssl_gtests/ssl_gtests.sh | 52 +----------------------------- 5 files changed, 117 insertions(+), 63 deletions(-) create mode 100644 tests/common/parsegtestreport.sh (limited to 'tests') diff --git a/tests/common/init.sh b/tests/common/init.sh index 658023d83..8c10bdd2a 100644 --- a/tests/common/init.sh +++ b/tests/common/init.sh @@ -253,6 +253,72 @@ if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then HTML_UNKNOWN='Unknown' TABLE_ARGS= + gtest_parse_report_helper() + { + # Check XML reports for normal test runs and failures. + local successes=$(gtest_parse_report_xpath "//testcase[@status='run'][count(*)=0]" "$@" ) + local failures=$(gtest_parse_report_xpath "//failure/.." "$@" ) + + # Print all tests that succeeded. + while read result name; do + html_passed_ignore_core "$name" + done <<< "$successes" + + # Print failing tests. + if [ -n "$failures" ]; then + printf "\nFAILURES:\n=========\n" + + while read result name; do + html_failed_ignore_core "$name" + done <<< "$failures" + + printf "\n" + fi + } + + # This legacy report parser can't actually detect failures. It always relied + # on the binary's exit code. Print the tests we ran to keep the old behavior. + gtest_parse_report_legacy() + { + while read result name && [ -n "$name" ]; do + if [ "$result" = "notrun" ]; then + echo "$name" SKIPPED + elif [ "$result" = "run" ]; then + html_passed_ignore_core "$name" + else + html_failed_ignore_core "$name" + fi + done <<< "$(sed -f "${COMMON}/parsegtestreport.sed" "$@" )" + # here's how we would use bash if it wasn't so slow + # done <<< "$(sh "${COMMON}/parsegtestreport.sh" "$@" )" + } + + gtest_parse_report_xpath() + { + # Query the XML report with the given XPath pattern. + xpath="$1" + shift + xmllint --xpath "${xpath}" "$@" 2>/dev/null | \ + # Insert newlines to help sed. + sed $'s//dev/null; then + echo "DEBUG: Using xmllint to parse GTest XML report(s)" + gtest_parse_report_helper "$@" + else + echo "DEBUG: Falling back to legacy XML report parsing using only sed" + gtest_parse_report_legacy "$@" + fi + } + + #directory name init SCRIPTNAME=init.sh diff --git a/tests/common/parsegtestreport.sed b/tests/common/parsegtestreport.sed index 11bd1d6af..4b6226248 100644 --- a/tests/common/parsegtestreport.sed +++ b/tests/common/parsegtestreport.sed @@ -1,8 +1,12 @@ /\ +# which value is selected from the label , which is specified +# as the 2nd parameter. The line to parse is the first parameter. +getvalue() +{ + pattern1='*'${2}'="' + pattern2='"*' + front=${1#${pattern1}} + if [[ "${front}" != "${1}" ]]; then + val=${front%%${pattern2}} + # as we output the result, restore any quotes that may have + # been in the original test names. + echo ${val//"/\"} + fi +} + +parse() +{ + while read line + do + if [[ "${line}" =~ " "$PARSED_REPORT" echo "processing the parsed report" - cat "$PARSED_REPORT" | while read result name; do - if [ "$result" = "notrun" ]; then - echo "$name" SKIPPED - elif [ "$result" = "run" ]; then - html_passed_ignore_core "$name" - else - html_failed_ignore_core "$name" - fi - done + gtest_parse_report ${GTESTREPORT} popd done } diff --git a/tests/ssl_gtests/ssl_gtests.sh b/tests/ssl_gtests/ssl_gtests.sh index 1783ef436..d2e8c7a4f 100755 --- a/tests/ssl_gtests/ssl_gtests.sh +++ b/tests/ssl_gtests/ssl_gtests.sh @@ -133,13 +133,7 @@ ssl_gtest_start() html_msg $? 0 "ssl_gtests ran successfully" # Parse XML report(s). - if type xmllint &>/dev/null; then - echo "DEBUG: Using xmllint to parse GTest XML report(s)" - parse_report - else - echo "DEBUG: Falling back to legacy XML report parsing using only sed" - parse_report_legacy - fi + gtest_parse_report "${SSLGTESTREPORT}".* } # Helper function used when 'parallel' isn't available. @@ -148,50 +142,6 @@ parallel_fallback() eval "${@//\{\}/0}" } -parse_report() -{ - # Check XML reports for normal test runs and failures. - local successes=$(parse_report_xpath "//testcase[@status='run'][count(*)=0]") - local failures=$(parse_report_xpath "//failure/..") - - # Print all tests that succeeded. - while read result name; do - html_passed_ignore_core "$name" - done <<< "$successes" - - # Print failing tests. - if [ -n "$failures" ]; then - printf "\nFAILURES:\n=========\n" - - while read result name; do - html_failed_ignore_core "$name" - done <<< "$failures" - - printf "\n" - fi -} - -parse_report_xpath() -{ - # Query the XML report with the given XPath pattern. - xmllint --xpath "$1" "${SSLGTESTREPORT}".* 2>/dev/null | \ - # Insert newlines to help sed. - sed $'s/