1 /* Self tests for memory-map for GDB, the GNU debugger.
3 Copyright (C) 2017-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "gdbsupport/selftest.h"
21 #include "memory-map.h"
23 #if defined(HAVE_LIBEXPAT)
26 namespace memory_map_tests
{
28 /* A simple valid test input for parse_memory_map. */
30 static const char valid_mem_map
[] = R
"(<?xml version="1.0"?>
32 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
33 "http://sourceware.org/gdb/gdb-memory-map.dtd">
35 <memory type
="ram" start
="0" length
="4096" />
36 <memory type
="rom" start
="65536" length
="256" />
37 <memory type
="flash" start
="131072" length
="65536">
38 <property name
="blocksize">1024</property
>
43 /* Validate memory region R against some expected values (the other
47 check_mem_region (const mem_region &r, CORE_ADDR lo, CORE_ADDR hi,
48 mem_access_mode mode, int blocksize)
50 SELF_CHECK (r.lo == lo);
51 SELF_CHECK (r.hi == hi);
52 SELF_CHECK (r.enabled_p);
54 SELF_CHECK (r.attrib.mode == mode);
55 SELF_CHECK (r.attrib.blocksize == blocksize);
59 /* Test the parse_memory_map function. */
62 parse_memory_map_tests ()
64 std::vector<mem_region> regions = parse_memory_map (valid_mem_map);
66 SELF_CHECK (regions.size () == 3);
68 check_mem_region (regions[0], 0, 0 + 4096, MEM_RW, -1);
69 check_mem_region (regions[1], 65536, 65536 + 256, MEM_RO, -1);
70 check_mem_region (regions[2], 131072, 131072 + 65536, MEM_FLASH, 1024);
73 } /* namespace memory_map_tests */
74 } /* namespace selftests */
76 #endif /* HAVE_LIBEXPAT */
78 void _initialize_memory_map_selftests ();
80 _initialize_memory_map_selftests ()
82 #if defined(HAVE_LIBEXPAT)
83 selftests::register_test
85 selftests::memory_map_tests::parse_memory_map_tests);