From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2HjBGna9SGFtFAAAWB0awg (envelope-from ) for ; Mon, 20 Sep 2021 12:57:26 -0400 Received: by simark.ca (Postfix, from userid 112) id 6BAAA1EE25; Mon, 20 Sep 2021 12:57:26 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=unavailable 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 146151EE14 for ; Mon, 20 Sep 2021 12:57:26 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5C683858407 for ; Mon, 20 Sep 2021 16:57:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5C683858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632157045; bh=syDIP4i2+HDRj/g3a7jcNNnShwdHzR9Fz0xUK/+qB4w=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JqtifAGX5fDZ1S9KvrV5ZQanPO863KigOyVfi73MWbYrXv+OmGMD4yMUz+GjPNpXM IIzM95N39vcKx/sCvwi5y//YysJDi+94eTo5xZAUkoeOlub4B3ni+CUgcWdFefFDNJ THRQkgghYB83JPCpECXOXyhY2cfEx0iPQwekrUwM= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id DA3863858C60 for ; Mon, 20 Sep 2021 16:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA3863858C60 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-out2.suse.de (Postfix) with ESMTPS id E57D6200FB; Mon, 20 Sep 2021 16:57:05 +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 B86E813AED; Mon, 20 Sep 2021 16:57:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QqZIK2G9SGFJUQAAMHmgww (envelope-from ); Mon, 20 Sep 2021 16:57:05 +0000 Subject: Re: [PATCH][gdb] Add register_test variant with std::function arg To: Simon Marchi , gdb-patches@sourceware.org References: <20210913154000.GA3078@delia.home> <058c08e8-dd93-74ba-f4f4-77b5dac00c6e@polymtl.ca> Message-ID: <434533d6-2c1b-c8a0-4073-2b22cf559745@suse.de> Date: Mon, 20 Sep 2021 18:57:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <058c08e8-dd93-74ba-f4f4-77b5dac00c6e@polymtl.ca> Content-Type: multipart/mixed; boundary="------------A882C1ADEA2F9919116D6CD5" Content-Language: en-US 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" This is a multi-part message in MIME format. --------------A882C1ADEA2F9919116D6CD5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 9/20/21 5:58 PM, Simon Marchi wrote: > On 2021-09-13 11:40 a.m., Tom de Vries via Gdb-patches wrote: > I presume this is for your other patch ([RFC][gdb/testsuite] Register > test for each arch separately in register_test_foreach_arch). Yes. > Since > this is just for tests and we don't care about performance (at least, we > care more about simplicity), I think it would be fine to just make the > existing register_test take an std::function. Ack, done. I'll commit like this, unless there are further comments (f.i., to not do the simple_selftest -> lambda_selftest rename). Thanks, - Tom --------------A882C1ADEA2F9919116D6CD5 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-Change-register_test-to-use-std-function-arg.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-Change-register_test-to-use-std-function-arg.patch" [gdb] Change register_test to use std::function arg Change register_test to use std::function arg, such that we can do: ... register_test (test_name, [=] () { SELF_CHECK (...); }); ... Tested on x86_64-linux. --- gdb/unittests/intrusive_list-selftests.c | 6 ++--- gdbsupport/selftest.cc | 39 +++++++++++++++++--------------- gdbsupport/selftest.h | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c index 8b2b2d1391e..1b38ac39edf 100644 --- a/gdb/unittests/intrusive_list-selftests.c +++ b/gdb/unittests/intrusive_list-selftests.c @@ -754,7 +754,7 @@ struct intrusive_list_test template static void -test_intrusive_list () +test_intrusive_list_1 () { intrusive_list_test tests; @@ -804,8 +804,8 @@ test_node_is_linked () static void test_intrusive_list () { - test_intrusive_list (); - test_intrusive_list (); + test_intrusive_list_1 (); + test_intrusive_list_1 (); test_node_is_linked (); } diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc index d0511abe654..55f530ad98e 100644 --- a/gdbsupport/selftest.cc +++ b/gdbsupport/selftest.cc @@ -21,6 +21,7 @@ #include "common-debug.h" #include "selftest.h" #include +#include namespace selftests { @@ -30,22 +31,6 @@ namespace selftests static std::map> tests; -/* A selftest that calls the test function without arguments. */ - -struct simple_selftest : public selftest -{ - simple_selftest (self_test_function *function_) - : function (function_) - {} - - void operator() () const override - { - function (); - } - - self_test_function *function; -}; - /* See selftest.h. */ void @@ -57,12 +42,30 @@ register_test (const std::string &name, selftest *test) tests[name] = std::unique_ptr (test); } +/* A selftest that calls the test function without arguments. */ + +struct lambda_selftest : public selftest +{ + lambda_selftest (std::function function_) + { + function = function_; + } + + void operator() () const override + { + function (); + } + + std::function function; +}; + /* See selftest.h. */ void -register_test (const std::string &name, self_test_function *function) +register_test (const std::string &name, + std::function function) { - register_test (name, new simple_selftest (function)); + register_test (name, new lambda_selftest (function)); } /* See selftest.h. */ diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h index 13441b05a21..b75e01e197f 100644 --- a/gdbsupport/selftest.h +++ b/gdbsupport/selftest.h @@ -44,7 +44,7 @@ extern void register_test (const std::string &name, selftest *test); /* Register a new self-test. */ extern void register_test (const std::string &name, - self_test_function *function); + std::function function); /* Run all the self tests. This print a message describing the number of test and the number of failures. --------------A882C1ADEA2F9919116D6CD5--