public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix register_test_foreach_arch
@ 2022-04-01 13:00 Lancelot SIX
  2022-04-01 13:00 ` [PATCH 1/3] gdbsupport/selftest: Replace for_each_selftest with an iterator_range Lancelot SIX
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Lancelot SIX @ 2022-04-01 13:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: lsix, Lancelot SIX

Hi,

While working on a selftest issue, I noticed that there is a silent
problem with register_test_foreach_arch:

        $ ./gdb/gdb \
            -data-directory ./gdb/data-directory \
            -quiet -batch -ex "maint selftest" 2>&1 \
            | grep -E "Ran [0-9]+ unit tests"
        Ran 145 unit tests, 0 failed
        $ GDB_REVERSE_INIT_FUNCTIONS=1 ./gdb/gdb \
            -data-directory ./gdb/data-directory \
            -quiet -batch -ex "maint selftest" 2>&1 \
            | grep -E "Ran [0-9]+ unit tests"
        Ran 82 unit tests, 0 failed

Notice that when the GDB_REVERSE_INIT_FUNCTIONS env variable is set, the
number of tests registered is different compared to when this env
variable is not set.

This is due to an issue with how register_test_foreach_arch is used and
how it works.  This function is used to register a generic selftest and
run it against each architecture GDB supports.  Such registration is
typically done during GDB's initialization (in _initialize_* functions).
At the point where this function is called, it will iterate over all the
architectures known to GDB and create an instance of the selftest for
it.  The problem is that at that point, because GDB's initialization
is not done yet, the best register_test_foreach_arch can do is register
the test for each architecture initialized so far.  All architectures
which are initialized at a later point will not have the selftest.

To fix this, this series proposes a lazy registration mechanism so
register_test_foreach_arch can delay the moment it iterates over the
known architectures to a point when GDB is fully initialized.

The first patch of the series does some preparatory refactoring which
will come in handy later.  Patch 2 introduces the lazy test generation
mechanism in the selftest framework, and patch 3 uses this mechanism to
fix register_test_foreach_arch.

Tested on x86_64-gnu-linux.

All feedbacks are welcome.

Best,
Lancelot.

Lancelot SIX (3):
  gdbsupport/selftest: Replace for_each_selftest with an iterator_range
  gdbsupport/selftest: Allow lazy registration
  gdb/selftest-arch: Make register_test_foreach_arch generate arch tests
    lazily

 gdb/maint.c                        | 13 ++++-----
 gdb/selftest-arch.c                | 29 +++++++++++++------
 gdb/selftest-arch.h                |  3 ++
 gdb/testsuite/gdb.gdb/unittest.exp | 25 ++++++++++++++--
 gdbsupport/selftest.cc             | 46 +++++++++++++++++++++---------
 gdbsupport/selftest.h              | 42 ++++++++++++++++++++++-----
 6 files changed, 120 insertions(+), 38 deletions(-)


base-commit: 5530c021ce01abf368a9cde26b22c4b34f320ee8
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-04-19 21:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 13:00 [PATCH 0/3] Fix register_test_foreach_arch Lancelot SIX
2022-04-01 13:00 ` [PATCH 1/3] gdbsupport/selftest: Replace for_each_selftest with an iterator_range Lancelot SIX
2022-04-01 13:00 ` [PATCH 2/3] gdbsupport/selftest: Allow lazy registration Lancelot SIX
2022-04-01 13:00 ` [PATCH 3/3] gdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily Lancelot SIX
2022-04-15 17:52   ` Tom Tromey
2022-04-15 18:10     ` Lancelot SIX
2022-04-15 18:50       ` Tom Tromey
2022-04-19 18:55   ` Simon Marchi
2022-04-19 21:10     ` Lancelot SIX
2022-04-12  8:17 ` [PING] [PATCH 0/3] Fix register_test_foreach_arch Lancelot SIX
2022-04-15 17:53 ` Tom Tromey
2022-04-19  8:18   ` Lancelot SIX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).