]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - gdbsupport/selftest.h
Fix an internal compiler error when attempting to create a second $GDB_DEBUG$ section.
[thirdparty/binutils-gdb.git] / gdbsupport / selftest.h
... / ...
CommitLineData
1/* GDB self-testing.
2 Copyright (C) 2016-2020 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#ifndef COMMON_SELFTEST_H
20#define COMMON_SELFTEST_H
21
22/* A test is just a function that does some checks and throws an
23 exception if something has gone wrong. */
24
25typedef void self_test_function (void);
26
27namespace selftests
28{
29
30/* Interface for the various kinds of selftests. */
31
32struct selftest
33{
34 virtual ~selftest () = default;
35 virtual void operator() () const = 0;
36};
37
38/* Register a new self-test. */
39
40extern void register_test (const std::string &name, selftest *test);
41
42/* Register a new self-test. */
43
44extern void register_test (const std::string &name,
45 self_test_function *function);
46
47/* Run all the self tests. This print a message describing the number
48 of test and the number of failures.
49
50 If FILTER is not NULL and not empty, only tests with names containing FILTER
51 will be ran. */
52
53extern void run_tests (const char *filter);
54
55/* Reset GDB or GDBserver's internal state. */
56extern void reset ();
57
58typedef void for_each_selftest_ftype (const std::string &name);
59
60/* Call FUNC for each registered selftest. */
61
62extern void for_each_selftest (for_each_selftest_ftype func);
63}
64
65/* Check that VALUE is true, and, if not, throw an exception. */
66
67#define SELF_CHECK(VALUE) \
68 do { \
69 if (!(VALUE)) \
70 error (_("self-test failed at %s:%d"), __FILE__, __LINE__); \
71 } while (0)
72
73#endif /* COMMON_SELFTEST_H */