[Pdbg] [PATCH v5 2/5] tests: Add tests for hexdump()

Amitay Isaacs amitay at ozlabs.org
Wed Apr 10 18:01:48 AEST 2019


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 Makefile.am              |   8 ++-
 src/tests/hexdump_test.c |  83 +++++++++++++++++++++++++++
 tests/test_hexdump.sh    | 119 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 src/tests/hexdump_test.c
 create mode 100755 tests/test_hexdump.sh

diff --git a/Makefile.am b/Makefile.am
index f1e06f6..d34cf20 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,12 +9,13 @@ libpdbg_tests = libpdbg_target_test \
 		libpdbg_probe_test3
 
 bin_PROGRAMS = pdbg
-check_PROGRAMS = $(libpdbg_tests) optcmd_test
+check_PROGRAMS = $(libpdbg_tests) optcmd_test hexdump_test
 
 PDBG_TESTS = \
 	tests/test_selection.sh 	\
 	tests/test_selection2.sh 	\
-	tests/test_hw_bmc.sh
+	tests/test_hw_bmc.sh		\
+	tests/test_hexdump.sh
 
 TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS)
 
@@ -67,6 +68,9 @@ DT_headers = $(DT:.dts=.dt.h)
 optcmd_test_SOURCES = src/optcmd.c src/parsers.c src/tests/optcmd_test.c
 optcmd_test_CFLAGS = -Wall -g
 
+hexdump_test_SOURCES = src/util.c src/tests/hexdump_test.c
+hexdump_test_CFLAGS = -Wall -g
+
 pdbg_SOURCES = \
 	src/cfam.c \
 	src/htm.c \
