Re: [PATCH v5 04/25] Unit testing for GDB-side remote memory tagging handling

Simon Marchi via Gdb-patches
2021-02-05T02:51:07Z

On 2021-01-27 3:20 p.m., Luis Machado via Gdb-patches wrote:
> Updated in v4:
>
> - Renamed functions based on reviews.
> - Adjusted code to cope with bool return value.
> - Restoring of global setting after unit testing.
>
> Updated in v2:
>
> - Adjusted unit tests to cope with new type field in the remote packets.
>
> --
>
> Include some unit testing for the functions handling the new qMemTags and
> QMemTags packets.
>
> gdb/ChangeLog:
>
> YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
>
> * remote: Include gdbsupport/selftest.h.
> (test_memory_tagging_functions): New function.
> (_initialize_remote): Register test_memory_tagging_functions.
> ---
> gdb/remote.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 93 insertions(+)
>
> diff --git a/gdb/remote.c b/gdb/remote.c
> index bb3473b04c..22cae2a94f 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -79,6 +79,7 @@
> #include <algorithm>
> #include <unordered_map>
> #include "async-event.h"
> +#include "gdbsupport/selftest.h"
>
> /* The remote target. */
>
> @@ -14603,6 +14604,93 @@ remote_target::store_memtags (CORE_ADDR address, size_t len,
> return packet_check_result (rs->buf.data ()) == PACKET_OK;
> }
>
> +#if GDB_SELF_TEST
> +
> +namespace selftests {
> +
> +static void
> +test_memory_tagging_functions ()
> +{
> + remote_target remote;
> +
> + struct packet_config *config
> + = &remote_protocol_packets[PACKET_memory_tagging_feature];
> +
> + scoped_restore restore_memtag_support_
> + = make_scoped_restore (&config->support,
> + config->support);

I think you could use the single-argument form here, if you want to
create the scoped_restore object but not modify the value right away.

Otherwise, LGTM.

Simon