]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdbsupport/selftest.h
[gdb/testsuite] Kfail gdb.cp/ambiguous.exp FAILs for PR26602
[thirdparty/binutils-gdb.git] / gdbsupport / selftest.h
CommitLineData
dcd1f979 1/* GDB self-testing.
b811d2c2 2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
dcd1f979
TT
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
1a5c2598
TT
19#ifndef COMMON_SELFTEST_H
20#define COMMON_SELFTEST_H
dcd1f979 21
ece5bc8a
SM
22#include "gdbsupport/array-view.h"
23
dcd1f979
TT
24/* A test is just a function that does some checks and throws an
25 exception if something has gone wrong. */
26
27typedef void self_test_function (void);
28
7649770c
YQ
29namespace selftests
30{
31
1526853e
SM
32/* Interface for the various kinds of selftests. */
33
34struct selftest
35{
30970df7 36 virtual ~selftest () = default;
1526853e
SM
37 virtual void operator() () const = 0;
38};
39
dcd1f979
TT
40/* Register a new self-test. */
41
1526853e
SM
42extern void register_test (const std::string &name, selftest *test);
43
44/* Register a new self-test. */
45
46extern void register_test (const std::string &name,
47 self_test_function *function);
dcd1f979
TT
48
49/* Run all the self tests. This print a message describing the number
1526853e
SM
50 of test and the number of failures.
51
ece5bc8a
SM
52 If FILTERS is not empty, only run tests with names containing one of the
53 element of FILTERS. */
dcd1f979 54
ece5bc8a 55extern void run_tests (gdb::array_view<const char *const> filters);
7649770c 56
6d580b63
YQ
57/* Reset GDB or GDBserver's internal state. */
58extern void reset ();
59
1526853e
SM
60typedef void for_each_selftest_ftype (const std::string &name);
61
62/* Call FUNC for each registered selftest. */
63
64extern void for_each_selftest (for_each_selftest_ftype func);
7649770c 65}
dcd1f979
TT
66
67/* Check that VALUE is true, and, if not, throw an exception. */
68
69#define SELF_CHECK(VALUE) \
70 do { \
71 if (!(VALUE)) \
72 error (_("self-test failed at %s:%d"), __FILE__, __LINE__); \
73 } while (0)
74
1a5c2598 75#endif /* COMMON_SELFTEST_H */