[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / AOR_v20.02 / string / test / strlen.c
blob16a9176495c512f7cf72608396bd6d6281d20825
1 /*
2 * strlen test.
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
7 */
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <limits.h>
14 #include "stringlib.h"
16 static const struct fun
18 const char *name;
19 size_t (*fun)(const char *s);
20 } funtab[] = {
21 #define F(x) {#x, x},
22 F(strlen)
23 #if __aarch64__
24 F(__strlen_aarch64)
25 F(__strlen_aarch64_mte)
26 # if __ARM_FEATURE_SVE
27 F(__strlen_aarch64_sve)
28 # endif
29 #elif __arm__
30 # if __ARM_ARCH >= 6 && __ARM_ARCH_ISA_THUMB == 2
31 F(__strlen_armv6t2)
32 # endif
33 #endif
34 #undef F
35 {0, 0}
38 static int test_status;
39 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
41 #define A 32
42 #define SP 512
43 #define LEN 250000
44 static char sbuf[LEN+2*A];
46 static void *alignup(void *p)
48 return (void*)(((uintptr_t)p + A-1) & -A);
51 static void test(const struct fun *fun, int align, int len)
53 char *src = alignup(sbuf);
54 char *s = src + align;
55 size_t r;
57 if (len > LEN || align >= A)
58 abort();
60 for (int i = 0; i < len + A; i++)
61 src[i] = '?';
62 for (int i = 0; i < len - 2; i++)
63 s[i] = 'a' + i%23;
64 s[len - 1] = '\0';
66 r = fun->fun(s);
67 if (r != len-1) {
68 ERR("%s(%p) returned %zu\n", fun->name, s, r);
69 ERR("input: %.*s\n", align+len+1, src);
70 ERR("expected: %d\n", len);
71 abort();
75 int main()
77 int r = 0;
78 for (int i=0; funtab[i].name; i++) {
79 test_status = 0;
80 for (int a = 0; a < A; a++) {
81 int n;
82 for (n = 1; n < 100; n++)
83 test(funtab+i, a, n);
84 for (; n < LEN; n *= 2)
85 test(funtab+i, a, n);
87 printf("%s %s\n", test_status ? "FAIL" : "PASS", funtab[i].name);
88 if (test_status)
89 r = -1;
91 return r;