diff mbox series

[1/2] test-lib: show missing prereq summary

Message ID 20211115160750.1208940-2-fs@gigacodes.de (mailing list archive)
State Superseded
Headers show
Series test-lib: improve missing prereq handling | expand

Commit Message

Fabian Stelzer Nov. 15, 2021, 4:07 p.m. UTC
When running the full test suite many tests can be skipped because of
missing prerequisites. It not easy right now to get an overview of which
ones are missing.
When switching to a new machine or environment some libraries and tools
might be missing or maybe a dependency broke completely. In this case
the tests would indicate nothing since all dependant tests are simply
skipped. This could hide broken behaviour or missing features in the
build. Therefore this patch summarizes the missing prereqs at the end of
the test run making it easier to spot such cases.

 - Add failed prereqs to the test results.
 - Aggregate and then show them with the totals.

Signed-off-by: Fabian Stelzer <fs@gigacodes.de>
---
 t/aggregate-results.sh | 17 +++++++++++++++++
 t/test-lib.sh          | 11 +++++++++++
 2 files changed, 28 insertions(+)

Comments

Ævar Arnfjörð Bjarmason Nov. 15, 2021, 5:44 p.m. UTC | #1
On Mon, Nov 15 2021, Fabian Stelzer wrote:

> When running the full test suite many tests can be skipped because of
> missing prerequisites. It not easy right now to get an overview of which
> ones are missing.
> When switching to a new machine or environment some libraries and tools
> might be missing or maybe a dependency broke completely. In this case
> the tests would indicate nothing since all dependant tests are simply
> skipped. This could hide broken behaviour or missing features in the
> build. Therefore this patch summarizes the missing prereqs at the end of
> the test run making it easier to spot such cases.
>
>  - Add failed prereqs to the test results.
>  - Aggregate and then show them with the totals.
>
> Signed-off-by: Fabian Stelzer <fs@gigacodes.de>
> ---
>  t/aggregate-results.sh | 17 +++++++++++++++++
>  t/test-lib.sh          | 11 +++++++++++
>  2 files changed, 28 insertions(+)
>
> diff --git a/t/aggregate-results.sh b/t/aggregate-results.sh
> index 7913e206ed..87c16fcee1 100755
> --- a/t/aggregate-results.sh
> +++ b/t/aggregate-results.sh
> @@ -6,6 +6,7 @@ success=0
>  failed=0
>  broken=0
>  total=0
> +missing_prereq=
>  
>  while read file
>  do
> @@ -30,10 +31,26 @@ do
>  			broken=$(($broken + $value)) ;;
>  		total)
>  			total=$(($total + $value)) ;;
> +		missing_prereq)
> +			missing_prereq="$missing_prereq,$value" ;;
>  		esac
>  	done <"$file"
>  done
>  
> +if test -n "$missing_prereq"
> +then
> +	unique_missing_prereq=$(
> +		echo $missing_prereq |
> +		tr -s "," "\n" |
> +		grep -v '^$' |
> +		sort -u |
> +		paste -s -d ',')

What is paste? Some out-of-tree debugging utility?

I think you might find a better way to do this shown in my
"ab/generate-command-list" topic, currently in seen. It removed most of
the same sort of tr|grep|sort etc. chain in generate-cmdlist.sh.
Junio C Hamano Nov. 15, 2021, 5:53 p.m. UTC | #2
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>> +if test -n "$missing_prereq"
>> +then
>> +	unique_missing_prereq=$(
>> +		echo $missing_prereq |
>> +		tr -s "," "\n" |
>> +		grep -v '^$' |
>> +		sort -u |
>> +		paste -s -d ',')
>
> What is paste? Some out-of-tree debugging utility?

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/paste.html

Don't feel bad for not knowing it.  I usually do not use cut or paste
myself and I had to look it up the other day while reviewing the RFC
phase of this series.

I am not sure '\n' is a good idea from portability perspective.  I
thought I wrote '\012' in the illustration in my review?
Fabian Stelzer Nov. 15, 2021, 7:56 p.m. UTC | #3
On 15.11.2021 09:53, Junio C Hamano wrote:
>Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>>> +if test -n "$missing_prereq"
>>> +then
>>> +	unique_missing_prereq=$(
>>> +		echo $missing_prereq |
>>> +		tr -s "," "\n" |
>>> +		grep -v '^$' |
>>> +		sort -u |
>>> +		paste -s -d ',')
>>
>> What is paste? Some out-of-tree debugging utility?
>
>https://pubs.opengroup.org/onlinepubs/9699919799/utilities/paste.html
>
>Don't feel bad for not knowing it.  I usually do not use cut or paste
>myself and I had to look it up the other day while reviewing the RFC
>phase of this series.
>
>I am not sure '\n' is a good idea from portability perspective.  I
>thought I wrote '\012' in the illustration in my review?

Yes, i was wondering why you did that. When i played around with your
variant i used \n since it's what i commonly use and find more readable.
And i'm by far no expert on partability. What platforms would have an
issue with \n ?

