coccinelle: Remove unnecessary variables for function return value
[qemu/ar7.git] / tests / test-logging.c
blob5ef5bb887d9f9495b535f5cdbacc4fdc56bceb1f
1 /*
2 * logging unit-tests
4 * Copyright (C) 2016 Linaro Ltd.
6 * Author: Alex Bennée <alex.bennee@linaro.org>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
27 #include "qemu/osdep.h"
29 #include "qemu-common.h"
30 #include "include/qemu/log.h"
32 static void test_parse_range(void)
34 qemu_set_dfilter_ranges("0x1000+0x100");
36 g_assert_false(qemu_log_in_addr_range(0xfff));
37 g_assert(qemu_log_in_addr_range(0x1000));
38 g_assert(qemu_log_in_addr_range(0x1001));
39 g_assert(qemu_log_in_addr_range(0x10ff));
40 g_assert_false(qemu_log_in_addr_range(0x1100));
42 qemu_set_dfilter_ranges("0x1000-0x100");
44 g_assert_false(qemu_log_in_addr_range(0x1001));
45 g_assert(qemu_log_in_addr_range(0x1000));
46 g_assert(qemu_log_in_addr_range(0x0f01));
47 g_assert_false(qemu_log_in_addr_range(0x0f00));
49 qemu_set_dfilter_ranges("0x1000..0x1100");
51 g_assert_false(qemu_log_in_addr_range(0xfff));
52 g_assert(qemu_log_in_addr_range(0x1000));
53 g_assert(qemu_log_in_addr_range(0x1100));
54 g_assert_false(qemu_log_in_addr_range(0x1101));
56 qemu_set_dfilter_ranges("0x1000..0x1000");
58 g_assert_false(qemu_log_in_addr_range(0xfff));
59 g_assert(qemu_log_in_addr_range(0x1000));
60 g_assert_false(qemu_log_in_addr_range(0x1001));
62 qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100");
63 g_assert(qemu_log_in_addr_range(0x1050));
64 g_assert(qemu_log_in_addr_range(0x2050));
65 g_assert(qemu_log_in_addr_range(0x3050));
68 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
69 static void test_parse_invalid_range_subprocess(void)
71 qemu_set_dfilter_ranges("0x1000+onehundred");
73 static void test_parse_invalid_range(void)
75 g_test_trap_subprocess("/logging/parse_invalid_range/subprocess", 0, 0);
76 g_test_trap_assert_failed();
77 g_test_trap_assert_stdout("");
78 g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+onehundred\n");
80 static void test_parse_zero_range_subprocess(void)
82 qemu_set_dfilter_ranges("0x1000+0");
84 static void test_parse_zero_range(void)
86 g_test_trap_subprocess("/logging/parse_zero_range/subprocess", 0, 0);
87 g_test_trap_assert_failed();
88 g_test_trap_assert_stdout("");
89 g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n");
92 /* As the only real failure from a bad log filename path spec is
93 * reporting to the user we have to use the g_test_trap_subprocess
94 * mechanism and check no errors reported on stderr.
96 static void test_parse_path_subprocess(void)
98 /* All these should work without issue */
99 qemu_set_log_filename("/tmp/qemu.log");
100 qemu_set_log_filename("/tmp/qemu-%d.log");
101 qemu_set_log_filename("/tmp/qemu.log.%d");
103 static void test_parse_path(void)
105 g_test_trap_subprocess ("/logging/parse_path/subprocess", 0, 0);
106 g_test_trap_assert_passed();
107 g_test_trap_assert_stdout("");
108 g_test_trap_assert_stderr("");
110 static void test_parse_invalid_path_subprocess(void)
112 qemu_set_log_filename("/tmp/qemu-%d%d.log");
114 static void test_parse_invalid_path(void)
116 g_test_trap_subprocess ("/logging/parse_invalid_path/subprocess", 0, 0);
117 g_test_trap_assert_passed();
118 g_test_trap_assert_stdout("");
119 g_test_trap_assert_stderr("Bad logfile format: /tmp/qemu-%d%d.log\n");
121 #endif /* CONFIG_HAS_GLIB_SUBPROCESS_TESTS */
123 int main(int argc, char **argv)
125 g_test_init(&argc, &argv, NULL);
127 g_test_add_func("/logging/parse_range", test_parse_range);
128 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
129 g_test_add_func("/logging/parse_invalid_range/subprocess", test_parse_invalid_range_subprocess);
130 g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range);
131 g_test_add_func("/logging/parse_zero_range/subprocess", test_parse_zero_range_subprocess);
132 g_test_add_func("/logging/parse_zero_range", test_parse_zero_range);
133 g_test_add_func("/logging/parse_path", test_parse_path);
134 g_test_add_func("/logging/parse_path/subprocess", test_parse_path_subprocess);
135 g_test_add_func("/logging/parse_invalid_path", test_parse_invalid_path);
136 g_test_add_func("/logging/parse_invalid_path/subprocess", test_parse_invalid_path_subprocess);
137 #endif
139 return g_test_run();