From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id CFB893857828 for ; Mon, 22 Mar 2021 13:21:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CFB893857828 Received: by mail-qk1-x72d.google.com with SMTP id z10so10422801qkz.13 for ; Mon, 22 Mar 2021 06:21:37 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oy/d5Eb4U2Qq0uSiuQgzgSw16rGBMbC4jx+1P1yfC78=; b=n01CnbCObpWUUZknzTAUCOdRd+Vobb4NzJn1HcmHrYJ44UWgD4g2udTeFkEyzh/sqm N3lZQLhqAqSnsD+NvIVi+Qbdn9zemMZKPs7gNV2JpvdHkmpChhdBkmYE5LorwvsbKqBh v4xQgyLuuF5AZNAL6BTEyF3//1xP8jgTJaP874VeuoMGqaVl4JZ1n5+NuqdevVKieGfC 9Q7P03mGPCw/w1QK8i43X6Dv9vIRqY30VWzPRW0W6cK6OuIT1J58FASDvokoxeD1AHVn EC1XQ/lUVzavJtc5CqmUCw9G6f4keTP4tlzyBzD3ooTdg76ZT1Ru0FxkJBLFn7qlfrWy E1+A== X-Gm-Message-State: AOAM533OjxljNWun9dWJFyVO6KgkmhrBmrbYkR/nufUd3U+cxGO1aPnw Kh8+raxjRrHXPhdpMPzDncH+hSlZIiQoDA== X-Google-Smtp-Source: ABdhPJxdnSxNmrDYjUBFBNJkJUsgapsXJZLEzag1LP6Q/ElYBPoTFLK8EootusJM4zefN/m6BWteqw== X-Received: by 2002:a37:a603:: with SMTP id p3mr10763951qke.362.1616419297315; Mon, 22 Mar 2021 06:21:37 -0700 (PDT) Received: from localhost.localdomain ([2804:7f0:4841:2841:2c21:ec8a:30f3:55a6]) by smtp.gmail.com with ESMTPSA id r35sm7364575qtd.95.2021.03.22.06.21.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 06:21:37 -0700 (PDT) From: Luis Machado To: gdb-patches@sourceware.org Subject: [PATCH v6 04/25] Unit testing for GDB-side remote memory tagging handling Date: Mon, 22 Mar 2021 10:20:58 -0300 Message-Id: <20210322132120.1202230-5-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210322132120.1202230-1-luis.machado@linaro.org> References: <20210322132120.1202230-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.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: Mon, 22 Mar 2021 13:21:39 -0000 Updates in v6: - Adjust scope restoration call. 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 | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 5131d78747f..ac7c50b57ea 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. */ @@ -14620,6 +14621,92 @@ 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); + + /* 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 () @@ -15153,4 +15240,9 @@ from the target."), /* 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