aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/selftest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport/selftest.cc')
-rw-r--r--gdbsupport/selftest.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
index 7077f11..1b862bb 100644
--- a/gdbsupport/selftest.cc
+++ b/gdbsupport/selftest.cc
@@ -30,6 +30,11 @@ namespace selftests
static selftests_registry tests;
+/* Set of callback functions used to register selftests after GDB is fully
+ initialized. */
+
+static std::vector<selftests_generator> lazy_generators;
+
/* See selftest.h. */
void
@@ -44,6 +49,14 @@ register_test (const std::string &name,
/* See selftest.h. */
+void
+add_lazy_generator (selftests_generator generator)
+{
+ lazy_generators.push_back (std::move (generator));
+}
+
+/* See selftest.h. */
+
static bool run_verbose_ = false;
/* See selftest.h. */
@@ -104,6 +117,14 @@ run_tests (gdb::array_view<const char *const> filters, bool verbose)
selftests_range
all_selftests ()
{
+ /* Execute any function which might still want to register tests. Once each
+ function has been executed, clear lazy_generators to ensure that
+ callback functions are only executed once. */
+ for (const auto &generator : lazy_generators)
+ for (selftest &test : generator ())
+ register_test (std::move (test.name), std::move (test.test));
+ lazy_generators.clear ();
+
return selftests_range (tests.cbegin (), tests.cend ());
}