diff options
author | Markus Armbruster <armbru@redhat.com> | 2016-06-15 19:27:16 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-06-20 16:39:08 +0200 |
commit | daa76aa416b1e18ab1fac650ff53d966d8f21f68 (patch) | |
tree | a906532b58132857a76f8979b04dd6869b5e69d5 /tests | |
parent | bd6fee9f1263dc5ba487c7ac57d33a727af63c00 (diff) |
log: Fix qemu_set_log_filename() error handling
When qemu_set_log_filename() detects an invalid file name, it reports
an error, closes the log file (if any), and starts logging to stderr
(unless daemonized or nothing is being logged).
This is wrong. Asking for an invalid log file on the command line
should be fatal. Asking for one in the monitor should fail without
messing up an existing logfile.
Fix by converting qemu_set_log_filename() to Error. Pass it
&error_fatal, except for hmp_logfile report errors.
This also permits testing without a subprocess, so do that.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1466011636-6112-4-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-logging.c | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/tests/test-logging.c b/tests/test-logging.c index e043adc8f8..440e75f5db 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -75,49 +75,24 @@ static void test_parse_range(void) error_free_or_abort(&err); } -#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS -/* As the only real failure from a bad log filename path spec is - * reporting to the user we have to use the g_test_trap_subprocess - * mechanism and check no errors reported on stderr. - */ -static void test_parse_path_subprocess(void) -{ - /* All these should work without issue */ - qemu_set_log_filename("/tmp/qemu.log"); - qemu_set_log_filename("/tmp/qemu-%d.log"); - qemu_set_log_filename("/tmp/qemu.log.%d"); -} static void test_parse_path(void) { - g_test_trap_subprocess ("/logging/parse_path/subprocess", 0, 0); - g_test_trap_assert_passed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr(""); -} -static void test_parse_invalid_path_subprocess(void) -{ - qemu_set_log_filename("/tmp/qemu-%d%d.log"); -} -static void test_parse_invalid_path(void) -{ - g_test_trap_subprocess ("/logging/parse_invalid_path/subprocess", 0, 0); - g_test_trap_assert_passed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr("Bad logfile format: /tmp/qemu-%d%d.log\n"); + Error *err = NULL; + + qemu_set_log_filename("/tmp/qemu.log", &error_abort); + qemu_set_log_filename("/tmp/qemu-%d.log", &error_abort); + qemu_set_log_filename("/tmp/qemu.log.%d", &error_abort); + + qemu_set_log_filename("/tmp/qemu-%d%d.log", &err); + error_free_or_abort(&err); } -#endif /* CONFIG_HAS_GLIB_SUBPROCESS_TESTS */ int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/logging/parse_range", test_parse_range); -#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS g_test_add_func("/logging/parse_path", test_parse_path); - g_test_add_func("/logging/parse_path/subprocess", test_parse_path_subprocess); - g_test_add_func("/logging/parse_invalid_path", test_parse_invalid_path); - g_test_add_func("/logging/parse_invalid_path/subprocess", test_parse_invalid_path_subprocess); -#endif return g_test_run(); } |