.. | .. |
---|
238 | 238 | /* terminator */ |
---|
239 | 239 | }}; |
---|
240 | 240 | |
---|
| 241 | +static const struct test_string strings_upper[] __initconst = { |
---|
| 242 | + { |
---|
| 243 | + .in = "abcdefgh1234567890test", |
---|
| 244 | + .out = "ABCDEFGH1234567890TEST", |
---|
| 245 | + }, |
---|
| 246 | + { |
---|
| 247 | + .in = "abCdeFgH1234567890TesT", |
---|
| 248 | + .out = "ABCDEFGH1234567890TEST", |
---|
| 249 | + }, |
---|
| 250 | +}; |
---|
| 251 | + |
---|
| 252 | +static const struct test_string strings_lower[] __initconst = { |
---|
| 253 | + { |
---|
| 254 | + .in = "ABCDEFGH1234567890TEST", |
---|
| 255 | + .out = "abcdefgh1234567890test", |
---|
| 256 | + }, |
---|
| 257 | + { |
---|
| 258 | + .in = "abCdeFgH1234567890TesT", |
---|
| 259 | + .out = "abcdefgh1234567890test", |
---|
| 260 | + }, |
---|
| 261 | +}; |
---|
| 262 | + |
---|
241 | 263 | static __init const char *test_string_find_match(const struct test_string_2 *s2, |
---|
242 | 264 | unsigned int flags) |
---|
243 | 265 | { |
---|
.. | .. |
---|
390 | 412 | test_string_get_size_one(4096, U64_MAX, "75.6 ZB", "64.0 ZiB"); |
---|
391 | 413 | } |
---|
392 | 414 | |
---|
| 415 | +static void __init test_string_upper_lower(void) |
---|
| 416 | +{ |
---|
| 417 | + char *dst; |
---|
| 418 | + int i; |
---|
| 419 | + |
---|
| 420 | + for (i = 0; i < ARRAY_SIZE(strings_upper); i++) { |
---|
| 421 | + const char *s = strings_upper[i].in; |
---|
| 422 | + int len = strlen(strings_upper[i].in) + 1; |
---|
| 423 | + |
---|
| 424 | + dst = kmalloc(len, GFP_KERNEL); |
---|
| 425 | + if (!dst) |
---|
| 426 | + return; |
---|
| 427 | + |
---|
| 428 | + string_upper(dst, s); |
---|
| 429 | + if (memcmp(dst, strings_upper[i].out, len)) { |
---|
| 430 | + pr_warn("Test 'string_upper' failed : expected %s, got %s!\n", |
---|
| 431 | + strings_upper[i].out, dst); |
---|
| 432 | + kfree(dst); |
---|
| 433 | + return; |
---|
| 434 | + } |
---|
| 435 | + kfree(dst); |
---|
| 436 | + } |
---|
| 437 | + |
---|
| 438 | + for (i = 0; i < ARRAY_SIZE(strings_lower); i++) { |
---|
| 439 | + const char *s = strings_lower[i].in; |
---|
| 440 | + int len = strlen(strings_lower[i].in) + 1; |
---|
| 441 | + |
---|
| 442 | + dst = kmalloc(len, GFP_KERNEL); |
---|
| 443 | + if (!dst) |
---|
| 444 | + return; |
---|
| 445 | + |
---|
| 446 | + string_lower(dst, s); |
---|
| 447 | + if (memcmp(dst, strings_lower[i].out, len)) { |
---|
| 448 | + pr_warn("Test 'string_lower failed : : expected %s, got %s!\n", |
---|
| 449 | + strings_lower[i].out, dst); |
---|
| 450 | + kfree(dst); |
---|
| 451 | + return; |
---|
| 452 | + } |
---|
| 453 | + kfree(dst); |
---|
| 454 | + } |
---|
| 455 | +} |
---|
| 456 | + |
---|
393 | 457 | static int __init test_string_helpers_init(void) |
---|
394 | 458 | { |
---|
395 | 459 | unsigned int i; |
---|
.. | .. |
---|
411 | 475 | /* Test string_get_size() */ |
---|
412 | 476 | test_string_get_size(); |
---|
413 | 477 | |
---|
| 478 | + /* Test string upper(), string_lower() */ |
---|
| 479 | + test_string_upper_lower(); |
---|
| 480 | + |
---|
414 | 481 | return -EINVAL; |
---|
415 | 482 | } |
---|
416 | 483 | module_init(test_string_helpers_init); |
---|