1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "qemu/osdep.h"
28#include <glib.h>
29
30#include "qemu-common.h"
31#include "include/qemu/log.h"
32
33static void test_parse_range(void)
34{
35 qemu_set_dfilter_ranges("0x1000+0x100");
36
37 g_assert_false(qemu_log_in_addr_range(0xfff));
38 g_assert(qemu_log_in_addr_range(0x1000));
39 g_assert(qemu_log_in_addr_range(0x1001));
40 g_assert(qemu_log_in_addr_range(0x10ff));
41 g_assert_false(qemu_log_in_addr_range(0x1100));
42
43 qemu_set_dfilter_ranges("0x1000-0x100");
44
45 g_assert_false(qemu_log_in_addr_range(0x1001));
46 g_assert(qemu_log_in_addr_range(0x1000));
47 g_assert(qemu_log_in_addr_range(0x0f01));
48 g_assert_false(qemu_log_in_addr_range(0x0f00));
49
50 qemu_set_dfilter_ranges("0x1000..0x1100");
51
52 g_assert_false(qemu_log_in_addr_range(0xfff));
53 g_assert(qemu_log_in_addr_range(0x1000));
54 g_assert(qemu_log_in_addr_range(0x1100));
55 g_assert_false(qemu_log_in_addr_range(0x1101));
56
57 qemu_set_dfilter_ranges("0x1000..0x1000");
58
59 g_assert_false(qemu_log_in_addr_range(0xfff));
60 g_assert(qemu_log_in_addr_range(0x1000));
61 g_assert_false(qemu_log_in_addr_range(0x1001));
62
63 qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100");
64 g_assert(qemu_log_in_addr_range(0x1050));
65 g_assert(qemu_log_in_addr_range(0x2050));
66 g_assert(qemu_log_in_addr_range(0x3050));
67}
68
69#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
70static void test_parse_invalid_range_subprocess(void)
71{
72 qemu_set_dfilter_ranges("0x1000+onehundred");
73}
74static void test_parse_invalid_range(void)
75{
76 g_test_trap_subprocess("/logging/parse_invalid_range/subprocess", 0, 0);
77 g_test_trap_assert_failed();
78 g_test_trap_assert_stdout("");
79 g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+onehundred\n");
80}
81static void test_parse_zero_range_subprocess(void)
82{
83 qemu_set_dfilter_ranges("0x1000+0");
84}
85static void test_parse_zero_range(void)
86{
87 g_test_trap_subprocess("/logging/parse_zero_range/subprocess", 0, 0);
88 g_test_trap_assert_failed();
89 g_test_trap_assert_stdout("");
90 g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n");
91}
92
93
94
95
96
97static void test_parse_path_subprocess(void)
98{
99
100 qemu_set_log_filename("/tmp/qemu.log");
101 qemu_set_log_filename("/tmp/qemu-%d.log");
102 qemu_set_log_filename("/tmp/qemu.log.%d");
103}
104static void test_parse_path(void)
105{
106 g_test_trap_subprocess ("/logging/parse_path/subprocess", 0, 0);
107 g_test_trap_assert_passed();
108 g_test_trap_assert_stdout("");
109 g_test_trap_assert_stderr("");
110}
111static void test_parse_invalid_path_subprocess(void)
112{
113 qemu_set_log_filename("/tmp/qemu-%d%d.log");
114}
115static void test_parse_invalid_path(void)
116{
117 g_test_trap_subprocess ("/logging/parse_invalid_path/subprocess", 0, 0);
118 g_test_trap_assert_passed();
119 g_test_trap_assert_stdout("");
120 g_test_trap_assert_stderr("Bad logfile format: /tmp/qemu-%d%d.log\n");
121}
122#endif
123
124int main(int argc, char **argv)
125{
126 g_test_init(&argc, &argv, NULL);
127
128 g_test_add_func("/logging/parse_range", test_parse_range);
129#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
130 g_test_add_func("/logging/parse_invalid_range/subprocess", test_parse_invalid_range_subprocess);
131 g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range);
132 g_test_add_func("/logging/parse_zero_range/subprocess", test_parse_zero_range_subprocess);
133 g_test_add_func("/logging/parse_zero_range", test_parse_zero_range);
134 g_test_add_func("/logging/parse_path", test_parse_path);
135 g_test_add_func("/logging/parse_path/subprocess", test_parse_path_subprocess);
136 g_test_add_func("/logging/parse_invalid_path", test_parse_invalid_path);
137 g_test_add_func("/logging/parse_invalid_path/subprocess", test_parse_invalid_path_subprocess);
138#endif
139
140 return g_test_run();
141}
142