I'll take a look at Ævars generate-cmdlist code and will use \012 in a
reroll.

Thanks
Junio C Hamano Nov. 15, 2021, 10:10 p.m. UTC | #4
Fabian Stelzer <fs@gigacodes.de> writes:

>>I am not sure '\n' is a good idea from portability perspective.  I
>>thought I wrote '\012' in the illustration in my review?
>
> Yes, i was wondering why you did that. When i played around with your
> variant i used \n since it's what i commonly use and find more readable.
> And i'm by far no expert on partability. What platforms would have an
> issue with \n ?

I think I misremembered.  b3b753b1 (Fit to Plan 9's ANSI/POSIX
compatibility layer, 2020-09-10) does talk about a system whose
"tr" does not fully emulate POSIX and wants an octal, but that
is not a platform we target for to begin with.

$ git grep '^[      ]*tr .*\\012['\''"]'
$ git grep '^[      ]*tr .*\\n['\''"]'

show the same number of hits, even back in v2.0.0.  You have to go
back to v1.6.0 (which I consider is the oldest and still usable
release of significance) to see the source tree without any hit for
the latter.  The first introduction of tr "\n" (which I consider is
a mistake---if we write octal, we do not have to worry about anybody
not supporting it) seems to be dea4562b (rerere forget path: forget
recorded resolution, 2009-12-25) made by me X-<.
Fabian Stelzer Nov. 16, 2021, 2:19 p.m. UTC | #5
On 15.11.2021 18:44, Ævar Arnfjörð Bjarmason wrote:
>
>On Mon, Nov 15 2021, Fabian Stelzer wrote:
>
>> +if test -n "$missing_prereq"
>> +then
>> +	unique_missing_prereq=$(
>> +		echo $missing_prereq |
>> +		tr -s "," "\n" |
>> +		grep -v '^$' |
>> +		sort -u |
>> +		paste -s -d ',')
>
>What is paste? Some out-of-tree debugging utility?
>
>I think you might find a better way to do this shown in my
>"ab/generate-command-list" topic, currently in seen. It removed most of
>the same sort of tr|grep|sort etc. chain in generate-cmdlist.sh.

I've looked at the generate-command-list code and TBH i still think this
is a better solution. If I read your change correctly you've removed the
sort and unique completely since it was not necessary for the use-case.
In this case i think it is. Since we call tr with `-s` the grep -v might
not be strictly necessary though. Also in this case these commands are
only called once at the end of the test run and not in any kind of loop
like in the cmdlist code so i think this variant is much easier to read
and debug with a negligible performance impact.

I tried writing a sh only variant and this is what i came up with. Not
sure if this could be much more simplified. It looses the sort though.

input="PCRE,JGIT2,JGIT2,,PCRE,JGIT2,PCRE,PCRE2,!PCRE,!WINDOWS,GPG,GPGSSH,PCRE,!GPG,GPG,JGIT2"

unique=
save_IFS=$IFS
IFS=,
for prereq in $input
do
	case "$prereq" in
	'')
		# Skip empty entries
		;;
	*)
		case ",$unique," in
		*,$prereq,*)
			# Skip over duplicates
			;;
		*)
			if test -z "$unique"
			then
				unique="$prereq"
			else
				unique="$unique,$prereq"
			fi
			;;
		esac
	esac
done
IFS=$save_IFS
echo $unique
Junio C Hamano Nov. 17, 2021, 8:19 a.m. UTC | #6
Fabian Stelzer <fs@gigacodes.de> writes:

> On 15.11.2021 18:44, Ævar Arnfjörð Bjarmason wrote:
>>
>>On Mon, Nov 15 2021, Fabian Stelzer wrote:
>>
>>> +if test -n "$missing_prereq"
>>> +then
>>> +	unique_missing_prereq=$(
>>> +		echo $missing_prereq |
>>> +		tr -s "," "\n" |
>>> +		grep -v '^$' |
>>> +		sort -u |
>>> +		paste -s -d ',')
>>
>>What is paste? Some out-of-tree debugging utility?
>>
>>I think you might find a better way to do this shown in my
>>"ab/generate-command-list" topic, currently in seen. It removed most of
>>the same sort of tr|grep|sort etc. chain in generate-cmdlist.sh.
>
> I've looked at the generate-command-list code and TBH i still think this
> is a better solution. If I read your change correctly you've removed the
> sort and unique completely since it was not necessary for the use-case.
> In this case i think it is. Since we call tr with `-s` the grep -v might
> not be strictly necessary though. Also in this case these commands are
> only called once at the end of the test run and not in any kind of loop
> like in the cmdlist code so i think this variant is much easier to read
> and debug with a negligible performance impact.

I tend to agree with you.  The snippet we see above is quite
straight-forward not over-engineered.

> I tried writing a sh only variant and this is what i came up with. Not
> sure if this could be much more simplified. It looses the sort though.

