From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 1FCC53857027 for ; Mon, 22 Mar 2021 13:21:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1FCC53857027 Received: by mail-qk1-x733.google.com with SMTP id v70so10434574qkb.8 for ; Mon, 22 Mar 2021 06:21:41 -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=pk8x4wERTeP78LV8X+iQIqnt90HfIs46L/dTA3jdC6I=; b=EWEuSIw8j9rCkD3koohLDiOx9tFi4sAFz1oMF+PIkOKoEn0JBV3uRnN7h0HMgaToXf 90geY6GH9LH1Ha9CvuvCaUSQHzQE44rcAw8BkTsK0U3hKYzCPBzqcHmATRiUQXXzhtlh P4NgQMOm2cBO2AcI378eNUfhIZ2+qsHfCKICmmjWGN1V8Hg2dobJe5czqEA/XTMyDNJ1 ZtM4lXtjk30CE9LbqDdqOaGQ3TEgBtQMTl5OMFhbvOjKON+GLZvNUidzhNSEVl+wk00f FskdiZmElAwtI7esgdsU2q/sDbD5vwHgL1kZjYLaEwQqPXPvVAxjzzV3aaS0re0kxp6L VuTQ== X-Gm-Message-State: AOAM530cCLLH3k3xLy+yns8OMP6K4m/eINxjPfn8LF/fMdMa2UsrdRfq rBryE2G+hG2TNWfoCXUlCsZvGygrEacKaQ== X-Google-Smtp-Source: ABdhPJwQ4lLkAMWAGyYmdq2+Ygrkd65x1GozmisNGdjc4DBgJGyS/P78LAUXp4tr3IrqKXE8dxUkjQ== X-Received: by 2002:ae9:e884:: with SMTP id a126mr10739561qkg.444.1616419300670; Mon, 22 Mar 2021 06:21:40 -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.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 06:21:40 -0700 (PDT) From: Luis Machado To: gdb-patches@sourceware.org Subject: [PATCH v6 06/25] Unit tests for gdbserver memory tagging remote packets Date: Mon, 22 Mar 2021 10:21:00 -0300 Message-Id: <20210322132120.1202230-7-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.4 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:42 -0000 Updates on v4: - Assert on invalid packet request instead of just returning an error code. Updates on v2: - Update unit tests to cope with additional tag type field in the remote packets. -- Add some unit testing to exercise the functions handling the qMemTags and QMemTags packets as well as feature support. gdbserver/ChangeLog: YYYY-MM-DD Luis Machado * server.cc (test_memory_tagging_functions): New function. (captured_main): Register test_memory_tagging_functions. --- gdbserver/server.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 5887133390a..fd5e7808363 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3653,6 +3653,81 @@ detach_or_kill_for_exit_cleanup () } } +#if GDB_SELF_TEST + +namespace selftests { + +static void +test_memory_tagging_functions (void) +{ + /* Setup testing. */ + gdb::char_vector packet; + gdb::byte_vector tags, bv; + std::string expected; + packet.resize (32000); + CORE_ADDR addr; + size_t len; + int type; + + /* Test parsing a qMemTags request. */ + + /* Valid request, addr, len and type updated. */ + addr = 0xff; + len = 255; + type = 255; + strcpy (packet.data (), "qMemTags:0,0:0"); + parse_fetch_memtags_request (packet.data (), &addr, &len, &type); + SELF_CHECK (addr == 0 && len == 0 && type == 0); + + /* Valid request, addr, len and type updated. */ + addr = 0; + len = 0; + type = 0; + strcpy (packet.data (), "qMemTags:deadbeef,ff:5"); + parse_fetch_memtags_request (packet.data (), &addr, &len, &type); + SELF_CHECK (addr == 0xdeadbeef && len == 255 && type == 5); + + /* Test creating a qMemTags reply. */ + + /* Non-empty tag data. */ + bv.resize (0); + + for (int i = 0; i < 5; i++) + bv.push_back (i); + + expected = "m0001020304"; + SELF_CHECK (create_fetch_memtags_reply (packet.data (), bv) == true); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + /* Test parsing a QMemTags request. */ + + /* Valid request and empty tag data: addr, len, type and tags updated. */ + addr = 0xff; + len = 255; + type = 255; + tags.resize (5); + strcpy (packet.data (), "QMemTags:0,0:0:"); + SELF_CHECK (parse_store_memtags_request (packet.data (), + &addr, &len, tags, &type) == true); + SELF_CHECK (addr == 0 && len == 0 && type == 0 && tags.size () == 0); + + /* Valid request and non-empty tag data: addr, len, type + and tags updated. */ + addr = 0; + len = 0; + type = 0; + tags.resize (0); + strcpy (packet.data (), + "QMemTags:deadbeef,ff:5:0001020304"); + SELF_CHECK (parse_store_memtags_request (packet.data (), &addr, &len, tags, + &type) == true); + SELF_CHECK (addr == 0xdeadbeef && len == 255 && type == 5 + && tags.size () == 5); +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + /* Main function. This is called by the real "main" function, wrapped in a TRY_CATCH that handles any uncaught exceptions. */ @@ -3670,6 +3745,9 @@ captured_main (int argc, char *argv[]) bool selftest = false; #if GDB_SELF_TEST std::vector selftest_filters; + + selftests::register_test ("remote_memory_tagging", + selftests::test_memory_tagging_functions); #endif current_directory = getcwd (NULL, 0); -- 2.25.1