GDBserver self tests
[deliverable/binutils-gdb.git] / gdb / common / selftest.c
1 /* GDB self-testing.
2 Copyright (C) 2016-2017 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 "common-defs.h"
20 #include "common-exceptions.h"
21 #include "common-debug.h"
22 #include "selftest.h"
23 #include <vector>
24
25 namespace selftests
26 {
27
28 /* All the tests that have been registered. */
29
30 static std::vector<self_test_function *> tests;
31
32 /* See selftest.h. */
33
34 void
35 register_test (self_test_function *function)
36 {
37 tests.push_back (function);
38 }
39
40 /* See selftest.h. */
41
42 void
43 run_tests (void)
44 {
45 int failed = 0;
46
47 for (int i = 0; i < tests.size (); ++i)
48 {
49 TRY
50 {
51 tests[i] ();
52 }
53 CATCH (ex, RETURN_MASK_ERROR)
54 {
55 ++failed;
56 debug_printf ("Self test failed: %s\n", ex.message);
57 }
58 END_CATCH
59
60 reset ();
61 }
62
63 debug_printf ("Ran %lu unit tests, %d failed\n",
64 (long) tests.size (), failed);
65 }
66 } // namespace selftests
This page took 0.032288 seconds and 5 git commands to generate.