1 /* Self tests for memory-map for GDB, the GNU debugger.
3 Copyright (C) 2017-2022 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/>. */
21 #include "gdbsupport/selftest.h"
22 #include "memory-map.h"
24 #if defined(HAVE_LIBEXPAT)
27 namespace memory_map_tests
{
29 /* A simple valid test input for parse_memory_map. */
31 static const char valid_mem_map
[] = R
"(<?xml version="1.0"?>
33 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
34 "http://sourceware.org/gdb/gdb-memory-map.dtd">
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
>
44 /* Validate memory region R against some expected values (the other
48 check_mem_region (const mem_region &r, CORE_ADDR lo, CORE_ADDR hi,
49 mem_access_mode mode, int blocksize)
51 SELF_CHECK (r.lo == lo);
52 SELF_CHECK (r.hi == hi);
53 SELF_CHECK (r.enabled_p);
55 SELF_CHECK (r.attrib.mode == mode);
56 SELF_CHECK (r.attrib.blocksize == blocksize);
60 /* Test the parse_memory_map function. */
63 parse_memory_map_tests ()
65 std::vector<mem_region> regions = parse_memory_map (valid_mem_map);
67 SELF_CHECK (regions.size () == 3);
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);
74 } /* namespace memory_map_tests */
75 } /* namespace selftests */
77 #endif /* HAVE_LIBEXPAT */
79 void _initialize_memory_map_selftests ();
81 _initialize_memory_map_selftests ()
83 #if defined(HAVE_LIBEXPAT)
84 selftests::register_test
86 selftests::memory_map_tests::parse_memory_map_tests);