diff options
author | Yury Norov <yury.norov@gmail.com> | 2019-05-14 18:43:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-05-14 22:52:49 -0400 |
commit | 6ea86bdfc169ba9df8484e9d2bb250a874b03c47 (patch) | |
tree | 42ef573a5544e806ec87158cb2e1b6b267545133 /lib/test_bitmap.c | |
parent | a4ab50509c76a03d338f434a271494b450250f0d (diff) |
lib/test_bitmap: add tests for bitmap_parselist_user()
Propagate existing bitmap_parselist() tests to bitmap_parselist_user().
Link: http://lkml.kernel.org/r/20190405173211.11373-6-ynorov@marvell.com
Signed-off-by: Yury Norov <ynorov@marvell.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mike Travis <travis@sgi.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/test_bitmap.c')
-rw-r--r-- | lib/test_bitmap.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6640a82ad44b..d3a501f2a81a 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/printk.h> | 11 | #include <linux/printk.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/string.h> | 13 | #include <linux/string.h> |
14 | #include <linux/uaccess.h> | ||
14 | 15 | ||
15 | #include "../tools/testing/selftests/kselftest_module.h" | 16 | #include "../tools/testing/selftests/kselftest_module.h" |
16 | 17 | ||
@@ -280,39 +281,63 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = { | |||
280 | {-EINVAL, "0-\n", NULL, 8, 0}, | 281 | {-EINVAL, "0-\n", NULL, 8, 0}, |
281 | }; | 282 | }; |
282 | 283 | ||
283 | static void __init test_bitmap_parselist(void) | 284 | static void __init __test_bitmap_parselist(int is_user) |
284 | { | 285 | { |
285 | int i; | 286 | int i; |
286 | int err; | 287 | int err; |
287 | ktime_t time; | 288 | ktime_t time; |
288 | DECLARE_BITMAP(bmap, 2048); | 289 | DECLARE_BITMAP(bmap, 2048); |
290 | char *mode = is_user ? "_user" : ""; | ||
289 | 291 | ||
290 | for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) { | 292 | for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) { |
291 | #define ptest parselist_tests[i] | 293 | #define ptest parselist_tests[i] |
292 | 294 | ||
293 | time = ktime_get(); | 295 | if (is_user) { |
294 | err = bitmap_parselist(ptest.in, bmap, ptest.nbits); | 296 | mm_segment_t orig_fs = get_fs(); |
295 | time = ktime_get() - time; | 297 | size_t len = strlen(ptest.in); |
298 | |||
299 | set_fs(KERNEL_DS); | ||
300 | time = ktime_get(); | ||
301 | err = bitmap_parselist_user(ptest.in, len, | ||
302 | bmap, ptest.nbits); | ||
303 | time = ktime_get() - time; | ||
304 | set_fs(orig_fs); | ||
305 | } else { | ||
306 | time = ktime_get(); | ||
307 | err = bitmap_parselist(ptest.in, bmap, ptest.nbits); | ||
308 | time = ktime_get() - time; | ||
309 | } | ||
296 | 310 | ||
297 | if (err != ptest.errno) { | 311 | if (err != ptest.errno) { |
298 | pr_err("test %d: input is %s, errno is %d, expected %d\n", | 312 | pr_err("parselist%s: %d: input is %s, errno is %d, expected %d\n", |
299 | i, ptest.in, err, ptest.errno); | 313 | mode, i, ptest.in, err, ptest.errno); |
300 | continue; | 314 | continue; |
301 | } | 315 | } |
302 | 316 | ||
303 | if (!err && ptest.expected | 317 | if (!err && ptest.expected |
304 | && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) { | 318 | && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) { |
305 | pr_err("test %d: input is %s, result is 0x%lx, expected 0x%lx\n", | 319 | pr_err("parselist%s: %d: input is %s, result is 0x%lx, expected 0x%lx\n", |
306 | i, ptest.in, bmap[0], *ptest.expected); | 320 | mode, i, ptest.in, bmap[0], |
321 | *ptest.expected); | ||
307 | continue; | 322 | continue; |
308 | } | 323 | } |
309 | 324 | ||
310 | if (ptest.flags & PARSE_TIME) | 325 | if (ptest.flags & PARSE_TIME) |
311 | pr_err("test %d: input is '%s' OK, Time: %llu\n", | 326 | pr_err("parselist%s: %d: input is '%s' OK, Time: %llu\n", |
312 | i, ptest.in, time); | 327 | mode, i, ptest.in, time); |
313 | } | 328 | } |
314 | } | 329 | } |
315 | 330 | ||
331 | static void __init test_bitmap_parselist(void) | ||
332 | { | ||
333 | __test_bitmap_parselist(0); | ||
334 | } | ||
335 | |||
336 | static void __init test_bitmap_parselist_user(void) | ||
337 | { | ||
338 | __test_bitmap_parselist(1); | ||
339 | } | ||
340 | |||
316 | #define EXP_BYTES (sizeof(exp) * 8) | 341 | #define EXP_BYTES (sizeof(exp) * 8) |
317 | 342 | ||
318 | static void __init test_bitmap_arr32(void) | 343 | static void __init test_bitmap_arr32(void) |
@@ -385,6 +410,7 @@ static void __init selftest(void) | |||
385 | test_copy(); | 410 | test_copy(); |
386 | test_bitmap_arr32(); | 411 | test_bitmap_arr32(); |
387 | test_bitmap_parselist(); | 412 | test_bitmap_parselist(); |
413 | test_bitmap_parselist_user(); | ||
388 | test_mem_optimisations(); | 414 | test_mem_optimisations(); |
389 | } | 415 | } |
390 | 416 | ||