diff options
| author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2014-10-13 18:55:14 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-13 20:18:26 -0400 |
| commit | 45ff337a54c154680edf0c538e5c9eb4a2f862cc (patch) | |
| tree | c0678933a57841062c68da0b42dff92d7b2e8903 /lib | |
| parent | d295634e965ecacdb44c6760b3ca4eae08812715 (diff) | |
lib / string_helpers: refactoring the test suite
This patch prepares test suite for a following update. It introduces
test_string_check_buf() helper which checks the result and dumps an error.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "John W . Linville" <linville@tuxdriver.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/test-string_helpers.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 6ac48de04c0e..ac44c9245dcf 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c | |||
| @@ -10,6 +10,26 @@ | |||
| 10 | #include <linux/string.h> | 10 | #include <linux/string.h> |
| 11 | #include <linux/string_helpers.h> | 11 | #include <linux/string_helpers.h> |
| 12 | 12 | ||
| 13 | static __init bool test_string_check_buf(const char *name, unsigned int flags, | ||
| 14 | char *in, size_t p, | ||
| 15 | char *out_real, size_t q_real, | ||
| 16 | char *out_test, size_t q_test) | ||
| 17 | { | ||
| 18 | if (q_real == q_test && !memcmp(out_test, out_real, q_test)) | ||
| 19 | return true; | ||
| 20 | |||
| 21 | pr_warn("Test '%s' failed: flags = %u\n", name, flags); | ||
| 22 | |||
| 23 | print_hex_dump(KERN_WARNING, "Input: ", DUMP_PREFIX_NONE, 16, 1, | ||
| 24 | in, p, true); | ||
| 25 | print_hex_dump(KERN_WARNING, "Expected: ", DUMP_PREFIX_NONE, 16, 1, | ||
| 26 | out_test, q_test, true); | ||
| 27 | print_hex_dump(KERN_WARNING, "Got: ", DUMP_PREFIX_NONE, 16, 1, | ||
| 28 | out_real, q_real, true); | ||
| 29 | |||
| 30 | return false; | ||
| 31 | } | ||
| 32 | |||
| 13 | struct test_string { | 33 | struct test_string { |
| 14 | const char *in; | 34 | const char *in; |
| 15 | const char *out; | 35 | const char *out; |
| @@ -39,7 +59,8 @@ static const struct test_string strings[] __initconst = { | |||
| 39 | }, | 59 | }, |
| 40 | }; | 60 | }; |
| 41 | 61 | ||
| 42 | static void __init test_string_unescape(unsigned int flags, bool inplace) | 62 | static void __init test_string_unescape(const char *name, unsigned int flags, |
| 63 | bool inplace) | ||
| 43 | { | 64 | { |
| 44 | char in[256]; | 65 | char in[256]; |
| 45 | char out_test[256]; | 66 | char out_test[256]; |
| @@ -77,15 +98,8 @@ static void __init test_string_unescape(unsigned int flags, bool inplace) | |||
| 77 | q_real = string_unescape(in, out_real, q_real, flags); | 98 | q_real = string_unescape(in, out_real, q_real, flags); |
| 78 | } | 99 | } |
| 79 | 100 | ||
| 80 | if (q_real != q_test || memcmp(out_test, out_real, q_test)) { | 101 | test_string_check_buf(name, flags, in, p - 1, out_real, q_real, |
| 81 | pr_warn("Test failed: flags = %u\n", flags); | 102 | out_test, q_test); |
| 82 | print_hex_dump(KERN_WARNING, "Input: ", | ||
| 83 | DUMP_PREFIX_NONE, 16, 1, in, p - 1, true); | ||
| 84 | print_hex_dump(KERN_WARNING, "Expected: ", | ||
| 85 | DUMP_PREFIX_NONE, 16, 1, out_test, q_test, true); | ||
| 86 | print_hex_dump(KERN_WARNING, "Got: ", | ||
| 87 | DUMP_PREFIX_NONE, 16, 1, out_real, q_real, true); | ||
| 88 | } | ||
| 89 | } | 103 | } |
| 90 | 104 | ||
| 91 | static int __init test_string_helpers_init(void) | 105 | static int __init test_string_helpers_init(void) |
| @@ -94,8 +108,9 @@ static int __init test_string_helpers_init(void) | |||
| 94 | 108 | ||
| 95 | pr_info("Running tests...\n"); | 109 | pr_info("Running tests...\n"); |
| 96 | for (i = 0; i < UNESCAPE_ANY + 1; i++) | 110 | for (i = 0; i < UNESCAPE_ANY + 1; i++) |
| 97 | test_string_unescape(i, false); | 111 | test_string_unescape("unescape", i, false); |
| 98 | test_string_unescape(get_random_int() % (UNESCAPE_ANY + 1), true); | 112 | test_string_unescape("unescape inplace", |
| 113 | get_random_int() % (UNESCAPE_ANY + 1), true); | ||
| 99 | 114 | ||
| 100 | return -EINVAL; | 115 | return -EINVAL; |
| 101 | } | 116 | } |
