From nobody Sun Feb 8 05:30:13 2026 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2EC9438FE0 for ; Thu, 22 Jan 2026 15:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769096504; cv=none; b=GCe0cjP8gVclsCveFM+VVC9Lhl77f1Ux57xuI3CisMZ9dTBR3pmxxUnUooFmmERy2EWJjceWATYqm0vaA7GD1ecs84f7HkLYdoot2/T69iqmElhMJ+zRKQGix4/P1YJIJTxIUnBzC92DBtkewN1FlkiZE/ZB4Le82Scm9aAm9Ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769096504; c=relaxed/simple; bh=wudWEKYPreGAPUIxJEMZqWY09Ag9UgTiAqGA8t6f2Zw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Zi52ny+W8O3mN+erj6BTGV73V+mgUg/yZonFcecQAr/b6l/tX85v9zlDN0JWB26rG417AXeqsFlkPrhNUL99fBV+t6UdB52L8CGdMYurXfoqHICfFeag5avCrKvl21//qCCzG2e+LeFFl9R4JR4KCheo6k6lQ5QJdl/+1LZyfTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QUtREw7V; arc=none smtp.client-ip=209.85.216.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QUtREw7V" Received: by mail-pj1-f68.google.com with SMTP id 98e67ed59e1d1-35305538592so1095690a91.0 for ; Thu, 22 Jan 2026 07:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769096500; x=1769701300; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=+XqTNnzBtHqsuJmIbaha9WOr325rGLJyk0DsDSO4FOo=; b=QUtREw7V8ULHOGl2TzMbJZsfH8I/x4Ubd88fvgJi8yio5pxMvG5/ss1E/lrNwPW7vB p1UMZalUdELomxZABMfUQR09c9H+991hPYZvcAw/QtRb+t5U8XR259+99VjE+YAPNDvN CPh1F1oTJsM/IjeJUammUuCYO+C3epOB/Mh6jBwfdCCJp2D13MIL8ImNYi+uRndSpnh7 /01+rdOTr/tVIhOfZEanX4pwAM9sPIWQuC4iePnSZhbDlpvtYGzchupGKqFOCoOXa+Gh JPHt6Xs3rQvf9LKT20XmqZPNAFDAFkDXi7t2tF80OpJd04IFdXebxBIdn9U5JQaNZ/PK XTgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769096500; x=1769701300; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+XqTNnzBtHqsuJmIbaha9WOr325rGLJyk0DsDSO4FOo=; b=i3ZTJ08ghivCKGR7CKWjsVxWlCD020YyXT+UPgsqRDSR9qtFRXnIuL3VFW9jcQOQJe aH+0fE/zPWEECDVNlV62mI3nX+wNZdfzha87nYXVlpJ1JlNRzXr/+N9Y/AFZ35RUy9lQ 7hi1/8XouwxMSGOLPnIUKHPDELZugDINaZznMb3Elk8HzcRLjQtpcN68lk7SYhsXVpgg tdyuyH3AwqAzx34FUR36uGyO3afAjflEOA+C0F61mtX0ssgh2esFMD6XdG2mCHG5vRYa OQQX5Q4Ix+bUFJgzVFs0qD42ljgg4ArVqrOkoTSgerWeuCxhaDS5Av/waOuG5tN2qijo EgpA== X-Gm-Message-State: AOJu0YwpgEX9ZkkOn3hM8Meh5UU45cYSi7w3pKB8ofYyST3bxskupT19 oei7j1WrQD5l+tKtyFXF/2omSG3mFk7Xc6L4baFwGU4KNcS8Bm0AbJdN X-Gm-Gg: AZuq6aJDQ3wqxj/+xatXMCgb3OWOqOZWGA643haySJx+NjBjVl3UBTcW2rA9FZ/YMps j+BSie7re8DJHi81kqhThc87mNUP2Ud4L5wAmVBzQR5t+UY6NQ+FMdOzlON3j2Rd13I4HzwHKHO Lf3fD06GUqwMeXAp+GqHtLDKRvIIGwrKtspl64cdry3pA/FqstDsNxmEqbh/QogAgZgj1ym2qOp 9f3PVRUFPZV5DNnIHHDynPHyypby6NTSfCnmzKkW0VxcSqUjn55A8gd2Kh/OxMta4nhpVULcBgD w6ys46zxKWZ3pQkpS+XXFnDTwR27hgiRrByUFtUqtmlHF94RpHkDtA0DdSiS1x6rgLVCLvAC4yS rMxcv9+1TyT2yu+NCYlCj/ENb2hR8q0B6D05kG3nhsFEXZHCNQ2d+jhLUBmv7xEjcAi+eiwSxGy nVyygADLSuLiRu2WYGdUA= X-Received: by 2002:a17:90b:5864:b0:340:d569:d295 with SMTP id 98e67ed59e1d1-352732547demr18427820a91.24.1769096499879; Thu, 22 Jan 2026 07:41:39 -0800 (PST) Received: from [172.16.80.107] ([210.228.119.9]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-353354a6b06sm2745659a91.10.2026.01.22.07.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 07:41:39 -0800 (PST) From: Ryota Sakamoto Date: Fri, 23 Jan 2026 00:40:41 +0900 Subject: [PATCH] lib/tests: extend KUnit test for bitops with more cases 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: <20260123-kunit-bitops-new-tests-v1-1-47e516054738@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x3MQQqDMBBG4auEWTtgQm2hVxEXJv62QyGGTNSCe HeDy2/x3kGKLFB6m4MyNlFZYoVtDIXvGD9gmarJte7ZWuf4t0Yp7KUsSTli5wItyh4TXnhYP4a OapwyZvnf4344zwtnoUMJaAAAAA== X-Change-ID: 20260122-kunit-bitops-new-tests-bede7e41bac5 To: Yury Norov , Rasmus Villemoes , Andrew Morton Cc: linux-kernel@vger.kernel.org, Ryota Sakamoto X-Mailer: b4 0.14.2 Extend a KUnit test suite for the bitops API to cover more APIs from include/asm-generic/bitops/instrumented-atomic.h. - change_bit() - test_and_set_bit() - test_and_clear_bit() - test_and_change_bit() Verified on x86_64, i386, and arm64 architectures. Sample KUnit output: KTAP version 1 # Subtest: test_change_bit ok 1 BITOPS_4 ok 2 BITOPS_7 ok 3 BITOPS_11 ok 4 BITOPS_31 ok 5 BITOPS_88 # test_change_bit: pass:5 fail:0 skip:0 total:5 ok 2 test_change_bit KTAP version 1 # Subtest: test_test_and_set_bit_test_and_clear_bit ok 1 BITOPS_4 ok 2 BITOPS_7 ok 3 BITOPS_11 ok 4 BITOPS_31 ok 5 BITOPS_88 # test_test_and_set_bit_test_and_clear_bit: pass:5 fail:0 skip:0 total:5 ok 3 test_test_and_set_bit_test_and_clear_bit KTAP version 1 # Subtest: test_test_and_change_bit ok 1 BITOPS_4 ok 2 BITOPS_7 ok 3 BITOPS_11 ok 4 BITOPS_31 ok 5 BITOPS_88 # test_test_and_change_bit: pass:5 fail:0 skip:0 total:5 ok 4 test_test_and_change_bit Signed-off-by: Ryota Sakamoto --- Note that this patch is built on top of bitmap-for-next. --- lib/Kconfig.debug | 4 +-- lib/tests/bitops_kunit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index e4f8ba2f9f322168a3e8b44e5e46322dd2bd62ae..c59b12cf633a70e702ea365348e= c20b106e75950 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2660,8 +2660,8 @@ config BITOPS_KUNIT This option enables the KUnit test for the bitops library which provides functions for bit operations. =20 - Note that this is a partial copy of the original test_bitops module. - For the full coverage, enable TEST_BITOPS. + Note that this is derived from the original test_bitops module. + For micro-benchmarks and compiler warning checks, enable TEST_BITOPS. =20 If unsure, say N. =20 diff --git a/lib/tests/bitops_kunit.c b/lib/tests/bitops_kunit.c index 5c47a12760611a0445feb37c252d00f3bf73f6a1..7fd9d697f131dfa38b5f261dc62= 55450dbdac156 100644 --- a/lib/tests/bitops_kunit.c +++ b/lib/tests/bitops_kunit.c @@ -66,6 +66,66 @@ static void test_set_bit_clear_bit(struct kunit *test) KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); } =20 +static void test_change_bit(struct kunit *test) +{ + const struct bitops_test_case *params =3D test->param_value; + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); + int bit_set; + + bitmap_zero(bitmap, BITOPS_LENGTH); + + change_bit(params->nr, bitmap); + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); + + change_bit(params->nr, bitmap); + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); + + bit_set =3D find_first_bit(bitmap, BITOPS_LENGTH); + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); +} + +static void test_test_and_set_bit_test_and_clear_bit(struct kunit *test) +{ + const struct bitops_test_case *params =3D test->param_value; + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); + int bit_set; + + bitmap_zero(bitmap, BITOPS_LENGTH); + + KUNIT_EXPECT_FALSE(test, test_and_set_bit(params->nr, bitmap)); + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); + + KUNIT_EXPECT_TRUE(test, test_and_set_bit(params->nr, bitmap)); + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); + + KUNIT_EXPECT_TRUE(test, test_and_clear_bit(params->nr, bitmap)); + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); + + KUNIT_EXPECT_FALSE(test, test_and_clear_bit(params->nr, bitmap)); + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); + + bit_set =3D find_first_bit(bitmap, BITOPS_LENGTH); + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); +} + +static void test_test_and_change_bit(struct kunit *test) +{ + const struct bitops_test_case *params =3D test->param_value; + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); + int bit_set; + + bitmap_zero(bitmap, BITOPS_LENGTH); + + KUNIT_EXPECT_FALSE(test, test_and_change_bit(params->nr, bitmap)); + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); + + KUNIT_EXPECT_TRUE(test, test_and_change_bit(params->nr, bitmap)); + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); + + bit_set =3D 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; @@ -121,6 +181,9 @@ static void test_get_count_order_long(struct kunit *tes= t) =20 static struct kunit_case bitops_test_cases[] =3D { KUNIT_CASE_PARAM(test_set_bit_clear_bit, bitops_gen_params), + KUNIT_CASE_PARAM(test_change_bit, bitops_gen_params), + KUNIT_CASE_PARAM(test_test_and_set_bit_test_and_clear_bit, bitops_gen_par= ams), + KUNIT_CASE_PARAM(test_test_and_change_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), --- base-commit: c39f47e6c43954822a36952f47c0da027aca9c2b change-id: 20260122-kunit-bitops-new-tests-bede7e41bac5 Best regards, --=20 Ryota Sakamoto