Skip to contentSkip to conversation

report: optionally gzip xunit output

PATCH New David Disseldorp 1 participant 3 messages Sep 14

lore
Share & tools
lore
#0 lore raw

cover report: optionally gzip xunit output

I collect fstests xunit reports for (possible) later analysis. The XML compresses quite well: for an auto group run with a handful of failures, uncompressed xunit is typically 10x larger than a gzipped result.xml.

This mostly trivial patchset adds a new xunit-gzip report type. The same can be achieved via e.g.
./check -R xunit ... && gzip <REPORT_DIR>/result.xml

 check         |  2 +-
 common/report | 97 +++++++++++++++++++++++++++++----------------------
 2 files changed, 57 insertions(+), 42 deletions(-)
#1 lore raw

PATCH 1/2 report: put failure cdata collection in a helper fn

xunit-quiet output omits all of this, so check for it once instead of chaining "if [ -z "$quiet" -a ..." conditions.

---
 common/report | 79 +++++++++++++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 37 deletions(-)
common/report +42 -37
index 2fa15e62..eff01a7f 100644
@@ -162,6 +162,46 @@ ENDL
 	echo "Xunit report: $out_fn"
 }
 
+_xunit_log_failure_cdata()
+{
+	local report="$1"
+	local test_name="$2"
+	local full_file="${REPORT_DIR}/${test_name}.full"
+	local dmesg_file="${REPORT_DIR}/${test_name}.dmesg"
+	local out_src="${SRC_DIR}/${test_name}.out"
+	local outbad_file="${REPORT_DIR}/${test_name}.out.bad"
+	local mountfail_file="${REPORT_DIR}/${test_name}.mountfail"
+
+	if [ -s "$full_file" ]; then
+		echo -e "\t\t<system-out>" >> $report
+		printf	'<![CDATA[\n' >>$report
+		cat "$full_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
+		printf ']]>\n'	>>$report
+		echo -e "\t\t</system-out>" >> $report
+	fi
+	if [ -f "$dmesg_file" ]; then
+		echo -e "\t\t<kernel-log>" >> $report
+		printf	'<![CDATA[\n' >>$report
+		cat "$dmesg_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
+		printf ']]>\n'	>>$report
+		echo -e "\t\t</kernel-log>" >> $report
+	fi
+	if [ -s "$outbad_file" ]; then
+		echo -e "\t\t<system-err>" >> $report
+		printf	'<![CDATA[\n' >>$report
+		$diff "$out_src" "$outbad_file" | encode_cdata >>$report
+		printf ']]>\n'	>>$report
+		echo -e "\t\t</system-err>" >> $report
+	fi
+	if [ -f "$mountfail_file" ]; then
+		echo -e "\t\t<mount-failure>" >> $report
+		printf	'<![CDATA[\n' >>$report
+		cat "$mountfail_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
+		printf ']]>\n'	>>$report
+		echo -e "\t\t</mount-failure>" >> $report
+	fi
+}
+
 _xunit_make_testcase_report()
 {
 	local sect_name="$1"
@@ -169,11 +209,6 @@ _xunit_make_testcase_report()
 	local test_status="$3"
 	local test_time="$4"
 	local report_format="$5"
-	local quiet
-
-	if [ "$report_format" = xunit-quiet ]; then
-		quiet=yes
-	fi
 
 	# TODO: other places may also win if no-section mode will be named like 'default/global'
 	if [ $sect_name == '-no-sections-' ]; then
@@ -198,42 +233,12 @@ _xunit_make_testcase_report()
 		echo -e "\t\t<skipped/>" >> $report
 		;;
 	"fail")
-		local out_src="${SRC_DIR}/${test_name}.out"
-		local full_file="${REPORT_DIR}/${test_name}.full"
-		local dmesg_file="${REPORT_DIR}/${test_name}.dmesg"
-		local mountfail_file="${REPORT_DIR}/${test_name}.mountfail"
-		local outbad_file="${REPORT_DIR}/${test_name}.out.bad"
 		if [ -z "$_err_msg" ]; then
 			_err_msg="Test $test_name failed, reason unknown"
 		fi
 		echo -e "\t\t<failure message=\"$_err_msg\" type=\"TestFail\" />" >> $report
