From patchwork Mon Jul 1 02:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DongdongZhang X-Patchwork-Id: 1954471 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=3CIYF0rB; 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 4WC9542p8Cz1xpP for ; Mon, 1 Jul 2024 12:30:48 +1000 (AEST) 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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=A6LHXAFUi845O3kE+evPJ6UZrBH0h0uu/YwwLwbrVTA=; b=3CIYF0rBJ3ZaPs /PlwSD9IE1SFILnyYZ1BtyJE5JFuLe32nPvY1oYYTAm3C9ZBo4H+lSl1aayVP9disHNV5Y7wOFiLA o2RvBH2DpBRPn+dUSQpDUXbVwH8xxYKtx8LuIbNoZd/7VAlxtyZqmgd5cwRz+jGxSCJBd66O4Fcga LrWQw6Aykf+O9DA+nb73kffOJL9YGGXS135LrOgMO3xSfZsJSNjHwGgEcmnEaMbLGk4/Ozk4HrDjy 9eU8TM0TVflp3QbSc11XHv6R72uavCQbX+X1LvjCsc9XOpiSWp1XIYK9WjwzvYHSLzqWn2xfLKF7G 2YuUHZZ336fx9pk4Le3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sO6oT-00000001TQ4-4BM3; Mon, 01 Jul 2024 02:30:42 +0000 Received: from azure-sdnproxy.icoremail.net ([52.237.72.81]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sO6oQ-00000001TOJ-2Pr9 for opensbi@lists.infradead.org; Mon, 01 Jul 2024 02:30:40 +0000 Received: from ubuntu18.eswin.cn (unknown [10.12.192.173]) by app1 (Coremail) with SMTP id TAJkCgA3zOO9FIJmwMQSAA--.2245S5; Mon, 01 Jul 2024 10:30:26 +0800 (CST) From: zhangdongdong@eswincomputing.com To: opensbi@lists.infradead.org Cc: zhangdongdong@eswincomputing.com Subject: [PATCH 1/1] lib:tests: add math test suite Date: Mon, 1 Jul 2024 10:30:06 +0800 Message-Id: <20240701023006.16977-2-zhangdongdong@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240701023006.16977-1-zhangdongdong@eswincomputing.com> References: <20240701023006.16977-1-zhangdongdong@eswincomputing.com> X-CM-TRANSID: TAJkCgA3zOO9FIJmwMQSAA--.2245S5 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr45WFW7Kr1UCFWkJr4UCFg_yoW5JrW8pa s3GF4Ykw4kXa4xJ3s3Ga4vgF93Aan5Zry7Arya9w1jy3WkJay8tF47KrW3Jr13JrWUZF45 C3WrXry5W3W5ZFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBC14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE 2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4 x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E 0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67 AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48I cxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwAKzVCY07xG64k0F24lc2xSY4AK6s vPMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWU JVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUOku4UUUUU X-CM-SenderInfo: x2kd0wpgrqwvxrqjqvxvzl0uprps33xlqjhudrp/1tbiAQEFCmaBJnAexAADsn X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240630_193039_094733_72904E28 X-CRM114-Status: GOOD ( 12.13 ) X-Spam-Score: -0.7 (/) 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: From: Dongdong Zhang This patch introduces a new math test suite to the SBI unit tests. The changes include: * Updating lib/sbi/tests/objects.mk to include math_test_suite and sbi_math_test.o. * Adding a new file lib/sbi/tests/sbi_math_test.c which contains tests for log2roundup function using various cases. Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [52.237.72.81 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [52.237.72.81 listed in wl.mailspike.net] 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: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Dongdong Zhang This patch introduces a new math test suite to the SBI unit tests. The changes include: * Updating lib/sbi/tests/objects.mk to include math_test_suite and sbi_math_test.o. * Adding a new file lib/sbi/tests/sbi_math_test.c which contains tests for log2roundup function using various cases. The addition of this test suite ensures that mathematical functions are verified and work as expected. Signed-off-by: Dongdong Zhang Reviewed-by: Anup Patel --- lib/sbi/tests/objects.mk | 3 +++ lib/sbi/tests/sbi_math_test.c | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/sbi/tests/sbi_math_test.c diff --git a/lib/sbi/tests/objects.mk b/lib/sbi/tests/objects.mk index 8f27289..82b6061 100644 --- a/lib/sbi/tests/objects.mk +++ b/lib/sbi/tests/objects.mk @@ -12,3 +12,6 @@ libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_atomic_test.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += locks_test_suite libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_locks_test.o + +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += math_test_suite +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o \ No newline at end of file diff --git a/lib/sbi/tests/sbi_math_test.c b/lib/sbi/tests/sbi_math_test.c new file mode 100644 index 0000000..81ed832 --- /dev/null +++ b/lib/sbi/tests/sbi_math_test.c @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. + * + * Author: Dongdong Zhang + */ +#include +#include + +static void log2roundup_test(struct sbiunit_test_case *test) +{ + struct { + unsigned long input; + unsigned long expected; + } cases[] = { + {1, 0}, + {2, 1}, + {3, 2}, + {4, 2}, + {5, 3}, + {8, 3}, + {9, 4}, + {15, 4}, + {16, 4}, + {17, 5}, + {31, 5}, + {32, 5}, + {33, 6}, + {63, 6}, + {64, 6}, + {65, 7}, + }; + + for (int i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { + unsigned long result = log2roundup(cases[i].input); + SBIUNIT_EXPECT_EQ(test, result, cases[i].expected); + } +} + +static struct sbiunit_test_case math_test_cases[] = { + SBIUNIT_TEST_CASE(log2roundup_test), + SBIUNIT_END_CASE, +}; + +SBIUNIT_TEST_SUITE(math_test_suite, math_test_cases);