diff --git a/src/tests/hexdump_test.c b/src/tests/hexdump_test.c
new file mode 100644
index 0000000..05ecc8b
--- /dev/null
+++ b/src/tests/hexdump_test.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../util.h"
+
+static void test1(uint8_t *bytes, int size)
+{
+	hexdump(0, bytes, size, 1);
+	hexdump(0, bytes, size, 2);
+	hexdump(0, bytes, size, 4);
+	hexdump(0, bytes, size, 8);
+}
+
+static void test2(uint8_t *bytes)
+{
+	int i;
+
+	for (i=16; i>0; i--) {
+		hexdump(0x1000, bytes, i, 1);
+	}
+}
+
+static void test3(uint8_t *bytes)
+{
+	int i;
+
+	for (i=15; i>=0; i--) {
+		hexdump(0x1000+i, bytes, 16-i, 1);
+	}
+}
+
+static void test4(uint8_t *bytes)
+{
+	int i;
+
+	for (i=0; i<16; i++) {
+		hexdump(0x2000+i, bytes, 16, 1);
+	}
+}
+
+int main(int argc, const char **argv)
+{
+	uint8_t bytes[1000];
+	int test_num, i;
+	int count = 0;
+
+	for (i=0; i<1000; i++)
+		bytes[i] = i % 0xff;
+
+	if (argc < 2) {
+		exit(1);
+	}
+
+	test_num = atoi(argv[1]);
+
+	switch (test_num) {
+	case 1:
+		if (argc == 3)
+			count = atoi(argv[2]);
+		if (count <= 0 || count > 1000)
+			count = 100;
+
+		test1(bytes, count);
+		break;
+
+	case 2:
+		test2(bytes);
+		break;
+
+	case 3:
+		test3(bytes);
+		break;
+
+	case 4:
+		test4(bytes);
+		break;
+
+	default:
+		exit(1);
+	}
+
+	return 0;
+}
diff --git a/tests/test_hexdump.sh b/tests/test_hexdump.sh
new file mode 100755
index 0000000..9289d2c
--- /dev/null
+++ b/tests/test_hexdump.sh
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. $(dirname "$0")/driver.sh
+
+test_group "hexdump tests"
+
+test_result 0 <<EOF
+0x0000000000000000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000000010: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
+0x0000000000000020: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
+0x0000000000000030: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 
+0x0000000000000040: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
+0x0000000000000050: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
+0x0000000000000060: 60 61 62 63 
+0x0000000000000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f 
+0x0000000000000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f 
+0x0000000000000020: 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f 
+0x0000000000000030: 3031 3233 3435 3637 3839 3a3b 3c3d 3e3f 
+0x0000000000000040: 4041 4243 4445 4647 4849 4a4b 4c4d 4e4f 
+0x0000000000000050: 5051 5253 5455 5657 5859 5a5b 5c5d 5e5f 
+0x0000000000000060: 6061 6263 
+0x0000000000000000: 00010203 04050607 08090a0b 0c0d0e0f 
+0x0000000000000010: 10111213 14151617 18191a1b 1c1d1e1f 
+0x0000000000000020: 20212223 24252627 28292a2b 2c2d2e2f 
+0x0000000000000030: 30313233 34353637 38393a3b 3c3d3e3f 
+0x0000000000000040: 40414243 44454647 48494a4b 4c4d4e4f 
+0x0000000000000050: 50515253 54555657 58595a5b 5c5d5e5f 
+0x0000000000000060: 60616263 
+0x0000000000000000: 0001020304050607 08090a0b0c0d0e0f 
+0x0000000000000010: 1011121314151617 18191a1b1c1d1e1f 
+0x0000000000000020: 2021222324252627 28292a2b2c2d2e2f 
+0x0000000000000030: 3031323334353637 38393a3b3c3d3e3f 
+0x0000000000000040: 4041424344454647 48494a4b4c4d4e4f 
+0x0000000000000050: 5051525354555657 58595a5b5c5d5e5f 
+0x0000000000000060: 60616263
+EOF
+
+test_run hexdump_test 1
+
+
+test_result 0 <<EOF
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 
+0x0000000000001000: 00 01 02 03 04 05 06 07 
+0x0000000000001000: 00 01 02 03 04 05 06 
+0x0000000000001000: 00 01 02 03 04 05 
+0x0000000000001000: 00 01 02 03 04 
+0x0000000000001000: 00 01 02 03 
+0x0000000000001000: 00 01 02 
+0x0000000000001000: 00 01 
+0x0000000000001000: 00 
+EOF
+
+test_run hexdump_test 2
+
+
+test_result 0 <<EOF
+0x0000000000001000:                                              00 
+0x0000000000001000:                                           00 01 
+0x0000000000001000:                                        00 01 02 
+0x0000000000001000:                                     00 01 02 03 
+0x0000000000001000:                                  00 01 02 03 04 
+0x0000000000001000:                               00 01 02 03 04 05 
+0x0000000000001000:                            00 01 02 03 04 05 06 
+0x0000000000001000:                         00 01 02 03 04 05 06 07 
+0x0000000000001000:                      00 01 02 03 04 05 06 07 08 
+0x0000000000001000:                   00 01 02 03 04 05 06 07 08 09 
+0x0000000000001000:                00 01 02 03 04 05 06 07 08 09 0a 
+0x0000000000001000:             00 01 02 03 04 05 06 07 08 09 0a 0b 
+0x0000000000001000:          00 01 02 03 04 05 06 07 08 09 0a 0b 0c 
+0x0000000000001000:       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 
+0x0000000000001000:    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 
+0x0000000000001000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+EOF
+
+test_run hexdump_test 3
+
+
+test_result 0 <<EOF
+0x0000000000002000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 
+0x0000000000002010: 0f 
+0x0000000000002000:       00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 
+0x0000000000002010: 0e 0f 
+0x0000000000002000:          00 01 02 03 04 05 06 07 08 09 0a 0b 0c 
+0x0000000000002010: 0d 0e 0f 
+0x0000000000002000:             00 01 02 03 04 05 06 07 08 09 0a 0b 
+0x0000000000002010: 0c 0d 0e 0f 
+0x0000000000002000:                00 01 02 03 04 05 06 07 08 09 0a 
+0x0000000000002010: 0b 0c 0d 0e 0f 
+0x0000000000002000:                   00 01 02 03 04 05 06 07 08 09 
+0x0000000000002010: 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                      00 01 02 03 04 05 06 07 08 
+0x0000000000002010: 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                         00 01 02 03 04 05 06 07 
+0x0000000000002010: 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                            00 01 02 03 04 05 06 
+0x0000000000002010: 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                               00 01 02 03 04 05 
+0x0000000000002010: 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                                  00 01 02 03 04 
+0x0000000000002010: 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                                     00 01 02 03 
+0x0000000000002010: 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                                        00 01 02 
+0x0000000000002010: 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                                           00 01 
+0x0000000000002010: 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+0x0000000000002000:                                              00 
+0x0000000000002010: 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
+EOF
+
+test_run hexdump_test 4
-- 
2.20.1



More information about the Pdbg mailing list