Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: pbonzini@redhat.com, jan.kiszka@siemens.com
Cc: kvm@vger.kernel.org
Subject: [PATCH][RFC] kvm-unit-tests: report: add report_skip
Date: Tue, 17 Jun 2014 14:21:14 +0200	[thread overview]
Message-ID: <1403007674-18481-1-git-send-email-drjones@redhat.com> (raw)

Add report_skip(), which is report(), but with another condition
allowing it to output PASS/FAIL/SKIP, rather than only PASS/FAIL.
This allows report output to stay more consistent between
systems/configurations that may or may not support all tests.
Currently I only have a downstream use case for this, but maybe
report output sequences of the following form

report(msg1, cond1)                           -> FAIL
report(msg2, cond1 && cond2)                  -> FAIL
report(msg3, cond1 && cond3)                  -> FAIL

would look better as

report(msg1, cond1)                           -> FAIL
report_skip(msg2, !cond1, cond1 && cond2)     -> SKIP
report_skip(msg3, !cond1, cond1 && cond3)     -> SKIP

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/libcflat.h |  1 +
 lib/report.c   | 34 ++++++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/lib/libcflat.h b/lib/libcflat.h
index f734fdee2df18..01f2769ad1773 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -61,5 +61,6 @@ extern long atol(const char *ptr);
 #define NULL ((void *)0UL)
 
 void report(const char *msg_fmt, bool pass, ...);
+void report_skip(const char *msg_fmt, bool can_skip, bool pass, ...);
 int report_summary(void);
 #endif
diff --git a/lib/report.c b/lib/report.c
index ff562a13c541e..77db22b6c2d8d 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -5,32 +5,50 @@
  *
  * Authors:
  *  Jan Kiszka <jan.kiszka@siemens.com>
+ *  Andrew Jones <drjones@redhat.com>
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 
 #include "libcflat.h"
 
-static unsigned int tests, failures;
+static unsigned int tests, failures, skipped;
 
-void report(const char *msg_fmt, bool pass, ...)
+void va_report_skip(const char *msg_fmt, bool can_skip, bool pass, va_list va)
 {
+	char *fail = can_skip ? "SKIP" : "FAIL";
 	char buf[2000];
-	va_list va;
 
 	tests++;
-	printf("%s: ", pass ? "PASS" : "FAIL");
-	va_start(va, pass);
+	printf("%s: ", pass ? "PASS" : fail);
 	vsnprintf(buf, sizeof(buf), msg_fmt, va);
-	va_end(va);
 	puts(buf);
 	puts("\n");
-	if (!pass)
+	if (!pass && can_skip)
+		skipped++;
+	else if (!pass)
 		failures++;
 }
 
+void report(const char *msg_fmt, bool pass, ...)
+{
+	va_list va;
+	va_start(va, pass);
+	va_report_skip(msg_fmt, false, pass, va);
+	va_end(va);
+}
+
+void report_skip(const char *msg_fmt, bool can_skip, bool pass, ...)
+{
+	va_list va;
+	va_start(va, pass);
+	va_report_skip(msg_fmt, can_skip, pass, va);
+	va_end(va);
+}
+
 int report_summary(void)
 {
-	printf("\nSUMMARY: %d tests, %d failures\n", tests, failures);
+	printf("\nSUMMARY: %d tests, %d failures, %d skipped\n",
+		tests, failures, skipped);
 	return failures > 0 ? 1 : 0;
 }
-- 
1.9.3


             reply	other threads:[~2014-06-17 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-17 12:21 Andrew Jones [this message]
2014-06-17 12:46 ` [PATCH][RFC] kvm-unit-tests: report: add report_skip Paolo Bonzini
2014-06-17 13:53   ` 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=1403007674-18481-1-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox