[kvm-unit-tests PATCH v5 06/18] lib: add vprintf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



va_report_xfail has the pattern

 char buf[]
 vsnprintf(buf, ...)
 puts(buf)

Before adding another one, replace it with vprintf.

Suggested-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/libcflat.h |  1 +
 lib/printf.c   | 14 +++++++++++++-
 lib/report.c   |  4 +---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/libcflat.h b/lib/libcflat.h
index 9747ccdbc9f1d..f7a5728c6759a 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -55,6 +55,7 @@ extern void abort(void);
 extern int printf(const char *fmt, ...);
 extern int snprintf(char *buf, int size, const char *fmt, ...);
 extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
+extern int vprintf(const char *fmt, va_list va);
 extern long atol(const char *ptr);
 
 void report_prefix_push(const char *prefix);
diff --git a/lib/printf.c b/lib/printf.c
index 5d83605afe829..2aec59aa6d6d4 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -1,5 +1,7 @@
 #include "libcflat.h"
 
+#define BUFSZ 2000
+
 typedef struct pstream {
     char *buffer;
     int remain;
@@ -235,10 +237,20 @@ int snprintf(char *buf, int size, const char *fmt, ...)
     return r;
 }
 
+int vprintf(const char *fmt, va_list va)
+{
+    char buf[BUFSZ];
+    int r;
+
+    r = vsnprintf(buf, sizeof(buf), fmt, va);
+    puts(buf);
+    return r;
+}
+
 int printf(const char *fmt, ...)
 {
     va_list va;
-    char buf[2000];
+    char buf[BUFSZ];
     int r;
 
     va_start(va, fmt);
diff --git a/lib/report.c b/lib/report.c
index 35e664108a921..c29e835b9c751 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -47,15 +47,13 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
 {
 	char *pass = xfail ? "XPASS" : "PASS";
 	char *fail = xfail ? "XFAIL" : "FAIL";
-	char buf[2000];
 
 	spin_lock(&lock);
 
 	tests++;
 	printf("%s: ", cond ? pass : fail);
 	puts(prefixes);
-	vsnprintf(buf, sizeof(buf), msg_fmt, va);
-	puts(buf);
+	vprintf(msg_fmt, va);
 	puts("\n");
 	if (xfail && cond)
 		failures++;
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux