diff options
author | Yury Norov <ynorov@caviumnetworks.com> | 2017-09-08 19:15:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:49 -0400 |
commit | 6df0d464dbcc1a55d10ded413beda167cb3c71b0 (patch) | |
tree | 9977ff8d52ff7feced3f93d51f0abee51aba2efe /lib/test_bitmap.c | |
parent | 0a5ce0831d04382aa9e2420e33dff958ddade542 (diff) |
lib/test_bitmap.c: add test for bitmap_parselist()
Do some basic checks for bitmap_parselist().
[akpm@linux-foundation.org: fix printk warning]
Link: http://lkml.kernel.org/r/20170807225438.16161-2-ynorov@caviumnetworks.com
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
Cc: Noam Camus <noamca@mellanox.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
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 | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 2526a2975c51..431c97fb1aa0 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c | |||
@@ -165,6 +165,79 @@ static void __init test_zero_fill_copy(void) | |||
165 | expect_eq_pbl("128-1023", bmap2, 1024); | 165 | expect_eq_pbl("128-1023", bmap2, 1024); |
166 | } | 166 | } |
167 | 167 | ||
168 | #define PARSE_TIME 0x1 | ||
169 | |||
170 | struct test_bitmap_parselist{ | ||
171 | const int errno; | ||
172 | const char *in; | ||
173 | const unsigned long *expected; | ||
174 | const int nbits; | ||
175 | const int flags; | ||
176 | }; | ||
177 | |||
178 | static const unsigned long exp[] = {1, 2, 0x0000ffff, 0xffff0000, 0x55555555, | ||
179 | 0xaaaaaaaa, 0x11111111, 0x22222222, 0xffffffff, | ||
180 | 0xfffffffe, 0x3333333311111111, 0xffffffff77777777}; | ||
181 | static const unsigned long exp2[] = {0x3333333311111111, 0xffffffff77777777}; | ||
182 | |||
183 | static const struct test_bitmap_parselist parselist_tests[] __initconst = { | ||
184 | {0, "0", &exp[0], 8, 0}, | ||
185 | {0, "1", &exp[1], 8, 0}, | ||
186 | {0, "0-15", &exp[2], 32, 0}, | ||
187 | {0, "16-31", &exp[3], 32, 0}, | ||
188 | {0, "0-31:1/2", &exp[4], 32, 0}, | ||
189 | {0, "1-31:1/2", &exp[5], 32, 0}, | ||
190 | {0, "0-31:1/4", &exp[6], 32, 0}, | ||
191 | {0, "1-31:1/4", &exp[7], 32, 0}, | ||
192 | {0, "0-31:4/4", &exp[8], 32, 0}, | ||
193 | {0, "1-31:4/4", &exp[9], 32, 0}, | ||
194 | {0, "0-31:1/4,32-63:2/4", &exp[10], 64, 0}, | ||
195 | {0, "0-31:3/4,32-63:4/4", &exp[11], 64, 0}, | ||
196 | |||
197 | {0, "0-31:1/4,32-63:2/4,64-95:3/4,96-127:4/4", exp2, 128, 0}, | ||
198 | |||
199 | {0, "0-2047:128/256", NULL, 2048, PARSE_TIME}, | ||
200 | |||
201 | {-EINVAL, "-1", NULL, 8, 0}, | ||
202 | {-EINVAL, "-0", NULL, 8, 0}, | ||
203 | {-EINVAL, "10-1", NULL, 8, 0}, | ||
204 | {-EINVAL, "0-31:10/1", NULL, 8, 0}, | ||
205 | }; | ||
206 | |||
207 | static void __init test_bitmap_parselist(void) | ||
208 | { | ||
209 | int i; | ||
210 | int err; | ||
211 | cycles_t cycles; | ||
212 | DECLARE_BITMAP(bmap, 2048); | ||
213 | |||
214 | for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) { | ||
215 | #define ptest parselist_tests[i] | ||
216 | |||
217 | cycles = get_cycles(); | ||
218 | err = bitmap_parselist(ptest.in, bmap, ptest.nbits); | ||
219 | cycles = get_cycles() - cycles; | ||
220 | |||
221 | if (err != ptest.errno) { | ||
222 | pr_err("test %d: input is %s, errno is %d, expected %d\n", | ||
223 | i, ptest.in, err, ptest.errno); | ||
224 | continue; | ||
225 | } | ||
226 | |||
227 | if (!err && ptest.expected | ||
228 | && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) { | ||
229 | pr_err("test %d: input is %s, result is 0x%lx, expected 0x%lx\n", | ||
230 | i, ptest.in, bmap[0], *ptest.expected); | ||
231 | continue; | ||
232 | } | ||
233 | |||
234 | if (ptest.flags & PARSE_TIME) | ||
235 | pr_err("test %d: input is '%s' OK, Time: %llu\n", | ||
236 | i, ptest.in, | ||
237 | (unsigned long long)cycles); | ||
238 | } | ||
239 | } | ||
240 | |||
168 | static void __init test_bitmap_u32_array_conversions(void) | 241 | static void __init test_bitmap_u32_array_conversions(void) |
169 | { | 242 | { |
170 | DECLARE_BITMAP(bmap1, 1024); | 243 | DECLARE_BITMAP(bmap1, 1024); |
@@ -365,6 +438,7 @@ static int __init test_bitmap_init(void) | |||
365 | { | 438 | { |
366 | test_zero_fill_copy(); | 439 | test_zero_fill_copy(); |
367 | test_bitmap_u32_array_conversions(); | 440 | test_bitmap_u32_array_conversions(); |
441 | test_bitmap_parselist(); | ||
368 | test_mem_optimisations(); | 442 | test_mem_optimisations(); |
369 | 443 | ||
370 | if (failed_tests == 0) | 444 | if (failed_tests == 0) |