From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by sourceware.org (Postfix) with ESMTPS id A45CC3857015 for ; Wed, 15 Jul 2020 19:46:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A45CC3857015 Received: by mail-qt1-x842.google.com with SMTP id u12so2695582qth.12 for ; Wed, 15 Jul 2020 12:46:44 -0700 (PDT) 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=GOH1OnOMjOJUU7iQFAuuDX6xZTLY1nv8C/FSd3KbdxU=; b=C9VAUt3cPMSZ9/xdm/ZZLJQI5iKj/9oIMpJ0AUFQmoB923wUGgc3d6xijO08PLclSX EZmPLM1tpl9aZaOvUk98I19KO3TGJQfi0lxoRBVB4DgTn0loX1yYp1+2YkKe8X5AArQA C/fQh+c0X107WUUrHAd9qmohryQraXaD91DWSg4TNJtpm6w4SuPqT8984dWOp9V4hDJ5 BcNpww7xFEtF/Vvc7Du666ecCzPAkE8UVqAl2awsMYyBTshyV2BueAeRF4X2UtfD5dtY vWyDFg1KBN9rdEi8ONnX7CQQ2oHm/eg6fCINwvO9xgRImH8qzeDsZ5vbqfGd9/R8NlFX p9Zw== X-Gm-Message-State: AOAM533veNqs5jB8V+YmcgiCgDKYC1LAklPx87VeI0bossY11vON6Eph XiEf61fcCc+752JMRLedgyCxBGDA3JU8Yg== X-Google-Smtp-Source: ABdhPJytFjsRRbIlUlQy9E0oo0RnFQrfArMy66EEcOu40Z53cqRQsxOUCTOkOWfLPtwSpadelf7YuA== X-Received: by 2002:ac8:1baf:: with SMTP id z44mr1555358qtj.129.1594842403931; Wed, 15 Jul 2020 12:46:43 -0700 (PDT) Received: from localhost.localdomain ([2804:7f0:8283:82c3:9daa:7611:ebe6:931]) by smtp.gmail.com with ESMTPSA id z18sm4340537qta.51.2020.07.15.12.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 12:46:43 -0700 (PDT) From: Luis Machado To: gdb-patches@sourceware.org, Alan.Hayward@arm.com Cc: omair.javaid@linaro.org, catalin.marinas@arm.com, david.spickett@linaro.org, jose.marchesi@oracle.com Subject: [PATCH 04/23] Unit testing for GDB-side remote memory tagging handling Date: Wed, 15 Jul 2020 16:44:54 -0300 Message-Id: <20200715194513.16641-5-luis.machado@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200715194513.16641-1-luis.machado@linaro.org> References: <20200715194513.16641-1-luis.machado@linaro.org> X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.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: , X-List-Received-Date: Wed, 15 Jul 2020 19:46:45 -0000 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 7a3f272995..55f3ae0c9d 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -78,6 +78,7 @@ #include #include #include "async-event.h" +#include "gdbsupport/selftest.h" /* The remote target. */ @@ -14516,6 +14517,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 () @@ -15029,4 +15113,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