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
16 #include "stringlib.h"
18 static const struct fun
21 char *(*fun
)(const char *s
, int c
);
26 F(__strchrnul_aarch64
)
27 # if __ARM_FEATURE_SVE
28 F(__strchrnul_aarch64_sve
)
35 static int test_status
;
36 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
41 static char sbuf
[LEN
+2*A
];
43 static void *alignup(void *p
)
45 return (void*)(((uintptr_t)p
+ A
-1) & -A
);
48 static void test(const struct fun
*fun
, int align
, int seekpos
, int len
)
50 char *src
= alignup(sbuf
);
51 char *s
= src
+ align
;
52 char *f
= seekpos
!= -1 ? s
+ seekpos
: s
+ len
- 1;
56 if (len
> LEN
|| seekpos
>= len
- 1 || align
>= A
)
58 if (seekchar
>= 'a' && seekchar
<= 'a' + 23)
61 for (int i
= 0; i
< len
+ A
; i
++)
63 for (int i
= 0; i
< len
- 2; i
++)
66 s
[seekpos
] = seekchar
;
69 p
= fun
->fun(s
, seekchar
);
72 ERR("%s(%p,0x%02x,%d) returned %p\n", fun
->name
, s
, seekchar
, len
, p
);
73 ERR("expected: %p\n", f
);
81 for (int i
=0; funtab
[i
].name
; i
++) {
83 for (int a
= 0; a
< A
; a
++) {
85 for (n
= 1; n
< 100; n
++) {
86 for (int sp
= 0; sp
< n
- 1; sp
++)
87 test(funtab
+i
, a
, sp
, n
);
88 test(funtab
+i
, a
, -1, n
);
90 for (; n
< LEN
; n
*= 2) {
91 test(funtab
+i
, a
, -1, n
);
92 test(funtab
+i
, a
, n
/ 2, n
);
95 printf("%s %s\n", test_status
? "FAIL" : "PASS", funtab
[i
].name
);