From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1585) id 214AB3849AD9; Fri, 19 Apr 2024 14:31:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 214AB3849AD9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713537093; bh=Po4H8f98+wO06itBY+MrPcCmOFlPswtKHUDOtDX2uMc=; h=From:To:Subject:Date:From; b=KzmQmcvpYQMzgIhcZ8TxbyMPsWMCMApVh/CiaWD6pkk9giKkO4cAw6RJlxDxEiz9K M5Q9nwSHrpcxMIW1HH5fr0eE/ZEEjZwnGfjW1y3B2oXOca3BbO19hNH6oOB9HP6olk qtjjbR/ZkG3f/GdbhvnO+cTYxXtElPoYY9OkN+Fk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Luis Machado To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: Add unit tests for qIsAddressTagged packet X-Act-Checkin: binutils-gdb X-Git-Author: Gustavo Romero X-Git-Refname: refs/heads/master X-Git-Oldrev: c040e0b107ca023b434746719d83bc9a3ad94276 X-Git-Newrev: 648a8c6168fac3332f4d67ef0266bdb6917eb6be Message-Id: <20240419143133.214AB3849AD9@sourceware.org> Date: Fri, 19 Apr 2024 14:31:33 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D648a8c6168fa= c3332f4d67ef0266bdb6917eb6be commit 648a8c6168fac3332f4d67ef0266bdb6917eb6be Author: Gustavo Romero Date: Thu Apr 18 20:10:38 2024 +0000 gdb/testsuite: Add unit tests for qIsAddressTagged packet =20 Add unit tests for testing qIsAddressTagged packet request creation and reply checks. =20 Signed-off-by: Gustavo Romero Approved-By: Luis Machado Tested-By: Luis Machado Diff: --- gdb/remote.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 67 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 3d034bb1ef8..cfb54de157d 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -15682,6 +15682,8 @@ test_memory_tagging_functions () scoped_restore restore_memtag_support_ =3D make_scoped_restore (&config->support); =20 + struct gdbarch *gdbarch =3D current_inferior ()->arch (); + /* Test memory tagging packet support. */ config->support =3D PACKET_SUPPORT_UNKNOWN; SELF_CHECK (remote.supports_memory_tagging () =3D=3D false); @@ -15748,6 +15750,71 @@ test_memory_tagging_functions () create_store_memtags_request (packet, 0xdeadbeef, 255, 1, tags); SELF_CHECK (memcmp (packet.data (), expected.c_str (), expected.length ()) =3D=3D 0); + + /* Test creating a qIsAddressTagged request. */ + expected =3D "qIsAddressTagged:deadbeef"; + create_is_address_tagged_request (gdbarch, packet, 0xdeadbeef); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) =3D=3D 0); + + /* Test error reply on qIsAddressTagged request. */ + reply =3D "E00"; + strcpy (packet.data (), reply.c_str ()); + /* is_tagged must not change, hence it's tested too. */ + bool is_tagged =3D false; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + false); + SELF_CHECK (is_tagged =3D=3D false); + + /* Test 'tagged' as reply. */ + reply =3D "01"; + strcpy (packet.data (), reply.c_str ()); + /* Because the byte is 01, is_tagged should be set to true. */ + is_tagged =3D false; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + true); + SELF_CHECK (is_tagged =3D=3D true); + + /* Test 'not tagged' as reply. */ + reply =3D "00"; + strcpy (packet.data (), reply.c_str ()); + /* Because the byte is 00, is_tagged should be set to false. */ + is_tagged =3D true; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + true); + SELF_CHECK (is_tagged =3D=3D false); + + /* Test an invalid reply (neither 00 nor 01). */ + reply =3D "04"; + strcpy (packet.data (), reply.c_str ()); + /* Because the byte is invalid is_tagged must not change. */ + is_tagged =3D false; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + false); + SELF_CHECK (is_tagged =3D=3D false); + + /* Test malformed reply of incorrect length. */ + reply =3D "0104A590001234006"; + strcpy (packet.data (), reply.c_str ()); + /* Because this is a malformed reply is_tagged must not change. */ + is_tagged =3D false; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + false); + SELF_CHECK (is_tagged =3D=3D false); + + /* Test empty reply. */ + reply =3D ""; + strcpy (packet.data (), reply.c_str ()); + /* is_tagged must not change, hence it's tested too. */ + is_tagged =3D true; + /* On the previous tests, qIsAddressTagged packet was auto detected and = set + as supported. But an empty reply means the packet is unsupported, so= for + testing the empty reply the support is reset to unknown state, otherw= ise + packet_ok will complain. */ + remote.m_features.m_protocol_packets[PACKET_qIsAddressTagged].support =3D + PACKET_SUPPORT_UNKNOWN; + SELF_CHECK (check_is_address_tagged_reply (&remote, packet, is_tagged) = =3D=3D + false); + SELF_CHECK (is_tagged =3D=3D true); } =20 static void