GDB (xrefs)
selftest.h
Go to the documentation of this file.
1 /* GDB self-testing.
2  Copyright (C) 2016-2018 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 #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 
27 namespace selftests
28 {
29 
30 /* Interface for the various kinds of selftests. */
31 
32 struct selftest
33 {
34  virtual ~selftest () = default;
35  virtual void operator() () const = 0;
36 };
37 
38 /* Register a new self-test. */
39 
40 extern void register_test (const std::string &name, selftest *test);
41 
42 /* Register a new self-test. */
43 
44 extern void register_test (const std::string &name,
45  self_test_function *function);
46 
47 /* Run all the self tests. This print a message describing the number
48  of test and the number of failures.
49 
50  If FILTER is not NULL and not empty, only tests with names containing FILTER
51  will be ran. */
52 
53 extern void run_tests (const char *filter);
54 
55 /* Reset GDB or GDBserver's internal state. */
56 extern void reset ();
57 
59 
60 /* Call FUNC for each registered selftest. */
61 
63 }
64 
65 /* Check that VALUE is true, and, if not, throw an exception. */
66 
67 #define SELF_CHECK(VALUE) \
68  do { \
69  if (!(VALUE)) \
70  error (_("self-test failed at %s:%d"), __FILE__, __LINE__); \
71  } while (0)
72 
73 #endif /* SELFTEST_H */
const char * string
Definition: signals.c:50
void reset()
void(* func)(char *)
virtual void operator()() const =0
void test()
Definition: 1.cc:95
const char *const name
Definition: aarch64-tdep.c:76
void for_each_selftest_ftype(const std::string &name)
Definition: selftest.h:58
virtual ~selftest()=default
void for_each_selftest(for_each_selftest_ftype func)
Definition: selftest.c:106
void run_tests(const char *filter)
Definition: selftest.c:71
void self_test_function(void)
Definition: selftest.h:25
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52