4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 #include "stringlib.h"
15 static const struct fun
18 int (*fun
)(const char *, const char *, size_t);
24 # if __ARM_FEATURE_SVE
25 F(__strncmp_aarch64_sve
)
32 static int test_status
;
33 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
37 static char s1buf
[LEN
+2*A
];
38 static char s2buf
[LEN
+2*A
];
40 static void *alignup(void *p
)
42 return (void*)(((uintptr_t)p
+ A
-1) & -A
);
45 static void test(const struct fun
*fun
, int s1align
, int s2align
, int maxlen
, int diffpos
, int len
)
47 char *src1
= alignup(s1buf
);
48 char *src2
= alignup(s2buf
);
49 char *s1
= src1
+ s1align
;
50 char *s2
= src2
+ s2align
;
53 if (len
> LEN
|| s1align
>= A
|| s2align
>= A
)
55 if (diffpos
> 1 && diffpos
>= len
-1)
58 for (int i
= 0; i
< len
+A
; i
++)
59 src1
[i
] = src2
[i
] = '?';
60 for (int i
= 0; i
< len
-1; i
++)
61 s1
[i
] = s2
[i
] = 'a' + i
%23;
64 s1
[len
] = s2
[len
] = '\0';
66 r
= fun
->fun(s1
, s2
, maxlen
);
68 diffpos
= maxlen
<= diffpos
? 0 : diffpos
;
70 if (((diffpos
<= 1) && r
!= 0) || (diffpos
> 1 && r
== 0)) {
71 ERR("%s(align %d, align %d, %d (%d)) failed, returned %d (%d)\n",
72 fun
->name
, s1align
, s2align
, maxlen
, len
, r
, diffpos
);
73 ERR("src1: %.*s\n", s1align
+len
+1, src1
);
74 ERR("src2: %.*s\n", s2align
+len
+1, src2
);
81 for (int i
=0; funtab
[i
].name
; i
++) {
83 for (int d
= 0; d
< A
; d
++)
84 for (int s
= 0; s
< A
; s
++) {
86 for (n
= 0; n
< 100; n
++) {
87 test(funtab
+i
, d
, s
, n
, 0, n
);
88 test(funtab
+i
, d
, s
, n
, n
/2, n
);
89 test(funtab
+i
, d
, s
, n
/2, 0, n
);
90 test(funtab
+i
, d
, s
, n
/2, n
/2, n
);
92 for (; n
< LEN
; n
*= 2) {
93 test(funtab
+i
, d
, s
, n
, 0, n
);
94 test(funtab
+i
, d
, s
, n
, n
/2, n
);
95 test(funtab
+i
, d
, s
, n
/2, 0, n
);
96 test(funtab
+i
, d
, s
, n
/2, n
/2, n
);
99 printf("%s %s\n", test_status
? "FAIL" : "PASS", funtab
[i
].name
);