From patchwork Sat Mar 22 09:23:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 14026176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6214C36002 for ; Sat, 22 Mar 2025 09:24:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AEF3810E032; Sat, 22 Mar 2025 09:24:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="AC9H9dOW"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F9AD10E271; Sat, 22 Mar 2025 09:24:21 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 15ED743B47; Sat, 22 Mar 2025 09:24:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 4F0AAC4CEEC; Sat, 22 Mar 2025 09:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742635452; bh=mgLIRy68HbDGD6UF+REEjw60ogvUejiteW3EXN74qAM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AC9H9dOWO2FOzwdE6+Qjxzuhag+ODBMUGWPM9epQqZ1TelUn4k+yo6rhtzwKCZuCN uvDYViUOpZ8LTtUi9/5lZUuIoNLF5kHH1lzTuV/7+mknBVx9pvZDI56ESpvXiWUD9U Du4bVvyBBrga/yxICVGF6Z3vnYHMVua7W93yQXGHqB79xUF5z1BCYCPN+8wnWvVMll fAksYIYb+uB6GzlONDtqGKoQ5dKJ7Rz6JcoOryQw8xegFJ1+87jFIB3OU2J+dJXN5W N0oG2UmwFoRx7USY9MCCDohT9+9vwPBzxdF7psL1vQ9wD8EuJqlTocYN95XHyp5ijY ymGHz0SQ3043A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4453DC36002; Sat, 22 Mar 2025 09:24:12 +0000 (UTC) Date: Sat, 22 Mar 2025 18:23:15 +0900 Subject: [PATCH v7 4/5] test_bits: add tests for GENMASK_U*() MIME-Version: 1.0 Message-Id: <20250322-fixed-type-genmasks-v7-4-da380ff1c5b9@wanadoo.fr> References: <20250322-fixed-type-genmasks-v7-0-da380ff1c5b9@wanadoo.fr> In-Reply-To: <20250322-fixed-type-genmasks-v7-0-da380ff1c5b9@wanadoo.fr> To: Yury Norov , Lucas De Marchi , Rasmus Villemoes , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Andrew Morton Cc: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Andi Shyti , David Laight , Andy Shevchenko , Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2278; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=uXmPSUMb6I24+A4UZIIzKbnGyB2R8aAlshU2V9V9BKo=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOn3Grc2H4w82urEpfmP56rm/wOCB9+JWYRx2EpElVi+T 9f7a7uso5SFQYyLQVZMkWVZOSe3Qkehd9ihv5Ywc1iZQIYwcHEKwEQqJjAybKhsnXE9u1rOKdPW 5vTUtc09KTrX7pxxK9NlVLd/JdpVwMhwpF8n5ODRHtbNv18aZlvIJ77h62ZgS1l8YorflwvSLrv ZAA== X-Developer-Key: i=mailhol.vincent@wanadoo.fr; a=openpgp; fpr=ED8F700574E67F20E574E8E2AB5FEB886DBB99C2 X-Endpoint-Received: by B4 Relay for mailhol.vincent@wanadoo.fr/default with auth_id=291 X-Original-From: Vincent Mailhol X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: mailhol.vincent@wanadoo.fr Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Vincent Mailhol From: Lucas De Marchi Add some additional tests in lib/test_bits.c to cover the expected/non-expected values of the fixed-type GENMASK_U*() macros. Also check that the result value matches the expected type. Since those are known at build time, use static_assert() instead of normal kunit tests. Signed-off-by: Lucas De Marchi Signed-off-by: Vincent Mailhol --- Changelog: v6 -> v7: v5 -> v6: - No changes. v4 -> v5: - Revert v4 change. GENMASK_U8()/GENMASK_U16() are now back to u8/u16. v3 -> v4: - Adjust the type of GENMASK_U8()/GENMASK_U16() from u8/u16 to unsigned int. - Reorder the tests to match the order in which the macros are declared in bits.h. --- lib/test_bits.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/test_bits.c b/lib/test_bits.c index c7b38d91e1f16d42b7ca92e62fbd6c19b37e76a0..f443476f3265c463c1219b13c1ef9663d238d58b 100644 --- a/lib/test_bits.c +++ b/lib/test_bits.c @@ -5,6 +5,16 @@ #include #include +#include + +#define assert_type(t, x) _Generic(x, t: x, default: 0) + +static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX); +static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX); +static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX); +static_assert(assert_type(u16, GENMASK_U16(15, 0)) == U16_MAX); +static_assert(assert_type(u32, GENMASK_U32(31, 0)) == U32_MAX); +static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX); static void genmask_test(struct kunit *test) @@ -14,11 +24,21 @@ static void genmask_test(struct kunit *test) KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1)); KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0)); + KUNIT_EXPECT_EQ(test, 1u, GENMASK_U8(0, 0)); + KUNIT_EXPECT_EQ(test, 3u, GENMASK_U16(1, 0)); + KUNIT_EXPECT_EQ(test, 0x10000, GENMASK_U32(16, 16)); + #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ GENMASK(0, 1); GENMASK(0, 10); GENMASK(9, 10); + + GENMASK_U32(0, 31); + GENMASK_U64(64, 0); + GENMASK_U32(32, 0); + GENMASK_U16(16, 0); + GENMASK_U8(8, 0); #endif