-		if [ -z "$quiet" -a -s "$full_file" ]; then
-			echo -e "\t\t<system-out>" >> $report
-			printf	'<![CDATA[\n' >>$report
-			cat "$full_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
-			printf ']]>\n'	>>$report
-			echo -e "\t\t</system-out>" >> $report
-		fi
-		if [ -z "$quiet" -a -f "$dmesg_file" ]; then
-			echo -e "\t\t<kernel-log>" >> $report
-			printf	'<![CDATA[\n' >>$report
-			cat "$dmesg_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
-			printf ']]>\n'	>>$report
-			echo -e "\t\t</kernel-log>" >> $report
-		fi
-		if [ -z "$quiet" -a -s "$outbad_file" ]; then
-			echo -e "\t\t<system-err>" >> $report
-			printf	'<![CDATA[\n' >>$report
-			$diff "$out_src" "$outbad_file" | encode_cdata >>$report
-			printf ']]>\n'	>>$report
-			echo -e "\t\t</system-err>" >> $report
-		fi
-		if [ -z "$quiet" -a -f "$mountfail_file" ]; then
-			echo -e "\t\t<mount-failure>" >> $report
-			printf	'<![CDATA[\n' >>$report
-			cat "$mountfail_file" | tr -dc '[:print:][:space:]' | encode_cdata >>$report
-			printf ']]>\n'	>>$report
-			echo -e "\t\t</mount-failure>" >> $report
+		if [ "$report_format" != xunit-quiet ]; then
+			_xunit_log_failure_cdata "$report" "$test_name"
 		fi
 		;;
 	*)
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 report: add xunit-gzip report type

In reply to David Disseldorp

xunit xml output is quite compressible, so provide an option to do it during report generation.

---
 check         |  2 +-
 common/report | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)
check +1 -1
index bca30215..eba515bc 100755
@@ -74,7 +74,7 @@ General options:
     -S section              exclude the specified section from the config file
     -T                      output timestamps
     -R fmt[,fmt]            generate report in formats specified. Supported
-                              formats: xunit, xunit-quiet
+                              formats: xunit, xunit-quiet, xunit-gzip
     --exact-order           run tests in the exact order specified
     --extra-space <size>    require minimum free space on scratch device
     --fs <type>             test the given FSTYP; valid types include:
common/report +14 -4
index eff01a7f..3aa8dcc2 100644
@@ -110,6 +110,7 @@ _xunit_make_section_report()
 	local bad_count="$3"
 	local notrun_count="$4"
 	local sect_time="$5"
+	local report_format="$6"
 	local timestamp
 	local tmp_fn="$REPORT_DIR/result.xml.new"
 	local out_fn="$REPORT_DIR/result.xml"
@@ -158,7 +159,13 @@ ENDL
 		cat $report >> "$tmp_fn"
 	fi
 	echo "</testsuite>" >> "$tmp_fn"
-	_sync_fs "$tmp_fn" && mv "$tmp_fn" "$out_fn"
+	_sync_fs "$tmp_fn" || return
+	if [ "$report_format" = "xunit-gzip" ]; then
+		out_fn="${out_fn}.gz"
+		"$GZIP_PROG" --stdout "$tmp_fn" > "$out_fn" && rm -f "$tmp_fn"
+	else
+		mv "$tmp_fn" "$out_fn"
+	fi
 	echo "Xunit report: $out_fn"
 }
 
@@ -260,10 +267,10 @@ _make_section_report()
 	local sect_time="$5"
 	for report in $REPORT_LIST; do
 		case "$report" in
-		"xunit"|"xunit-quiet")
+		"xunit"|"xunit-quiet"|"xunit-gzip")
 			_xunit_make_section_report "$sect_name" "$tests_count" \
 						   "$bad_count" "$notrun_count" \
-						   "$sect_time"
+						   "$sect_time" "$report"
 			;;
 		*)
 			_dump_err "format '$report' is not supported"
@@ -280,7 +287,7 @@ _make_testcase_report()
 	local test_time="$4"
 	for report in $REPORT_LIST; do
 		case "$report" in
-		"xunit"|"xunit-quiet")
+		"xunit"|"xunit-quiet"|"xunit-gzip")
 			_xunit_make_testcase_report "$sect_name" "$test_seq" \
 						    "$test_status" "$test_time" "$report"
 			;;
@@ -296,6 +303,9 @@ _assert_report_list() {
 		case "$report" in
 		"xunit"|"xunit-quiet")
 			;;
+		"xunit-gzip")
+			[ -x "$GZIP_PROG" ] || _fatal "'$report' requires gzip"
+			;;
 		*)
 			_fatal "report format '$report' is not supported"
 			;;
Signature · 1 line
2.55.0