On Thu, Sep 25, 2025 at 10:44:31AM +0100, Daniel P. Berrangé wrote:
The current unit tests rely on monitor.o not being linked, such that the monitor stubs get linked instead. Since error_vprintf is in monitor.o this allows a stub error_vprintf impl to be used that calls g_test_message.
This takes a different approach, with error_vprintf moving back to error-report.c such that it is always linked into the tests. The monitor_vprintf() stub is then changed to use g_test_message if QTEST_SLENT_ERROS is set, otherwise it will
Double typo; should be QTEST_SILENT_ERRORS...
return -1 and trigger error_vprintf to call vfprintf.
The end result is functionally equivalent for the purposes of the unit tests.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> ---
+++ b/stubs/monitor-core.c @@ -18,5 +18,17 @@ void qapi_event_emit(QAPIEvent event, QDict *qdict)
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { - abort(); + /* + * Pretend 'g_test_message' is our monitor console to + * stop the caller sending messages to stderr + */ + if (g_test_initialized() && !g_test_subprocess() && + getenv("QTEST_SILENT_ERRORS")) {
...to match the code. With that fixed, Reviewed-by: Eric Blake <eblake@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org