From patchwork Fri Mar 1 16:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Orlov X-Patchwork-Id: 1906760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=knkGmuti; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Sb9I3Mlp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TmXrh6PvJz23hc for ; Sat, 2 Mar 2024 03:01:24 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jffvO2CIITc02y79c8+76xv8XmP5YOw5vME3NUbSmKY=; b=knkGmuti6ywdfY iICA/I+N+OAQV2gc/pmR7kNlQmAbl0oLq42AuemKhBuhuruCYxiGtvR1BDoAvoJLQI2dZqKIajOC4 mrMp+lKnG+JoyQpxtEMWNIbbHVnZxWCSeuGpn3l7xHFJ0HThjlAWV7xMonr+zy8DDGjrWt6KPNA+b qhwGcooUr3BWwuTPpc3pVbgIQa710gaFmkS6kmJPsUxrWwvuSPOswULnX7TEuCApmYiTD7yJm8ivs RezmWLj+7FL1G9yhwoT8A6PzCPxTnojyF4YTwwVX9TUSYsg+q5TJVUGBCMDPkfgpbTLj3oAkWEl9B R7Ts/WQM4ZfHhHjJoBIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rg5K1-0000000103Y-0W3F; Fri, 01 Mar 2024 16:01:17 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rg5Jy-0000000100P-0Whc for opensbi@lists.infradead.org; Fri, 01 Mar 2024 16:01:15 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-412ae6392f0so2772265e9.1 for ; Fri, 01 Mar 2024 08:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709308869; x=1709913669; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3sxv3Sm6gFLbsb858IpXmS8/DPDuC2z4MgH3wIns0Ws=; b=Sb9I3Mlp3rXnIhM0bkNuZNQtsWAKJodJqMfZW0VBnGDoHxdhe5Xvw5uVGlhj1CLqYp 9hU5tGufoAThy26JBhqZx64fN/nRz/1QMfHjaffCljd5J0RxuMI+a/6RfwA8hfHid2km oxpoEjekHHIxxz5o/Dy4j/ULmcTJABOov4Uc7J/XQ2djbszA3b10cB9z0EnJ90jBl80e 2DlWUdZ/S8zfoNHll/M5qE6JfQ8T99OwiwAegej0X57s8UH0PJs1ayHmMEBmVIUqcogX BhMhmH65XzxsVfesG2xigBFRBzweuGiAhRd13WYhJn9kRod23a8q69qqSxQzEdJ6D5Lp NLjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709308869; x=1709913669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3sxv3Sm6gFLbsb858IpXmS8/DPDuC2z4MgH3wIns0Ws=; b=jSNRbBDYpdlKksr5RMsRl0N8NUy/357ujROYpNcypMLoUDBOTy6GuVDy2UigYb6DzP myqJI6C6RFIyVee0K46LptD1F+KK7y4dqwdbPZIoswqTZjWPwo7wt2xq+WnO5StelJ2/ K3spQTcseh+/ZTzi33p+UXUGGDj/5xKiVl9qXM0jwjpdVBObC5ontWe32Oeyrn2FmLQj KvDVQDT4kUHLcL9TOXgESSx0swUE6crrYvtpjKiL7FK4Wzz2OZBYNbXfOeRXKwSaceC4 jqwxnKLHknA96OlarKkv4bnx2F2FShJ5BiY+JlqYHkWOmTJP0thiVg2OSiW+ri3QsKgb x4Xg== X-Forwarded-Encrypted: i=1; AJvYcCXO2hayw2cs4yAHgrSp1h96j6wskEZdtr9WzPOCTBhTO8d4DJAx6aGCiEjQZt4sJEjLvG417oimUB7WvZhM2XyZ9+XCjA0NSWnl8No= X-Gm-Message-State: AOJu0Yx/5Swwxnb2UxOj0qKAJnD3Nq96/yIrzxZYzhtVMrEwhHIGU/aE NOh4kX9WuptIfzNDsgJ7/NWos6Uv+4gbLd0riQek0st5pOoyhR5W X-Google-Smtp-Source: AGHT+IEeZVh18foRnl4F1GjuKiFqNRv4T0p2s7tzOOufRKGssf9lYD2HP1J/EzJYiwM77wtKIR0gnw== X-Received: by 2002:a05:600c:3b26:b0:412:a1c1:2d9f with SMTP id m38-20020a05600c3b2600b00412a1c12d9fmr1708779wms.1.1709308868984; Fri, 01 Mar 2024 08:01:08 -0800 (PST) Received: from ivan-HLYL-WXX9.guest.codethink.co.uk ([167.98.27.226]) by smtp.gmail.com with ESMTPSA id s16-20020a05600c45d000b00412b67388f0sm8133175wmo.6.2024.03.01.08.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 08:01:07 -0800 (PST) From: Ivan Orlov To: anup@brainfault.org, ajones@ventanamicro.com Cc: Ivan Orlov , opensbi@lists.infradead.org Subject: [PATCH v3 3/4] lib: tests: Add a test for sbi_bitmap Date: Fri, 1 Mar 2024 16:00:44 +0000 Message-Id: <20240301160046.267814-4-ivan.orlov0322@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301160046.267814-1-ivan.orlov0322@gmail.com> References: <20240301160046.267814-1-ivan.orlov0322@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240301_080114_191189_CDAE2747 X-CRM114-Status: GOOD ( 16.40 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add test suite covering all of the functions from lib/sbi/sbi_bitmap.c: __bitmap_and, __bitmap_or and __bitmap_xor. Signed-off-by: Ivan Orlov --- V1 -> V2: - Extract the part of the commit description to the cover letter - Update to use the carray functionality instead of placing the pointer to the test suite dir [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:331 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ivan.orlov0322(at)gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [ivan.orlov0322(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add test suite covering all of the functions from lib/sbi/sbi_bitmap.c: __bitmap_and, __bitmap_or and __bitmap_xor. Signed-off-by: Ivan Orlov Reviewed-by: Andrew Jones --- V1 -> V2: - Extract the part of the commit description to the cover letter - Update to use the carray functionality instead of placing the pointer to the test suite directly into the sources - Fix codestyle issues - Use the references to the data_* arrays when defining the expected test results, instead of repeating the same numbers again and again V2 -> V3: - Use the SBIUNIT_END_CASE macro in the test cases list instead of '{}' - Remove redundant 'include' statement lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_bitmap_test.c | 102 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 lib/sbi/sbi_bitmap_test.c diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 08959f1..b4c273f 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -14,6 +14,9 @@ libsbi-objs-y += riscv_locks.o libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o +libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite + libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.o diff --git a/lib/sbi/sbi_bitmap_test.c b/lib/sbi/sbi_bitmap_test.c new file mode 100644 index 0000000..2563934 --- /dev/null +++ b/lib/sbi/sbi_bitmap_test.c @@ -0,0 +1,102 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Author: Ivan Orlov + */ +#include +#include + +#define DATA_SIZE sizeof(data_zero) +#define DATA_BIT_SIZE (DATA_SIZE * 8) + +static u64 data_a[] = { 0xDEADBEEF, 0x00BAB10C, 0x1BADB002, 0xABADBABE }; +static u64 data_b[] = { 0xC00010FF, 0x00BAB10C, 0xBAAAAAAD, 0xBADDCAFE }; +static u64 data_zero[] = { 0, 0, 0, 0 }; + +static void bitmap_and_test(struct sbiunit_test_case *test) +{ + u64 res[DATA_SIZE]; + u64 a_and_b[] = { data_a[0] & data_b[0], data_a[1] & data_b[1], + data_a[2] & data_b[2], data_a[3] & data_b[3] }; + + __bitmap_and(res, data_a, data_b, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, a_and_b, DATA_SIZE); + + /* a & a = a */ + __bitmap_and(res, data_a, data_a, DATA_BIT_SIZE); + SBIUNIT_ASSERT_MEMEQ(test, res, data_a, DATA_SIZE); + + /* a & 0 = 0 */ + __bitmap_and(res, data_a, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); + + /* 0 & 0 = 0 */ + __bitmap_and(res, data_zero, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); + + sbi_memcpy(res, data_zero, DATA_SIZE); + /* Cover zero 'bits' argument */ + __bitmap_and(res, data_a, data_b, 0); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); +} + +static void bitmap_or_test(struct sbiunit_test_case *test) +{ + u64 res[DATA_SIZE]; + u64 a_or_b[] = { data_a[0] | data_b[0], data_a[1] | data_b[1], + data_a[2] | data_b[2], data_a[3] | data_b[3] }; + + __bitmap_or(res, data_a, data_b, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, a_or_b, DATA_SIZE); + + /* a | a = a */ + __bitmap_or(res, data_a, data_a, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_a, DATA_SIZE); + + /* a | 0 = a */ + __bitmap_or(res, data_a, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_a, DATA_SIZE); + + /* 0 | 0 = 0 */ + __bitmap_or(res, data_zero, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); + + sbi_memcpy(res, data_zero, DATA_SIZE); + __bitmap_or(res, data_a, data_b, 0); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); +} + +static void bitmap_xor_test(struct sbiunit_test_case *test) +{ + u64 res[DATA_SIZE]; + u64 a_xor_b[] = { data_a[0] ^ data_b[0], data_a[1] ^ data_b[1], + data_a[2] ^ data_b[2], data_a[3] ^ data_b[3] }; + + __bitmap_xor(res, data_a, data_b, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, a_xor_b, DATA_SIZE); + + /* a ^ 0 = a */ + __bitmap_xor(res, data_a, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_a, DATA_SIZE); + + /* a ^ a = 0 */ + __bitmap_xor(res, data_a, data_a, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); + + /* 0 ^ 0 = 0 */ + __bitmap_xor(res, data_zero, data_zero, DATA_BIT_SIZE); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); + + sbi_memcpy(res, data_zero, DATA_SIZE); + __bitmap_xor(res, data_a, data_b, 0); + SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); +} + +static struct sbiunit_test_case bitmap_test_cases[] = { + SBIUNIT_TEST_CASE(bitmap_and_test), + SBIUNIT_TEST_CASE(bitmap_or_test), + SBIUNIT_TEST_CASE(bitmap_xor_test), + SBIUNIT_END_CASE, +}; + +SBIUNIT_TEST_SUITE(bitmap_test_suite, bitmap_test_cases);