From nobody Tue Feb 10 08:26:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B120F2222B5 for ; Thu, 6 Mar 2025 11:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741260667; cv=none; b=OVXrJ7UuZ69eCcnAWEL+dOQYq1QWuLfj1b1MqyKFRwkO7Wc5HoP8vQQD1gnpeXobXY+s8Gu+PRHviWmXTKfCpYtmUQ4pC3MmfPN78FYALyJu0Gq/Rs7HJBQmFLp0UziMXBsi3hTK/T3wsx01VfGi8I87TtcptLhoVu1M4sN1yhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741260667; c=relaxed/simple; bh=1eenmwUznpXpLxtCJHjJ9cE369ZzivA0n55tr3Vvsro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ChlovQJq2dskQR2C+ahbW0/4PAfd0xN2atIrFc2KnU9jP0aQU4RTzvzzd+hYsvdfE5YyMg1mfekKfcEtfrVoVQcn525Zb+PqjyyK0Pki9EIe7RuHJAiLMT5e8NtIWscHeHk5sloYzFiPHtE8yR4lhPupNt9reaUAPnE0237zi9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=na24+4iw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="na24+4iw" Received: by smtp.kernel.org (Postfix) with ESMTPS id 75AD6C4CEF2; Thu, 6 Mar 2025 11:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741260667; bh=1eenmwUznpXpLxtCJHjJ9cE369ZzivA0n55tr3Vvsro=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=na24+4iw4ShKrXCURAfwMe8EXg5VLe+DlxFhIcG1g5tl3qPcY2PCKlGeh+2cf7FTZ xepkB8drAYWOmcYfpFTQG8q1xxyKxnMwzwQ9qyJnDqnL5bdN5Myiu7rgQT4rPyoJxV KRQRcJJal1CV2RwfpaoWcOyMlgDv0qviZwVi32z8/pP9pbPKQIKZpI/QlYqH91i39U Ut6yeP0xFV1ICncs3DhAhwWtQWYnvb7wRpi96ijAkwuolGa7VFLOHSDW3ieHnuFOYj 5nIuzvp5036tLAi7cq684GBGRXJPWacGBnaItpUNoySFodNEvAkxOuoqlcFActyh6z rqFyzbFkDzf0w== 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 6D4FFC282EC; Thu, 6 Mar 2025 11:31:07 +0000 (UTC) From: Vincent Mailhol via B4 Relay Date: Thu, 06 Mar 2025 20:29:57 +0900 Subject: [PATCH v5 6/7] test_bits: add tests for GENMASK_U*() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250306-fixed-type-genmasks-v5-6-b443e9dcba63@wanadoo.fr> References: <20250306-fixed-type-genmasks-v5-0-b443e9dcba63@wanadoo.fr> In-Reply-To: <20250306-fixed-type-genmasks-v5-0-b443e9dcba63@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=2231; i=mailhol.vincent@wanadoo.fr; h=from:subject:message-id; bh=1TWDnZuK4H6aZXY1mDhIfDoxCABP+2rzCCCoYFZzW3c=; b=owGbwMvMwCV2McXO4Xp97WbG02pJDOkn24tfHts45ZydRU3ZwfPRKzjfrH2zc5VWccrCbTcP8 h62u/9XtKOUhUGMi0FWTJFlWTknt0JHoXfYob+WMHNYmUCGMHBxCsBEMiUYGXYdf5+38IuJbOXq cgO3xxn5O7dl5E15d9V64XnlXZNUVpkwMpzwWawu8vF+7ZPSDKmvXxfqsmicj6+4pZ+epHfI1Z2 jjAcA 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 Reply-To: mailhol.vincent@wanadoo.fr 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: 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/test_bits.c b/lib/test_bits.c index dc93ded9fdb201e0d44b3c1cd71e233fd62258a5..91968227687bb11b7d1361b153c= 27eb851c6c1c2 100644 --- a/lib/test_bits.c +++ b/lib/test_bits.c @@ -5,7 +5,16 @@ =20 #include #include +#include =20 +#define assert_type(t, x) _Generic(x, t: x, default: 0) + +static_assert(assert_type(unsigned long, GENMASK(31, 0)) =3D=3D U32_MAX); +static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) =3D=3D U= 64_MAX); +static_assert(assert_type(u8, GENMASK_U8(7, 0)) =3D=3D U8_MAX); +static_assert(assert_type(u16, GENMASK_U16(15, 0)) =3D=3D U16_MAX); +static_assert(assert_type(u32, GENMASK_U32(31, 0)) =3D=3D U32_MAX); +static_assert(assert_type(u64, GENMASK_U64(63, 0)) =3D=3D U64_MAX); =20 static void __genmask_test(struct kunit *test) { @@ -30,11 +39,21 @@ static void genmask_test(struct kunit *test) KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1)); KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0)); =20 + 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 =20 =20 --=20 2.45.3