]>
Commit | Line | Data |
---|---|---|
3514552e AB |
1 | /* |
2 | * logging unit-tests | |
3 | * | |
4 | * Copyright (C) 2016 Linaro Ltd. | |
5 | * | |
6 | * Author: Alex Bennée <[email protected]> | |
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" | |
3514552e AB |
28 | |
29 | #include "qemu-common.h" | |
bd6fee9f MA |
30 | #include "qapi/error.h" |
31 | #include "qemu/log.h" | |
3514552e AB |
32 | |
33 | static void test_parse_range(void) | |
34 | { | |
bd6fee9f MA |
35 | Error *err = NULL; |
36 | ||
37 | qemu_set_dfilter_ranges("0x1000+0x100", &error_abort); | |
3514552e AB |
38 | |
39 | g_assert_false(qemu_log_in_addr_range(0xfff)); | |
40 | g_assert(qemu_log_in_addr_range(0x1000)); | |
41 | g_assert(qemu_log_in_addr_range(0x1001)); | |
42 | g_assert(qemu_log_in_addr_range(0x10ff)); | |
43 | g_assert_false(qemu_log_in_addr_range(0x1100)); | |
44 | ||
bd6fee9f | 45 | qemu_set_dfilter_ranges("0x1000-0x100", &error_abort); |
3514552e AB |
46 | |
47 | g_assert_false(qemu_log_in_addr_range(0x1001)); | |
48 | g_assert(qemu_log_in_addr_range(0x1000)); | |
49 | g_assert(qemu_log_in_addr_range(0x0f01)); | |
50 | g_assert_false(qemu_log_in_addr_range(0x0f00)); | |
51 | ||
bd6fee9f | 52 | qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort); |
3514552e AB |
53 | |
54 | g_assert_false(qemu_log_in_addr_range(0xfff)); | |
55 | g_assert(qemu_log_in_addr_range(0x1000)); | |
56 | g_assert(qemu_log_in_addr_range(0x1100)); | |
57 | g_assert_false(qemu_log_in_addr_range(0x1101)); | |
58 | ||
bd6fee9f | 59 | qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort); |
3514552e AB |
60 | |
61 | g_assert_false(qemu_log_in_addr_range(0xfff)); | |
62 | g_assert(qemu_log_in_addr_range(0x1000)); | |
63 | g_assert_false(qemu_log_in_addr_range(0x1001)); | |
64 | ||
bd6fee9f MA |
65 | qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100", |
66 | &error_abort); | |
3514552e AB |
67 | g_assert(qemu_log_in_addr_range(0x1050)); |
68 | g_assert(qemu_log_in_addr_range(0x2050)); | |
69 | g_assert(qemu_log_in_addr_range(0x3050)); | |
3514552e | 70 | |
58e19e6e MA |
71 | qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort); |
72 | g_assert(qemu_log_in_addr_range(UINT64_MAX)); | |
73 | g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1)); | |
74 | ||
75 | qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err); | |
58eeb83c MA |
76 | g_assert(qemu_log_in_addr_range(0)); |
77 | g_assert(qemu_log_in_addr_range(UINT64_MAX)); | |
78 | ||
58e19e6e MA |
79 | qemu_set_dfilter_ranges("2..1", &err); |
80 | error_free_or_abort(&err); | |
81 | ||
bd6fee9f MA |
82 | qemu_set_dfilter_ranges("0x1000+onehundred", &err); |
83 | error_free_or_abort(&err); | |
84 | ||
85 | qemu_set_dfilter_ranges("0x1000+0", &err); | |
86 | error_free_or_abort(&err); | |
3514552e | 87 | } |
f6880b7f | 88 | |
f6880b7f AB |
89 | static void test_parse_path(void) |
90 | { | |
daa76aa4 MA |
91 | Error *err = NULL; |
92 | ||
93 | qemu_set_log_filename("/tmp/qemu.log", &error_abort); | |
94 | qemu_set_log_filename("/tmp/qemu-%d.log", &error_abort); | |
95 | qemu_set_log_filename("/tmp/qemu.log.%d", &error_abort); | |
96 | ||
97 | qemu_set_log_filename("/tmp/qemu-%d%d.log", &err); | |
98 | error_free_or_abort(&err); | |
f6880b7f | 99 | } |
3514552e AB |
100 | |
101 | int main(int argc, char **argv) | |
102 | { | |
103 | g_test_init(&argc, &argv, NULL); | |
104 | ||
105 | g_test_add_func("/logging/parse_range", test_parse_range); | |
f6880b7f | 106 | g_test_add_func("/logging/parse_path", test_parse_path); |
3514552e AB |
107 | |
108 | return g_test_run(); | |
109 | } |