[gdb/testsuite] Register test for each arch separately in register_test_foreach_arch
[binutils-gdb.git] / gdb / selftest-arch.c
1 /* GDB self-test for each gdbarch.
2 Copyright (C) 2017-2021 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include "defs.h"
20 #include <functional>
21
22 #if GDB_SELF_TEST
23 #include "gdbsupport/selftest.h"
24 #include "selftest-arch.h"
25 #include "arch-utils.h"
26
27 namespace selftests {
28
29 static bool skip_arch (const char *arch)
30 {
31 if (strcmp ("fr300", arch) == 0)
32 {
33 /* PR 20946 */
34 return true;
35 }
36
37 if (strcmp ("powerpc:EC603e", arch) == 0
38 || strcmp ("powerpc:e500mc", arch) == 0
39 || strcmp ("powerpc:e500mc64", arch) == 0
40 || strcmp ("powerpc:titan", arch) == 0
41 || strcmp ("powerpc:vle", arch) == 0
42 || strcmp ("powerpc:e5500", arch) == 0
43 || strcmp ("powerpc:e6500", arch) == 0)
44 {
45 /* PR 19797 */
46 return true;
47 }
48
49 return false;
50 }
51
52 /* Register a kind of selftest that calls the test function once for each
53 gdbarch known to GDB. */
54
55 void
56 register_test_foreach_arch (const std::string &name,
57 self_test_foreach_arch_function *function)
58 {
59 std::vector<const char *> arches = gdbarch_printable_names ();
60 for (const char *arch : arches)
61 {
62 if (skip_arch (arch))
63 continue;
64
65 auto test_fn
66 = ([=] ()
67 {
68 struct gdbarch_info info;
69 info.bfd_arch_info = bfd_scan_arch (arch);
70 struct gdbarch *gdbarch = gdbarch_find_by_info (info);
71 SELF_CHECK (gdbarch != NULL);
72 function (gdbarch);
73 reset ();
74 });
75
76 std::string test_name
77 = name + std::string ("::") + std::string (arch);
78 register_test (test_name, test_fn);
79 }
80 }
81
82 void
83 reset ()
84 {
85 /* Clear GDB internal state. */
86 registers_changed ();
87 reinit_frame_cache ();
88 }
89 } // namespace selftests
90 #endif /* GDB_SELF_TEST */