summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Relyea <rrelyea@redhat.com>2021-07-15 15:59:36 -0700
committerRobert Relyea <rrelyea@redhat.com>2021-07-15 15:59:36 -0700
commitdbb32786e08ca7cf654a7631dd525c9768d0d9b6 (patch)
tree7a91bda50813311f0ff5f3246691576c26bca6cd /tests
parent42861f66c7a68ea46fab490ab9e4065d7170e109 (diff)
downloadnss-hg-dbb32786e08ca7cf654a7631dd525c9768d0d9b6.tar.gz
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
Diffstat (limited to 'tests')
-rw-r--r--tests/common/init.sh66
-rw-r--r--tests/common/parsegtestreport.sed6
-rw-r--r--tests/common/parsegtestreport.sh44
-rwxr-xr-xtests/gtests/gtests.sh12
-rwxr-xr-xtests/ssl_gtests/ssl_gtests.sh52
5 files changed, 117 insertions, 63 deletions
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='</TD><TD>Unknown</TD><TR>'
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/<testcase/\\\n<testcase/g' | \
+ # Use sed to parse the report.
+ sed -f "${COMMON}/parsegtestreport.sed"
+ # here's how we would use bash if it wasn't so slow
+ #sh "${COMMON}/parsegtestreport.sh"
+ }
+
+ gtest_parse_report()
+ {
+ if type xmllint &>/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 @@
/\<testcase/{
- s/^.* name="\([^"]*\)" value_param="\([^"]*\)" status="\([^"]*\)" time="[^"]*" classname="\([^"]*\)".*$/\3 '\4: \1 \2'/
+ s/^.* name="\([^"]*\)" value_param="\([^"]*\)" status="\([^"]*\)" time="[^"]*" classname="\([^"]*\).*$/\3 '\4: \1 \2'/
t end
s/^.* name="\([^"]*\)" status="\([^"]*\)" time="[^"]*" classname="\([^"]*\)".*$/\2 '\3: \1'/
t end
+ s/^.* name="\([^"]*\)" value_param="\([^"]*\)" status="\([^"]*\)" result="[^"]*" time="[^"]*" timestamp="[^"]*" classname="\([^"]*\)".*$/\3 '\4: \1 \2'/
+ t end
+ s/^.* name="\([^"]*\)" status="\([^"]*\)" result="[^"]*" time="[^"]*" timestamp="[^"]*" classname="\([^"]*\)".*$/\2 '\3: \1'/
+ t end
}
d
: end
diff --git a/tests/common/parsegtestreport.sh b/tests/common/parsegtestreport.sh
new file mode 100644
index 000000000..f0a879a42
--- /dev/null
+++ b/tests/common/parsegtestreport.sh
@@ -0,0 +1,44 @@
+#! /bin/sh
+#
+# parse the gtest results file this replaces a sed script which produced
+# the identical output. This new script is now independent of new unknown
+# labels being introduced in future revisions of gtests.
+
+#this function extracts the appropriate value from
+# <testcase label="value1" label2="value2" label3="value3" />
+# 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//&quot;/\"}
+ fi
+}
+
+parse()
+{
+ while read line
+ do
+ if [[ "${line}" =~ "<testcase " ]]; then
+ name=$(getvalue "${line}" "name")
+ value=$(getvalue "${line}" "value_param")
+ stat=$(getvalue "${line}" "status")
+ class=$(getvalue "${line}" "classname")
+ echo "${stat} '${class}: $(echo ${name} ${value})'"
+ fi
+ done
+}
+
+# if no arguments, just take standard in, if arguments, take the args as
+# files and cat them together to parse
+if [ $# -eq 0 ]; then
+ parse
+else
+ cat "$@" | parse
+fi
diff --git a/tests/gtests/gtests.sh b/tests/gtests/gtests.sh
index 4005a16a6..8c6047736 100755
--- a/tests/gtests/gtests.sh
+++ b/tests/gtests/gtests.sh
@@ -86,18 +86,8 @@ gtest_start()
fi
echo "test output dir: ${GTESTREPORT}"
- echo "executing sed to parse the xml report"
- sed -f "${COMMON}/parsegtestreport.sed" "$GTESTREPORT" > "$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/<testcase/\\\n<testcase/g' | \
- # Use sed to parse the report.
- sed -f "${COMMON}/parsegtestreport.sed"
-}
-
-# 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.
-parse_report_legacy()
-{
- while read result name && [ -n "$name" ]; do
- if [ "$result" = "run" ]; then
- html_passed_ignore_core "$name"
- fi
- done <<< "$(sed -f "${COMMON}/parsegtestreport.sed" "${SSLGTESTREPORT}".*)"
-}
-
ssl_gtest_cleanup()
{
cd ${QADIR}