Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1286952 > unrolled thread

[PATCH v2 0/9] hexdump: update test suite

Started byAndy Shevchenko <andriy.shevchenko@linux.intel.com>
First post2015-12-09 02:00 +0100
Last post2015-12-09 02:00 +0100
Articles 5 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH v2 0/9] hexdump: update test suite Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-09 02:00 +0100
    [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-09 02:00 +0100
    [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-09 02:00 +0100
    [PATCH v2 6/9] test_hexdump: switch to memcmp() Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-09 02:00 +0100
    [PATCH v2 1/9] test_hexdump: rename to test_hexdump Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-09 02:00 +0100

#1286952 — [PATCH v2 0/9] hexdump: update test suite

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2015-12-09 02:00 +0100
Subject[PATCH v2 0/9] hexdump: update test suite
Message-ID<qDBgR-17E-3@gated-at.bofh.it>
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1286953 — [PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2015-12-09 02:00 +0100
Subject[PATCH v2 8/9] test_hexdump: test all possible group sizes for overflow
Message-ID<qDBgS-17E-17@gated-at.bofh.it>
In reply to#1286952
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1286954 — [PATCH v2 3/9] test_hexdump: define FILL_CHAR constant

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2015-12-09 02:00 +0100
Subject[PATCH v2 3/9] test_hexdump: define FILL_CHAR constant
Message-ID<qDBgS-17E-15@gated-at.bofh.it>
In reply to#1286952
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1286956 — [PATCH v2 6/9] test_hexdump: switch to memcmp()

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2015-12-09 02:00 +0100
Subject[PATCH v2 6/9] test_hexdump: switch to memcmp()
Message-ID<qDBgS-17E-23@gated-at.bofh.it>
In reply to#1286952
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1286957 — [PATCH v2 1/9] test_hexdump: rename to test_hexdump

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2015-12-09 02:00 +0100
Subject[PATCH v2 1/9] test_hexdump: rename to test_hexdump
Message-ID<qDBgS-17E-21@gated-at.bofh.it>
In reply to#1286952
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web