mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Yury Norov <yury.norov@gmail.com>
Subject: [PATCH v3 2/8] bitmap: add test for bitmap_*_region() functions
Date: Tue, 15 Aug 2023 16:36:22 -0700	[thread overview]
Message-ID: <20230815233628.45016-3-yury.norov@gmail.com> (raw)
In-Reply-To: <20230815233628.45016-1-yury.norov@gmail.com>

Test basic functionality of bitmap_{allocate,release,find_free}_region()
functions.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 lib/test_bitmap.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index f2ea9f30c7c5..def7d2f9bd14 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -330,6 +330,29 @@ static void __init test_copy(void)
 	expect_eq_pbl("0-108,128-1023", bmap2, 1024);
 }
 
+static void __init test_bitmap_region(void)
+{
+	int pos, order;
+
+	DECLARE_BITMAP(bmap, 1000);
+
+	bitmap_zero(bmap, 1000);
+
+	for (order = 0; order < 10; order++) {
+		pos = bitmap_find_free_region(bmap, 1000, order);
+		if (order == 0)
+			expect_eq_uint(pos, 0);
+		else
+			expect_eq_uint(pos, BIT(order) < 512 ? BIT(order) : -ENOMEM);
+	}
+
+	bitmap_release_region(bmap, 0, 0);
+	for (order = 1; order < 9; order++)
+		bitmap_release_region(bmap, BIT(order), order);
+
+	expect_eq_uint(bitmap_weight(bmap, 1000), 0);
+}
+
 #define EXP2_IN_BITS	(sizeof(exp2) * 8)
 
 static void __init test_replace(void)
@@ -1227,6 +1250,7 @@ static void __init selftest(void)
 	test_zero_clear();
 	test_fill_set();
 	test_copy();
+	test_bitmap_region();
 	test_replace();
 	test_bitmap_arr32();
 	test_bitmap_arr64();
-- 
2.39.2


  parent reply	other threads:[~2023-08-15 23:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 23:36 [PATCH v3 0/8] bitmap: cleanup bitmap_*_region() implementation Yury Norov
2023-08-15 23:36 ` [PATCH v3 1/8] bitmap: align __reg_op() wrappers with modern coding style Yury Norov
2023-08-17  9:39   ` Andy Shevchenko
2023-08-17 14:22     ` Yury Norov
2023-08-17 15:47       ` Andy Shevchenko
2023-08-15 23:36 ` Yury Norov [this message]
2023-08-17  9:43   ` [PATCH v3 2/8] bitmap: add test for bitmap_*_region() functions Andy Shevchenko
2023-08-15 23:36 ` [PATCH v3 3/8] bitmap: fix opencoded bitmap_allocate_region() Yury Norov
2023-08-17  9:45   ` Andy Shevchenko
2023-08-29  1:36     ` Yury Norov
2023-08-15 23:36 ` [PATCH v3 4/8] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Yury Norov
2023-08-17  9:46   ` Andy Shevchenko
2023-08-15 23:36 ` [PATCH v3 5/8] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Yury Norov
2023-08-17  9:46   ` Andy Shevchenko
2023-08-15 23:36 ` [PATCH v3 6/8] bitmap: replace _reg_op(REG_OP_ISFREE) with find_next_bit() Yury Norov
2023-08-15 23:36 ` [PATCH v3 7/8] bitmap: drop _reg_op() function Yury Norov
2023-08-17  9:47   ` Andy Shevchenko
2023-08-29  1:53     ` Yury Norov
2023-08-15 23:36 ` [PATCH v3 8/8] bitmap: move bitmap_*_region functions to bitmap.h Yury Norov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230815233628.45016-3-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®