From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oEZLLbh2qV/WbwAAWB0awg (envelope-from ) for ; Mon, 09 Nov 2020 12:04:56 -0500 Received: by simark.ca (Postfix, from userid 112) id 8E7A61F09B; Mon, 9 Nov 2020 12:04:54 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0365A1F08B for ; Mon, 9 Nov 2020 12:04:54 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B15A53896C0C; Mon, 9 Nov 2020 17:04:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B15A53896C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604941493; bh=d33vK0DeQF79dhXtg8qTBH6r1Xc5H+8sOaeo53BtT84=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=S5LZE+1aFJAurfAfawg9llNeDmYRxcFMzv+LFjiI3PRjc+EFPlfNfpRhR7UcIeOw6 2z2E3b6w0mBkYq/e56ftVxz/yGiYh4PgzegIQd23MqF+8B4PM7jU3lK3NWMccTNNJn M3dNszI/zabeB5N3TIRpv0gXs8SqxCEH8Zah87qc= Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 42BE9385EC57 for ; Mon, 9 Nov 2020 17:04:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 42BE9385EC57 Received: by mail-qk1-x72e.google.com with SMTP id n132so7467441qke.1 for ; Mon, 09 Nov 2020 09:04:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d33vK0DeQF79dhXtg8qTBH6r1Xc5H+8sOaeo53BtT84=; b=R1x8e1OI5DOhZbjV2TPs6N/E4+igpUEa92VzhNHn2hBuRRqraJlKCTClve0vnu5dvm 5z5EaMwy3Jy0/6HdV6SnTxbzqMLJmMH6W38OH7WnazDilM2EqLcrJU3/10rUbIngVsr2 r16AZNTzkGozQVjCyVWOInMdMSRUBkIFsCxtp5z6QXeAQ7oxEreA1fs1s5KeYMYP2AtD GHxBvpIe+0wCR8fOSo0RJh6JFIC9pn/4N1iF2S8QhNVg2Nin2gyFLCWCghe2k9vEyn7F 546/rtjds4QU5ASPyukV3zWVHRX+FyLY8z1442WHQ+iX8xl7fCX2jLSK6dDZgCUYBszI DHJg== X-Gm-Message-State: AOAM532WwGHjCvQ2KNsrklM9KATrbM22qW7qXQLguvFaqsIVig4mh5bx 5IxcFDMCKjlfi26yJwQUaT1ZVXp7IpeeSg== X-Google-Smtp-Source: ABdhPJyGG62XxefQxir1xf67Sfr0D7ushPpvEmNLrOHgDPdQhdEL05EVm3mKimntWoRtvNnagtxa6A== X-Received: by 2002:a37:e311:: with SMTP id y17mr15115294qki.260.1604941491629; Mon, 09 Nov 2020 09:04:51 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:1487:5c3b:b268:ad95:5f37]) by smtp.gmail.com with ESMTPSA id s2sm5948358qtw.44.2020.11.09.09.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 09:04:51 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v3 04/24] Unit testing for GDB-side remote memory tagging handling Date: Mon, 9 Nov 2020 14:04:15 -0300 Message-Id: <20201109170435.15766-5-luis.machado@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109170435.15766-1-luis.machado@linaro.org> References: <20201109170435.15766-1-luis.machado@linaro.org> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: david.spickett@linaro.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 * remote: Include gdbsupport/selftest.h. (test_memory_tagging_functions): New function. (_initialize_remote): Register test_memory_tagging_functions. --- gdb/remote.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index e45eef4bee..6db7a74542 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -79,6 +79,7 @@ #include #include #include "async-event.h" +#include "gdbsupport/selftest.h" /* The remote target. */ @@ -14529,6 +14530,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:0"; + create_fmemtags_request (packet, 0x0, 0x0, 0); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + expected = "qMemTags:deadbeef,10:1"; + create_fmemtags_request (packet, 0xdeadbeef, 16, 1); + 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:0:"; + create_smemtags_request (packet, 0x0, 0x0, 0, 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:1:0001020304"; + create_smemtags_request (packet, 0xdeadbeef, 255, 1, tags); + SELF_CHECK (memcmp (packet.data (), expected.c_str (), + expected.length ()) == 0); +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + void _initialize_remote (); void _initialize_remote () @@ -15042,4 +15126,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 } -- 2.17.1