From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010060.outbound.protection.outlook.com [52.101.61.60]) (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 5CD241E2834 for ; Sun, 11 Jan 2026 03:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.60 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768102954; cv=fail; b=Z4SBLfJzi88wprEb6J5bpsdeR9zlW0wLvqU9+OdJkTDgyILC7a6TWrfVv17ev6KTeODR5T0N4pr33oexeN4HEKE+54tbvnSD4XaeRwaC3EcozbKWBXeJ0lFXmuIFZrjHz8D1algUGQ5UEevzpg9ZWfDDoxPIP1Vd4xxPtcdysKg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768102954; c=relaxed/simple; bh=54BDmDOQNCvQkms0IlpFDSfnV+txat+VY+abQgM8S0A=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=aa3EOSROKQOhjPLES3HzaZbFmNkVMoi8j0ROsEoxb2Kkx0ApiYD/GWDAqyOFiXXCGT/NqIUZQrQuV4b8zwMIqkXxJqr3KD9TD5mdYGGNMKADgRfYu6zWfNGQAbr7sC0YU62iWsNRi9E+Psb3rrWL4uNBhuOvAAaSKkvrMUTB/PM= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=hSpWmCFy; arc=fail smtp.client-ip=52.101.61.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="hSpWmCFy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KsUYlIdYTYRnf4b1gWut0RhMtp5mjqLwCiflaGcB2DJuvUpyRbMTkBVJ5EbwYxglBzt+p4WC2hNcCe98f64MpNtCOhDKN7yYpIpKTe9VAojeVyXwOqoF1U1dD2XcQdjn3OeEEdY9d1xCcX5/778Yg25tVBPwrRe0e4mB4n09eK9O5WQyvVRTmNyD4xECiPAmJhDy6Y1NIBtphQa2TmuT2F/fw5vQ3M8Or6CB/d/3DzP53Ff9XKGJd6StLFjomcwbhHMMnlqV9ebDC64wZTSHDLwD66BFjwSRQdZZdEL9T8Bts5bqWK9zntSXhGpWBPXLCW8LKdrJoQAT8BGCg9dZhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mg/rH6SQ8jeielYWaM8uS8cFrTPJHVFCn9NVVabNBL0=; b=Mw7Z3hsPKdImA3j47PSqx8Nc/enRngOe5Zn0MbnUgiIm663d4ktVxUIkhuxwC+L/IbYYTM2pUrg5fmi0pVa6uSYCC7zAz8lA7SmGtSgwlqYgouojY2NTBVgwrX8VfTJFHXBTZGPTUIR6K06Qev6u30xrrMc95LrYOb6ulZQCtJNc1kpsL/7OREX51N5Wy7eC+WX6OW7UmD5dB6tODZ4eIg5kQp9+E/3eEMQ5QOGUfAlHCz0bYBkHbkbYyzNUZEa8vamJLWcjDITJ0UauncdDbhruUyz4aU7InIyNcqHWxbOqFyYINXKLaXDrf+IwxQ2bH63xERWihSMS5SZH5Hj/Jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mg/rH6SQ8jeielYWaM8uS8cFrTPJHVFCn9NVVabNBL0=; b=hSpWmCFy/m++opzo4m0K3pGJUgKXzsQeZa062WtGXl9n3s+3mUTZ5E0z5jb1tWao03XZRVGL+BPO+bNzXqzlssDq9no3us8Q5PyxbesmiXDcxYyLwqdtqpk2T3xIygGvG/HaDCucyn4OJWUY9bx0brg0dIzNZRXTnHh+6//eMJV70tVVBhXsg0bzzGGXR9eetO/+pxEc31cAPHqZbUEFLAwShipkBrF3ZS/2VIfLghDwee0B8On1vmNn0PvqxNoQmL3h6ntODPAwSLpBLu0Jcrs1EbwCZQ9UTxc9ELZFGDA45u44P0UO7V7UZPimmdeqLufQjyEhTReEXm1ccrceAw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from PH0PR12MB8800.namprd12.prod.outlook.com (2603:10b6:510:26f::12) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.6; Sun, 11 Jan 2026 03:42:29 +0000 Received: from PH0PR12MB8800.namprd12.prod.outlook.com ([fe80::bdb6:e12f:18b6:2b77]) by PH0PR12MB8800.namprd12.prod.outlook.com ([fe80::bdb6:e12f:18b6:2b77%5]) with mapi id 15.20.9499.005; Sun, 11 Jan 2026 03:42:29 +0000 Date: Sat, 10 Jan 2026 22:42:26 -0500 From: Yury Norov To: Ryota Sakamoto Cc: Andrew Morton , Yury Norov , Rasmus Villemoes , Jesse Brandeburg , Wei Yang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] lib/tests: add KUnit test for bitops Message-ID: References: <20260111-kunit-bitops-v2-1-8c5b15341060@gmail.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260111-kunit-bitops-v2-1-8c5b15341060@gmail.com> X-ClientProxiedBy: BN0PR02CA0046.namprd02.prod.outlook.com (2603:10b6:408:e5::21) To PH0PR12MB8800.namprd12.prod.outlook.com (2603:10b6:510:26f::12) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR12MB8800:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: b95809d7-b78e-4e7f-ebc0-08de50c3718f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|10070799003|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?apC8m80iJzI1lTrRWlZCetats35LDY/qXaFjTYlfS0Wajwd55CyLEaMmJ/HP?= =?us-ascii?Q?A8xcIhHIqtvu3hmLEMgyVTGE6o0ezB5K12hS8AkR4KKNW1D6yM9Ow/v7GtUT?= =?us-ascii?Q?JS1gof8lS/I2yNHDZzk5+FGtmL2jm5Vlv4/Om9Pe8D/CDehgcBMqWt9UI3yo?= =?us-ascii?Q?1rHCzSfjxKN3KH0xDrK5mUybnbSp3PekgTaf1kcBUFe8D6Z6WRJeU04BF/yK?= =?us-ascii?Q?wfg8s489JtmPw4hqKfeZMuvZM/S6AqujfZ66HPaRyDwl6QeV39XPsLfQqr9L?= =?us-ascii?Q?obgxGTJOg3+v69Wzy8kPdyAQEURoNYJ2QRgF07U3vPEI4yImHOlXRocvTJiA?= =?us-ascii?Q?FpThtQfaOh2CKBKKurp7BNwty6mxHerTB/kumV8GvU+2iupAR4yJ481SXvJW?= =?us-ascii?Q?se6zvRiL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?us-ascii?Q?UX69s8jh2VroP+IqHm6o7ZNpsaQ5aIQRB87K0pX9HPlkS7d1gJ3NvEkzSUc8?= =?us-ascii?Q?EsR7qtpe8+S8WqEUtpAQsXG1BHsQOzEF3RR4JeYhZmk00ZPBA7cy8Mch3dhH?= =?us-ascii?Q?PpXL+MYQW0OSjSW2Tod5dsT3gAuFgrcm?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR12MB8800.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(10070799003)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?bDgQA56+MC8EE3WimNI5ixy41XmdSPGyaI866Fxp1/VillSG/QYeA3RvuWss?= =?us-ascii?Q?c4TfMnrXo978/koBh8MDenypqyKnXhl2Q6tYiN2Z9LdepNw1+PdxHCxvUEPm?= =?us-ascii?Q?2hfvfssxk+mB2j0pfclfZvW6zzecLqx0xw5netnVLQz2S047HbZ9yc/AW/gz?= =?us-ascii?Q?KrrUha3hccGe51TKCqDPbti4C0/9UdUdi/t0+IZKoT4CN0a1vZ79dtBOIuvU?= =?us-ascii?Q?D0ctLfEovg4or2hbMgfGhmTwGLWb4ynKYZcIRphmyCQBjDf4GqWFYpRDi8c8?= =?us-ascii?Q?f0Hg8FP33t0Nj1whkc+27UbF7xuEyiGFDMsB335k+GJ3CN7Rub0DhGdvH5bk?= =?us-ascii?Q?ObTGfZUaDsO2mAbTV2qDM5/GMRo2RGbIoFZqW3QTIxoCSZzDHiv6WMzDoKq6?= =?us-ascii?Q?kjDliZuOuIb84AekZrgLkhPqtGkMV03aNvduiMYzc/LXEqbjTSKfDrOi+9+C?= =?us-ascii?Q?UKDsu8GHjF97atKllG3F2kGjjf26ZoCMVEqj7Y+MGBWT/bYlDF3nQJsDoKnm?= =?us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DULBzXT6RBLClFpS4yptT/HziJRR5xY8sbcERt6a4asi?= =?us-ascii?Q?SHLbbqm0BqOp3XpdCrfY3/zRqSt6vNF9636KWZyLeV3Ue416ZNS/WxI0888s?= =?us-ascii?Q?LGRWbtKEOonG5F8HAJ1r3kfYlx3Wtsk16/pahzCBS6LhwW1rnmHBicsjUA2X?= =?us-ascii?Q?rjpjHp1qJFjH8AgDfrlm82/5i5HQq4Uh0oBtB7LGQ/qdhGnG+0Y5gLYheAT8?= =?us-ascii?Q?pSpp25nJ1HKFijYJ+7PYLJIAZIdymr5Zyn/9j1Sv8xkY3AMa/sidTcbnzDjA?= =?us-ascii?Q?JOSCRfOrlaahBVS58pwrfyYsltVnCYqpO2dXcQ3d31XhRlD2tfHouvMtXkLD?= =?us-ascii?Q?kVXBC9oRFQ+KFrepLTxmDeScRItpgQ0glgFHYS9aEIWpA4LWpRvO?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b95809d7-b78e-4e7f-ebc0-08de50c3718f X-MS-Exchange-CrossTenant-AuthSource: PH0PR12MB8800.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2026 03:42:28.9030 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KSy6Q+y8AsWBjqcPvVorqpFtz/JdxWoDqcV0E70QS5WFMDH1AUdLxT+AaFlpjtU0w5OQ6sQ6yKC9BrPKcAJNgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 On Sun, Jan 11, 2026 at 02:38:07AM +0900, Ryota Sakamoto wrote: > Add a KUnit test suite for the bitops API. > > The existing 'lib/test_bitops.c' is preserved as-is because it contains > ad-hoc micro-benchmarks 'test_fns' and is intended to ensure no compiler > warnings from C=1 sparse checker or -Wextra compilations. > > Introduce 'lib/tests/bitops_kunit.c' for functional regression testing. It > ports the test logic and data patterns from 'lib/test_bitops.c' to KUnit, > verifying correct behavior across various input patterns and > architecture-specific edge cases using isolated stack-allocated bitmaps. > > The following test logic has been ported from test_bitops_startup() in > lib/test_bitops.c: > - set_bit() / clear_bit() / find_first_bit() validation -> > test_set_bit_clear_bit() > - get_count_order() validation -> test_get_count_order() > - get_count_order_long() validation -> test_get_count_order_long() > > Also improve the find_first_bit() test to check the full bitmap length > (BITOPS_LENGTH) instead of omitting the last bit, ensuring the bitmap is > completely empty after cleanup. > > Verified on x86_64, i386, and arm64 architectures. > > Sample KUnit output: > > KTAP version 1 > # Subtest: bitops > # module: bitops_kunit > 1..3 > KTAP version 1 > # Subtest: test_set_bit_clear_bit > ok 1 BITOPS_4 > ok 2 BITOPS_7 > ok 3 BITOPS_11 > ok 4 BITOPS_31 > ok 5 BITOPS_88 > # test_set_bit_clear_bit: pass:5 fail:0 skip:0 total:5 > ok 1 test_set_bit_clear_bit > KTAP version 1 > # Subtest: test_get_count_order > ok 1 0x00000003 > ok 2 0x00000004 > ok 3 0x00001fff > ok 4 0x00002000 > ok 5 0x50000000 > ok 6 0x80000000 > ok 7 0x80003000 > # test_get_count_order: pass:7 fail:0 skip:0 total:7 > ok 2 test_get_count_order > KTAP version 1 > # Subtest: test_get_count_order_long > ok 1 0x0000000300000000 > ok 2 0x0000000400000000 > ok 3 0x00001fff00000000 > ok 4 0x0000200000000000 > ok 5 0x5000000000000000 > ok 6 0x8000000000000000 > ok 7 0x8000300000000000 > # test_get_count_order_long: pass:7 fail:0 skip:0 total:7 > ok 3 test_get_count_order_long > > Signed-off-by: Ryota Sakamoto Added in bitmap-for-next for testing. Thanks, Yury > --- > Changes in v2: > - List extracted test logic in the commit message > - Include KTAP execution output > - Clarify in Kconfig help text that this is a partial copy > - Add original authors to CC > - Link to v1: https://lore.kernel.org/r/20260110-kunit-bitops-v1-1-fe39a1ff1a02@gmail.com > --- > MAINTAINERS | 1 + > lib/Kconfig.debug | 14 +++++ > lib/tests/Makefile | 1 + > lib/tests/bitops_kunit.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 158 insertions(+) > > diff --git a/MAINTAINERS b/MAINTAINERS > index a0dd762f5648b7e4e6fc62560662e43720422e01..ad978698deedca3e6acdf62145a48d45b579cec2 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -4468,6 +4468,7 @@ F: include/asm-generic/bitops.h > F: include/linux/bitops.h > F: lib/hweight.c > F: lib/test_bitops.c > +F: lib/tests/bitops_kunit.c > F: tools/*/bitops* > > BITOPS API BINDINGS [RUST] > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index ba36939fda79bf890834b586c366a28acd434ef9..a3642ab0363d0fa17eb8a395655cdc4b56f031d8 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -2652,6 +2652,20 @@ config TEST_SYSCTL > > If unsure, say N. > > +config BITOPS_KUNIT > + tristate "KUnit test for bitops" if !KUNIT_ALL_TESTS > + depends on KUNIT > + default KUNIT_ALL_TESTS > + help > + This option enables the KUnit test suite for the bitops library > + which provides functions for bit operations. > + The test suite checks the functionality of the bitops library. > + > + Note that this is a partial copy of the original test_bitops module. > + For the full coverage, enable TEST_BITOPS. > + > + If unsure, say N. > + > config BITFIELD_KUNIT > tristate "KUnit test bitfield functions at runtime" if !KUNIT_ALL_TESTS > depends on KUNIT > diff --git a/lib/tests/Makefile b/lib/tests/Makefile > index 601dba4b7d966d568d0bb6671dffaf4d68489549..0f24048f36845b13daebcb504e182f738e0a807f 100644 > --- a/lib/tests/Makefile > +++ b/lib/tests/Makefile > @@ -5,6 +5,7 @@ > # KUnit tests > CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN) > obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o > +obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o > obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o > obj-$(CONFIG_BITS_TEST) += test_bits.o > obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o > diff --git a/lib/tests/bitops_kunit.c b/lib/tests/bitops_kunit.c > new file mode 100644 > index 0000000000000000000000000000000000000000..5c47a12760611a0445feb37c252d00f3bf73f6a1 > --- /dev/null > +++ b/lib/tests/bitops_kunit.c > @@ -0,0 +1,142 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2020 Intel Corporation > + * Copyright (C) 2026 Ryota Sakamoto > + */ > + > +#include > +#include > +#include > + > +/* use an enum because that's the most common BITMAP usage */ > +enum bitops_fun { > + BITOPS_4 = 4, > + BITOPS_7 = 7, > + BITOPS_11 = 11, > + BITOPS_31 = 31, > + BITOPS_88 = 88, > + BITOPS_LENGTH = 256 > +}; > + > +struct bitops_test_case { > + const char *str; > + const long nr; > +}; > + > +static struct bitops_test_case bitops_cases[] = { > + { > + .str = "BITOPS_4", > + .nr = BITOPS_4, > + }, > + { > + .str = "BITOPS_7", > + .nr = BITOPS_7, > + }, > + { > + .str = "BITOPS_11", > + .nr = BITOPS_11, > + }, > + { > + .str = "BITOPS_31", > + .nr = BITOPS_31, > + }, > + { > + .str = "BITOPS_88", > + .nr = BITOPS_88, > + }, > +}; > + > +KUNIT_ARRAY_PARAM_DESC(bitops, bitops_cases, str); > + > +static void test_set_bit_clear_bit(struct kunit *test) > +{ > + const struct bitops_test_case *params = test->param_value; > + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); > + int bit_set; > + > + bitmap_zero(bitmap, BITOPS_LENGTH); > + > + set_bit(params->nr, bitmap); > + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); > + > + clear_bit(params->nr, bitmap); > + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); > + > + bit_set = find_first_bit(bitmap, BITOPS_LENGTH); > + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); > +} > + > +struct order_test_case { > + const char *str; > + const unsigned int count; > + const int expected; > +}; > + > +static struct order_test_case order_test_cases[] = { > + {"0x00000003", 0x00000003, 2}, > + {"0x00000004", 0x00000004, 2}, > + {"0x00001fff", 0x00001fff, 13}, > + {"0x00002000", 0x00002000, 13}, > + {"0x50000000", 0x50000000, 31}, > + {"0x80000000", 0x80000000, 31}, > + {"0x80003000", 0x80003000, 32}, > +}; > + > +KUNIT_ARRAY_PARAM_DESC(order, order_test_cases, str); > + > +static void test_get_count_order(struct kunit *test) > +{ > + const struct order_test_case *params = test->param_value; > + > + KUNIT_EXPECT_EQ(test, get_count_order(params->count), params->expected); > + KUNIT_EXPECT_EQ(test, get_count_order_long(params->count), params->expected); > +} > + > +#ifdef CONFIG_64BIT > +struct order_long_test_case { > + const char *str; > + const unsigned long count; > + const int expected; > +}; > + > +static struct order_long_test_case order_long_test_cases[] = { > + {"0x0000000300000000", 0x0000000300000000, 34}, > + {"0x0000000400000000", 0x0000000400000000, 34}, > + {"0x00001fff00000000", 0x00001fff00000000, 45}, > + {"0x0000200000000000", 0x0000200000000000, 45}, > + {"0x5000000000000000", 0x5000000000000000, 63}, > + {"0x8000000000000000", 0x8000000000000000, 63}, > + {"0x8000300000000000", 0x8000300000000000, 64}, > +}; > + > +KUNIT_ARRAY_PARAM_DESC(order_long, order_long_test_cases, str); > + > +static void test_get_count_order_long(struct kunit *test) > +{ > + const struct order_long_test_case *params = test->param_value; > + > + KUNIT_EXPECT_EQ(test, get_count_order_long(params->count), params->expected); > +} > +#endif > + > +static struct kunit_case bitops_test_cases[] = { > + KUNIT_CASE_PARAM(test_set_bit_clear_bit, bitops_gen_params), > + KUNIT_CASE_PARAM(test_get_count_order, order_gen_params), > +#ifdef CONFIG_64BIT > + KUNIT_CASE_PARAM(test_get_count_order_long, order_long_gen_params), > +#endif > + {}, > +}; > + > +static struct kunit_suite bitops_test_suite = { > + .name = "bitops", > + .test_cases = bitops_test_cases, > +}; > + > +kunit_test_suite(bitops_test_suite); > + > +MODULE_AUTHOR("Jesse Brandeburg "); > +MODULE_AUTHOR("Wei Yang "); > +MODULE_AUTHOR("Ryota Sakamoto "); > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("Bit testing module"); > > --- > base-commit: 79b95d74470dd97d7d0908d5a3c0734a23e51aa4 > change-id: 20260109-kunit-bitops-9abb5cac8cba > > Best regards, > -- > Ryota Sakamoto