Skip to contentSkip to conversation

check: minor cleanups and xunit report fix

PATCH In review David Disseldorp 2 participants 14 messages Jun 20, 2022 – Jun 22, 2022

lore
Share & tools
lore
#0 lore raw

cover check: minor cleanups and xunit report fix

Hi,

This patchset contains a few cleanups which I came across while working on a larger set of changes for test-rerun-on-failure[1] support. One minor fix for the tests count in the xunit report is included.

Diffstat:

 check         | 148 +++++++++++++++++++++-----------------------------
 common/report |  14 +++--
 2 files changed, 71 insertions(+), 91 deletions(-)

1. test-rerun-on-failure proposal by Ted Ts'o:
https://lwn.net/Articles/897061/

Cheers, David

#1 lore raw

PATCH 1/6 check: avoid FSTYP=<fstyp parameter> repetition

---
 check | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
check +7 -9
index de11b37e..42925e09 100755
@@ -277,15 +277,13 @@ while [ $# -gt 0 ]; do
 	case "$1" in
 	-\? | -h | --help) usage ;;
 
-	-nfs)		FSTYP=nfs ;;
-	-glusterfs)	FSTYP=glusterfs ;;
-	-cifs)		FSTYP=cifs ;;
-	-9p)		FSTYP=9p ;;
-	-virtiofs)	FSTYP=virtiofs ;;
-	-overlay)	FSTYP=overlay; export OVERLAY=true ;;
-	-pvfs2)		FSTYP=pvfs2 ;;
-	-tmpfs)		FSTYP=tmpfs ;;
-	-ubifs)		FSTYP=ubifs ;;
+	-nfs|-glusterfs|-cifs|-9p|-virtiofs|-pvfs2|-tmpfs|-ubifs)
+		FSTYP="${1:1}"
+		;;
+	-overlay)
+		FSTYP=overlay
+		export OVERLAY=true
+		;;
 
 	-g)	group=$2 ; shift ;
 		GROUP_LIST="$GROUP_LIST ${group//,/ }"
Signature · 1 line
2.35.3
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] check: avoid FSTYP=<fstyp parameter> repetition

Quoted 19 lines · David Disseldorp
---
 check | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
check +0 -6
index de11b37e..42925e09 100755
@@ -277,15 +277,13 @@ while [ $# -gt 0 ]; do
 	case "$1" in
 	-\? | -h | --help) usage ;;
 
-	-nfs)		FSTYP=nfs ;;
-	-glusterfs)	FSTYP=glusterfs ;;
-	-cifs)		FSTYP=cifs ;;
-	-9p)		FSTYP=9p ;;
-	-virtiofs)	FSTYP=virtiofs ;;
-	-overlay)	FSTYP=overlay; export OVERLAY=true ;;

check while [ $# -gt 0 ]; do · line 286

Quoted 10 lines
check +7 -3
-	-pvfs2)		FSTYP=pvfs2 ;;
-	-tmpfs)		FSTYP=tmpfs ;;
-	-ubifs)		FSTYP=ubifs ;;
+	-nfs|-glusterfs|-cifs|-9p|-virtiofs|-pvfs2|-tmpfs|-ubifs)
+		FSTYP="${1:1}"
+		;;
+	-overlay)
+		FSTYP=overlay
+		export OVERLAY=true
+		;;

Looks good.

Quoted 6 lines
check +0 -0
 	-g)	group=$2 ; shift ;
 		GROUP_LIST="$GROUP_LIST ${group//,/ }"
Signature · 1 line
2.35.3
#3 lore raw

PATCH 2/6 check: simplify check.time parsing

In reply to David Disseldorp

There's no need to use grep and awk when the latter can do all that's needed, including the pretty printing.

---
 check | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
check +3 -7
index 42925e09..43c072d2 100755
@@ -819,13 +819,9 @@ function run_section()
 		try="$try $seqnum"
 		n_try=`expr $n_try + 1`
 
-		# slashes now in names, sed barfs on them so use grep
-		lasttime=`grep -w ^$seqnum $check.time | awk '// {print $2}'`
-		if [ "X$lasttime" != X ]; then
-			echo -n " ${lasttime}s ... "
-		else
-			echo -n "	" # prettier output with timestamps.
-		fi
+		awk 'BEGIN {lasttime="       "} \
+		     $1 == "'$seqnum'" {lasttime=" " $2 "s ... "; exit} \
+		     END {printf "%s", lasttime}' "$check.time"
 		rm -f core $seqres.notrun
 
 		start=`_wallclock`
Signature · 1 line
2.35.3
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] check: simplify check.time parsing

Quoted 16 lines · David Disseldorp

