diff options
author | Anton Blanchard <anton@samba.org> | 2015-01-20 20:27:39 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-01-23 00:44:23 -0500 |
commit | 521adf5357105f6f750fbe7bca958fab3b19df2e (patch) | |
tree | 74f9dc6108221b20aa7ded50b1ed47528d1a9538 | |
parent | 15c2d45d17418cc4a712608c78ff3b5f0583d83b (diff) |
selftests/powerpc: Add memcmp testcase
Add a testcase for the new ppc64 memcmp.
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
6 files changed, 133 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile index f6ff90a76bd7..1d5e7ad2c460 100644 --- a/tools/testing/selftests/powerpc/Makefile +++ b/tools/testing/selftests/powerpc/Makefile | |||
@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR | |||
13 | 13 | ||
14 | export CC CFLAGS | 14 | export CC CFLAGS |
15 | 15 | ||
16 | TARGETS = pmu copyloops mm tm primitives | 16 | TARGETS = pmu copyloops mm tm primitives stringloops |
17 | 17 | ||
18 | endif | 18 | endif |
19 | 19 | ||
diff --git a/tools/testing/selftests/powerpc/stringloops/.gitignore b/tools/testing/selftests/powerpc/stringloops/.gitignore new file mode 100644 index 000000000000..0b43da74ee46 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/.gitignore | |||
@@ -0,0 +1 @@ | |||
memcmp | |||
diff --git a/tools/testing/selftests/powerpc/stringloops/Makefile b/tools/testing/selftests/powerpc/stringloops/Makefile new file mode 100644 index 000000000000..506d77346477 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/Makefile | |||
@@ -0,0 +1,20 @@ | |||
1 | # The loops are all 64-bit code | ||
2 | CFLAGS += -m64 | ||
3 | CFLAGS += -I$(CURDIR) | ||
4 | |||
5 | PROGS := memcmp | ||
6 | EXTRA_SOURCES := memcmp_64.S ../harness.c | ||
7 | |||
8 | all: $(PROGS) | ||
9 | |||
10 | $(PROGS): $(EXTRA_SOURCES) | ||
11 | |||
12 | run_tests: all | ||
13 | @-for PROG in $(PROGS); do \ | ||
14 | ./$$PROG; \ | ||
15 | done; | ||
16 | |||
17 | clean: | ||
18 | rm -f $(PROGS) *.o | ||
19 | |||
20 | .PHONY: all run_tests clean | ||
diff --git a/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h b/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h new file mode 100644 index 000000000000..11bece87e880 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/asm/ppc_asm.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #include <ppc-asm.h> | ||
2 | |||
3 | #ifndef r1 | ||
4 | #define r1 sp | ||
5 | #endif | ||
6 | |||
7 | #define _GLOBAL(A) FUNC_START(test_ ## A) | ||
diff --git a/tools/testing/selftests/powerpc/stringloops/memcmp.c b/tools/testing/selftests/powerpc/stringloops/memcmp.c new file mode 100644 index 000000000000..17417dd70708 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/memcmp.c | |||
@@ -0,0 +1,103 @@ | |||
1 | #include <malloc.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "../utils.h" | ||
5 | |||
6 | #define SIZE 256 | ||
7 | #define ITERATIONS 10000 | ||
8 | |||
9 | int test_memcmp(const void *s1, const void *s2, size_t n); | ||
10 | |||
11 | /* test all offsets and lengths */ | ||
12 | static void test_one(char *s1, char *s2) | ||
13 | { | ||
14 | unsigned long offset, size; | ||
15 | |||
16 | for (offset = 0; offset < SIZE; offset++) { | ||
17 | for (size = 0; size < (SIZE-offset); size++) { | ||
18 | int x, y; | ||
19 | unsigned long i; | ||
20 | |||
21 | y = memcmp(s1+offset, s2+offset, size); | ||
22 | x = test_memcmp(s1+offset, s2+offset, size); | ||
23 | |||
24 | if (((x ^ y) < 0) && /* Trick to compare sign */ | ||
25 | ((x | y) != 0)) { /* check for zero */ | ||
26 | printf("memcmp returned %d, should have returned %d (offset %ld size %ld)\n", x, y, offset, size); | ||
27 | |||
28 | for (i = offset; i < offset+size; i++) | ||
29 | printf("%02x ", s1[i]); | ||
30 | printf("\n"); | ||
31 | |||
32 | for (i = offset; i < offset+size; i++) | ||
33 | printf("%02x ", s2[i]); | ||
34 | printf("\n"); | ||
35 | abort(); | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | static int testcase(void) | ||
42 | { | ||
43 | char *s1; | ||
44 | char *s2; | ||
45 | unsigned long i; | ||
46 | |||
47 | s1 = memalign(128, SIZE); | ||
48 | if (!s1) { | ||
49 | perror("memalign"); | ||
50 | exit(1); | ||
51 | } | ||
52 | |||
53 | s2 = memalign(128, SIZE); | ||
54 | if (!s2) { | ||
55 | perror("memalign"); | ||
56 | exit(1); | ||
57 | } | ||
58 | |||
59 | srandom(1); | ||
60 | |||
61 | for (i = 0; i < ITERATIONS; i++) { | ||
62 | unsigned long j; | ||
63 | unsigned long change; | ||
64 | |||
65 | for (j = 0; j < SIZE; j++) | ||
66 | s1[j] = random(); | ||
67 | |||
68 | memcpy(s2, s1, SIZE); | ||
69 | |||
70 | /* change one byte */ | ||
71 | change = random() % SIZE; | ||
72 | s2[change] = random() & 0xff; | ||
73 | |||
74 | test_one(s1, s2); | ||
75 | } | ||
76 | |||
77 | srandom(1); | ||
78 | |||
79 | for (i = 0; i < ITERATIONS; i++) { | ||
80 | unsigned long j; | ||
81 | unsigned long change; | ||
82 | |||
83 | for (j = 0; j < SIZE; j++) | ||
84 | s1[j] = random(); | ||
85 | |||
86 | memcpy(s2, s1, SIZE); | ||
87 | |||
88 | /* change multiple bytes, 1/8 of total */ | ||
89 | for (j = 0; j < SIZE / 8; j++) { | ||
90 | change = random() % SIZE; | ||
91 | s2[change] = random() & 0xff; | ||
92 | } | ||
93 | |||
94 | test_one(s1, s2); | ||
95 | } | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | int main(void) | ||
101 | { | ||
102 | return test_harness(testcase, "memcmp"); | ||
103 | } | ||
diff --git a/tools/testing/selftests/powerpc/stringloops/memcmp_64.S b/tools/testing/selftests/powerpc/stringloops/memcmp_64.S new file mode 120000 index 000000000000..9bc87e438ae9 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/memcmp_64.S | |||
@@ -0,0 +1 @@ | |||
../../../../../arch/powerpc/lib/memcmp_64.S \ No newline at end of file | |||