diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-06-15 15:22:13 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2020-06-25 13:23:38 -0300 |
commit | ebd61ee8b5161ded8653c32da0ec57927e1ba9c1 (patch) | |
tree | b4596db3279d67e148d1fe33009d64b82d0e739e | |
parent | 455ae6919e9bba74f0f724c3f61084869bed5e3c (diff) | |
download | gdb-ebd61ee8b5161ded8653c32da0ec57927e1ba9c1.zip gdb-ebd61ee8b5161ded8653c32da0ec57927e1ba9c1.tar.gz gdb-ebd61ee8b5161ded8653c32da0ec57927e1ba9c1.tar.bz2 |
Unit testing for GDB-side remote memory tagging handling
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.
-rw-r--r-- | gdb/remote.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index 51436ec..e5ad331 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -78,6 +78,7 @@ #include <algorithm> #include <unordered_map> #include "async-event.h" +#include "gdbsupport/selftest.h" /* The remote target. */ @@ -14504,6 +14505,89 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, return 0; } +#if GDB_SELF_TEST + +namespace selftests { + +static void +test_memory_tagging_functions (void) +{ + remote_target remote; + + struct packet_config *config + = &remote_protocol_packets[PACKET_memory_tagging_feature]; + + /* Test memory tagging packet support. */ + config->support = PACKET_SUPPORT_UNKNOWN; + SELF_CHECK (remote.supports_memory_tagging () == false); + config->support = PACKET_DISABLE; + SELF_CHECK (remote.supports_memory_tagging () == false); + config->support = PACKET_ENABLE; + SELF_CHECK (remote.supports_memory_tagging () == true); + + /* Setup testing. */ + gdb::char_vector packet; + gdb::byte_vector tags, bv; + std::string expected, reply; + packet.resize (32000); + + /* Test creating a qMemTags request. */ + + expected = "qMemTags:0,0"; + create_fmemtags_request (packet, 0x0, 0x0); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + expected = "qMemTags:deadbeef,10"; + create_fmemtags_request (packet, 0xdeadbeef, 16); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + /* Test parsing a qMemTags reply. */ + + /* Error reply, tags vector unmodified. */ + reply = "E00"; + strcpy (packet.data (), reply.c_str ()); + tags.resize (0); + SELF_CHECK (parse_fmemtags_reply (packet, tags) != 0); + SELF_CHECK (tags.size () == 0); + + /* Valid reply, tags vector updated. */ + tags.resize (0); + bv.resize (0); + + for (int i = 0; i < 5; i++) + bv.push_back (i); + + reply = "m" + bin2hex (bv.data (), bv.size ()); + strcpy (packet.data (), reply.c_str ()); + + SELF_CHECK (parse_fmemtags_reply (packet, tags) == 0); + SELF_CHECK (tags.size () == 5); + + for (int i = 0; i < 5; i++) + SELF_CHECK (tags[i] == i); + + /* Test creating a QMemTags request. */ + + /* Empty tag data. */ + tags.resize (0); + expected = "QMemTags:0,0:"; + create_smemtags_request (packet, 0x0, 0x0, tags); + SELF_CHECK (memcmp (packet.data (), expected.c_str (), + expected.length ()) == 0); + + /* Non-empty tag data. */ + tags.resize (0); + for (int i = 0; i < 5; i++) + tags.push_back (i); + expected = "QMemTags:deadbeef,ff:0001020304"; + create_smemtags_request (packet, 0xdeadbeef, 255, tags); + SELF_CHECK (memcmp (packet.data (), expected.c_str (), + expected.length ()) == 0); +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + void _initialize_remote (); void _initialize_remote () @@ -15017,4 +15101,9 @@ Specify \"unlimited\" to display all the characters."), /* Eventually initialize fileio. See fileio.c */ initialize_remote_fileio (&remote_set_cmdlist, &remote_show_cmdlist); + +#if GDB_SELF_TEST + selftests::register_test ("remote_memory_tagging", + selftests::test_memory_tagging_functions); +#endif } |