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