Fun, but I'd rather not go there, unless this is a performance
critical bit, which it is not.

Thanks.


>
> input="PCRE,JGIT2,JGIT2,,PCRE,JGIT2,PCRE,PCRE2,!PCRE,!WINDOWS,GPG,GPGSSH,PCRE,!GPG,GPG,JGIT2"
>
> unique=
> save_IFS=$IFS
> IFS=,
> for prereq in $input
> do
> 	case "$prereq" in
> 	'')
> 		# Skip empty entries
> 		;;
> 	*)
> 		case ",$unique," in
> 		*,$prereq,*)
> 			# Skip over duplicates
> 			;;
> 		*)
> 			if test -z "$unique"
> 			then
> 				unique="$prereq"
> 			else
> 				unique="$unique,$prereq"
> 			fi
> 			;;
> 		esac
> 	esac
> done
> IFS=$save_IFS
> echo $unique
Fabian Stelzer Nov. 17, 2021, 9:05 a.m. UTC | #7
On 17.11.2021 00:19, Junio C Hamano wrote:
>Fabian Stelzer <fs@gigacodes.de> writes:
>
>> On 15.11.2021 18:44, Ævar Arnfjörð Bjarmason wrote:
>>>
>>>On Mon, Nov 15 2021, Fabian Stelzer wrote:
>>>
>>>> +if test -n "$missing_prereq"
>>>> +then
>>>> +	unique_missing_prereq=$(
>>>> +		echo $missing_prereq |
>>>> +		tr -s "," "\n" |
>>>> +		grep -v '^$' |
>>>> +		sort -u |
>>>> +		paste -s -d ',')
>>>
>>>What is paste? Some out-of-tree debugging utility?
>>>
>>>I think you might find a better way to do this shown in my
>>>"ab/generate-command-list" topic, currently in seen. It removed most of
>>>the same sort of tr|grep|sort etc. chain in generate-cmdlist.sh.
>>
>> I've looked at the generate-command-list code and TBH i still think this
>> is a better solution. If I read your change correctly you've removed the
>> sort and unique completely since it was not necessary for the use-case.
>> In this case i think it is. Since we call tr with `-s` the grep -v might
>> not be strictly necessary though. Also in this case these commands are
>> only called once at the end of the test run and not in any kind of loop
>> like in the cmdlist code so i think this variant is much easier to read
>> and debug with a negligible performance impact.
>
>I tend to agree with you.  The snippet we see above is quite
>straight-forward not over-engineered.
>
>> I tried writing a sh only variant and this is what i came up with. Not
>> sure if this could be much more simplified. It looses the sort though.
>
>Fun, but I'd rather not go there, unless this is a performance
>critical bit, which it is not.
>
>Thanks.
>

Ok, i've sent an update fixing the commit msg typo and with \012 instead
of \n. Even if might not be an issue it won't hurt.

Thanks
diff mbox series

Patch

diff --git a/t/aggregate-results.sh b/t/aggregate-results.sh
index 7913e206ed..87c16fcee1 100755
--- a/t/aggregate-results.sh
+++ b/t/aggregate-results.sh
@@ -6,6 +6,7 @@  success=0
 failed=0
 broken=0
 total=0
+missing_prereq=
 
 while read file
 do
@@ -30,10 +31,26 @@  do
 			broken=$(($broken + $value)) ;;
 		total)
 			total=$(($total + $value)) ;;
+		missing_prereq)
+			missing_prereq="$missing_prereq,$value" ;;
 		esac
 	done <"$file"
 done
 
+if test -n "$missing_prereq"
+then
+	unique_missing_prereq=$(
+		echo $missing_prereq |
+		tr -s "," "\n" |
+		grep -v '^$' |
+		sort -u |
+		paste -s -d ',')
+	if test -n $unique_missing_prereq
+	then
+		printf "\nmissing prereq: $unique_missing_prereq\n\n"
+	fi
+fi
+
 if test -n "$failed_tests"
 then
 	printf "\nfailed test(s):$failed_tests\n\n"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 2679a7596a..f61da562f6 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -669,6 +669,8 @@  test_fixed=0
 test_broken=0
 test_success=0
 
+test_missing_prereq=
+
 test_external_has_tap=0
 
 die () {
@@ -1069,6 +1071,14 @@  test_skip () {
 			of_prereq=" of $test_prereq"
 		fi
 		skipped_reason="missing $missing_prereq${of_prereq}"
+
+		# Keep a list of all the missing prereq for result aggregation
+		if test -z "$missing_prereq"
+		then
+			test_missing_prereq=$missing_prereq
+		else
+			test_missing_prereq="$test_missing_prereq,$missing_prereq"
+		fi
 	fi
 
 	case "$to_skip" in
@@ -1175,6 +1185,7 @@  test_done () {
 		fixed $test_fixed
 		broken $test_broken
 		failed $test_failure
+		missing_prereq $test_missing_prereq
 
 		EOF
 	fi