• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版46650d30740f2be1de65ede159c23f80c9c90fb7 (tree)
时间2020-06-16 21:58:32
作者Luis Machado <luis.machado@lina...>
CommiterLuis Machado

Log Message

Unit tests for memory tagging for gdbserver.

Add some unit testing to exercise the functions handling the qMemTags and
QMemTags packets as well as feature support.

gdbserver/ChangeLog:

YYYY-MM-DD Luis Machado <luis.machado@linaro.org>

* server.cc (test_memory_tagging_functions): New function.
(captured_main): Register test_memory_tagging_functions.

更改概述

差异

--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -3689,6 +3689,91 @@ detach_or_kill_for_exit_cleanup ()
36893689 }
36903690 }
36913691
3692+#if GDB_SELF_TEST
3693+
3694+namespace selftests {
3695+
3696+static void
3697+test_memory_tagging_functions (void)
3698+{
3699+ /* Setup testing. */
3700+ gdb::char_vector packet;
3701+ gdb::byte_vector tags, bv;
3702+ std::string expected;
3703+ packet.resize (32000);
3704+ CORE_ADDR addr;
3705+ size_t len;
3706+
3707+ /* Test parsing a qMemTags request. */
3708+
3709+ /* Invalid request, addr and len unchanged. */
3710+ addr = 0xff;
3711+ len = 255;
3712+ strcpy (packet.data (), "qMemTags_wrong:0,0");
3713+ SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len) != 0);
3714+ SELF_CHECK (addr == 0xff && len == 255);
3715+
3716+ /* Valid request, addr and len updated. */
3717+ addr = 0xff;
3718+ len = 255;
3719+ strcpy (packet.data (), "qMemTags:0,0");
3720+ SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len) == 0);
3721+ SELF_CHECK (addr == 0 && len == 0);
3722+
3723+ /* Valid request, addr and len updated. */
3724+ addr = 0;
3725+ len = 0;
3726+ strcpy (packet.data (), "qMemTags:deadbeef,ff");
3727+ SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len) == 0);
3728+ SELF_CHECK (addr == 0xdeadbeef && len == 255);
3729+
3730+ /* Test creating a qMemTags reply. */
3731+
3732+ /* Non-empty tag data. */
3733+ bv.resize (0);
3734+
3735+ for (int i = 0; i < 5; i++)
3736+ bv.push_back (i);
3737+
3738+ expected = "m0001020304";
3739+ SELF_CHECK (create_fmemtags_reply (packet.data (), bv) == 0);
3740+ SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0);
3741+
3742+ /* Empty tag data (error). */
3743+ bv.clear ();
3744+ SELF_CHECK (create_fmemtags_reply (packet.data (), bv) != 0);
3745+
3746+ /* Test parsing a QMemTags request. */
3747+
3748+ /* Invalid request and non-empty tag data: addr, len and tags unchanged. */
3749+ addr = 0xff;
3750+ len = 255;
3751+ tags.resize (5);
3752+ strcpy (packet.data (), "QMemTags_wrong:0,0:");
3753+ SELF_CHECK (parse_smemtags_request (packet.data (), &addr, &len, tags) != 0);
3754+ SELF_CHECK (addr == 0xff && len == 255 && tags.size () == 5);
3755+
3756+ /* Valid request and empty tag data: addr, len and tags updated. */
3757+ addr = 0xff;
3758+ len = 255;
3759+ tags.resize (5);
3760+ strcpy (packet.data (), "QMemTags:0,0:");
3761+ SELF_CHECK (parse_smemtags_request (packet.data (), &addr, &len, tags) == 0);
3762+ SELF_CHECK (addr == 0 && len == 0 && tags.size () == 0);
3763+
3764+ /* Valid request and non-empty tag data: addr, len and tags updated. */
3765+ addr = 0;
3766+ len = 0;
3767+ tags.resize (0);
3768+ strcpy (packet.data (),
3769+ "QMemTags:deadbeef,ff:0001020304");
3770+ SELF_CHECK (parse_smemtags_request (packet.data (), &addr, &len, tags) == 0);
3771+ SELF_CHECK (addr == 0xdeadbeef && len == 255 && tags.size () == 5);
3772+}
3773+
3774+} // namespace selftests
3775+#endif /* GDB_SELF_TEST */
3776+
36923777 /* Main function. This is called by the real "main" function,
36933778 wrapped in a TRY_CATCH that handles any uncaught exceptions. */
36943779
@@ -3706,6 +3791,9 @@ captured_main (int argc, char *argv[])
37063791 bool selftest = false;
37073792 #if GDB_SELF_TEST
37083793 const char *selftest_filter = NULL;
3794+
3795+ selftests::register_test ("remote_memory_tagging",
3796+ selftests::test_memory_tagging_functions);
37093797 #endif
37103798
37113799 current_directory = getcwd (NULL, 0);