* [PATCH v2 0/9] hexdump: update test suite
@ 2015-12-09 0:49 Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 1/9] test_hexdump: rename to test_hexdump Andy Shevchenko
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:49 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
The test suite currently doesn't cover many corner cases when
hex_dump_to_buffer() runs into overflow. Refactor and amend test suite to cover
most of the cases.
Andrew, please, update entire series in your pool.
Changelog v2:
- address Rasmus' comments
- add tags
Andy Shevchenko (9):
test_hexdump: rename to test_hexdump
test_hexdump: introduce test_hexdump_prepare_test() helper
test_hexdump: define FILL_CHAR constant
test_hexdump: go through all possible lengths of buffer
test_hexdump: replace magic numbers by their meaning
test_hexdump: switch to memcmp()
test_hexdump: check all bytes in real buffer
test_hexdump: test all possible group sizes for overflow
test_hexdump: print statistics at the end
lib/Makefile | 2 +-
lib/{test-hexdump.c => test_hexdump.c} | 146 +++++++++++++++++++++++----------
2 files changed, 103 insertions(+), 45 deletions(-)
rename lib/{test-hexdump.c => test_hexdump.c} (52%)
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/9] test_hexdump: rename to test_hexdump
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
@ 2015-12-09 0:49 ` Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 2/9] test_hexdump: introduce test_hexdump_prepare_test() helper Andy Shevchenko
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:49 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
Just to follow the scheme that most of the test modules are using.
There is no fuctional change.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/Makefile | 2 +-
lib/{test-hexdump.c => test_hexdump.c} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename lib/{test-hexdump.c => test_hexdump.c} (100%)
diff --git a/lib/Makefile b/lib/Makefile
index eab8592..67945a4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -32,7 +32,7 @@ obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
obj-y += string_helpers.o
obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
obj-y += hexdump.o
-obj-$(CONFIG_TEST_HEXDUMP) += test-hexdump.o
+obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
obj-y += kstrtox.o
obj-$(CONFIG_TEST_BPF) += test_bpf.o
obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
diff --git a/lib/test-hexdump.c b/lib/test_hexdump.c
similarity index 100%
rename from lib/test-hexdump.c
rename to lib/test_hexdump.c
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/9] test_hexdump: introduce test_hexdump_prepare_test() helper
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 1/9] test_hexdump: rename to test_hexdump Andy Shevchenko
@ 2015-12-09 0:49 ` Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant Andy Shevchenko
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:49 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
The function prepares the expected result in the provided buffer.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/test_hexdump.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 5241df3..ed7c6a7 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -42,19 +42,16 @@ static const char * const test_data_8_le[] __initconst = {
"e9ac0f9cad319ca6", "0cafb1439919d14c",
};
-static void __init test_hexdump(size_t len, int rowsize, int groupsize,
- bool ascii)
+static void __init test_hexdump_prepare_test(size_t len, int rowsize,
+ int groupsize, char *test,
+ size_t testlen, bool ascii)
{
- char test[32 * 3 + 2 + 32 + 1];
- char real[32 * 3 + 2 + 32 + 1];
char *p;
const char * const *result;
size_t l = len;
int gs = groupsize, rs = rowsize;
unsigned int i;
- hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
-
if (rs != 16 && rs != 32)
rs = 16;
@@ -73,7 +70,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
else
result = test_data_1_le;
- memset(test, ' ', sizeof(test));
+ memset(test, ' ', testlen);
/* hex dump */
p = test;
@@ -95,6 +92,21 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
}
*p = '\0';
+}
+
+#define TEST_HEXDUMP_BUF_SIZE (32 * 3 + 2 + 32 + 1)
+
+static void __init test_hexdump(size_t len, int rowsize, int groupsize,
+ bool ascii)
+{
+ char test[TEST_HEXDUMP_BUF_SIZE];
+ char real[TEST_HEXDUMP_BUF_SIZE];
+
+ hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real),
+ ascii);
+
+ test_hexdump_prepare_test(len, rowsize, groupsize, test, sizeof(test),
+ ascii);
if (strcmp(test, real)) {
pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 1/9] test_hexdump: rename to test_hexdump Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 2/9] test_hexdump: introduce test_hexdump_prepare_test() helper Andy Shevchenko
@ 2015-12-09 0:49 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 4/9] test_hexdump: go through all possible lengths of buffer Andy Shevchenko
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:49 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
Define a character to fill the test buffers. Though the character should be
printable since it's used when errors are reported. It should neither be from
hex digit [a-fA-F0-9] dictionary nor space. It is recommended not to use one
which is present in ASCII part of the test data. Later on we might switch to
unprintable character to make test case more robust.
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_hexdump.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index ed7c6a7..1ecdb97 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -42,6 +42,8 @@ static const char * const test_data_8_le[] __initconst = {
"e9ac0f9cad319ca6", "0cafb1439919d14c",
};
+#define FILL_CHAR '#'
+
static void __init test_hexdump_prepare_test(size_t len, int rowsize,
int groupsize, char *test,
size_t testlen, bool ascii)
@@ -70,7 +72,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,
else
result = test_data_1_le;
- memset(test, ' ', testlen);
+ memset(test, FILL_CHAR, testlen);
/* hex dump */
p = test;
@@ -79,14 +81,19 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,
size_t amount = strlen(q);
strncpy(p, q, amount);
- p += amount + 1;
+ p += amount;
+
+ *p++ = ' ';
}
if (i)
p--;
/* ASCII part */
if (ascii) {
- p = test + rs * 2 + rs / gs + 1;
+ do {
+ *p++ = ' ';
+ } while (p < test + rs * 2 + rs / gs + 1);
+
strncpy(p, data_a, l);
p += l;
}
@@ -134,7 +141,7 @@ static void __init test_hexdump_overflow(bool ascii)
bool a;
int e, r;
- memset(buf, ' ', sizeof(buf));
+ memset(buf, FILL_CHAR, sizeof(buf));
r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, l, ascii);
@@ -145,14 +152,14 @@ static void __init test_hexdump_overflow(bool ascii)
buf[e + 2] = '\0';
if (!l) {
- a = r == e && buf[0] == ' ';
+ a = r == e && buf[0] == FILL_CHAR;
} else if (l < 3) {
a = r == e && buf[0] == '\0';
} else if (l < 4) {
a = r == e && !strcmp(buf, t);
} else if (ascii) {
if (l < 51)
- a = r == e && buf[l - 1] == '\0' && buf[l - 2] == ' ';
+ a = r == e && buf[l - 1] == '\0' && buf[l - 2] == FILL_CHAR;
else
a = r == e && buf[50] == '\0' && buf[49] == '.';
} else {
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 4/9] test_hexdump: go through all possible lengths of buffer
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (2 preceding siblings ...)
2015-12-09 0:49 ` [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 5/9] test_hexdump: replace magic numbers by their meaning Andy Shevchenko
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
When test for overflow do iterate the buffer length in a range
0 .. BUF_SIZE.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/test_hexdump.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 1ecdb97..940b1d3 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -133,17 +133,16 @@ static void __init test_hexdump_set(int rowsize, bool ascii)
test_hexdump(len, rowsize, 1, ascii);
}
-static void __init test_hexdump_overflow(bool ascii)
+static void __init test_hexdump_overflow(size_t buflen, bool ascii)
{
- char buf[56];
+ char buf[TEST_HEXDUMP_BUF_SIZE];
const char *t = test_data_1_le[0];
- size_t l = get_random_int() % sizeof(buf);
bool a;
int e, r;
memset(buf, FILL_CHAR, sizeof(buf));
- r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, l, ascii);
+ r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, buflen, ascii);
if (ascii)
e = 50;
@@ -151,15 +150,15 @@ static void __init test_hexdump_overflow(bool ascii)
e = 2;
buf[e + 2] = '\0';
- if (!l) {
+ if (!buflen) {
a = r == e && buf[0] == FILL_CHAR;
- } else if (l < 3) {
+ } else if (buflen < 3) {
a = r == e && buf[0] == '\0';
- } else if (l < 4) {
+ } else if (buflen < 4) {
a = r == e && !strcmp(buf, t);
} else if (ascii) {
- if (l < 51)
- a = r == e && buf[l - 1] == '\0' && buf[l - 2] == FILL_CHAR;
+ if (buflen < 51)
+ a = r == e && buf[buflen - 1] == '\0' && buf[buflen - 2] == FILL_CHAR;
else
a = r == e && buf[50] == '\0' && buf[49] == '.';
} else {
@@ -167,7 +166,7 @@ static void __init test_hexdump_overflow(bool ascii)
}
if (!a) {
- pr_err("Len: %zu rc: %u strlen: %zu\n", l, r, strlen(buf));
+ pr_err("Len: %zu rc: %u strlen: %zu\n", buflen, r, strlen(buf));
pr_err("Result: '%s'\n", buf);
}
}
@@ -187,11 +186,11 @@ static int __init test_hexdump_init(void)
for (i = 0; i < 16; i++)
test_hexdump_set(rowsize, true);
- for (i = 0; i < 16; i++)
- test_hexdump_overflow(false);
+ for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
+ test_hexdump_overflow(i, false);
- for (i = 0; i < 16; i++)
- test_hexdump_overflow(true);
+ for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
+ test_hexdump_overflow(i, true);
return -EINVAL;
}
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 5/9] test_hexdump: replace magic numbers by their meaning
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (3 preceding siblings ...)
2015-12-09 0:50 ` [PATCH v2 4/9] test_hexdump: go through all possible lengths of buffer Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 6/9] test_hexdump: switch to memcmp() Andy Shevchenko
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
The magic numbers of the length are converted to their actual meaning,
such as end of the buffer with and without ASCII part.
We don't touch the rest of the magic constants that will be removed in the
following commits.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/test_hexdump.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 940b1d3..141d031 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -137,17 +137,26 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii)
{
char buf[TEST_HEXDUMP_BUF_SIZE];
const char *t = test_data_1_le[0];
+ size_t len = 1;
+ int rs = 16, gs = 1;
+ int ae, he, e, r;
bool a;
- int e, r;
memset(buf, FILL_CHAR, sizeof(buf));
- r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, buflen, ascii);
+ r = hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii);
+
+ /*
+ * Caller must provide the data length multiple of groupsize. The
+ * calculations below are made with that assumption in mind.
+ */
+ ae = rs * 2 /* hex */ + rs / gs /* spaces */ + 1 /* space */ + len /* ascii */;
+ he = (gs * 2 /* hex */ + 1 /* space */) * len / gs - 1 /* no trailing space */;
if (ascii)
- e = 50;
+ e = ae;
else
- e = 2;
+ e = he;
buf[e + 2] = '\0';
if (!buflen) {
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 6/9] test_hexdump: switch to memcmp()
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (4 preceding siblings ...)
2015-12-09 0:50 ` [PATCH v2 5/9] test_hexdump: replace magic numbers by their meaning Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 7/9] test_hexdump: check all bytes in real buffer Andy Shevchenko
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
Better to use memcmp() against entire buffer to check that nothing is happened
to the data in the tail.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_hexdump.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 141d031..4b949aa 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -72,8 +72,6 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize,
else
result = test_data_1_le;
- memset(test, FILL_CHAR, testlen);
-
/* hex dump */
p = test;
for (i = 0; i < l / gs; i++) {
@@ -109,13 +107,15 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
char test[TEST_HEXDUMP_BUF_SIZE];
char real[TEST_HEXDUMP_BUF_SIZE];
+ memset(real, FILL_CHAR, sizeof(real));
hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real),
ascii);
+ memset(test, FILL_CHAR, sizeof(test));
test_hexdump_prepare_test(len, rowsize, groupsize, test, sizeof(test),
ascii);
- if (strcmp(test, real)) {
+ if (memcmp(test, real, TEST_HEXDUMP_BUF_SIZE)) {
pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
pr_err("Result: '%s'\n", real);
pr_err("Expect: '%s'\n", test);
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 7/9] test_hexdump: check all bytes in real buffer
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (5 preceding siblings ...)
2015-12-09 0:50 ` [PATCH v2 6/9] test_hexdump: switch to memcmp() Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 9/9] test_hexdump: print statistics at the end Andy Shevchenko
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
After processing by hex_dump_to_buffer() check all the parts to be expected.
Part 1. The actual expected hex dump with or without ASCII part.
Part 2. Check if the buffer is dirty beyond needed.
Part 3. Return code should be as expected.
This is done by using comparison of the return code and memcmp() against the
test buffer. We fill the buffer by FILL_CHAR ('#') characters, so, we expect to
have a tail of the buffer will be left untouched. The terminating NUL is also
checked by memcmp().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/test_hexdump.c | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 4b949aa..16a7593 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -135,11 +135,10 @@ static void __init test_hexdump_set(int rowsize, bool ascii)
static void __init test_hexdump_overflow(size_t buflen, bool ascii)
{
+ char test[TEST_HEXDUMP_BUF_SIZE];
char buf[TEST_HEXDUMP_BUF_SIZE];
- const char *t = test_data_1_le[0];
- size_t len = 1;
- int rs = 16, gs = 1;
- int ae, he, e, r;
+ int rs = rowsize, gs = groupsize;
+ int ae, he, e, f, r;
bool a;
memset(buf, FILL_CHAR, sizeof(buf));
@@ -157,26 +156,23 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii)
e = ae;
else
e = he;
- buf[e + 2] = '\0';
-
- if (!buflen) {
- a = r == e && buf[0] == FILL_CHAR;
- } else if (buflen < 3) {
- a = r == e && buf[0] == '\0';
- } else if (buflen < 4) {
- a = r == e && !strcmp(buf, t);
- } else if (ascii) {
- if (buflen < 51)
- a = r == e && buf[buflen - 1] == '\0' && buf[buflen - 2] == FILL_CHAR;
- else
- a = r == e && buf[50] == '\0' && buf[49] == '.';
- } else {
- a = r == e && buf[e] == '\0';
+
+ f = min_t(int, e + 1, buflen);
+ if (buflen) {
+ test_hexdump_prepare_test(len, rs, gs, test, sizeof(test), ascii);
+ test[f - 1] = '\0';
}
+ memset(test + f, FILL_CHAR, sizeof(test) - f);
+
+ a = r == e && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE);
+
+ buf[sizeof(buf) - 1] = '\0';
if (!a) {
- pr_err("Len: %zu rc: %u strlen: %zu\n", buflen, r, strlen(buf));
- pr_err("Result: '%s'\n", buf);
+ pr_err("Len: %zu buflen: %zu strlen: %zu\n",
+ len, buflen, strnlen(buf, sizeof(buf)));
+ pr_err("Result: %d '%s'\n", r, buf);
+ pr_err("Expect: %d '%s'\n", e, test);
}
}
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (6 preceding siblings ...)
2015-12-09 0:50 ` [PATCH v2 7/9] test_hexdump: check all bytes in real buffer Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 9/9] test_hexdump: print statistics at the end Andy Shevchenko
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
Currently the only one combination is tested for overflow, i.e. rowsize = 16,
groupsize = 1, len = 1. Do various test to go through all possible branches.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/test_hexdump.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 16a7593..11d45f5 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -133,7 +133,9 @@ static void __init test_hexdump_set(int rowsize, bool ascii)
test_hexdump(len, rowsize, 1, ascii);
}
-static void __init test_hexdump_overflow(size_t buflen, bool ascii)
+static void __init test_hexdump_overflow(size_t buflen, size_t len,
+ int rowsize, int groupsize,
+ bool ascii)
{
char test[TEST_HEXDUMP_BUF_SIZE];
char buf[TEST_HEXDUMP_BUF_SIZE];
@@ -176,6 +178,19 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii)
}
}
+static void __init test_hexdump_overflow_set(size_t buflen, bool ascii)
+{
+ unsigned int i = 0;
+ int rs = (get_random_int() % 2 + 1) * 16;
+
+ do {
+ int gs = 1 << i;
+ size_t len = get_random_int() % rs + gs;
+
+ test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii);
+ } while (i++ < 3);
+}
+
static int __init test_hexdump_init(void)
{
unsigned int i;
@@ -192,10 +207,10 @@ static int __init test_hexdump_init(void)
test_hexdump_set(rowsize, true);
for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
- test_hexdump_overflow(i, false);
+ test_hexdump_overflow_set(i, false);
for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
- test_hexdump_overflow(i, true);
+ test_hexdump_overflow_set(i, true);
return -EINVAL;
}
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 9/9] test_hexdump: print statistics at the end
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
` (7 preceding siblings ...)
2015-12-09 0:50 ` [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow Andy Shevchenko
@ 2015-12-09 0:50 ` Andy Shevchenko
8 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2015-12-09 0:50 UTC (permalink / raw)
To: Rasmus Villemoes, Andrew Morton, linux-kernel; +Cc: Andy Shevchenko
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>
---
lib/test_hexdump.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 11d45f5..3f415d8 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -44,6 +44,9 @@ static const char * const test_data_8_le[] __initconst = {
#define FILL_CHAR '#'
+static unsigned total_tests __initdata;
+static unsigned failed_tests __initdata;
+
static void __init test_hexdump_prepare_test(size_t len, int rowsize,
int groupsize, char *test,
size_t testlen, bool ascii)
@@ -107,6 +110,8 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
char test[TEST_HEXDUMP_BUF_SIZE];
char real[TEST_HEXDUMP_BUF_SIZE];
+ total_tests++;
+
memset(real, FILL_CHAR, sizeof(real));
hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real),
ascii);
@@ -119,6 +124,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
pr_err("Result: '%s'\n", real);
pr_err("Expect: '%s'\n", test);
+ failed_tests++;
}
}
@@ -143,6 +149,8 @@ static void __init test_hexdump_overflow(size_t buflen, size_t len,
int ae, he, e, f, r;
bool a;
+ total_tests++;
+
memset(buf, FILL_CHAR, sizeof(buf));
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,
len, buflen, strnlen(buf, sizeof(buf)));
pr_err("Result: %d '%s'\n", r, buf);
pr_err("Expect: %d '%s'\n", e, test);
+ failed_tests++;
}
}
@@ -196,8 +205,6 @@ static int __init test_hexdump_init(void)
unsigned int i;
int rowsize;
- pr_info("Running tests...\n");
-
rowsize = (get_random_int() % 2 + 1) * 16;
for (i = 0; i < 16; i++)
test_hexdump_set(rowsize, false);
@@ -212,7 +219,20 @@ static int __init test_hexdump_init(void)
for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
test_hexdump_overflow_set(i, true);
- return -EINVAL;
+ if (failed_tests == 0)
+ pr_info("all %u tests passed\n", total_tests);
+ else
+ pr_err("failed %u out of %u tests\n", failed_tests, total_tests);
+
+ return failed_tests ? -EINVAL : 0;
}
module_init(test_hexdump_init);
+
+static void __exit test_hexdump_exit(void)
+{
+ /* do nothing */
+}
+module_exit(test_hexdump_exit);
+
+MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
MODULE_LICENSE("Dual BSD/GPL");
--
2.6.2
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-12-09 0:52 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-09 0:49 [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 1/9] test_hexdump: rename to test_hexdump Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 2/9] test_hexdump: introduce test_hexdump_prepare_test() helper Andy Shevchenko
2015-12-09 0:49 ` [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 4/9] test_hexdump: go through all possible lengths of buffer Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 5/9] test_hexdump: replace magic numbers by their meaning Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 6/9] test_hexdump: switch to memcmp() Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 7/9] test_hexdump: check all bytes in real buffer Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow Andy Shevchenko
2015-12-09 0:50 ` [PATCH v2 9/9] test_hexdump: print statistics at the end Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome