From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gJLHG07LEWA2TwAAWB0awg (envelope-from ) for ; Wed, 27 Jan 2021 15:21:34 -0500 Received: by simark.ca (Postfix, from userid 112) id 6F1ED1EF84; Wed, 27 Jan 2021 15:21:34 -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 E884A1EF7A for ; Wed, 27 Jan 2021 15:21:32 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A0DC398B82D; Wed, 27 Jan 2021 20:21:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A0DC398B82D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611778892; bh=CMF9WDtmGsAhtua0XLo1EwulUGSdTaUGpu15ydbzFNw=; 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=RbGMQNrVKepTyE2bnj/ghKA3QlpJ7Wz8b9eVE2eo3rFLuGx2T0WCif8D4PfyRQxQO l/mw91XhE6q9t+EPB75tu9JKqOHMD29zhT++74hmt2zGxLSP5b8ZN4MB1giJSB4KDQ jb3ItNREBmdZkDUUFi1gGiK0fWiUc3AOu9Ipyk38= Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id E06F5398B827 for ; Wed, 27 Jan 2021 20:21:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E06F5398B827 Received: by mail-qv1-xf2d.google.com with SMTP id es14so1733097qvb.3 for ; Wed, 27 Jan 2021 12:21:29 -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=CMF9WDtmGsAhtua0XLo1EwulUGSdTaUGpu15ydbzFNw=; b=XlxOnvbKuKV8qAnNs5qNWss9kNvjX/crd7uU+gexkC6v0NhdZd1iF92rrNGaOYYbjT h5cYzh+EXzlQ7KBZSLse/de/VF/Diyoo53pfMydmCHYWS3HtYiiaodU1TvuXP5nNA93Y tBVlz94JtBRKVRa2f3oy2AumouclGqoac2g9LM+eA4mJ2QIG0YoVCBvEDK866TNYGhWt m236GD6EDYssROdSgsD8rQ3GMUlsPgC0wMbgu6qLb3ws6iKhSuwoDTv4+f/Qcfn2ZWFf 4zuY0tKxRmxTQN3LgNcTJNwXVt1AVrKyCHTBBhCoa2Bb3OuvNteHg0TpLKaxzCWOnuS0 gD6A== X-Gm-Message-State: AOAM531aIo2CcKbr6spW87FsLLrnt/VbnxUVORxikuCtSGR4cOipkUQ5 I50XOFu/T8iWLORaO0Lo8V/S7PADu8Cmag== X-Google-Smtp-Source: ABdhPJxooxcB1m7PSnEpgdbJDaqS3l1Lhej8f9YGXs1tucLDaD9XXxLppy2su2z4/qdS7X6R9kjGAQ== X-Received: by 2002:a05:6214:725:: with SMTP id c5mr12224873qvz.27.1611778889476; Wed, 27 Jan 2021 12:21:29 -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.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 12:21:29 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v5 06/25] Unit tests for gdbserver memory tagging remote packets Date: Wed, 27 Jan 2021 17:20:53 -0300 Message-Id: <20210127202112.2485702-7-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" 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 69635742a8..700db0f7d8 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3644,6 +3644,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. */ @@ -3661,6 +3736,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