diff mbox series

[5/5] tests: Log stderr output (if any) on test failure

Message ID 20181108041311.182694-6-amitay@ozlabs.org
State Superseded
Headers show
Series Test framework improvements | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Amitay Isaacs Nov. 8, 2018, 4:13 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 tests/driver.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Alistair Popple Nov. 9, 2018, 2:51 a.m. UTC | #1
On Thursday, 8 November 2018 3:13:11 PM AEDT Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
> ---
>  tests/driver.sh | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/driver.sh b/tests/driver.sh
> index 16d6b71..9a68305 100644
> --- a/tests/driver.sh
> +++ b/tests/driver.sh
> @@ -370,9 +370,9 @@ test_run ()
>  		output_mismatch=1
>  	fi
> 
> +	output_stderr_raw=$(cat "$stderr_file")
> +	output_stderr=$(cat "$stderr_file" | result_filter)
>  	if [ $test_stderr -eq 1 ] ; then
> -		output_stderr_raw=$(cat "$stderr_file")
> -		output_stderr=$(cat "$stderr_file" | result_filter)
>  		if [ "$output_stderr" != "$required_output_stderr" ] ; then
>  			test_log "expected stderr:"
>  			test_log "$required_output_stderr"
> @@ -384,6 +384,11 @@ test_run ()
>  			fi
>  			output_mismatch=1
>  		fi
> +	else
> +		if [ -n "$output_stderr_raw" ] ; then
> +			test_log "output stderr:"
> +			test_log "$output_stderr_raw"
> +		fi

Would it make sense to consolidate the above logic by removing the stderr 
logging from the failure branch to make it bit easier to follow? It seems we 
could just do:

			test_log "output stderr:"
			test_log "$output_stderr"

And then just output stderr_raw in case of mistmatch regardless of if we're 
testing stderr. In fact doesn't this always log stderr except if we're testing 
stderr in which case it only gets logged if that's the cause of the mismatch? 
Or am I missing something here?

- Alistair

>  	fi
> 
>  	rm -f "$stderr_file"
Amitay Isaacs Nov. 9, 2018, 4:39 a.m. UTC | #2
On Fri, 2018-11-09 at 13:51 +1100, Alistair Popple wrote:
> On Thursday, 8 November 2018 3:13:11 PM AEDT Amitay Isaacs wrote:
> > Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
> > ---
> >  tests/driver.sh | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tests/driver.sh b/tests/driver.sh
> > index 16d6b71..9a68305 100644
> > --- a/tests/driver.sh
> > +++ b/tests/driver.sh
> > @@ -370,9 +370,9 @@ test_run ()
> >  		output_mismatch=1
> >  	fi
> > 
> > +	output_stderr_raw=$(cat "$stderr_file")
> > +	output_stderr=$(cat "$stderr_file" | result_filter)
> >  	if [ $test_stderr -eq 1 ] ; then
> > -		output_stderr_raw=$(cat "$stderr_file")
> > -		output_stderr=$(cat "$stderr_file" | result_filter)
> >  		if [ "$output_stderr" != "$required_output_stderr" ] ;
> > then
> >  			test_log "expected stderr:"
> >  			test_log "$required_output_stderr"
> > @@ -384,6 +384,11 @@ test_run ()
> >  			fi
> >  			output_mismatch=1
> >  		fi
> > +	else
> > +		if [ -n "$output_stderr_raw" ] ; then
> > +			test_log "output stderr:"
> > +			test_log "$output_stderr_raw"
> > +		fi
> 
> Would it make sense to consolidate the above logic by removing the
> stderr 
> logging from the failure branch to make it bit easier to follow? It
> seems we 
> could just do:
> 
> 			test_log "output stderr:"
> 			test_log "$output_stderr"
> 
> And then just output stderr_raw in case of mistmatch regardless of if
> we're 
> testing stderr. In fact doesn't this always log stderr except if
> we're testing 
> stderr in which case it only gets logged if that's the cause of the
> mismatch? 
> Or am I missing something here?

Well the motivation to log as much information as possible if the test
fails.   If the test passes, then there is no reason to log extra
information.

From that point of view,

- if the filtered output on stderr does not match
  * log $otuput_stderr

- if the filtered output is not the same as output
  * log $output_stderr_raw

If the test is not trying to match any output on stderr, then the
output on stderr is currently ignored.

This patch was added because a test was failing, but I could not figure
out why.  The error message was on stderr and was ignored.  That's why
I decided to log the $output_stderr_raw.

I can make it stricter by only logging when the test has failed
(mismatched rc or mismatched output_stdout).

Amitay.
Alistair Popple Nov. 9, 2018, 5:17 a.m. UTC | #3
> If the test is not trying to match any output on stderr, then the
> output on stderr is currently ignored.

Fair point actually. Guess we don't really need progress bars in our log files 
:-)
 
> This patch was added because a test was failing, but I could not figure
> out why.  The error message was on stderr and was ignored.  That's why
> I decided to log the $output_stderr_raw.
> 
> I can make it stricter by only logging when the test has failed
> (mismatched rc or mismatched output_stdout).
> 
> Amitay.
diff mbox series

Patch

diff --git a/tests/driver.sh b/tests/driver.sh
index 16d6b71..9a68305 100644
--- a/tests/driver.sh
+++ b/tests/driver.sh
@@ -370,9 +370,9 @@  test_run ()
 		output_mismatch=1
 	fi
 
+	output_stderr_raw=$(cat "$stderr_file")
+	output_stderr=$(cat "$stderr_file" | result_filter)
 	if [ $test_stderr -eq 1 ] ; then
-		output_stderr_raw=$(cat "$stderr_file")
-		output_stderr=$(cat "$stderr_file" | result_filter)
 		if [ "$output_stderr" != "$required_output_stderr" ] ; then
 			test_log "expected stderr:"
 			test_log "$required_output_stderr"
@@ -384,6 +384,11 @@  test_run ()
 			fi
 			output_mismatch=1
 		fi
+	else
+		if [ -n "$output_stderr_raw" ] ; then
+			test_log "output stderr:"
+			test_log "$output_stderr_raw"
+		fi
 	fi
 
 	rm -f "$stderr_file"