Skip to contentSkip to conversation

test-hexdump: test the return value of the hex_dump_to_buffer

PATCH In review Wang Long 2 participants 3 messages Feb 15, 2015 – Feb 26, 2015 Library code

lore
Share & tools
lore

Wang Long

author
#0 lore raw

PATCH 1/1 test-hexdump: test the return value of the hex_dump_to_buffer

As the function hex_dump_to_buffer returns the amount of bytes placed in the buffer without terminating NUL. the test-hexdump should test the return value of it.

---
 lib/test-hexdump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/test-hexdump.c +3 -2
index daf29a39..9243be7 100644
@@ -52,8 +52,9 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 	size_t l = len;
 	int gs = groupsize, rs = rowsize;
 	unsigned int i;
+	int r;
 
-	hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
+	r = hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
 
 	if (rs != 16 && rs != 32)
 		rs = 16;
@@ -96,7 +97,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 
 	*p = '\0';
 
-	if (strcmp(test, real)) {
+	if (strcmp(test, real) || r != strlen(real)) {
 		pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
 		pr_err("Result: '%s'\n", real);
 		pr_err("Expect: '%s'\n", test);
Signature · 1 line
1.8.3.4
#1 lore raw
Quoted 3 lines · Wang Long

As the function hex_dump_to_buffer returns the amount of bytes placed in the buffer without terminating NUL. the test-hexdump should test the return value of it.

I don't think it's needed. When the prototype was changed the new test case had been introduced to cover the overflow cases, i.e. test_hexdump_overflow().

Quoted 30 lines
---
 lib/test-hexdump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/test-hexdump.c +3 -2
index daf29a39..9243be7 100644
@@ -52,8 +52,9 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 	size_t l = len;
 	int gs = groupsize, rs = rowsize;
 	unsigned int i;
+	int r;
 
-	hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
+	r = hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
 
 	if (rs != 16 && rs != 32)
 		rs = 16;
@@ -96,7 +97,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 
 	*p = '\0';
 
-	if (strcmp(test, real)) {
+	if (strcmp(test, real) || r != strlen(real)) {
 		pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
 		pr_err("Result: '%s'\n", real);
 		pr_err("Expect: '%s'\n", test);
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#2 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Wang Long

As the function hex_dump_to_buffer returns the amount of bytes placed in the buffer without terminating NUL. the test-hexdump should test the return value of it.

I don't think it's needed. When the prototype was changed the new test case had been introduced to cover the overflow cases, i.e. test_hexdump_overflow().

ok, thanks.

Quoted 32 lines
Quoted 30 lines
---
 lib/test-hexdump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/test-hexdump.c +3 -2
index daf29a39..9243be7 100644
@@ -52,8 +52,9 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 	size_t l = len;
 	int gs = groupsize, rs = rowsize;
 	unsigned int i;
+	int r;
 
-	hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
+	r = hex_dump_to_buffer(data_b, l, rs, gs, real, sizeof(real), ascii);
 
 	if (rs != 16 && rs != 32)
 		rs = 16;
@@ -96,7 +97,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize,
 
 	*p = '\0';
 
-	if (strcmp(test, real)) {
+	if (strcmp(test, real) || r != strlen(real)) {
 		pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
 		pr_err("Result: '%s'\n", real);
 		pr_err("Expect: '%s'\n", test);