GDB (xrefs)

memrange-selftests.c
Go to the documentation of this file.
1 /* Self tests for mem ranges for GDB, the GNU debugger.
2
3 Copyright (C) 2017-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "selftest.h"
22 #include "memrange.h"
23
24 namespace selftests {
25 namespace memrange_tests {
26
27 static void
28 normalize_mem_ranges_tests ()
29 {
30 /* Empty vector. */
31 {
32 std::vector<mem_range> ranges;
33
34 normalize_mem_ranges (&ranges);
35
36 SELF_CHECK (ranges.size () == 0);
37 }
38
39 /* With one range. */
40 {
41 std::vector<mem_range> ranges;
42
43 ranges.emplace_back (10, 20);
44
45 normalize_mem_ranges (&ranges);
46
47 SELF_CHECK (ranges.size () == 1);
48 SELF_CHECK (ranges[0] == mem_range (10, 20));
49 }
50
51 /* Completely disjoint ranges. */
52 {
53 std::vector<mem_range> ranges;
54
55 ranges.emplace_back (20, 1);
56 ranges.emplace_back (10, 1);
57
58 normalize_mem_ranges (&ranges);
59
60 SELF_CHECK (ranges.size () == 2);
61 SELF_CHECK (ranges[0] == mem_range (10, 1));
62 SELF_CHECK (ranges[1] == mem_range (20, 1));
63 }
64
65 /* Overlapping and contiguous ranges. */
66 {
67 std::vector<mem_range> ranges;
68
69 ranges.emplace_back (5, 10);
70 ranges.emplace_back (10, 10);
71 ranges.emplace_back (15, 10);
72
73 normalize_mem_ranges (&ranges);
74
75 SELF_CHECK (ranges.size () == 1);
76 SELF_CHECK (ranges[0] == mem_range (5, 20));
77 }
78
79 /* Duplicate ranges. */
80 {
81 std::vector<mem_range> ranges;
82
83 ranges.emplace_back (10, 10);
84 ranges.emplace_back (10, 10);
85
86 normalize_mem_ranges (&ranges);
87
88 SELF_CHECK (ranges.size () == 1);
89 SELF_CHECK (ranges[0] == mem_range (10, 10));
90 }
91
92 /* Range completely inside another. */
93 {
94 std::vector<mem_range> ranges;
95
96 ranges.emplace_back (14, 2);
97 ranges.emplace_back (10, 10);
98
99 normalize_mem_ranges (&ranges);
100
101 SELF_CHECK (ranges.size () == 1);
102 SELF_CHECK (ranges[0] == mem_range (10, 10));
103 }
104 }
105
106 } /* namespace memrange_tests */
107 } /* namespace selftests */
108
109 void
110 _initialize_memrange_selftests ()
111 {
112 selftests::register_test
113 ("normalize_mem_ranges",
114 selftests::memrange_tests::normalize_mem_ranges_tests);
115 }
memrange.h
defs.h
selftests
Definition: selftest.c:25
mem_range
Definition: memrange.h:27
normalize_mem_ranges
void normalize_mem_ranges(std::vector< mem_range > *memory)
Definition: memrange.c:45
selftests::memrange_tests::normalize_mem_ranges_tests
static void normalize_mem_ranges_tests()
Definition: memrange-selftests.c:28
_initialize_memrange_selftests
void _initialize_memrange_selftests()
Definition: memrange-selftests.c:110
selftest.h
selftests::register_test
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52
SELF_CHECK
#define SELF_CHECK(VALUE)
Definition: selftest.h:67