From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gBVtKjFxP2HPKAAAWB0awg (envelope-from ) for ; Mon, 13 Sep 2021 11:41:37 -0400 Received: by simark.ca (Postfix, from userid 112) id ABA641EE25; Mon, 13 Sep 2021 11:41:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AF6401EDDB for ; Mon, 13 Sep 2021 11:41:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B03A3857411 for ; Mon, 13 Sep 2021 15:41:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B03A3857411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631547696; bh=R9iEl6qo4I961TE15LaO4wD5NS2r1ySZnT42Rzpu7U0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=L5kpM3PquO6wKR7/zRaytFbYzlUdbWF1kVmqTg03Qnom2JsZJLDHO+oduckgvoVum RlAkU6NycnQ26uOiGma+GRhCywW5UbMJmyyAWwQEZl9aZZIAQUetM5x3Mpei0hkGK6 djkXT8PPB+VVfVZOGS04G/MYsXOq893GnDoy54DQ= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id DFB96385742B for ; Mon, 13 Sep 2021 15:40:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFB96385742B Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2714C22001 for ; Mon, 13 Sep 2021 15:40:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1601813AB5 for ; Mon, 13 Sep 2021 15:40:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jnJVBPpwP2HaDQAAMHmgww (envelope-from ) for ; Mon, 13 Sep 2021 15:40:42 +0000 Date: Mon, 13 Sep 2021 17:40:35 +0200 To: gdb-patches@sourceware.org Subject: [RFC][gdb/testsuite] Register test for each arch separately in register_test_foreach_arch Message-ID: <20210913154034.GA3115@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 . */ #include "defs.h" +#include #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 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 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