summaryrefslogtreecommitdiffstats
path: root/security/nss/tests/ssl_gtests/ssl_gtests.sh
diff options
context:
space:
mode:
Diffstat (limited to 'security/nss/tests/ssl_gtests/ssl_gtests.sh')
-rwxr-xr-xsecurity/nss/tests/ssl_gtests/ssl_gtests.sh105
1 files changed, 90 insertions, 15 deletions
diff --git a/security/nss/tests/ssl_gtests/ssl_gtests.sh b/security/nss/tests/ssl_gtests/ssl_gtests.sh
index 9768c5ed9..ac39f212c 100755
--- a/security/nss/tests/ssl_gtests/ssl_gtests.sh
+++ b/security/nss/tests/ssl_gtests/ssl_gtests.sh
@@ -127,23 +127,98 @@ ssl_gtest_start()
fi
SSLGTESTREPORT="${SSLGTESTDIR}/report.xml"
- PARSED_REPORT="${SSLGTESTDIR}/report.parsed"
- echo "executing ssl_gtest"
- ${BINDIR}/ssl_gtest -d "${SSLGTESTDIR}" --gtest_output=xml:"${SSLGTESTREPORT}" \
- --gtest_filter="${GTESTFILTER-*}"
- html_msg $? 0 "ssl_gtest run successfully"
- echo "executing sed to parse the xml report"
- sed -f ${COMMON}/parsegtestreport.sed "${SSLGTESTREPORT}" > "${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
+
+ local nshards=1
+ local prefix=""
+ local postfix=""
+
+ export -f parallel_fallback
+
+ # Determine the number of chunks.
+ if [ -n "$GTESTFILTER" ]; then
+ echo "DEBUG: Not parallelizing ssl_gtests because \$GTESTFILTER is set"
+ elif type parallel 2>/dev/null; then
+ nshards=$(parallel --number-of-cores || 1)
+ fi
+
+ if [ "$nshards" != 1 ]; then
+ local indices=$(for ((i=0; i<$nshards; i++)); do echo $i; done)
+ prefix="parallel -j$nshards --line-buffer --halt soon,fail=1"
+ postfix="\&\& exit 0 \|\| exit 1 ::: $indices"
+ fi
+
+ echo "DEBUG: ssl_gtests will be divided into $nshards chunk(s)"
+
+ # Run tests.
+ ${prefix:-parallel_fallback} \
+ GTEST_SHARD_INDEX={} \
+ GTEST_TOTAL_SHARDS=$nshards \
+ DYLD_LIBRARY_PATH="${DIST}/${OBJDIR}/lib" \
+ ${BINDIR}/ssl_gtest -d "${SSLGTESTDIR}" \
+ --gtest_output=xml:"${SSLGTESTREPORT}.{}" \
+ --gtest_filter="${GTESTFILTER-*}" \
+ $postfix
+
+ 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
+}
+
+# Helper function used when 'parallel' isn't available.
+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
+ done <<< "$(sed -f "${COMMON}/parsegtestreport.sed" "${SSLGTESTREPORT}".*)"
}
ssl_gtest_cleanup()