From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb] Add register_test variant with std::function arg
Date: Mon, 20 Sep 2021 11:58:25 -0400 [thread overview]
Message-ID: <058c08e8-dd93-74ba-f4f4-77b5dac00c6e@polymtl.ca> (raw)
In-Reply-To: <20210913154000.GA3078@delia.home>
On 2021-09-13 11:40 a.m., Tom de Vries via Gdb-patches wrote:
> Hi,
>
> Add register_test variant with std::function arg, such that we can do:
> ...
> register_test (test_name, [=] () { SELF_CHECK (...); });
> ...
>
> Any comments?
>
> Thanks,
> - Tom
>
> [gdb] Add register_test variant with std::function arg
>
> ---
> gdbsupport/selftest.cc | 25 +++++++++++++++++++++++++
> gdbsupport/selftest.h | 3 +++
> 2 files changed, 28 insertions(+)
>
> diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
> index d0511abe654..6d92844880f 100644
> --- a/gdbsupport/selftest.cc
> +++ b/gdbsupport/selftest.cc
> @@ -21,6 +21,7 @@
> #include "common-debug.h"
> #include "selftest.h"
> #include <map>
> +#include <functional>
>
> namespace selftests
> {
> @@ -57,6 +58,30 @@ register_test (const std::string &name, selftest *test)
> tests[name] = std::unique_ptr<selftest> (test);
> }
>
> +struct lambda_selftest : public selftest
> +{
> + lambda_selftest (std::function<void(void)> function_)
> + {
> + function = function_;
> + }
> +
> + void operator() () const override
> + {
> + function ();
> + }
> +
> + std::function<void(void)> function;
> +};
> +
> +/* See selftest.h. */
> +
> +void
> +register_test (const std::string &name,
> + std::function<void(void)> function)
> +{
> + register_test (name, new lambda_selftest (function));
> +}
> +
> /* See selftest.h. */
I presume this is for your other patch ([RFC][gdb/testsuite] Register
test for each arch separately in register_test_foreach_arch). 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.
Simon
next prev parent reply other threads:[~2021-09-20 15:58 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
2021-09-20 15:58 ` Simon Marchi via Gdb-patches [this message]
2021-09-20 16:57 ` 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=058c08e8-dd93-74ba-f4f4-77b5dac00c6e@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
--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