hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/testing/selftests/powerpc/stringloops/memcmp.c
....@@ -2,7 +2,9 @@
22 #include <malloc.h>
33 #include <stdlib.h>
44 #include <string.h>
5
+#include <sys/mman.h>
56 #include <time.h>
7
+
68 #include "utils.h"
79
810 #define SIZE 256
....@@ -12,6 +14,9 @@
1214 #define LARGE_ITERATIONS 1000
1315 #define LARGE_MAX_OFFSET 32
1416 #define LARGE_SIZE_START 4096
17
+
18
+/* This is big enough to fit LARGE_SIZE and works on 4K & 64K kernels */
19
+#define MAP_SIZE (64 * 1024)
1520
1621 #define MAX_OFFSET_DIFF_S1_S2 48
1722
....@@ -68,25 +73,25 @@
6873
6974 static int testcase(bool islarge)
7075 {
71
- char *s1;
72
- char *s2;
73
- unsigned long i;
76
+ unsigned long i, comp_size, alloc_size;
77
+ char *p, *s1, *s2;
78
+ int iterations;
7479
75
- unsigned long comp_size = (islarge ? LARGE_SIZE : SIZE);
76
- unsigned long alloc_size = comp_size + MAX_OFFSET_DIFF_S1_S2;
77
- int iterations = islarge ? LARGE_ITERATIONS : ITERATIONS;
80
+ comp_size = (islarge ? LARGE_SIZE : SIZE);
81
+ alloc_size = comp_size + MAX_OFFSET_DIFF_S1_S2;
82
+ iterations = islarge ? LARGE_ITERATIONS : ITERATIONS;
7883
79
- s1 = memalign(128, alloc_size);
80
- if (!s1) {
81
- perror("memalign");
82
- exit(1);
83
- }
84
+ p = mmap(NULL, 4 * MAP_SIZE, PROT_READ | PROT_WRITE,
85
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
86
+ FAIL_IF(p == MAP_FAILED);
8487
85
- s2 = memalign(128, alloc_size);
86
- if (!s2) {
87
- perror("memalign");
88
- exit(1);
89
- }
88
+ /* Put s1/s2 at the end of a page */
89
+ s1 = p + MAP_SIZE - alloc_size;
90
+ s2 = p + 3 * MAP_SIZE - alloc_size;
91
+
92
+ /* And unmap the subsequent page to force a fault if we overread */
93
+ munmap(p + MAP_SIZE, MAP_SIZE);
94
+ munmap(p + 3 * MAP_SIZE, MAP_SIZE);
9095
9196 srandom(time(0));
9297
....@@ -147,6 +152,11 @@
147152
148153 static int testcases(void)
149154 {
155
+#ifdef __powerpc64__
156
+ // vcmpequd used in memcmp_64.S is v2.07
157
+ SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
158
+#endif
159
+
150160 testcase(0);
151161 testcase(1);
152162 return 0;