]> git.proxmox.com Git - mirror_qemu.git/blob - tests/test-logging.c
tests: Remove unnecessary glib.h includes
[mirror_qemu.git] / tests / test-logging.c
1 /*
2 * logging unit-tests
3 *
4 * Copyright (C) 2016 Linaro Ltd.
5 *
6 * Author: Alex Bennée <alex.bennee@linaro.org>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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.
25 */
26
27 #include "qemu/osdep.h"
28
29 #include "qemu-common.h"
30 #include "include/qemu/log.h"
31
32 static void test_parse_range(void)
33 {
34 qemu_set_dfilter_ranges("0x1000+0x100");
35
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));
41
42 qemu_set_dfilter_ranges("0x1000-0x100");
43
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));
48
49 qemu_set_dfilter_ranges("0x1000..0x1100");
50
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));
55
56 qemu_set_dfilter_ranges("0x1000..0x1000");
57
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));
61
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));
66 }
67
68 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
69 static void test_parse_invalid_range_subprocess(void)
70 {
71 qemu_set_dfilter_ranges("0x1000+onehundred");
72 }
73 static void test_parse_invalid_range(void)
74 {
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");
79 }
80 static void test_parse_zero_range_subprocess(void)
81 {
82 qemu_set_dfilter_ranges("0x1000+0");
83 }
84 static void test_parse_zero_range(void)
85 {
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");
90 }
91
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.
95 */
96 static void test_parse_path_subprocess(void)
97 {
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");
102 }
103 static void test_parse_path(void)
104 {
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("");
109 }
110 static void test_parse_invalid_path_subprocess(void)
111 {
112 qemu_set_log_filename("/tmp/qemu-%d%d.log");
113 }
114 static void test_parse_invalid_path(void)
115 {
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");
120 }
121 #endif /* CONFIG_HAS_GLIB_SUBPROCESS_TESTS */
122
123 int main(int argc, char **argv)
124 {
125 g_test_init(&argc, &argv, NULL);
126
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
138
139 return g_test_run();
140 }