Skip to contentSkip to conversation

tests: silence error_report in tests

PATCH In review Paolo Bonzini 3 participants 7 messages Oct 24, 2016 – Oct 26, 2016

lore
Share & tools
lore
#0 lore raw

cover tests: silence error_report in tests

This is my (counter)proposal for silencing test-vmstate.

Thanks,

Paolo

Paolo Bonzini (2):
qemu-error: remove dependency of stubs on monitor
tests: send error_report to test log

 include/glib-compat.h       | 13 +++++++++++++
 include/qemu/error-report.h |  1 +
 monitor.c                   | 21 +++++++++++++++++++++
 stubs/Makefile.objs         |  2 +-
 stubs/error-printf.c        | 19 +++++++++++++++++++
 stubs/mon-printf.c          | 11 -----------
 util/qemu-error.c           | 26 +++-----------------------
 7 files changed, 58 insertions(+), 35 deletions(-)
 create mode 100644 stubs/error-printf.c
 delete mode 100644 stubs/mon-printf.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 qemu-error: remove dependency of stubs on monitor

Leave the implementation of error_vprintf and error_vprintf_unless_qmp (the latter now trivially wrapped by error_printf_unless_qmp) to libqemustub.a and monitor.c. This has two advantages: it lets us remove the monitor_printf and monitor_vprintf stubs, and it lets tests provide a different implementation of the functions that uses g_test_message.

---
 include/qemu/error-report.h |  1 +
 monitor.c                   | 21 +++++++++++++++++++++
 stubs/Makefile.objs         |  2 +-
 stubs/error-printf.c        | 13 +++++++++++++
 stubs/mon-printf.c          | 11 -----------
 util/qemu-error.c           | 26 +++-----------------------
 6 files changed, 39 insertions(+), 35 deletions(-)
 create mode 100644 stubs/error-printf.c
 delete mode 100644 stubs/mon-printf.c
include/qemu/error-report.h +1 -0
index 499ec8b..3001865 100644
@@ -32,6 +32,7 @@ void loc_set_file(const char *fname, int lno);
 
 void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_set_progname(const char *argv0);
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
monitor.c +21 -0
index b73a999..a02c883 100644
@@ -3957,6 +3957,27 @@ static void monitor_readline_flush(void *opaque)
     monitor_flush(opaque);
 }
 
