]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/selftest.c
Remove some GDB specific stuff from selftest.c
[thirdparty/binutils-gdb.git] / gdb / selftest.c
CommitLineData
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#include "defs.h"
20#include "selftest.h"
816d7b53 21#include <vector>
dcd1f979 22
7649770c
YQ
23namespace selftests
24{
25
dcd1f979
TT
26/* All the tests that have been registered. */
27
816d7b53 28static std::vector<self_test_function *> tests;
dcd1f979
TT
29
30/* See selftest.h. */
31
32void
7649770c 33register_test (self_test_function *function)
dcd1f979 34{
816d7b53 35 tests.push_back (function);
dcd1f979
TT
36}
37
38/* See selftest.h. */
39
40void
7649770c 41run_tests (void)
dcd1f979 42{
dcd1f979
TT
43 int failed = 0;
44
816d7b53 45 for (int i = 0; i < tests.size (); ++i)
dcd1f979 46 {
dcd1f979
TT
47 TRY
48 {
816d7b53 49 tests[i] ();
dcd1f979
TT
50 }
51 CATCH (ex, RETURN_MASK_ERROR)
52 {
53 ++failed;
86dcbf50 54 debug_printf ("Self test failed: %s\n", ex.message);
dcd1f979
TT
55 }
56 END_CATCH
7a3929c4
YQ
57
58 /* Clear GDB internal state. */
59 registers_changed ();
60 reinit_frame_cache ();
dcd1f979
TT
61 }
62
86dcbf50
YQ
63 debug_printf ("Ran %lu unit tests, %d failed\n",
64 (long) tests.size (), failed);
dcd1f979 65}
7649770c 66} // namespace selftests