On 4/23/20 5:22 PM, Peter Krempa wrote:
Until now we've tried to report errors from the test monitor code by passing them back as failures from the qemu we simulate. This doesn't work well in cases when the monitor logic does not detect failures or has fallback code. Additionally there isn't much use for continuing the test execution after first failure as in most cases the test data will be misaligned and all other calls will fail as well. To make the errors more obvious this patch moves away from reporting them via the simulated monitor to reporting them to stderr and exit()ing afterwards. While this might be less convenient when developing tests it actually makes failures in the test suite really obvious and doesn't require any opt-in from the tests themselves. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- build-aux/syntax-check.mk | 1 + tests/qemumonitortestutils.c | 121 +++++++++++++++++------------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index cbcdf445aa..bf8832a2a5 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -900,6 +900,7 @@ sc_flake8: sc_prohibit_exit_in_tests: @prohibit='\<exit *\(' \ in_vc_files='tests/.*\.c$$' \ + exclude='exempt from syntax-check' \ halt='use return, not exit(), in tests' \ $(_sc_search_regexp) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index dc753dd417..bc3b2f5f92 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -153,18 +153,6 @@ qemuMonitorTestAddErrorResponseInternal(qemuMonitorTestPtr test, } -static int -qemuMonitorTestAddUnexpectedErrorResponse(qemuMonitorTestPtr test, - const char *command) -{ - g_autofree char *msg = NULL; - - msg = g_strdup_printf("unexpected command: '%s'", command); - - return qemuMonitorTestAddErrorResponseInternal(test, msg); -} - - int qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTestPtr test, const char *expectedcommand, @@ -201,6 +189,33 @@ qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, const char *errmsg, ... } +static void G_GNUC_NORETURN G_GNUC_PRINTF(1, 2) +qemuMonitorTestError(const char *errmsg, + ...) +{ + va_list msgargs; + + va_start(msgargs, errmsg); + + fflush(stderr); + g_fprintf(stderr, "\n"); + g_vfprintf(stderr, errmsg, msgargs); + g_fprintf(stderr, "\n"); + fflush(stderr); + exit(EXIT_FAILURE); /* exempt from syntax-check */
Are these fflush() calls needed? I mean, stderr is unbuffered, isn't it? Michal