There's no need to use grep and awk when the latter can do all that's needed, including the pretty printing.

---
 check | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
check +0 -0
index 42925e09..43c072d2 100755
@@ -819,13 +819,9 @@ function run_section()
 		try="$try $seqnum"
 		n_try=`expr $n_try + 1`
 

check function run_section() · line 824

Quoted 10 lines
check +3 -7
-		# slashes now in names, sed barfs on them so use grep
-		lasttime=`grep -w ^$seqnum $check.time | awk '// {print $2}'`
-		if [ "X$lasttime" != X ]; then
-			echo -n " ${lasttime}s ... "
-		else
-			echo -n "	" # prettier output with timestamps.
-		fi
+		awk 'BEGIN {lasttime="       "} \
+		     $1 == "'$seqnum'" {lasttime=" " $2 "s ... "; exit} \
+		     END {printf "%s", lasttime}' "$check.time"

I'm not good at 'awk' so much, but this change looks not break old format.

Quoted 6 lines
check +0 -0
 		rm -f core $seqres.notrun
 
 		start=`_wallclock`
Signature · 1 line
2.35.3
#5 lore raw

PATCH 3/6 report: drop unused _xunit_make_section_report parameter

In reply to David Disseldorp
---
 common/report | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/report +1 -1
index 6cac71fc..bf05afa9 100644
@@ -152,7 +152,7 @@ _make_section_report()
 	for report in $REPORT_LIST; do
 		case "$report" in
 		"xunit")
-			_xunit_make_section_report "$test_status"
+			_xunit_make_section_report
 			;;
 		*)
 			_dump_err "format '$report' is not supported"
Signature · 1 line
2.35.3
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] report: drop unused _xunit_make_section_report parameter

Quoted 10 lines · David Disseldorp
---
 common/report | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/report +0 -0
index 6cac71fc..bf05afa9 100644

common/report _make_section_report() · line 155

Quoted 5 lines
common/report +1 -1
@@ -152,7 +152,7 @@ _make_section_report()
 	for report in $REPORT_LIST; do
 		case "$report" in
 		"xunit")
-			_xunit_make_section_report "$test_status"
+			_xunit_make_section_report

Hmm... I checked the history about _xunit_make_section_report, it was brought in by f9fde7db2fa5 ("report: Add xunit format report generator") in 2017. But it doesn't use any arguments at that time. So this "$test_status" is useless from beginning.

Quoted 6 lines
common/report +0 -0
 			;;
 		*)
 			_dump_err "format '$report' is not supported"
Signature · 1 line
2.35.3
#7 lore raw

PATCH 4/6 report: fix xunit tests count

In reply to David Disseldorp

The xunit "section report" provides a tests attribute, which according to https://llg.cubic.org/docs/junit/ represents:
tests="" <!-- The total number of tests in the suite, required. -->

The current value is generated as a sum of the $n_try and $n_notrun counters. This is incorrect as the $n_try counter already includes tests which are run but complete with _notrun.
One special case exists for $showme (check -n), where $n_try remains zero, so $n_notrun can be used as-is.

---
 check         | 13 ++++++-------
 common/report | 14 +++++++++-----
 2 files changed, 15 insertions(+), 12 deletions(-)
check +6 -7
index 43c072d2..a5183d3a 100755
@@ -430,13 +430,12 @@ _wrapup()
 	seq="check"
 	check="$RESULT_BASE/check"
 
-	if $showme; then
-		if $needwrap; then
-			if $do_report; then
-				_make_section_report
-			fi
-			needwrap=false
+	if $showme && $needwrap; then
+		if $do_report; then
+			# $showme = all selected tests are notrun (no tries)
+			_make_section_report "$n_notrun" "0" "$n_notrun"
 		fi
+		needwrap=false
 	elif $needwrap; then
 		if [ -f $check.time -a -f $tmp.time ]; then
 			cat $check.time $tmp.time  \
@@ -495,7 +494,7 @@ _wrapup()
 		fi
 		echo "" >>$tmp.summary
 		if $do_report; then
-			_make_section_report
+			_make_section_report "$n_try" "$n_bad" "$n_notrun"
 		fi
 		needwrap=false
 	fi
