Commit | Line | Data |
---|---|---|
07431908 SM |
1 | /* Self tests for memory-map for GDB, the GNU debugger. |
2 | ||
3 | Copyright (C) 2017 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 "memory-map.h" | |
23 | ||
24 | namespace selftests { | |
25 | namespace memory_map_tests { | |
26 | ||
27 | /* A simple valid test input for parse_memory_map. */ | |
28 | ||
29 | static const char *valid_mem_map = R"(<?xml version="1.0"?> | |
30 | <!DOCTYPE memory-map | |
31 | PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN" | |
32 | "http://sourceware.org/gdb/gdb-memory-map.dtd"> | |
33 | <memory-map> | |
34 | <memory type="ram" start="0" length="4096" /> | |
35 | <memory type="rom" start="65536" length="256" /> | |
36 | <memory type="flash" start="131072" length="65536"> | |
37 | <property name="blocksize">1024</property> | |
38 | </memory> | |
39 | </memory-map> | |
40 | )"; | |
41 | ||
42 | /* Validate memory region R against some expected values (the other | |
43 | parameters). */ | |
44 | ||
45 | static void | |
46 | check_mem_region (const mem_region &r, CORE_ADDR lo, CORE_ADDR hi, | |
47 | mem_access_mode mode, int blocksize) | |
48 | { | |
49 | SELF_CHECK (r.lo == lo); | |
50 | SELF_CHECK (r.hi == hi); | |
51 | SELF_CHECK (r.enabled_p); | |
52 | ||
53 | SELF_CHECK (r.attrib.mode == mode); | |
54 | SELF_CHECK (r.attrib.blocksize == blocksize); | |
55 | ||
56 | } | |
57 | ||
58 | /* Test the parse_memory_map function. */ | |
59 | ||
60 | static void | |
61 | parse_memory_map_tests () | |
62 | { | |
63 | std::vector<mem_region> regions = parse_memory_map (valid_mem_map); | |
64 | ||
65 | SELF_CHECK (regions.size () == 3); | |
66 | ||
67 | check_mem_region (regions[0], 0, 0 + 4096, MEM_RW, -1); | |
68 | check_mem_region (regions[1], 65536, 65536 + 256, MEM_RO, -1); | |
69 | check_mem_region (regions[2], 131072, 131072 + 65536, MEM_FLASH, 1024); | |
70 | } | |
71 | ||
72 | } /* namespace memory_map_tests */ | |
73 | } /* namespace selftests */ | |
74 | ||
75 | void | |
76 | _initialize_memory_map_selftests () | |
77 | { | |
78 | selftests::register_test | |
79 | ("parse_memory_map", | |
80 | selftests::memory_map_tests::parse_memory_map_tests); | |
81 | } |