+/*
+ * Print to current monitor if we have one, else to stderr.
+ * TODO should return int, so callers can calculate width, but that
+ * requires surgery to monitor_vprintf().  Left for another day.
+ */
+void error_vprintf(const char *fmt, va_list ap)
+{
+    if (cur_mon && !monitor_cur_is_qmp()) {
+        monitor_vprintf(cur_mon, fmt, ap);
+    } else {
+        vfprintf(stderr, fmt, ap);
+    }
+}
+
+void error_vprintf_unless_qmp(const char *fmt, va_list ap)
+{
+    if (cur_mon && !monitor_cur_is_qmp()) {
+        monitor_vprintf(cur_mon, fmt, ap);
+    }
+}
+
 static void __attribute__((constructor)) monitor_lock_init(void)
 {
     qemu_mutex_init(&monitor_lock);
stubs/Makefile.objs +1 -1
index c5850e8..044bb47 100644
@@ -9,6 +9,7 @@ stub-obj-y += clock-warp.o
 stub-obj-y += cpu-get-clock.o
 stub-obj-y += cpu-get-icount.o
 stub-obj-y += dump.o
+stub-obj-y += error-printf.o
 stub-obj-y += fdset-add-fd.o
 stub-obj-y += fdset-find-fd.o
 stub-obj-y += fdset-get-fd.o
@@ -22,7 +23,6 @@ stub-obj-y += is-daemonized.o
 stub-obj-y += machine-init-done.o
 stub-obj-y += migr-blocker.o
 stub-obj-y += mon-is-qmp.o
-stub-obj-y += mon-printf.o
 stub-obj-y += monitor-init.o
 stub-obj-y += notify-event.o
 stub-obj-y += qtest.o
stubs/error-printf.c new file +13 -0
new file mode 100644
index 0000000..56379e6
@@ -0,0 +1,13 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/error-report.h"
+
+void error_vprintf(const char *fmt, va_list ap)
+{
+    vfprintf(stderr, fmt, ap);
+}
+
+void error_vprintf_unless_qmp(const char *fmt, va_list ap)
+{
+    error_vprintf(fmt, ap);
+}
stubs/mon-printf.c deleted +0 -11
deleted file mode 100644
index e7c1e0c..0000000
@@ -1,11 +0,0 @@
-#include "qemu/osdep.h"
-#include "qemu-common.h"
-#include "monitor/monitor.h"
-
-void monitor_printf(Monitor *mon, const char *fmt, ...)
-{
-}
-
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
-{
-}
util/qemu-error.c +3 -23
index 1ef3566..b331f8f 100644
@@ -14,24 +14,6 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 
-/*
- * Print to current monitor if we have one, else to stderr.
- * TODO should return int, so callers can calculate width, but that
- * requires surgery to monitor_vprintf().  Left for another day.
- */
-void error_vprintf(const char *fmt, va_list ap)
-{
-    if (cur_mon && !monitor_cur_is_qmp()) {
-        monitor_vprintf(cur_mon, fmt, ap);
-    } else {
-        vfprintf(stderr, fmt, ap);
-    }
-}
-
-/*
- * Print to current monitor if we have one, else to stderr.
- * TODO just like error_vprintf()
- */
 void error_printf(const char *fmt, ...)
 {
     va_list ap;
@@ -45,11 +27,9 @@ void error_printf_unless_qmp(const char *fmt, ...)
 {
     va_list ap;
 
-    if (!monitor_cur_is_qmp()) {
-        va_start(ap, fmt);
-        error_vprintf(fmt, ap);
-        va_end(ap);
-    }
+    va_start(ap, fmt);
+    error_vprintf_unless_qmp(fmt, ap);
+    va_end(ap);
 }
 
 static Location std_loc = {
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 tests: send error_report to test log

In reply to Paolo Bonzini

Implement error_vprintf to send the output of error_report to the test log. This silences test-vmstate.

---
 include/glib-compat.h | 13 +++++++++++++
 stubs/error-printf.c  |  8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
include/glib-compat.h +13 -0
index 8093163..9f86dc8 100644
@@ -304,4 +304,17 @@ static inline void g_slist_free_full(GSList *list, GDestroyNotify free_func)
 }
 #endif
 
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+/* Always fail.  This will not include error_report output in the test log,
+ * sending it instead to stderr.
+ */
+#define g_test_initialized() (0)
+#endif
+#if !GLIB_CHECK_VERSION(2, 38, 0)
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+#error schizophrenic detection of glib subprocess testing
+#endif
+#define g_test_subprocess() (0)
+#endif
+
 #endif
stubs/error-printf.c +7 -1
index 56379e6..ac6b92a 100644
@@ -4,7 +4,13 @@
 
 void error_vprintf(const char *fmt, va_list ap)
 {
-    vfprintf(stderr, fmt, ap);
+    if (g_test_initialized() && !g_test_subprocess()) {
+        char *msg = g_strdup_vprintf(fmt, ap);
+        g_test_message("%s", msg);
+        g_free(msg);
+    } else {
+        vfprintf(stderr, fmt, ap);
+    }
 }
 
 void error_vprintf_unless_qmp(const char *fmt, va_list ap)
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] tests: send error_report to test log

Quoted 4 lines · Paolo Bonzini

Implement error_vprintf to send the output of error_report to the test log. This silences test-vmstate.

[..]

stubs/error-printf.c line 7

Quoted 4 lines

void error_vprintf(const char *fmt, va_list ap)
{

stubs/error-printf.c +1 -1
-    vfprintf(stderr, fmt, ap);
+    if (g_test_initialized() && !g_test_subprocess()) {

I like the approach. What I do not like is:
* we still generate noise only less visible
* it's indiscriminate (silences all error reports of this type)
* can't be incorporated into the test logic

IMHO these are no major problems, and what I'm going to suggest might be over-engineering, but I will ask nevertheless.

Have you considered a thread local function pointer to defaulting to something sane (eg. to this test log stuff or to a wrapped vprintf)?

This would invalidate all the points above, and make the compat macros unnecessary -- which have bitten me on my ancient RHEL (because glib is too old). I have tried out the idea, so if you want I can send you a patch on top of this.

Halil

Quoted 10 lines
stubs/error-printf.c +6 -0
+        char *msg = g_strdup_vprintf(fmt, ap);
+        g_test_message("%s", msg);
+        g_free(msg);
+    } else {
+        vfprintf(stderr, fmt, ap);
+    }
 }
 
 void error_vprintf_unless_qmp(const char *fmt, va_list ap)
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] tests: send error_report to test log