common/report +9 -5
index bf05afa9..84d9e0a7 100644
@@ -49,9 +49,11 @@ _xunit_add_property()
 _xunit_make_section_report()
 {
 	# xfstest:section ==> xunit:testsuite
+	local tests_count="$1"
+	local bad_count="$2"
+	local notrun_count="$3"
 	local sect_name=$section
 	local sect_time=`expr $sect_stop - $sect_start`
-	local n_total=`expr $n_try + $n_notrun`
 
 	if [ $sect_name == '-no-sections-' ]; then
 		sect_name='global'
@@ -62,9 +64,8 @@ _xunit_make_section_report()
 	if [ -z "$date_time" ]; then
 		date_time=$(date +"%F %T")
 	fi
-	local dtime=`echo $date_time| tr  " " 'T'`
-	local stats="failures=\"$n_bad\" skipped=\"$n_notrun\" tests=\"$n_total\" time=\"$sect_time\""
-	local hw_info="hostname=\"$HOST\" timestamp=\"$dtime\" "
+	local stats="failures=\"$bad_count\" skipped=\"$notrun_count\" tests=\"$tests_count\" time=\"$sect_time\""
+	local hw_info="hostname=\"$HOST\" timestamp=\"${date_time/ /T}\" "
 	echo "<testsuite name=\"xfstests\" $stats  $hw_info >" >> $REPORT_DIR/result.xml
 
 	# Properties
@@ -149,10 +150,13 @@ _xunit_make_testcase_report()
 #  Common report generator entry points
 _make_section_report()
 {
+	local tests_count="$1"
+	local bad_count="$2"
+	local notrun_count="$3"
 	for report in $REPORT_LIST; do
 		case "$report" in
 		"xunit")
-			_xunit_make_section_report
+			_xunit_make_section_report "$tests_count" "$bad_count" "$notrun_count"
 			;;
 		*)
 			_dump_err "format '$report' is not supported"
Signature · 1 line
2.35.3
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] report: fix xunit tests count

Quoted 9 lines · David Disseldorp

The xunit "section report" provides a tests attribute, which according to https://llg.cubic.org/docs/junit/ represents:
tests="" <!-- The total number of tests in the suite, required. -->

The current value is generated as a sum of the $n_try and $n_notrun counters. This is incorrect as the $n_try counter already includes tests which are run but complete with _notrun.
One special case exists for $showme (check -n), where $n_try remains zero, so $n_notrun can be used as-is.

Thanks for fixing it. So the n_total of xunit report is wrong. I think this change won't affect anyone's regular testing, but just notice that if someone use the xunit report, especially depends on the n_total number.

Quoted 86 lines
---
 check         | 13 ++++++-------
 common/report | 14 +++++++++-----
 2 files changed, 15 insertions(+), 12 deletions(-)
check +6 -7
index 43c072d2..a5183d3a 100755
@@ -430,13 +430,12 @@ _wrapup()
 	seq="check"
 	check="$RESULT_BASE/check"
 
-	if $showme; then
-		if $needwrap; then
-			if $do_report; then
-				_make_section_report
-			fi
-			needwrap=false
+	if $showme && $needwrap; then
+		if $do_report; then
+			# $showme = all selected tests are notrun (no tries)
+			_make_section_report "$n_notrun" "0" "$n_notrun"
 		fi
+		needwrap=false
 	elif $needwrap; then
 		if [ -f $check.time -a -f $tmp.time ]; then
 			cat $check.time $tmp.time  \
@@ -495,7 +494,7 @@ _wrapup()
 		fi
 		echo "" >>$tmp.summary
 		if $do_report; then
-			_make_section_report
+			_make_section_report "$n_try" "$n_bad" "$n_notrun"
 		fi
 		needwrap=false
 	fi
common/report +9 -5
index bf05afa9..84d9e0a7 100644
@@ -49,9 +49,11 @@ _xunit_add_property()
 _xunit_make_section_report()
 {
 	# xfstest:section ==> xunit:testsuite
+	local tests_count="$1"
+	local bad_count="$2"
+	local notrun_count="$3"
 	local sect_name=$section
 	local sect_time=`expr $sect_stop - $sect_start`
-	local n_total=`expr $n_try + $n_notrun`
 
 	if [ $sect_name == '-no-sections-' ]; then
 		sect_name='global'
@@ -62,9 +64,8 @@ _xunit_make_section_report()
 	if [ -z "$date_time" ]; then
 		date_time=$(date +"%F %T")
 	fi
-	local dtime=`echo $date_time| tr  " " 'T'`
-	local stats="failures=\"$n_bad\" skipped=\"$n_notrun\" tests=\"$n_total\" time=\"$sect_time\""
-	local hw_info="hostname=\"$HOST\" timestamp=\"$dtime\" "
+	local stats="failures=\"$bad_count\" skipped=\"$notrun_count\" tests=\"$tests_count\" time=\"$sect_time\""
+	local hw_info="hostname=\"$HOST\" timestamp=\"${date_time/ /T}\" "
 	echo "<testsuite name=\"xfstests\" $stats  $hw_info >" >> $REPORT_DIR/result.xml
 
 	# Properties
@@ -149,10 +150,13 @@ _xunit_make_testcase_report()
 #  Common report generator entry points
 _make_section_report()
 {
+	local tests_count="$1"
+	local bad_count="$2"
+	local notrun_count="$3"
 	for report in $REPORT_LIST; do
 		case "$report" in
 		"xunit")
-			_xunit_make_section_report
+			_xunit_make_section_report "$tests_count" "$bad_count" "$notrun_count"
 			;;
 		*)
 			_dump_err "format '$report' is not supported"
