diff options
Diffstat (limited to 'lib/test-string_helpers.c')
| -rw-r--r-- | lib/test-string_helpers.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 8e376efd88a4..98866a770770 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c | |||
| @@ -326,6 +326,39 @@ out: | |||
| 326 | kfree(out_test); | 326 | kfree(out_test); |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | #define string_get_size_maxbuf 16 | ||
| 330 | #define test_string_get_size_one(size, blk_size, units, exp_result) \ | ||
| 331 | do { \ | ||
| 332 | BUILD_BUG_ON(sizeof(exp_result) >= string_get_size_maxbuf); \ | ||
| 333 | __test_string_get_size((size), (blk_size), (units), \ | ||
| 334 | (exp_result)); \ | ||
| 335 | } while (0) | ||
| 336 | |||
| 337 | |||
| 338 | static __init void __test_string_get_size(const u64 size, const u64 blk_size, | ||
| 339 | const enum string_size_units units, | ||
| 340 | const char *exp_result) | ||
| 341 | { | ||
| 342 | char buf[string_get_size_maxbuf]; | ||
| 343 | |||
| 344 | string_get_size(size, blk_size, units, buf, sizeof(buf)); | ||
| 345 | if (!memcmp(buf, exp_result, strlen(exp_result) + 1)) | ||
| 346 | return; | ||
| 347 | |||
| 348 | buf[sizeof(buf) - 1] = '\0'; | ||
| 349 | pr_warn("Test 'test_string_get_size_one' failed!\n"); | ||
| 350 | pr_warn("string_get_size(size = %llu, blk_size = %llu, units = %d\n", | ||
| 351 | size, blk_size, units); | ||
| 352 | pr_warn("expected: '%s', got '%s'\n", exp_result, buf); | ||
| 353 | } | ||
| 354 | |||
| 355 | static __init void test_string_get_size(void) | ||
| 356 | { | ||
| 357 | test_string_get_size_one(16384, 512, STRING_UNITS_2, "8.00 MiB"); | ||
| 358 | test_string_get_size_one(8192, 4096, STRING_UNITS_10, "32.7 MB"); | ||
| 359 | test_string_get_size_one(1, 512, STRING_UNITS_10, "512 B"); | ||
| 360 | } | ||
| 361 | |||
| 329 | static int __init test_string_helpers_init(void) | 362 | static int __init test_string_helpers_init(void) |
| 330 | { | 363 | { |
| 331 | unsigned int i; | 364 | unsigned int i; |
| @@ -344,6 +377,9 @@ static int __init test_string_helpers_init(void) | |||
| 344 | for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) | 377 | for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) |
| 345 | test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1); | 378 | test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1); |
| 346 | 379 | ||
| 380 | /* Test string_get_size() */ | ||
| 381 | test_string_get_size(); | ||
| 382 | |||
| 347 | return -EINVAL; | 383 | return -EINVAL; |
| 348 | } | 384 | } |
| 349 | module_init(test_string_helpers_init); | 385 | module_init(test_string_helpers_init); |
