Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [RFC][gdb/testsuite] Register test for each arch separately in register_test_foreach_arch
Date: Mon, 13 Sep 2021 17:40:35 +0200	[thread overview]
Message-ID: <20210913154034.GA3115@delia.home> (raw)

Hi,

In gdb/disasm-selftests.c we have:
...
  selftests::register_test_foreach_arch ("print_one_insn",
                                         selftests::print_one_insn_test);
...
and we get:
...
$ gdb -q -batch -ex "maint selftest print_one_insn" 2>&1 \
  | grep ^Running
Running selftest print_one_insn.
$
...

Change the semantics register_test_foreach_arch such that a version of
print_one_insn is registered for each architecture, such that we have:
...
$ gdb -q -batch -ex "maint selftest print_one_insn" 2>&1 \
  | grep ^Running
Running selftest print_one_insn::A6.
Running selftest print_one_insn::A7.
Running selftest print_one_insn::ARC600.
  ...
$
...

This makes it f.i. possible to do:
...
$ gdb -q -batch a.out -ex "maint selftest print_one_insn::armv8.1-m.main"
Running selftest print_one_insn::armv8.1-m.main.
Self test failed: self-test failed at src/gdb/disasm-selftests.c:165
Ran 1 unit tests, 1 failed
...

Currently this runs into a bfd problem, filed at PR28336 - "bfd printable arch
names not unique" ( https://sourceware.org/bugzilla/show_bug.cgi?id=28336 ).

Any comments?

Thanks,
- Tom

[gdb/testsuite] Register test for each arch separately in register_test_foreach_arch

---
 gdb/selftest-arch.c | 105 ++++++++++++++++++++++------------------------------
 1 file changed, 45 insertions(+), 60 deletions(-)

diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c
index 052daed9196..935459def27 100644
--- a/gdb/selftest-arch.c
+++ b/gdb/selftest-arch.c
@@ -17,6 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include <functional>
 
 #if GDB_SELF_TEST
 #include "gdbsupport/selftest.h"
@@ -25,73 +26,57 @@
 
 namespace selftests {
 
-/* A kind of selftest that calls the test function once for each gdbarch known
-   to GDB.  */
-
-struct gdbarch_selftest : public selftest
+static bool skip_arch (const char *arch)
 {
-  gdbarch_selftest (self_test_foreach_arch_function *function_)
-  : function (function_)
-  {}
-
-  void operator() () const override
-  {
-    std::vector<const char *> arches = gdbarch_printable_names ();
-    bool pass = true;
-
-    for (const char *arch : arches)
-      {
-	if (strcmp ("fr300", arch) == 0)
-	  {
-	    /* PR 20946 */
-	    continue;
-	  }
-	else if (strcmp ("powerpc:EC603e", arch) == 0
-		 || strcmp ("powerpc:e500mc", arch) == 0
-		 || strcmp ("powerpc:e500mc64", arch) == 0
-		 || strcmp ("powerpc:titan", arch) == 0
-		 || strcmp ("powerpc:vle", arch) == 0
-		 || strcmp ("powerpc:e5500", arch) == 0
-		 || strcmp ("powerpc:e6500", arch) == 0)
-	  {
-	    /* PR 19797 */
-	    continue;
-	  }
-
-	QUIT;
-
-	try
-	  {
-	    struct gdbarch_info info;
-
-	    info.bfd_arch_info = bfd_scan_arch (arch);
-
-	    struct gdbarch *gdbarch = gdbarch_find_by_info (info);
-	    SELF_CHECK (gdbarch != NULL);
-
-	    function (gdbarch);
-	  }
-	catch (const gdb_exception_error &ex)
-	  {
-	    pass = false;
-	    exception_fprintf (gdb_stderr, ex,
-			       _("Self test failed: arch %s: "), arch);
-	  }
-
-	reset ();
-      }
-
-    SELF_CHECK (pass);
-  }
+  if (strcmp ("fr300", arch) == 0)
+    {
+      /* PR 20946 */
+      return true;
+    }
+
+  if (strcmp ("powerpc:EC603e", arch) == 0
+      || strcmp ("powerpc:e500mc", arch) == 0
+      || strcmp ("powerpc:e500mc64", arch) == 0
+      || strcmp ("powerpc:titan", arch) == 0
+      || strcmp ("powerpc:vle", arch) == 0
+      || strcmp ("powerpc:e5500", arch) == 0
+      || strcmp ("powerpc:e6500", arch) == 0)
+    {
+      /* PR 19797 */
+      return true;
+    }
+
+  return false;
+}
 
-  self_test_foreach_arch_function *function;
-};
+/* Register a kind of selftest that calls the test function once for each
+   gdbarch known to GDB.  */
 
 void
 register_test_foreach_arch (const std::string &name,
 			    self_test_foreach_arch_function *function)
 {
-  register_test (name, new gdbarch_selftest (function));
+  std::vector<const char *> arches = gdbarch_printable_names ();
+  for (const char *arch : arches)
+    {
+      if (skip_arch (arch))
+	continue;
+
+      auto test_fn
+	= ([=] ()
+	   {
+	     struct gdbarch_info info;
+	     info.bfd_arch_info = bfd_scan_arch (arch);
+	     struct gdbarch *gdbarch = gdbarch_find_by_info (info);
+	     SELF_CHECK (gdbarch != NULL);
+	     function (gdbarch);
+	     reset ();
+	   });
+
+      std::string test_name
+	= name + std::string ("::") + std::string (arch);
+      register_test (test_name, test_fn);
+    }
 }
 
 void

             reply	other threads:[~2021-09-13 15:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 15:40 Tom de Vries via Gdb-patches [this message]
2021-09-20 16:01 ` Simon Marchi via Gdb-patches
2021-09-20 18:07   ` Tom de Vries via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210913154034.GA3115@delia.home \
    --to=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox