summaryrefslogtreecommitdiff
path: root/tests/test-logging.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2016-06-15 19:27:15 +0200
committerMarkus Armbruster <armbru@redhat.com>2016-06-20 16:38:31 +0200
commitbd6fee9f1263dc5ba487c7ac57d33a727af63c00 (patch)
treed4bfe62cf9142dd4868e66fd04399198da54966a /tests/test-logging.c
parent2ec62faea274aabb2feaad2b8f85961161b5e1e4 (diff)
downloadqemu-bd6fee9f1263dc5ba487c7ac57d33a727af63c00.tar.gz
log: Fix qemu_set_dfilter_ranges() error reporting
g_error() is not an acceptable way to report errors to the user: $ qemu-system-x86_64 -dfilter 1000+0 ** (process:17187): ERROR **: Failed to parse range in: 1000+0 Trace/breakpoint trap (core dumped) g_assert() isn't, either: $ qemu-system-x86_64 -dfilter 1000x+64 ** ERROR:/work/armbru/qemu/util/log.c:180:qemu_set_dfilter_ranges: assertion failed: (e == range_op) Aborted (core dumped) Convert qemu_set_dfilter_ranges() to Error. Rework its deeply nested control flow. Touch up the error messages. Call it with &error_fatal. This also permits testing without a subprocess, so do that. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1466011636-6112-3-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests/test-logging.c')
-rw-r--r--tests/test-logging.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/tests/test-logging.c b/tests/test-logging.c
index 5ef5bb887d..e043adc8f8 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -27,11 +27,14 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
-#include "include/qemu/log.h"
+#include "qapi/error.h"
+#include "qemu/log.h"
static void test_parse_range(void)
{
- qemu_set_dfilter_ranges("0x1000+0x100");
+ Error *err = NULL;
+
+ qemu_set_dfilter_ranges("0x1000+0x100", &error_abort);
g_assert_false(qemu_log_in_addr_range(0xfff));
g_assert(qemu_log_in_addr_range(0x1000));
@@ -39,56 +42,40 @@ static void test_parse_range(void)
g_assert(qemu_log_in_addr_range(0x10ff));
g_assert_false(qemu_log_in_addr_range(0x1100));
- qemu_set_dfilter_ranges("0x1000-0x100");
+ qemu_set_dfilter_ranges("0x1000-0x100", &error_abort);
g_assert_false(qemu_log_in_addr_range(0x1001));
g_assert(qemu_log_in_addr_range(0x1000));
g_assert(qemu_log_in_addr_range(0x0f01));
g_assert_false(qemu_log_in_addr_range(0x0f00));
- qemu_set_dfilter_ranges("0x1000..0x1100");
+ qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort);
g_assert_false(qemu_log_in_addr_range(0xfff));
g_assert(qemu_log_in_addr_range(0x1000));
g_assert(qemu_log_in_addr_range(0x1100));
g_assert_false(qemu_log_in_addr_range(0x1101));
- qemu_set_dfilter_ranges("0x1000..0x1000");
+ qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort);
g_assert_false(qemu_log_in_addr_range(0xfff));
g_assert(qemu_log_in_addr_range(0x1000));
g_assert_false(qemu_log_in_addr_range(0x1001));
- qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100");
+ qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100",
+ &error_abort);
g_assert(qemu_log_in_addr_range(0x1050));
g_assert(qemu_log_in_addr_range(0x2050));
g_assert(qemu_log_in_addr_range(0x3050));
-}
-#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
-static void test_parse_invalid_range_subprocess(void)
-{
- qemu_set_dfilter_ranges("0x1000+onehundred");
-}
-static void test_parse_invalid_range(void)
-{
- g_test_trap_subprocess("/logging/parse_invalid_range/subprocess", 0, 0);
- g_test_trap_assert_failed();
- g_test_trap_assert_stdout("");
- g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+onehundred\n");
-}
-static void test_parse_zero_range_subprocess(void)
-{
- qemu_set_dfilter_ranges("0x1000+0");
-}
-static void test_parse_zero_range(void)
-{
- g_test_trap_subprocess("/logging/parse_zero_range/subprocess", 0, 0);
- g_test_trap_assert_failed();
- g_test_trap_assert_stdout("");
- g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n");
+ qemu_set_dfilter_ranges("0x1000+onehundred", &err);
+ error_free_or_abort(&err);
+
+ qemu_set_dfilter_ranges("0x1000+0", &err);
+ 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.
@@ -126,10 +113,6 @@ int main(int argc, char **argv)
g_test_add_func("/logging/parse_range", test_parse_range);
#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
- g_test_add_func("/logging/parse_invalid_range/subprocess", test_parse_invalid_range_subprocess);
- g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range);
- g_test_add_func("/logging/parse_zero_range/subprocess", test_parse_zero_range_subprocess);
- g_test_add_func("/logging/parse_zero_range", test_parse_zero_range);
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);