Skip to content

Commit db73130

Browse files
committed
lib: bitmap: add performance test for bitmap_print_to_pagebuf
Functional tests for bitmap_print_to_pagebuf() are provided in lib/test_printf.c. This patch adds performance test for a case of fully set bitmap. Signed-off-by: Yury Norov <yury.norov@gmail.com> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent ec288a2 commit db73130

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/test_bitmap.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,42 @@ static void __init test_bitmap_parselist(void)
446446
}
447447
}
448448

449+
static void __init test_bitmap_printlist(void)
450+
{
451+
unsigned long *bmap = kmalloc(PAGE_SIZE, GFP_KERNEL);
452+
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
453+
char expected[256];
454+
int ret, slen;
455+
ktime_t time;
456+
457+
if (!buf || !bmap)
458+
goto out;
459+
460+
memset(bmap, -1, PAGE_SIZE);
461+
slen = snprintf(expected, 256, "0-%ld", PAGE_SIZE * 8 - 1);
462+
if (slen < 0)
463+
goto out;
464+
465+
time = ktime_get();
466+
ret = bitmap_print_to_pagebuf(true, buf, bmap, PAGE_SIZE * 8);
467+
time = ktime_get() - time;
468+
469+
if (ret != slen + 1) {
470+
pr_err("bitmap_print_to_pagebuf: result is %d, expected %d\n", ret, slen);
471+
goto out;
472+
}
473+
474+
if (strncmp(buf, expected, slen)) {
475+
pr_err("bitmap_print_to_pagebuf: result is %s, expected %s\n", buf, expected);
476+
goto out;
477+
}
478+
479+
pr_err("bitmap_print_to_pagebuf: input is '%s', Time: %llu\n", buf, time);
480+
out:
481+
kfree(buf);
482+
kfree(bmap);
483+
}
484+
449485
static const unsigned long parse_test[] __initconst = {
450486
BITMAP_FROM_U64(0),
451487
BITMAP_FROM_U64(1),
@@ -818,6 +854,7 @@ static void __init selftest(void)
818854
test_bitmap_arr32();
819855
test_bitmap_parse();
820856
test_bitmap_parselist();
857+
test_bitmap_printlist();
821858
test_mem_optimisations();
822859
test_for_each_set_clump8();
823860
test_bitmap_cut();

0 commit comments

Comments
 (0)