Commit | Line | Data |
---|---|---|
dcd1f979 | 1 | /* GDB self-testing. |
42a4f53d | 2 | Copyright (C) 2016-2019 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 TT |
21 | |
22 | /* A test is just a function that does some checks and throws an | |
23 | exception if something has gone wrong. */ | |
24 | ||
25 | typedef void self_test_function (void); | |
26 | ||
7649770c YQ |
27 | namespace selftests |
28 | { | |
29 | ||
1526853e SM |
30 | /* Interface for the various kinds of selftests. */ |
31 | ||
32 | struct selftest | |
33 | { | |
30970df7 | 34 | virtual ~selftest () = default; |
1526853e SM |
35 | virtual void operator() () const = 0; |
36 | }; | |
37 | ||
dcd1f979 TT |
38 | /* Register a new self-test. */ |
39 | ||
1526853e SM |
40 | extern void register_test (const std::string &name, selftest *test); |
41 | ||
42 | /* Register a new self-test. */ | |
43 | ||
44 | extern void register_test (const std::string &name, | |
45 | self_test_function *function); | |
dcd1f979 TT |
46 | |
47 | /* Run all the self tests. This print a message describing the number | |
1526853e SM |
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. */ | |
dcd1f979 | 52 | |
1526853e | 53 | extern void run_tests (const char *filter); |
7649770c | 54 | |
6d580b63 YQ |
55 | /* Reset GDB or GDBserver's internal state. */ |
56 | extern void reset (); | |
57 | ||
1526853e SM |
58 | typedef void for_each_selftest_ftype (const std::string &name); |
59 | ||
60 | /* Call FUNC for each registered selftest. */ | |
61 | ||
62 | extern void for_each_selftest (for_each_selftest_ftype func); | |
7649770c | 63 | } |
dcd1f979 TT |
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 | ||
1a5c2598 | 73 | #endif /* COMMON_SELFTEST_H */ |