GNU Binutils with patches for OS216
Revision | ebd61ee8b5161ded8653c32da0ec57927e1ba9c1 (tree) |
---|---|
Zeit | 2020-06-26 01:23:38 |
Autor | Luis Machado <luis.machado@lina...> |
Commiter | Luis Machado |
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.
@@ -78,6 +78,7 @@ | ||
78 | 78 | #include <algorithm> |
79 | 79 | #include <unordered_map> |
80 | 80 | #include "async-event.h" |
81 | +#include "gdbsupport/selftest.h" | |
81 | 82 | |
82 | 83 | /* The remote target. */ |
83 | 84 |
@@ -14504,6 +14505,89 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, | ||
14504 | 14505 | return 0; |
14505 | 14506 | } |
14506 | 14507 | |
14508 | +#if GDB_SELF_TEST | |
14509 | + | |
14510 | +namespace selftests { | |
14511 | + | |
14512 | +static void | |
14513 | +test_memory_tagging_functions (void) | |
14514 | +{ | |
14515 | + remote_target remote; | |
14516 | + | |
14517 | + struct packet_config *config | |
14518 | + = &remote_protocol_packets[PACKET_memory_tagging_feature]; | |
14519 | + | |
14520 | + /* Test memory tagging packet support. */ | |
14521 | + config->support = PACKET_SUPPORT_UNKNOWN; | |
14522 | + SELF_CHECK (remote.supports_memory_tagging () == false); | |
14523 | + config->support = PACKET_DISABLE; | |
14524 | + SELF_CHECK (remote.supports_memory_tagging () == false); | |
14525 | + config->support = PACKET_ENABLE; | |
14526 | + SELF_CHECK (remote.supports_memory_tagging () == true); | |
14527 | + | |
14528 | + /* Setup testing. */ | |
14529 | + gdb::char_vector packet; | |
14530 | + gdb::byte_vector tags, bv; | |
14531 | + std::string expected, reply; | |
14532 | + packet.resize (32000); | |
14533 | + | |
14534 | + /* Test creating a qMemTags request. */ | |
14535 | + | |
14536 | + expected = "qMemTags:0,0"; | |
14537 | + create_fmemtags_request (packet, 0x0, 0x0); | |
14538 | + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); | |
14539 | + | |
14540 | + expected = "qMemTags:deadbeef,10"; | |
14541 | + create_fmemtags_request (packet, 0xdeadbeef, 16); | |
14542 | + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); | |
14543 | + | |
14544 | + /* Test parsing a qMemTags reply. */ | |
14545 | + | |
14546 | + /* Error reply, tags vector unmodified. */ | |
14547 | + reply = "E00"; | |
14548 | + strcpy (packet.data (), reply.c_str ()); | |
14549 | + tags.resize (0); | |
14550 | + SELF_CHECK (parse_fmemtags_reply (packet, tags) != 0); | |
14551 | + SELF_CHECK (tags.size () == 0); | |
14552 | + | |
14553 | + /* Valid reply, tags vector updated. */ | |
14554 | + tags.resize (0); | |
14555 | + bv.resize (0); | |
14556 | + | |
14557 | + for (int i = 0; i < 5; i++) | |
14558 | + bv.push_back (i); | |
14559 | + | |
14560 | + reply = "m" + bin2hex (bv.data (), bv.size ()); | |
14561 | + strcpy (packet.data (), reply.c_str ()); | |
14562 | + | |
14563 | + SELF_CHECK (parse_fmemtags_reply (packet, tags) == 0); | |
14564 | + SELF_CHECK (tags.size () == 5); | |
14565 | + | |
14566 | + for (int i = 0; i < 5; i++) | |
14567 | + SELF_CHECK (tags[i] == i); | |
14568 | + | |
14569 | + /* Test creating a QMemTags request. */ | |
14570 | + | |
14571 | + /* Empty tag data. */ | |
14572 | + tags.resize (0); | |
14573 | + expected = "QMemTags:0,0:"; | |
14574 | + create_smemtags_request (packet, 0x0, 0x0, tags); | |
14575 | + SELF_CHECK (memcmp (packet.data (), expected.c_str (), | |
14576 | + expected.length ()) == 0); | |
14577 | + | |
14578 | + /* Non-empty tag data. */ | |
14579 | + tags.resize (0); | |
14580 | + for (int i = 0; i < 5; i++) | |
14581 | + tags.push_back (i); | |
14582 | + expected = "QMemTags:deadbeef,ff:0001020304"; | |
14583 | + create_smemtags_request (packet, 0xdeadbeef, 255, tags); | |
14584 | + SELF_CHECK (memcmp (packet.data (), expected.c_str (), | |
14585 | + expected.length ()) == 0); | |
14586 | +} | |
14587 | + | |
14588 | +} // namespace selftests | |
14589 | +#endif /* GDB_SELF_TEST */ | |
14590 | + | |
14507 | 14591 | void _initialize_remote (); |
14508 | 14592 | void |
14509 | 14593 | _initialize_remote () |
@@ -15017,4 +15101,9 @@ Specify \"unlimited\" to display all the characters."), | ||
15017 | 15101 | |
15018 | 15102 | /* Eventually initialize fileio. See fileio.c */ |
15019 | 15103 | initialize_remote_fileio (&remote_set_cmdlist, &remote_show_cmdlist); |
15104 | + | |
15105 | +#if GDB_SELF_TEST | |
15106 | + selftests::register_test ("remote_memory_tagging", | |
15107 | + selftests::test_memory_tagging_functions); | |
15108 | +#endif | |
15020 | 15109 | } |