From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kE+EN1PLEWA2TwAAWB0awg (envelope-from ) for ; Wed, 27 Jan 2021 15:21:39 -0500 Received: by simark.ca (Postfix, from userid 112) id CA89C1EF88; Wed, 27 Jan 2021 15:21:39 -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 609A61EF7A for ; Wed, 27 Jan 2021 15:21:37 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64C8E398B830; Wed, 27 Jan 2021 20:21:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64C8E398B830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611778896; bh=coBsa2ZLxJ31EfXVQdHNFdE0PffzPCFx0uJLaJd6mRU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=b54ZY96ozWWfh9WqUkVfBOgdMDmGVeha7w3Y/jSGH6CWMGBOWoR5WeT6Y+7vYOom9 78U6hFXxaQ0AKrKv1kIC2dMhuuPukBzuGUtTqC5UgKAlz/V2lVV6EGcu0hh1bScAEy JBU4fDHDTqNuSYazsvL6bFx8B3PSXgtNRt7qHM18= Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id E1744398B827 for ; Wed, 27 Jan 2021 20:21:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E1744398B827 Received: by mail-qt1-x82a.google.com with SMTP id v3so2433939qtw.4 for ; Wed, 27 Jan 2021 12:21: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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=coBsa2ZLxJ31EfXVQdHNFdE0PffzPCFx0uJLaJd6mRU=; b=haoZU3gLV0iBg494ekAYiCq2WTXNuZ/GO+K1A7uaFbvmvqdir3YdZxD5X2btAu9uox GZJKTOf5izzlfhDgf2pMDX4amXQiLaTj8DLMlF3pCfS3IMoZxTpptpr4XjWbJrcvtcxw fKft8xyZA7GT//uZWcSUvONrGwMmpRfuDJEQkPq/yASMuOGD2/Os0Y7ME7LgHdhg0AUE gdbMyjvg77zqVChDSge7adPIkLIu+W2WR6mtaeQUe1QK/2pUU+oBC2bA+NbtcXlCfGr+ /e3mjQ10Wvk+IxXCOpKze4YoGulSuuLV7PNv/ecafS2I+1uWDJzTdpbf1ejKxYU3qtmq K8SQ== X-Gm-Message-State: AOAM530RE5Uy4gIfTS7dAZ+mBHHOi5a3LYdFq28F5hx4thi8VsEUowjU HKabQ3Qz+Mwxw9JunGeXMiHAC1IqqjQz2A== X-Google-Smtp-Source: ABdhPJz3jk0Os1WVZm/WaXcuqNN+c4nDwh4jPhQUWiyHqD7a0kW4mgsj/yMj1V3r+5WKKd+slhLkRQ== X-Received: by 2002:ac8:5992:: with SMTP id e18mr11469151qte.177.1611778886579; Wed, 27 Jan 2021 12:21:26 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:874d:b82c:87fc:4324:adab]) by smtp.gmail.com with ESMTPSA id b194sm1854531qkc.102.2021.01.27.12.21.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 12:21:25 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v5 04/25] Unit testing for GDB-side remote memory tagging handling Date: Wed, 27 Jan 2021 17:20:51 -0300 Message-Id: <20210127202112.2485702-5-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127202112.2485702-1-luis.machado@linaro.org> References: <20210127202112.2485702-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 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 bb3473b04c..22cae2a94f 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. */ @@ -14603,6 +14604,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 () @@ -15136,4 +15224,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