All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH kvm-unit-tests v2 05/12] lib/report: allow test skipping
Date: Thu, 17 Dec 2015 13:37:02 -0600	[thread overview]
Message-ID: <20151217193702.GF14168@hawk.localdomain> (raw)
In-Reply-To: <20151217193023.GE14168@hawk.localdomain>

On Thu, Dec 17, 2015 at 01:30:23PM -0600, Andrew Jones wrote:
> On Thu, Dec 17, 2015 at 06:53:36PM +0100, Radim Krčmář wrote:
> > We can now explicitly mark a unit-test as skipped.
> > If all unit-tests were skipped, the whole test is reported as skipped as
> > well.  This also includes the case where no tests were run, but still
> > ended with report_summary().
> > 
> > When the whole test is skipped, ./run_tests.sh prints yellow "SKIP"
> > instead of green "PASS".
> > 
> > Return value of 77 is used to please Autotools.  I also renamed few
> > things in reporting code and chose to refactor a logic while at it.
> > 
> > Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
> > ---
> >  v2:
> >  - turned skip into yellow SKIP [Drew]
> >  - wrapped line at 80 characters [Drew]
> >  - added static to va_report
> >  
> >  lib/libcflat.h   |  1 +
> >  lib/report.c     | 44 ++++++++++++++++++++++++++++++--------------
> >  scripts/run.bash | 12 +++++++-----
> >  3 files changed, 38 insertions(+), 19 deletions(-)
> > 
> > diff --git a/lib/libcflat.h b/lib/libcflat.h
> > index 9747ccdbc9f1..070818354ee1 100644
> > --- a/lib/libcflat.h
> > +++ b/lib/libcflat.h
> > @@ -61,6 +61,7 @@ void report_prefix_push(const char *prefix);
> >  void report_prefix_pop(void);
> >  void report(const char *msg_fmt, bool pass, ...);
> >  void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...);
> > +void report_skip(const char *msg_fmt, ...);
> >  int report_summary(void);
> >  
> >  #define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
> > diff --git a/lib/report.c b/lib/report.c
> > index 35e664108a92..a47f2e00b529 100644
> > --- a/lib/report.c
> > +++ b/lib/report.c
> > @@ -13,7 +13,7 @@
> >  #include "libcflat.h"
> >  #include "asm/spinlock.h"
> >  
> > -static unsigned int tests, failures, xfailures;
> > +static unsigned int tests, failures, xfailures, skipped;
> >  static char prefixes[256];
> >  static struct spinlock lock;
> >  
> > @@ -43,25 +43,28 @@ void report_prefix_pop(void)
> >  	spin_unlock(&lock);
> >  }
> >  
> > -void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
> > +static void va_report(const char *msg_fmt, bool pass, bool xfail, bool skip,
> > +		va_list va)
> 
> Making this static disallows unit test writers to create their own
> variable arg report() wrapper functions. Perhaps to determine whether
> or not a skip is in order, e.g.
> 
>  xyz_report(msg, pass, ...)
>  {
>     va_list va;
>     va_start(va, pass);
>     if (xyz)
>        va_report(msg, pass, false, false, va);
>     else
>        va_report(msg, false, false, true, va);
>     va_end(va);
>  }

Hmm, while I still think we should avoid using static, to allow new wrappers,
the wrapper I wrote here as an example wouldn't be necessary if report_skip's
inputs were instead 

void report_skip(const char *msg_fmt, bool pass, bool skip, ...)

Why not do that?

