Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andy Shevchenko and committed by
Linus Torvalds
45ff337a d295634e

+27 -12
+27 -12
lib/test-string_helpers.c
··· 10 10 #include <linux/string.h> 11 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 33 struct test_string { 14 34 const char *in; 15 35 const char *out; ··· 59 39 }, 60 40 }; 61 41 62 - static void __init test_string_unescape(unsigned int flags, bool inplace) 42 + static void __init test_string_unescape(const char *name, unsigned int flags, 43 + bool inplace) 63 44 { 64 45 char in[256]; 65 46 char out_test[256]; ··· 98 77 q_real = string_unescape(in, out_real, q_real, flags); 99 78 } 100 79 101 - if (q_real != q_test || memcmp(out_test, out_real, q_test)) { 102 - pr_warn("Test failed: flags = %u\n", flags); 103 - print_hex_dump(KERN_WARNING, "Input: ", 104 - DUMP_PREFIX_NONE, 16, 1, in, p - 1, true); 105 - print_hex_dump(KERN_WARNING, "Expected: ", 106 - DUMP_PREFIX_NONE, 16, 1, out_test, q_test, true); 107 - print_hex_dump(KERN_WARNING, "Got: ", 108 - DUMP_PREFIX_NONE, 16, 1, out_real, q_real, true); 109 - } 80 + test_string_check_buf(name, flags, in, p - 1, out_real, q_real, 81 + out_test, q_test); 110 82 } 111 83 112 84 static int __init test_string_helpers_init(void) ··· 108 94 109 95 pr_info("Running tests...\n"); 110 96 for (i = 0; i < UNESCAPE_ANY + 1; i++) 111 - test_string_unescape(i, false); 112 - test_string_unescape(get_random_int() % (UNESCAPE_ANY + 1), true); 97 + test_string_unescape("unescape", i, false); 98 + test_string_unescape("unescape inplace", 99 + get_random_int() % (UNESCAPE_ANY + 1), true); 113 100 114 101 return -EINVAL; 115 102 }