[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231203193307.542794-1-yury.norov@gmail.com>
Date: Sun, 3 Dec 2023 11:32:34 -0800
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
"David S. Miller" <davem@...emloft.net>,
"H. Peter Anvin" <hpa@...or.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"K. Y. Srinivasan" <kys@...rosoft.com>,
"Md. Haris Iqbal" <haris.iqbal@...os.com>,
Akinobu Mita <akinobu.mita@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Bjorn Andersson <andersson@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Chaitanya Kulkarni <kch@...dia.com>,
Christian Brauner <brauner@...nel.org>,
Damien Le Moal <damien.lemoal@...nsource.wdc.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
David Disseldorp <ddiss@...e.de>,
Edward Cree <ecree.xilinx@...il.com>,
Eric Dumazet <edumazet@...gle.com>,
Fenghua Yu <fenghua.yu@...el.com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Gregory Greenman <gregory.greenman@...el.com>,
Hans Verkuil <hverkuil@...all.nl>,
Hans de Goede <hdegoede@...hat.com>,
Hugh Dickins <hughd@...gle.com>,
Ingo Molnar <mingo@...hat.com>,
Jakub Kicinski <kuba@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>,
Jason Gunthorpe <jgg@...pe.ca>, Jens Axboe <axboe@...nel.dk>,
Jiri Pirko <jiri@...nulli.us>,
Jiri Slaby <jirislaby@...nel.org>,
Kalle Valo <kvalo@...nel.org>,
Karsten Graul <kgraul@...ux.ibm.com>,
Karsten Keil <isdn@...ux-pingi.de>,
Kees Cook <keescook@...omium.org>,
Leon Romanovsky <leon@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Martin Habets <habetsm.xilinx@...il.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Michael Ellerman <mpe@...erman.id.au>,
Michal Simek <monstr@...str.eu>,
Nicholas Piggin <npiggin@...il.com>,
Oliver Neukum <oneukum@...e.com>,
Paolo Abeni <pabeni@...hat.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Ping-Ke Shih <pkshih@...ltek.com>,
Rich Felker <dalias@...c.org>, Rob Herring <robh@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Sean Christopherson <seanjc@...gle.com>,
Shuai Xue <xueshuai@...ux.alibaba.com>,
Stanislaw Gruszka <stf_xl@...pl>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Thomas Gleixner <tglx@...utronix.de>,
Valentin Schneider <vschneid@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wenjia Zhang <wenjia@...ux.ibm.com>,
Will Deacon <will@...nel.org>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
GR-QLogic-Storage-Upstream@...vell.com,
alsa-devel@...a-project.org, ath10k@...ts.infradead.org,
dmaengine@...r.kernel.org, iommu@...ts.linux.dev,
kvm@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-arm-msm@...r.kernel.org, linux-block@...r.kernel.org,
linux-bluetooth@...r.kernel.org, linux-hyperv@...r.kernel.org,
linux-m68k@...ts.linux-m68k.org, linux-media@...r.kernel.org,
linux-mips@...r.kernel.org, linux-net-drivers@....com,
linux-pci@...r.kernel.org, linux-rdma@...r.kernel.org,
linux-s390@...r.kernel.org, linux-scsi@...r.kernel.org,
linux-serial@...r.kernel.org, linux-sh@...r.kernel.org,
linux-sound@...r.kernel.org, linux-usb@...r.kernel.org,
linux-wireless@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
mpi3mr-linuxdrv.pdl@...adcom.com, netdev@...r.kernel.org,
sparclinux@...r.kernel.org, x86@...nel.org
Cc: Yury Norov <yury.norov@...il.com>, Jan Kara <jack@...e.cz>,
Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
Matthew Wilcox <willy@...radead.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Maxim Kuvyrkov <maxim.kuvyrkov@...aro.org>,
Alexey Klimov <klimov.linux@...il.com>,
Bart Van Assche <bvanassche@....org>,
Sergey Shtylyov <s.shtylyov@....ru>
Subject: [PATCH v2 02/35] lib/find: add test for atomic find_bit() ops
Add basic functionality test for new API.
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
lib/test_bitmap.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 65f22c2578b0..277e1ca9fd28 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -221,6 +221,65 @@ static void __init test_zero_clear(void)
expect_eq_pbl("", bmap, 1024);
}
+static void __init test_find_and_bit(void)
+{
+ unsigned long w, w_part, bit, cnt = 0;
+ DECLARE_BITMAP(bmap, EXP1_IN_BITS);
+
+ /*
+ * Test find_and_clear{_next}_bit() and corresponding
+ * iterators
+ */
+ bitmap_copy(bmap, exp1, EXP1_IN_BITS);
+ w = bitmap_weight(bmap, EXP1_IN_BITS);
+
+ for_each_test_and_clear_bit(bit, bmap, EXP1_IN_BITS)
+ cnt++;
+
+ expect_eq_uint(w, cnt);
+ expect_eq_uint(0, bitmap_weight(bmap, EXP1_IN_BITS));
+
+ bitmap_copy(bmap, exp1, EXP1_IN_BITS);
+ w = bitmap_weight(bmap, EXP1_IN_BITS);
+ w_part = bitmap_weight(bmap, EXP1_IN_BITS / 3);
+
+ cnt = 0;
+ bit = EXP1_IN_BITS / 3;
+ for_each_test_and_clear_bit_from(bit, bmap, EXP1_IN_BITS)
+ cnt++;
+
+ expect_eq_uint(bitmap_weight(bmap, EXP1_IN_BITS), bitmap_weight(bmap, EXP1_IN_BITS / 3));
+ expect_eq_uint(w_part, bitmap_weight(bmap, EXP1_IN_BITS));
+ expect_eq_uint(w - w_part, cnt);
+
+ /*
+ * Test find_and_set{_next}_bit() and corresponding
+ * iterators
+ */
+ bitmap_copy(bmap, exp1, EXP1_IN_BITS);
+ w = bitmap_weight(bmap, EXP1_IN_BITS);
+ cnt = 0;
+
+ for_each_test_and_set_bit(bit, bmap, EXP1_IN_BITS)
+ cnt++;
+
+ expect_eq_uint(EXP1_IN_BITS - w, cnt);
+ expect_eq_uint(EXP1_IN_BITS, bitmap_weight(bmap, EXP1_IN_BITS));
+
+ bitmap_copy(bmap, exp1, EXP1_IN_BITS);
+ w = bitmap_weight(bmap, EXP1_IN_BITS);
+ w_part = bitmap_weight(bmap, EXP1_IN_BITS / 3);
+ cnt = 0;
+
+ bit = EXP1_IN_BITS / 3;
+ for_each_test_and_set_bit_from(bit, bmap, EXP1_IN_BITS)
+ cnt++;
+
+ expect_eq_uint(EXP1_IN_BITS - bitmap_weight(bmap, EXP1_IN_BITS),
+ EXP1_IN_BITS / 3 - bitmap_weight(bmap, EXP1_IN_BITS / 3));
+ expect_eq_uint(EXP1_IN_BITS * 2 / 3 - (w - w_part), cnt);
+}
+
static void __init test_find_nth_bit(void)
{
unsigned long b, bit, cnt = 0;
@@ -1273,6 +1332,8 @@ static void __init selftest(void)
test_for_each_clear_bitrange_from();
test_for_each_set_clump8();
test_for_each_set_bit_wrap();
+
+ test_find_and_bit();
}
KSTM_MODULE_LOADERS(test_bitmap);
--
2.40.1
Powered by blists - more mailing lists