Commit | Line | Data |
---|---|---|
dcd1f979 | 1 | /* GDB self-testing. |
61baf725 | 2 | Copyright (C) 2016-2017 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 | ||
19 | #ifndef SELFTEST_H | |
20 | #define 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 | ||
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 | { | |
34 | virtual void operator() () const = 0; | |
35 | }; | |
36 | ||
dcd1f979 TT |
37 | /* Register a new self-test. */ |
38 | ||
1526853e SM |
39 | extern void register_test (const std::string &name, selftest *test); |
40 | ||
41 | /* Register a new self-test. */ | |
42 | ||
43 | extern void register_test (const std::string &name, | |
44 | self_test_function *function); | |
dcd1f979 TT |
45 | |
46 | /* Run all the self tests. This print a message describing the number | |
1526853e SM |
47 | of test and the number of failures. |
48 | ||
49 | If FILTER is not NULL and not empty, only tests with names containing FILTER | |
50 | will be ran. */ | |
dcd1f979 | 51 | |
1526853e | 52 | extern void run_tests (const char *filter); |
7649770c | 53 | |
6d580b63 YQ |
54 | /* Reset GDB or GDBserver's internal state. */ |
55 | extern void reset (); | |
56 | ||
1526853e SM |
57 | typedef void for_each_selftest_ftype (const std::string &name); |
58 | ||
59 | /* Call FUNC for each registered selftest. */ | |
60 | ||
61 | extern void for_each_selftest (for_each_selftest_ftype func); | |
7649770c | 62 | } |
dcd1f979 TT |
63 | |
64 | /* Check that VALUE is true, and, if not, throw an exception. */ | |
65 | ||
66 | #define SELF_CHECK(VALUE) \ | |
67 | do { \ | |
68 | if (!(VALUE)) \ | |
69 | error (_("self-test failed at %s:%d"), __FILE__, __LINE__); \ | |
70 | } while (0) | |
71 | ||
72 | #endif /* SELFTEST_H */ |