From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6BoPKjqf7F8ACwAAWB0awg (envelope-from ) for ; Wed, 30 Dec 2020 10:39:38 -0500 Received: by simark.ca (Postfix, from userid 112) id A9A131E965; Wed, 30 Dec 2020 10:39:38 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 97B981E965 for ; Wed, 30 Dec 2020 10:39:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E64DC388C023; Wed, 30 Dec 2020 15:39:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E64DC388C023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609342774; bh=SqtNmK+SvDNdUP9GBvWCgTGbYpmznfLkC6sQrD5YkGk=; 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=pRgjy4usohJyKrEDoJIN6Vd2/YpvroRrIhbFJG7geoJQOWIQgqQkGlJ+B5NgL7vG8 E+bGiIYJLeKgMmczD2eZf0oTvn9k4EtxiLPt0iSWOgRtIS4hF8rbCMqazGwTTEg6He KHDSJqhKUv8VlQFJ0yveXBE+r6LF9qGBzcUtbUwY= Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 2E56A388C01C for ; Wed, 30 Dec 2020 15:39:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2E56A388C01C Received: by mail-qk1-x731.google.com with SMTP id f26so14230422qka.0 for ; Wed, 30 Dec 2020 07:39:31 -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:mime-version:content-transfer-encoding; bh=SqtNmK+SvDNdUP9GBvWCgTGbYpmznfLkC6sQrD5YkGk=; b=bnvNxuuMbUA7qy2uBEBXCtWPxVUZz9USIzyscOYSMvNxUGAUNdOEAmlDD7z/jyVywm 0iNIniDHuvcPdxO/dxH5ANZBwCgwiFHgBPtNBV94iAzpeQwLuRkY3+m2u9jRUM5dcLRX aCKoVnTf8oJZ0yCgWRNje32QF9XRNq8gxE3yxzDpk7Nnkc1TPKVe/8kvXnzFZovCJyFM 4PR+Zv1fSGfgGDO9zUoYPXTfT9JUccuQV4I7/O9uKB1UAyqsPbSNsZKJf+kkM+oKIUba dw1EAtHhSf4ZtqUPbMJTMEgUqdoac6hRVt/Bv5czVmXIj4F2o42Vu3n9L/Oa8SC3Tczv M3Vg== X-Gm-Message-State: AOAM531/zx9Z3qo7gHGaj7yYd2mjhKdQEIdLfSf18sIDxnB8efhadz78 e1JMk1nA0E/s/mBDgenVjQLxI2tHUdK7QA== X-Google-Smtp-Source: ABdhPJztlnffaBOO/phVyvAxfNlWdTOMrSBS4Kc0yGKY8uKlFYExqNpNH2HwQdk+f+UsiJ57Qa5ZHA== X-Received: by 2002:a37:a8c4:: with SMTP id r187mr52169194qke.481.1609342770594; Wed, 30 Dec 2020 07:39:30 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:370e:c9ba:c4ec:737b:57da]) by smtp.gmail.com with ESMTPSA id f6sm28589336qkh.2.2020.12.30.07.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:39:30 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v4 04/25] Unit testing for GDB-side remote memory tagging handling Date: Wed, 30 Dec 2020 12:38:55 -0300 Message-Id: <20201230153916.1586725-5-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230153916.1586725-1-luis.machado@linaro.org> References: <20201230153916.1586725-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 v4: - Renamed functions based on reviews. - Adjusted code to cope with bool return value. - Restoring of global setting after unit testing. 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 | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 77e3ecca86..39c12a9e24 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. */ @@ -14520,6 +14521,93 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, return packet_check_result (rs->buf.data ()) == PACKET_OK; } +#if GDB_SELF_TEST + +namespace selftests { + +static void +test_memory_tagging_functions () +{ + remote_target remote; + + struct packet_config *config + = &remote_protocol_packets[PACKET_memory_tagging_feature]; + + scoped_restore restore_memtag_support_ + = make_scoped_restore (&config->support, + config->support); + + /* 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_fetch_memtags_request (packet, 0x0, 0x0, 0); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + expected = "qMemTags:deadbeef,10:1"; + create_fetch_memtags_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_fetch_memtags_reply (packet, tags) == false); + 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_fetch_memtags_reply (packet, tags) == true); + 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_store_memtags_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_store_memtags_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 () @@ -15033,4 +15121,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.25.1