diff options
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 | ||