> 
> >  {
> > -	char *pass = xfail ? "XPASS" : "PASS";
> > -	char *fail = xfail ? "XFAIL" : "FAIL";
> >  	char buf[2000];
> > +	char *prefix = skip ? "SKIP"
> > +	                    : xfail ? (pass ? "XPASS" : "XFAIL")
> > +	                            : (pass ? "PASS"  : "FAIL");
> >  
> >  	spin_lock(&lock);
> >  
> >  	tests++;
> > -	printf("%s: ", cond ? pass : fail);
> > +	printf("%s: ", prefix);
> >  	puts(prefixes);
> >  	vsnprintf(buf, sizeof(buf), msg_fmt, va);
> >  	puts(buf);
> >  	puts("\n");
> > -	if (xfail && cond)
> > -		failures++;
> > -	else if (xfail)
> > +
> > +	if (skip)
> > +		skipped++;
> > +	else if (xfail && !pass)
> >  		xfailures++;
> > -	else if (!cond)
> > +	else if (xfail || !pass)
> >  		failures++;
> >  
> >  	spin_unlock(&lock);
> > @@ -71,7 +74,7 @@ void report(const char *msg_fmt, bool pass, ...)
> >  {
> >  	va_list va;
> >  	va_start(va, pass);
> > -	va_report_xfail(msg_fmt, false, pass, va);
> > +	va_report(msg_fmt, pass, false, false, va);
> >  	va_end(va);
> >  }
> >  
> > @@ -79,7 +82,15 @@ void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...)
> >  {
> >  	va_list va;
> >  	va_start(va, pass);
> > -	va_report_xfail(msg_fmt, xfail, pass, va);
> > +	va_report(msg_fmt, pass, xfail, false, va);
> > +	va_end(va);
> > +}
> > +
> > +void report_skip(const char *msg_fmt, ...)
> > +{
> > +	va_list va;
> > +	va_start(va, msg_fmt);
> > +	va_report(msg_fmt, false, false, true, va);
> >  	va_end(va);
> >  }
> >  
> > @@ -89,9 +100,14 @@ int report_summary(void)
> >  
> >  	printf("\nSUMMARY: %d tests, %d unexpected failures", tests, failures);
> >  	if (xfailures)
> > -		printf(", %d expected failures\n", xfailures);
> > -	else
> > -		printf("\n");
> > +		printf(", %d expected failures", xfailures);
> > +	if (skipped)
> > +		printf(", %d skipped", skipped);
> > +	printf("\n");
> > +
> > +	if (tests == skipped)
> > +		return 77; /* blame AUTOTOOLS */
> > +
> >  	return failures > 0 ? 1 : 0;
> >  
> >  	spin_unlock(&lock);
> > diff --git a/scripts/run.bash b/scripts/run.bash
> > index 243586c6d2fc..b92611c29fbb 100644
> > --- a/scripts/run.bash
> > +++ b/scripts/run.bash
> > @@ -46,11 +46,13 @@ function run()
> >      # Unit-tests' return value is shifted by one.
> >      ret=$(($? >> 1))
> >  
> > -    if [ $ret -eq 0 ]; then
> > -        echo -e "\e[32mPASS\e[0m $1"
> > -    else
> > -        echo -e "\e[31mFAIL\e[0m $1"
> > -    fi
> > +    case $ret in
> > +    0)  echo -ne "\e[32mPASS\e[0m" ;;
> > +    77) echo -ne "\e[33mSKIP\e[0m" ;;
> > +    *)  echo -ne "\e[31mFAIL\e[0m"
> > +    esac
> > +
> > +    echo " $1"
> 
> While touching this, please change this to $testname, and anything
> else in run() that still uses $N instead of its local var name.
> 
> >  
> >      return $ret
> >  }
> > -- 
> > 2.6.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2015-12-17 19:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 17:53 [PATCH kvm-unit-tests v2 00/12] Improve the output of test runners Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 01/12] run_tests: move run() to scripts/ Radim Krčmář
2015-12-17 18:45   ` Andrew Jones
2015-12-18 10:42     ` Radim Krčmář
2015-12-18 18:52       ` Andrew Jones
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 02/12] run_tests: prepare for changes in scripts/mkstandalone Radim Krčmář
2015-12-17 18:53   ` Andrew Jones
2015-12-18 10:49     ` Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 03/12] scripts/mkstandalone: use common run function Radim Krčmář
2015-12-17 19:09   ` Andrew Jones
2015-12-18 11:02     ` Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 04/12] scripts/mkstandalone: improve exit paths Radim Krčmář
2015-12-17 19:15   ` Andrew Jones
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 05/12] lib/report: allow test skipping Radim Krčmář
2015-12-17 19:30   ` Andrew Jones
2015-12-17 19:37     ` Andrew Jones [this message]
2015-12-18 11:18       ` Radim Krčmář
2015-12-18 18:55         ` Andrew Jones
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 06/12] x86/*: report skipped tests Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 07/12] x86/pmu: expect failure with nmi_watchdog Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 08/12] scripts/run: generalize check Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 09/12] x86/hyperv_synic: check for support before testing Radim Krčmář
2015-12-17 19:42   ` Andrew Jones
2015-12-18 12:13     ` Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 10/12] run_tests: print summary Radim Krčmář
2015-12-17 19:55   ` Andrew Jones
2015-12-18 12:24     ` Radim Krčmář
2015-12-17 20:06   ` Andrew Jones
2015-12-18 12:25     ` Radim Krčmář
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 11/12] wrappers: consolidate skip output Radim Krčmář
2015-12-17 19:59   ` Andrew Jones
2015-12-17 17:53 ` [PATCH kvm-unit-tests v2 12/12] run_tests: suppress stderr Radim Krčmář
2015-12-17 20:01   ` Andrew Jones
2015-12-17 20:04 ` [PATCH kvm-unit-tests v2 00/12] Improve the output of test runners Andrew Jones
2015-12-18 12:38   ` Radim Krčmář
2015-12-18 18:57     ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151217193702.GF14168@hawk.localdomain \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.