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" | |
21 | #include "vec.h" | |
22 | ||
23 | typedef self_test_function *self_test_function_ptr; | |
24 | ||
25 | DEF_VEC_P (self_test_function_ptr); | |
26 | ||
27 | /* All the tests that have been registered. */ | |
28 | ||
29 | static VEC (self_test_function_ptr) *tests; | |
30 | ||
31 | /* See selftest.h. */ | |
32 | ||
33 | void | |
34 | register_self_test (self_test_function *function) | |
35 | { | |
36 | VEC_safe_push (self_test_function_ptr, tests, function); | |
37 | } | |
38 | ||
39 | /* See selftest.h. */ | |
40 | ||
41 | void | |
42 | run_self_tests (void) | |
43 | { | |
44 | int i; | |
45 | self_test_function_ptr func; | |
46 | int failed = 0; | |
47 | ||
48 | for (i = 0; VEC_iterate (self_test_function_ptr, tests, i, func); ++i) | |
49 | { | |
50 | QUIT; | |
51 | ||
52 | TRY | |
53 | { | |
54 | (*func) (); | |
55 | } | |
56 | CATCH (ex, RETURN_MASK_ERROR) | |
57 | { | |
58 | ++failed; | |
59 | exception_fprintf (gdb_stderr, ex, | |
60 | _("Self test threw exception")); | |
61 | } | |
62 | END_CATCH | |
63 | } | |
64 | ||
65 | printf_filtered (_("Ran %u unit tests, %d failed\n"), | |
66 | VEC_length (self_test_function_ptr, tests), failed); | |
67 | } |