Signature · 1 line
2.35.3
#9 lore raw

PATCH 5/6 check: use arrays instead of separate n_ counters

In reply to David Disseldorp

The separate n_try, n_bad and n_notrun counters are unnecessary when the corresponding lists are switched to bash arrays.

---
 check | 72 ++++++++++++++++++++++++++---------------------------------
 1 file changed, 32 insertions(+), 40 deletions(-)
check +32 -40
index a5183d3a..8423d7a1 100755
@@ -8,13 +8,10 @@ tmp=/tmp/$$
 status=0
 needwrap=true
 needsum=true
-n_try=0
-try=""
-n_bad=0
+try=()
 sum_bad=0
-bad=""
-n_notrun=0
-notrun=""
+bad=()
+notrun=()
 interrupt=true
 diff="diff -u"
 showme=false
@@ -412,10 +409,9 @@ fi
 
 _wipe_counters()
 {
-	n_try="0"
-	n_bad="0"
-	n_notrun="0"
-	unset try notrun bad
+	try=()
+	notrun=()
+	bad=()
 }
 
 _global_log() {
@@ -433,7 +429,7 @@ _wrapup()
 	if $showme && $needwrap; then
 		if $do_report; then
 			# $showme = all selected tests are notrun (no tries)
-			_make_section_report "$n_notrun" "0" "$n_notrun"
+			_make_section_report "${#notrun[*]}" "0" "${#notrun[*]}"
 		fi
 		needwrap=false
 	elif $needwrap; then
@@ -458,12 +454,12 @@ _wrapup()
 
 		echo "SECTION       -- $section" >>$tmp.summary
 		echo "=========================" >>$tmp.summary
-		if [ ! -z "$n_try" -a $n_try != 0 ]; then
+		if ((${#try[*]} > 0)); then
 			if [ $brief_test_summary == "false" ]; then
-				echo "Ran:$try"
-				echo "Ran:$try" >>$tmp.summary
+				echo "Ran: ${try[*]}"
+				echo "Ran: ${try[*]}" >>$tmp.summary
 			fi
-			_global_log "Ran:$try"
+			_global_log "Ran: ${try[*]}"
 		fi
 
 		$interrupt && echo "Interrupted!" | tee -a $check.log
@@ -472,34 +468,34 @@ _wrapup()
 				${REPORT_DIR}/check.log
 		fi
 
-		if [ ! -z "$notrun" ]; then
+		if ((${#notrun[*]} > 0)); then
 			if [ $brief_test_summary == "false" ]; then
-				echo "Not run:$notrun"
-				echo "Not run:$notrun" >>$tmp.summary
+				echo "Not run: ${notrun[*]}"
+				echo "Not run: ${notrun[*]}" >>$tmp.summary
 			fi
-			_global_log "Not run:$notrun"
+			_global_log "Not run: ${notrun[*]}"
 		fi
 
-		if [ ! -z "$n_bad" -a $n_bad != 0 ]; then
-			echo "Failures:$bad"
-			echo "Failed $n_bad of $n_try tests"
-			_global_log "Failures:$bad"
-			_global_log "Failed $n_bad of $n_try tests"
-			echo "Failures:$bad" >>$tmp.summary
-			echo "Failed $n_bad of $n_try tests" >>$tmp.summary
+		if ((${#bad[*]} > 0)); then
+			echo "Failures: ${bad[*]}"
+			echo "Failed ${#bad[*]} of ${#try[*]} tests"
+			_global_log "Failures: ${bad[*]}"
+			_global_log "Failed ${#bad[*]} of ${#try[*]} tests"
+			echo "Failures: ${bad[*]}" >>$tmp.summary
+			echo "Failed ${#bad[*]} of ${#try[*]} tests" >>$tmp.summary
 		else
-			echo "Passed all $n_try tests"
-			_global_log "Passed all $n_try tests"
-			echo "Passed all $n_try tests" >>$tmp.summary
+			echo "Passed all ${#try[*]} tests"
+			_global_log "Passed all ${#try[*]} tests"
+			echo "Passed all ${#try[*]} tests" >>$tmp.summary
 		fi
 		echo "" >>$tmp.summary
 		if $do_report; then
-			_make_section_report "$n_try" "$n_bad" "$n_notrun"
+			_make_section_report "${#try[*]}" "${#bad[*]}" "${#notrun[*]}"
 		fi
 		needwrap=false
 	fi
 
-	sum_bad=`expr $sum_bad + $n_bad`
+	sum_bad=`expr $sum_bad + ${#bad[*]}`
 	_wipe_counters
 	rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
 	if ! $OPTIONS_HAVE_SECTIONS; then
@@ -735,8 +731,7 @@ function run_section()
 	for seq in $list ; do
 		# Run report for previous test!
 		if $err ; then
-			bad="$bad $seqnum"
-			n_bad=`expr $n_bad + 1`
+			bad+=("$seqnum")
 			tc_status="fail"
 		fi
 		if $do_report && ! $first_test ; then
@@ -794,7 +789,7 @@ function run_section()
 			start=0
 			stop=0
 			tc_status="list"
-			n_notrun=`expr $n_notrun + 1`
+			notrun+=("$seqnum")
 			continue
 		fi
 
@@ -815,8 +810,7 @@ function run_section()
 		fi
 
 		# record that we really tried to run this test.
-		try="$try $seqnum"
-		n_try=`expr $n_try + 1`
+		try+=("$seqnum")
 
 		awk 'BEGIN {lasttime="       "} \
 		     $1 == "'$seqnum'" {lasttime=" " $2 "s ... "; exit} \
@@ -861,8 +855,7 @@ function run_section()
 			$timestamp && echo " [not run]" && \
 				      echo -n "	$seqnum -- "
 			cat $seqres.notrun
-			notrun="$notrun $seqnum"
-			n_notrun=`expr $n_notrun + 1`
+			notrun+=("$seqnum")
 			tc_status="notrun"
 
 			# Unmount the scratch fs so that we can wipe the scratch
@@ -947,8 +940,7 @@ function run_section()
 
 	# make sure we record the status of the last test we ran.
 	if $err ; then
-		bad="$bad $seqnum"
-		n_bad=`expr $n_bad + 1`
+		bad+=("$seqnum")
 		tc_status="fail"
 	fi
 	if $do_report && ! $first_test ; then
Signature · 1 line
2.35.3
Reviewed-by on v1 5/6
#10 lore raw

Re: [PATCH 5/6] check: use arrays instead of separate n_ counters

Quoted 56 lines · David Disseldorp

The separate n_try, n_bad and n_notrun counters are unnecessary when the corresponding lists are switched to bash arrays.

---

 check | 72 ++++++++++++++++++++++++++---------------------------------
 1 file changed, 32 insertions(+), 40 deletions(-)
check +7 -11
index a5183d3a..8423d7a1 100755
@@ -8,13 +8,10 @@ tmp=/tmp/$$
 status=0
 needwrap=true
 needsum=true
-n_try=0
-try=""
-n_bad=0
+try=()
 sum_bad=0
-bad=""
-n_notrun=0
-notrun=""
+bad=()
+notrun=()
 interrupt=true
 diff="diff -u"
 showme=false
@@ -412,10 +409,9 @@ fi
 
 _wipe_counters()
 {
-	n_try="0"
-	n_bad="0"
-	n_notrun="0"
-	unset try notrun bad
+	try=()
+	notrun=()
+	bad=()
 }
 
 _global_log() {
@@ -433,7 +429,7 @@ _wrapup()
 	if $showme && $needwrap; then
 		if $do_report; then
 			# $showme = all selected tests are notrun (no tries)
-			_make_section_report "$n_notrun" "0" "$n_notrun"
+			_make_section_report "${#notrun[*]}" "0" "${#notrun[*]}"
 		fi
 		needwrap=false
 	elif $needwrap; then

check _wrapup() · line 459

Quoted 9 lines
check +2 -3
@@ -458,12 +454,12 @@ _wrapup()
 
 		echo "SECTION       -- $section" >>$tmp.summary
 		echo "=========================" >>$tmp.summary
-		if [ ! -z "$n_try" -a $n_try != 0 ]; then
+		if ((${#try[*]} > 0)); then
 			if [ $brief_test_summary == "false" ]; then
-				echo "Ran:$try"
-				echo "Ran:$try" >>$tmp.summary
+				echo "Ran: ${try[*]}"
                                          ^

No objection from me. And you even took into account the head space in original format :)

Quoted 110 lines
check +23 -26
+				echo "Ran: ${try[*]}" >>$tmp.summary
 			fi
-			_global_log "Ran:$try"
+			_global_log "Ran: ${try[*]}"
 		fi
 
 		$interrupt && echo "Interrupted!" | tee -a $check.log
@@ -472,34 +468,34 @@ _wrapup()
 				${REPORT_DIR}/check.log
 		fi
 
-		if [ ! -z "$notrun" ]; then
+		if ((${#notrun[*]} > 0)); then
 			if [ $brief_test_summary == "false" ]; then
-				echo "Not run:$notrun"
-				echo "Not run:$notrun" >>$tmp.summary
+				echo "Not run: ${notrun[*]}"
+				echo "Not run: ${notrun[*]}" >>$tmp.summary
 			fi
-			_global_log "Not run:$notrun"
+			_global_log "Not run: ${notrun[*]}"
 		fi
 
-		if [ ! -z "$n_bad" -a $n_bad != 0 ]; then
-			echo "Failures:$bad"
-			echo "Failed $n_bad of $n_try tests"
-			_global_log "Failures:$bad"
-			_global_log "Failed $n_bad of $n_try tests"
-			echo "Failures:$bad" >>$tmp.summary
-			echo "Failed $n_bad of $n_try tests" >>$tmp.summary
+		if ((${#bad[*]} > 0)); then
+			echo "Failures: ${bad[*]}"
+			echo "Failed ${#bad[*]} of ${#try[*]} tests"
+			_global_log "Failures: ${bad[*]}"
+			_global_log "Failed ${#bad[*]} of ${#try[*]} tests"
+			echo "Failures: ${bad[*]}" >>$tmp.summary
+			echo "Failed ${#bad[*]} of ${#try[*]} tests" >>$tmp.summary
 		else
-			echo "Passed all $n_try tests"
-			_global_log "Passed all $n_try tests"
-			echo "Passed all $n_try tests" >>$tmp.summary
+			echo "Passed all ${#try[*]} tests"
+			_global_log "Passed all ${#try[*]} tests"
+			echo "Passed all ${#try[*]} tests" >>$tmp.summary
 		fi
 		echo "" >>$tmp.summary
 		if $do_report; then
-			_make_section_report "$n_try" "$n_bad" "$n_notrun"
+			_make_section_report "${#try[*]}" "${#bad[*]}" "${#notrun[*]}"
 		fi
 		needwrap=false
 	fi
 
-	sum_bad=`expr $sum_bad + $n_bad`
+	sum_bad=`expr $sum_bad + ${#bad[*]}`
 	_wipe_counters
 	rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
 	if ! $OPTIONS_HAVE_SECTIONS; then
@@ -735,8 +731,7 @@ function run_section()
 	for seq in $list ; do
 		# Run report for previous test!
 		if $err ; then
-			bad="$bad $seqnum"
-			n_bad=`expr $n_bad + 1`
+			bad+=("$seqnum")
 			tc_status="fail"
 		fi
 		if $do_report && ! $first_test ; then
@@ -794,7 +789,7 @@ function run_section()
 			start=0
 			stop=0
 			tc_status="list"
-			n_notrun=`expr $n_notrun + 1`
+			notrun+=("$seqnum")
 			continue
 		fi
 
@@ -815,8 +810,7 @@ function run_section()
 		fi
 
 		# record that we really tried to run this test.
-		try="$try $seqnum"
-		n_try=`expr $n_try + 1`
+		try+=("$seqnum")
 
 		awk 'BEGIN {lasttime="       "} \
 		     $1 == "'$seqnum'" {lasttime=" " $2 "s ... "; exit} \
@@ -861,8 +855,7 @@ function run_section()
 			$timestamp && echo " [not run]" && \
 				      echo -n "	$seqnum -- "
 			cat $seqres.notrun
-			notrun="$notrun $seqnum"
-			n_notrun=`expr $n_notrun + 1`
+			notrun+=("$seqnum")
 			tc_status="notrun"
 
 			# Unmount the scratch fs so that we can wipe the scratch
@@ -947,8 +940,7 @@ function run_section()
 
 	# make sure we record the status of the last test we ran.
 	if $err ; then
-		bad="$bad $seqnum"
-		n_bad=`expr $n_bad + 1`
+		bad+=("$seqnum")
 		tc_status="fail"
 	fi
 	if $do_report && ! $first_test ; then
Signature · 1 line
2.35.3
#11 lore raw

PATCH 6/6 check: remove err and first_test variables

In reply to David Disseldorp

tc_status can be used for both of these.

---
 check | 41 ++++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)
check +16 -25
index 8423d7a1..2ea2920f 100755
@@ -725,23 +725,17 @@ function run_section()
 	seqres="$check"
 	_check_test_fs
 
-	err=false
-	first_test=true
+	local tc_status="init"
 	prev_seq=""
 	for seq in $list ; do
 		# Run report for previous test!
-		if $err ; then
+		if [ "$tc_status" == "fail" ]; then
 			bad+=("$seqnum")
-			tc_status="fail"
 		fi
-		if $do_report && ! $first_test ; then
-			if [ $tc_status != "expunge" ] ; then
-				_make_testcase_report "$prev_seq" "$tc_status"
-			fi
+		if $do_report && [[ ! $tc_status =~ ^(init|expunge)$ ]]; then
+			_make_testcase_report "$prev_seq" "$tc_status"
 		fi
-		first_test=false
 
-		err=false
 		prev_seq="$seq"
 		if [ ! -f $seq ]; then
 			# Try to get full name in case the user supplied only
@@ -845,7 +839,7 @@ function run_section()
 		if [ -f core ]; then
 			_dump_err_cont "[dumped core]"
 			mv core $RESULT_BASE/$seqnum.core
-			err=true
+			tc_status="fail"
 		fi
 
 		if [ -f $seqres.notrun ]; then
@@ -870,15 +864,15 @@ function run_section()
 			_scratch_unmount 2> /dev/null
 			rm -f ${RESULT_DIR}/require_test*
 			rm -f ${RESULT_DIR}/require_scratch*
-			err=true
+			tc_status="fail"
 		else
 			# The test apparently passed, so check for corruption
 			# and log messages that shouldn't be there.  Run the
 			# checking tools from a subshell with adjusted OOM
 			# score so that the OOM killer will target them instead
 			# of the check script itself.
-			(_adjust_oom_score 250; _check_filesystems) || err=true
-			_check_dmesg || err=true
+			(_adjust_oom_score 250; _check_filesystems) || tc_status="fail"
+			_check_dmesg || tc_status="fail"
 		fi
 
 		# Reload the module after each test to check for leaks or
@@ -892,7 +886,7 @@ function run_section()
 
 		# Scan for memory leaks after every test so that associating
 		# a leak to a particular test will be as accurate as possible.
-		_check_kmemleak || err=true
+		_check_kmemleak || tc_status="fail"
 
 		# test ends after all checks are done.
 		$timestamp && _timestamp
@@ -900,7 +894,7 @@ function run_section()
 
 		if [ ! -f $seq.out ]; then
 			_dump_err "no qualified output"
-			err=true
+			tc_status="fail"
 			continue;
 		fi
 
@@ -909,7 +903,7 @@ function run_section()
 		# version.
 		sed -i "s/\`/\'/g" $tmp.out
 		if diff $seq.out $tmp.out >/dev/null 2>&1 ; then
-			if ! $err ; then
+			if [ "$tc_status" != "fail" ]; then
 				echo "$seqnum `expr $stop - $start`" >>$tmp.time
 				echo -n " `expr $stop - $start`s"
 			fi
@@ -926,10 +920,10 @@ function run_section()
 				echo "(Run '$diff $here/$seq.out $seqres.out.bad'" \
 					" to see the entire diff)"
 			fi; } | sed -e 's/^\(.\)/    \1/'
-			err=true
+			tc_status="fail"
 		fi
 		if [ -f $seqres.hints ]; then
-			if $err; then
+			if [ "$tc_status" == "fail" ]; then
 				echo
 				cat $seqres.hints
 			else
@@ -939,14 +933,11 @@ function run_section()
 	done
 
 	# make sure we record the status of the last test we ran.
-	if $err ; then
+	if [ "$tc_status" == "fail" ]; then
 		bad+=("$seqnum")
-		tc_status="fail"
 	fi
-	if $do_report && ! $first_test ; then
-		if [ $tc_status != "expunge" ] ; then
-			_make_testcase_report "$prev_seq" "$tc_status"
-		fi
+	if $do_report && [[ ! $tc_status =~ ^(init|expunge)$ ]]; then
+		_make_testcase_report "$prev_seq" "$tc_status"
 	fi
 
 	sect_stop=`_wallclock`
Signature · 1 line
2.35.3
Reviewed-by on v1 6/6
#12 lore raw

Re: [PATCH 6/6] check: remove err and first_test variables

Quoted 4 lines · David Disseldorp

tc_status can be used for both of these.

---

Make sense.

Quoted 124 lines
 check | 41 ++++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)
check +16 -25
index 8423d7a1..2ea2920f 100755
@@ -725,23 +725,17 @@ function run_section()
 	seqres="$check"
 	_check_test_fs
 
-	err=false
-	first_test=true
+	local tc_status="init"
 	prev_seq=""
 	for seq in $list ; do
 		# Run report for previous test!
-		if $err ; then
+		if [ "$tc_status" == "fail" ]; then
 			bad+=("$seqnum")
-			tc_status="fail"
 		fi
-		if $do_report && ! $first_test ; then
-			if [ $tc_status != "expunge" ] ; then
-				_make_testcase_report "$prev_seq" "$tc_status"
-			fi
+		if $do_report && [[ ! $tc_status =~ ^(init|expunge)$ ]]; then
+			_make_testcase_report "$prev_seq" "$tc_status"
 		fi
-		first_test=false
 
-		err=false
 		prev_seq="$seq"
 		if [ ! -f $seq ]; then
 			# Try to get full name in case the user supplied only
@@ -845,7 +839,7 @@ function run_section()
 		if [ -f core ]; then
 			_dump_err_cont "[dumped core]"
 			mv core $RESULT_BASE/$seqnum.core
-			err=true
+			tc_status="fail"
 		fi
 
 		if [ -f $seqres.notrun ]; then
@@ -870,15 +864,15 @@ function run_section()
 			_scratch_unmount 2> /dev/null
 			rm -f ${RESULT_DIR}/require_test*
 			rm -f ${RESULT_DIR}/require_scratch*
-			err=true
+			tc_status="fail"
 		else
 			# The test apparently passed, so check for corruption
 			# and log messages that shouldn't be there.  Run the
 			# checking tools from a subshell with adjusted OOM
 			# score so that the OOM killer will target them instead
 			# of the check script itself.
-			(_adjust_oom_score 250; _check_filesystems) || err=true
-			_check_dmesg || err=true
+			(_adjust_oom_score 250; _check_filesystems) || tc_status="fail"
+			_check_dmesg || tc_status="fail"
 		fi
 
 		# Reload the module after each test to check for leaks or
@@ -892,7 +886,7 @@ function run_section()
 
 		# Scan for memory leaks after every test so that associating
 		# a leak to a particular test will be as accurate as possible.
-		_check_kmemleak || err=true
+		_check_kmemleak || tc_status="fail"
 
 		# test ends after all checks are done.
 		$timestamp && _timestamp
@@ -900,7 +894,7 @@ function run_section()
 
 		if [ ! -f $seq.out ]; then
 			_dump_err "no qualified output"
-			err=true
+			tc_status="fail"
 			continue;
 		fi
 
@@ -909,7 +903,7 @@ function run_section()
 		# version.
 		sed -i "s/\`/\'/g" $tmp.out
 		if diff $seq.out $tmp.out >/dev/null 2>&1 ; then
-			if ! $err ; then
+			if [ "$tc_status" != "fail" ]; then
 				echo "$seqnum `expr $stop - $start`" >>$tmp.time
 				echo -n " `expr $stop - $start`s"
 			fi
@@ -926,10 +920,10 @@ function run_section()
 				echo "(Run '$diff $here/$seq.out $seqres.out.bad'" \
 					" to see the entire diff)"
 			fi; } | sed -e 's/^\(.\)/    \1/'
-			err=true
+			tc_status="fail"
 		fi
 		if [ -f $seqres.hints ]; then
-			if $err; then
+			if [ "$tc_status" == "fail" ]; then
 				echo
 				cat $seqres.hints
 			else
@@ -939,14 +933,11 @@ function run_section()
 	done
 
 	# make sure we record the status of the last test we ran.
-	if $err ; then
+	if [ "$tc_status" == "fail" ]; then
 		bad+=("$seqnum")
-		tc_status="fail"
 	fi
-	if $do_report && ! $first_test ; then
-		if [ $tc_status != "expunge" ] ; then
-			_make_testcase_report "$prev_seq" "$tc_status"
-		fi
+	if $do_report && [[ ! $tc_status =~ ^(init|expunge)$ ]]; then
+		_make_testcase_report "$prev_seq" "$tc_status"
 	fi
 
 	sect_stop=`_wallclock`
Signature · 1 line
2.35.3
#13 lore raw
In reply to David Disseldorp
Quoted 5 lines · David Disseldorp

Hi,

This patchset contains a few cleanups which I came across while working on a larger set of changes for test-rerun-on-failure[1] support. One minor fix for the tests count in the xunit report is included.

Thanks for this pre-fix patchset, I'd like to ack this change at first, if no more objections. And give your another patchset [1] a little more reviewing time. Welcome review points on that [1].

Thanks,
Zorro

[1]
[RFC PATCH 0/2] add option to rerun failed tests

Quoted 12 lines

Diffstat:

 check         | 148 +++++++++++++++++++++-----------------------------
 common/report |  14 +++--
 2 files changed, 71 insertions(+), 91 deletions(-)

1. test-rerun-on-failure proposal by Ted Ts'o:

   https://lwn.net/Articles/897061/

Cheers, David