From patchwork Fri Mar 7 16:48:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol via B4 Relay X-Patchwork-Id: 14006778 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 8B589C28B23 for ; Fri, 7 Mar 2025 16:49:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9A1510EC01; Fri, 7 Mar 2025 16:49:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="DILCqc9S"; dkim-atps=neutral Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1D5010EBED; Fri, 7 Mar 2025 16:49:39 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2A719A44222; Fri, 7 Mar 2025 16:44:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 5781CC4CEEA; Fri, 7 Mar 2025 16:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741366178; bh=A27ZByqIu85Vwzbq7Hul+aBd0ddgD7GBq45M2NSodA0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DILCqc9SpFreQAOblXW0klkY3CUBCqIyxvfrN5t0Hb3jxlDYnwo4fz9GWUleuf9Tt sJG35oQrGjn7bLdQUUc8wLPfQ78HSyXkPGVFjiF5Awjsy7g1XuZWVSoXyBIxNkh+J6 Kmo1+wQHW/le1NHerHoyPIjGFeLhud51qexof9m8Q+O60jamnZxXgy5E7ntq1crqt+ md+ypSqTfUof23q03VqgTgSBUti5qAfLWmDNQPuq7uZMSWgtbvUYoIsXqokZWRZP2w 5fTMQozAwNpBkByFEonx+Kl+9+DASn/ZoaTv2DOpeXJkLCz3rFXUVd0txQknwlF+sj zO8CTb0fnBYRA== 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 4D2BFC28B24; Fri, 7 Mar 2025 16:49:38 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Sat, 08 Mar 2025 01:48:53 +0900 Subject: [PATCH v6 6/7] test_bits: add tests for GENMASK_U*() MIME-Version: 1.0 Message-Id: <20250308-fixed-type-genmasks-v6-6-f59315e73c29@wanadoo.fr> References: <20250308-fixed-type-genmasks-v6-0-f59315e73c29@wanadoo.fr> In-Reply-To: <20250308-fixed-type-genmasks-v6-0-f59315e73c29@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 , Dmitry Baryshkov , Andy Shevchenko , Vincent Mailhol X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2296; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=j0nK1n7HyOdR4Oswzr/6a6KRsk/rL8POHAuDHHXcC7A=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOmnlad/36Sy9GaiYs0v3tIA9782E159iZ51/0KCRvNRI RXt4zyKHaUsDGJcDLJiiizLyjm5FToKvcMO/bWEmcPKBDKEgYtTACYiW87wP6v0Vgbf/EcmEtMu 7/7Dy851YoZM7MmHnjN+SIicZeRlWsfwP+jM1ZCu9uYks69Kf+ccklnuqlSdYnDdMPOOv/VbQ0c LLgA= 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: 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: 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 b0c29b01fb30cbcc759ac1e7106457b18bcd73a0..87112d1895194da33c0ffdf0a6fe6df43ce6b1e7 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); /* FIXME: add a test case written in asm for GENMASK() and GENMASK_ULL() */ @@ -31,11 +41,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