Quoted 7 lines · Halil Pasic
Quoted 4 lines · Paolo Bonzini

Implement error_vprintf to send the output of error_report to the test log. This silences test-vmstate.

Quoted 8 lines

[..]

stubs/error-printf.c line 7

Quoted 4 lines

void error_vprintf(const char *fmt, va_list ap)
{

stubs/error-printf.c +1 -1
-    vfprintf(stderr, fmt, ap);
+    if (g_test_initialized() && !g_test_subprocess()) {

I like the approach. What I do not like is:
* we still generate noise only less visible

It's not noise if it ends up exactly in the right place (the test logs). :)

Paolo

Quoted 28 lines

* it's indiscriminate (silences all error reports of this type)
* can't be incorporated into the test logic

IMHO these are no major problems, and what I'm going to suggest might be over-engineering, but I will ask nevertheless.

Have you considered a thread local function pointer to defaulting to something sane (eg. to this test log stuff or to a wrapped vprintf)?

This would invalidate all the points above, and make the compat macros unnecessary -- which have bitten me on my ancient RHEL (because glib is too old). I have tried out the idea, so if you want I can send you a patch on top of this.

Halil

Quoted 10 lines
stubs/error-printf.c +6 -0
+        char *msg = g_strdup_vprintf(fmt, ap);
+        g_test_message("%s", msg);
+        g_free(msg);
+    } else {
+        vfprintf(stderr, fmt, ap);
+    }
 }
 
 void error_vprintf_unless_qmp(const char *fmt, va_list ap)
Reviewed-by
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] tests: send error_report to test log

Quoted 15 lines · Paolo Bonzini
Quoted 13 lines · Halil Pasic
Quoted 13 lines · Paolo Bonzini
Quoted 4 lines
Quoted 4 lines

Implement error_vprintf to send the output of error_report to the test log. This silences test-vmstate.

[..]

Quoted 4 lines
Quoted 4 lines

void error_vprintf(const char *fmt, va_list ap)
{

stubs/error-printf.c +1 -1
-    vfprintf(stderr, fmt, ap);
+    if (g_test_initialized() && !g_test_subprocess()) {
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

I like the approach. What I do not like is:
* we still generate noise only less visible

It's not noise if it ends up exactly in the right place (the test logs). :)

Paolo

I assumed (for some strange reason) that the messages (submitted via g_test_message) will not only appear in the xml report but also in the html report. I was wrong. And while I still believe that the messages in question (the vmstate test) do not add any value to the xml report and on the other hand that situations could emerge where having the error reported more prominently would be more convenient, I am very much fine with this solution.

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] tests: send error_report to test log

In reply to Paolo Bonzini
Quoted 4 lines · * Paolo Bonzini ([email protected]) wrote:

Implement error_vprintf to send the output of error_report to the test log. This silences test-vmstate.

I think I'm OK with that, as long as people are happy with them still getting stuff on stderr on older glib's.

The advantage over mine is that there's no per-test change.

Dave

Quoted 50 lines
---
 include/glib-compat.h | 13 +++++++++++++
 stubs/error-printf.c  |  8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
include/glib-compat.h +13 -0
index 8093163..9f86dc8 100644
@@ -304,4 +304,17 @@ static inline void g_slist_free_full(GSList *list, GDestroyNotify free_func)
 }
 #endif
 
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+/* Always fail.  This will not include error_report output in the test log,
+ * sending it instead to stderr.
+ */
+#define g_test_initialized() (0)
+#endif
+#if !GLIB_CHECK_VERSION(2, 38, 0)
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+#error schizophrenic detection of glib subprocess testing
+#endif
+#define g_test_subprocess() (0)
+#endif
+
 #endif
stubs/error-printf.c +7 -1
index 56379e6..ac6b92a 100644
@@ -4,7 +4,13 @@
 
 void error_vprintf(const char *fmt, va_list ap)
 {
-    vfprintf(stderr, fmt, ap);
+    if (g_test_initialized() && !g_test_subprocess()) {
+        char *msg = g_strdup_vprintf(fmt, ap);
+        g_test_message("%s", msg);
+        g_free(msg);
+    } else {
+        vfprintf(stderr, fmt, ap);
+    }
 }
 
 void error_vprintf_unless_qmp(const char *fmt, va_list ap)
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK