aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/selftest.h
diff options
context:
space:
mode:
authorLancelot SIX <lancelot.six@amd.com>2022-03-23 15:29:53 +0000
committerLancelot SIX <lancelot.six@amd.com>2022-04-19 09:12:42 +0100
commitc57207c15c4fa980263e6849d0e6472c33e647fc (patch)
tree5f84e945862557442b82ee973afb7db620117dd5 /gdbsupport/selftest.h
parent2aaee75f81a130011c96a0ab38475dba894114c3 (diff)
downloadgdb-c57207c15c4fa980263e6849d0e6472c33e647fc.zip
gdb-c57207c15c4fa980263e6849d0e6472c33e647fc.tar.gz
gdb-c57207c15c4fa980263e6849d0e6472c33e647fc.tar.bz2
gdbsupport/selftest: Replace for_each_selftest with an iterator_range
Remove the callback-based selftests::for_each_selftest function and use an iterator_range instead. Also use this iterator range in run_tests so all iterations over the selftests are done in a consistent way. This will become useful in a later commit. Change-Id: I0b3a5349a7987fbcb0071f11c394e353df986583
Diffstat (limited to 'gdbsupport/selftest.h')
-rw-r--r--gdbsupport/selftest.h31
1 files changed, 24 insertions, 7 deletions
diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h
index 3c343e1..5ca9bdc 100644
--- a/gdbsupport/selftest.h
+++ b/gdbsupport/selftest.h
@@ -21,6 +21,8 @@
#include "gdbsupport/array-view.h"
#include "gdbsupport/function-view.h"
+#include "gdbsupport/iterator-range.h"
+#include <set>
/* A test is just a function that does some checks and throws an
exception if something has gone wrong. */
@@ -28,6 +30,28 @@
namespace selftests
{
+/* Selftests are registered under a unique name. */
+
+struct selftest
+{
+ selftest (std::string name, std::function<void (void)> test)
+ : name { std::move (name) }, test { std::move (test) }
+ { }
+ bool operator< (const selftest &rhs) const
+ { return name < rhs.name; }
+
+ std::string name;
+ std::function<void (void)> test;
+};
+
+/* Type of the container of all the registered selftests. */
+using selftests_registry = std::set<selftest>;
+using selftests_range = iterator_range<selftests_registry::const_iterator>;
+
+/* Create a range to iterate over all registered tests. */
+
+selftests_range all_selftests ();
+
/* True if selftest should run verbosely. */
extern bool run_verbose ();
@@ -48,13 +72,6 @@ extern void run_tests (gdb::array_view<const char *const> filters,
/* Reset GDB or GDBserver's internal state. */
extern void reset ();
-
-using for_each_selftest_ftype
- = gdb::function_view<void(const std::string &name)>;
-
-/* Call FUNC for each registered selftest. */
-
-extern void for_each_selftest (for_each_selftest_ftype func);
}
/* Check that VALUE is true, and, if not, throw an exception. */