Commit | Line | Data |
---|---|---|
dcd1f979 TT |
1 | /* GDB self-testing. |
2 | Copyright (C) 2016 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 "selftest.h" | |
816d7b53 | 21 | #include <vector> |
dcd1f979 TT |
22 | |
23 | /* All the tests that have been registered. */ | |
24 | ||
816d7b53 | 25 | static std::vector<self_test_function *> tests; |
dcd1f979 TT |
26 | |
27 | /* See selftest.h. */ | |
28 | ||
29 | void | |
30 | register_self_test (self_test_function *function) | |
31 | { | |
816d7b53 | 32 | tests.push_back (function); |
dcd1f979 TT |
33 | } |
34 | ||
35 | /* See selftest.h. */ | |
36 | ||
37 | void | |
38 | run_self_tests (void) | |
39 | { | |
dcd1f979 TT |
40 | int failed = 0; |
41 | ||
816d7b53 | 42 | for (int i = 0; i < tests.size (); ++i) |
dcd1f979 TT |
43 | { |
44 | QUIT; | |
45 | ||
46 | TRY | |
47 | { | |
816d7b53 | 48 | tests[i] (); |
dcd1f979 TT |
49 | } |
50 | CATCH (ex, RETURN_MASK_ERROR) | |
51 | { | |
52 | ++failed; | |
53 | exception_fprintf (gdb_stderr, ex, | |
54 | _("Self test threw exception")); | |
55 | } | |
56 | END_CATCH | |
57 | } | |
58 | ||
816d7b53 TT |
59 | printf_filtered (_("Ran %lu unit tests, %d failed\n"), |
60 | (long) tests.size (), failed); | |
dcd1f979 | 61 | } |