From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aEDzHb12qV/vbwAAWB0awg (envelope-from ) for ; Mon, 09 Nov 2020 12:05:01 -0500 Received: by simark.ca (Postfix, from userid 112) id 73DA71F08B; Mon, 9 Nov 2020 12:05:01 -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 F00F51F086 for ; Mon, 9 Nov 2020 12:04:59 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3E6A3896C04; Mon, 9 Nov 2020 17:04:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3E6A3896C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604941499; bh=RQ7YCImQM74rlhgI6xU7HW4gY32SU8sR73kPsnSJ3TU=; 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=TPW8kkTExKD4udcnGXkIPX4wVmxGrxRAevvijKL0M6YPHMJ3w1BDD+rely78FMt8n RvElPcdQsXCMK0o1wLwberFsVaonoMvlnk7XA8Hb6vHt9mB2RVr+hbqq7JkYs518pG VzLcIZUaE3Gyxa5NbN8PpvxfM0HxtvjHnALeemPI= 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 9283B3896C04 for ; Mon, 9 Nov 2020 17:04:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9283B3896C04 Received: by mail-qt1-x842.google.com with SMTP id p12so6473260qtp.7 for ; Mon, 09 Nov 2020 09:04:56 -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; bh=RQ7YCImQM74rlhgI6xU7HW4gY32SU8sR73kPsnSJ3TU=; b=SRTrlzWIE3VK446ksiVOO2hgBRIWD8AIrUGkza1YNHPFFknWbCPDKhX9Fg/NnNfJnv PGS9LiwinHi5y7DAusGTndyFMQtoFyw4in4mMYQy5L/672cys7H2M7X6Yu21/TiWDXzb H5bXaA70GgfoexbzhiEKB/FQbXDSwEwGNjhNW670jTFUSQdcZVing3pfLRRDACFeg6IQ r11dgbLZaCSx+HMwQg4w27ohEUIH2Rt0vBXY6vzwMG36zeRJjWgzhoKK+fOpdwgt6Z9B lgJ1ZQk57/KT7f/TUzg68UJ4tP3ZQUzbpcHvniliSJp4IhK+dDkplQOm4kYn2YEyWvRY FI9A== X-Gm-Message-State: AOAM5310iJG3gQo9W8bWoJF0cSnxgzVx9sjG2KOgXMZYFLGJ7l4Tgq+8 D6odRwuq9I83ZUNVnf1wW4KsdV1fvwACTA== X-Google-Smtp-Source: ABdhPJw1NWJqgrG40Vw66kge7V2u2th3IyBCEFfVTnl9bnbPNqqRLIqMGdSEixJC8clgIj+Ni6++Lw== X-Received: by 2002:ac8:594:: with SMTP id a20mr5530936qth.98.1604941495663; Mon, 09 Nov 2020 09:04:55 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:1487:5c3b:b268:ad95:5f37]) by smtp.gmail.com with ESMTPSA id s2sm5948358qtw.44.2020.11.09.09.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 09:04:55 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v3 06/24] Unit tests for gdbserver memory tagging remote packets Date: Mon, 9 Nov 2020 14:04:17 -0300 Message-Id: <20201109170435.15766-7-luis.machado@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201109170435.15766-1-luis.machado@linaro.org> References: <20201109170435.15766-1-luis.machado@linaro.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: , 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" 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 | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 7eddd0e01f..6812b624f8 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3647,6 +3647,103 @@ 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. */ + + /* Invalid request, addr len and type unchanged. */ + addr = 0xff; + len = 255; + type = 255; + strcpy (packet.data (), "qMemTags_wrong:0,0:0"); + SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len, &type) != 0); + SELF_CHECK (addr == 0xff && len == 255 && type == 255); + + /* Valid request, addr, len and type updated. */ + addr = 0xff; + len = 255; + type = 255; + strcpy (packet.data (), "qMemTags:0,0:0"); + SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len, &type) == 0); + 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"); + SELF_CHECK (parse_fmemtags_request (packet.data (), &addr, &len, &type) == 0); + 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_fmemtags_reply (packet.data (), bv) == 0); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + /* Empty tag data (error). */ + bv.clear (); + SELF_CHECK (create_fmemtags_reply (packet.data (), bv) != 0); + + /* Test parsing a QMemTags request. */ + + /* Invalid request and non-empty tag data: addr, len, type and tags + unchanged. */ + addr = 0xff; + len = 255; + type = 255; + tags.resize (5); + strcpy (packet.data (), "QMemTags_wrong:0,0:0:0001020304"); + SELF_CHECK (parse_smemtags_request (packet.data (), &addr, &len, tags, + &type) != 0); + SELF_CHECK (addr == 0xff && len == 255 && type == 255 && tags.size () == 5); + + /* 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_smemtags_request (packet.data (), &addr, &len, tags, + &type) == 0); + 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_smemtags_request (packet.data (), &addr, &len, tags, + &type) == 0); + 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. */ @@ -3664,6 +3761,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.17.1