aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_hexdump.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2016-01-20 17:59:07 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 20:09:18 -0500
commit7aaf4c3e1235cca77dcc1c5a0848687e7d26a42f (patch)
treecc3fc3d1f1eb791ca024f74c6e76c55e5dd37cc5 /lib/test_hexdump.c
parent1dacd9ddd359eed63b210bd9b5000c2cfae287ff (diff)
test_hexdump: print statistics at the end
Like others test are doing print the gathered statistics after test module is finished. Return from the module based on the result. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/test_hexdump.c')
-rw-r--r--lib/test_hexdump.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 11d45f510d6c..3f415d8101f3 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -44,6 +44,9 @@ static const char * const test_data_8_le[] __initconst = {
44 44
45#define FILL_CHAR '#' 45#define FILL_CHAR '#'
46 46
47static unsigned total_tests __initdata;
48static unsigned failed_tests __initdata;
49
47static void __init test_hexdump_prepare_test(size_t len, int rowsize, 50static void __init test_hexdump_prepare_test(size_t len, int rowsize,
48 int groupsize, char *test, 51 int groupsize, char *test,
49 size_t testlen, bool ascii) 52 size_t testlen, bool ascii)
@@ -107,6 +110,8 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
107 char test[TEST_HEXDUMP_BUF_SIZE]; 110 char test[TEST_HEXDUMP_BUF_SIZE];
108 char real[TEST_HEXDUMP_BUF_SIZE]; 111 char real[TEST_HEXDUMP_BUF_SIZE];
109 112
113 total_tests++;
114
110 memset(real, FILL_CHAR, sizeof(real)); 115 memset(real, FILL_CHAR, sizeof(real));
111 hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real), 116 hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real),
112 ascii); 117 ascii);
@@ -119,6 +124,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
119 pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize); 124 pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
120 pr_err("Result: '%s'\n", real); 125 pr_err("Result: '%s'\n", real);
121 pr_err("Expect: '%s'\n", test); 126 pr_err("Expect: '%s'\n", test);
127 failed_tests++;
122 } 128 }
123} 129}
124 130
@@ -143,6 +149,8 @@ static void __init test_hexdump_overflow(size_t buflen, size_t len,
143 int ae, he, e, f, r; 149 int ae, he, e, f, r;
144 bool a; 150 bool a;
145 151
152 total_tests++;
153
146 memset(buf, FILL_CHAR, sizeof(buf)); 154 memset(buf, FILL_CHAR, sizeof(buf));
147 155
148 r = hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii); 156 r = hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii);
@@ -175,6 +183,7 @@ static void __init test_hexdump_overflow(size_t buflen, size_t len,
175 len, buflen, strnlen(buf, sizeof(buf))); 183 len, buflen, strnlen(buf, sizeof(buf)));
176 pr_err("Result: %d '%s'\n", r, buf); 184 pr_err("Result: %d '%s'\n", r, buf);
177 pr_err("Expect: %d '%s'\n", e, test); 185 pr_err("Expect: %d '%s'\n", e, test);
186 failed_tests++;
178 } 187 }
179} 188}
180 189
@@ -196,8 +205,6 @@ static int __init test_hexdump_init(void)
196 unsigned int i; 205 unsigned int i;
197 int rowsize; 206 int rowsize;
198 207
199 pr_info("Running tests...\n");
200
201 rowsize = (get_random_int() % 2 + 1) * 16; 208 rowsize = (get_random_int() % 2 + 1) * 16;
202 for (i = 0; i < 16; i++) 209 for (i = 0; i < 16; i++)
203 test_hexdump_set(rowsize, false); 210 test_hexdump_set(rowsize, false);
@@ -212,7 +219,20 @@ static int __init test_hexdump_init(void)
212 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 219 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
213 test_hexdump_overflow_set(i, true); 220 test_hexdump_overflow_set(i, true);
214 221
215 return -EINVAL; 222 if (failed_tests == 0)
223 pr_info("all %u tests passed\n", total_tests);
224 else
225 pr_err("failed %u out of %u tests\n", failed_tests, total_tests);
226
227 return failed_tests ? -EINVAL : 0;
216} 228}
217module_init(test_hexdump_init); 229module_init(test_hexdump_init);
230
231static void __exit test_hexdump_exit(void)
232{
233 /* do nothing */
234}
235module_exit(test_hexdump_exit);
236
237MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
218MODULE_LICENSE("Dual BSD/GPL"); 238MODULE_LICENSE("Dual BSD/GPL");