[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / AOR_v20.02 / string / test / strcpy.c
blobd00fbefd792d018f01f7be6b282d0f5a41fdada5
1 /*
2 * strcpy 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 "stringlib.h"
15 static const struct fun
17 const char *name;
18 char *(*fun)(char *dest, const char *src);
19 } funtab[] = {
20 #define F(x) {#x, x},
21 F(strcpy)
22 #if __aarch64__
23 F(__strcpy_aarch64)
24 # if __ARM_FEATURE_SVE
25 F(__strcpy_aarch64_sve)
26 # endif
27 #elif __arm__ && defined (__thumb2__) && !defined (__thumb__)
28 F(__strcpy_arm)
29 #endif
30 #undef F
31 {0, 0}
34 static int test_status;
35 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
37 #define A 32
38 #define LEN 250000
39 static char dbuf[LEN+2*A];
40 static char sbuf[LEN+2*A];
41 static char wbuf[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 dalign, int salign, int len)
50 char *src = alignup(sbuf);
51 char *dst = alignup(dbuf);
52 char *want = wbuf;
53 char *s = src + salign;
54 char *d = dst + dalign;
55 char *w = want + dalign;
56 void *p;
57 int i;
59 if (len > LEN || dalign >= A || salign >= A)
60 abort();
61 for (i = 0; i < len+A; i++) {
62 src[i] = '?';
63 want[i] = dst[i] = '*';
65 for (i = 0; i < len; i++)
66 s[i] = w[i] = 'a' + i%23;
67 s[i] = w[i] = '\0';
69 p = fun->fun(d, s);
70 if (p != d)
71 ERR("%s(%p,..) returned %p\n", fun->name, d, p);
72 for (i = 0; i < len+A; i++) {
73 if (dst[i] != want[i]) {
74 ERR("%s(align %d, align %d, %d) failed\n", fun->name, dalign, salign, len);
75 ERR("got : %.*s\n", dalign+len+1, dst);
76 ERR("want: %.*s\n", dalign+len+1, want);
77 break;
82 int main()
84 int r = 0;
85 for (int i=0; funtab[i].name; i++) {
86 test_status = 0;
87 for (int d = 0; d < A; d++)
88 for (int s = 0; s < A; s++) {
89 int n;
90 for (n = 0; n < 100; n++)
91 test(funtab+i, d, s, n);
92 for (; n < LEN; n *= 2)
93 test(funtab+i, d, s, n);
95 printf("%s %s\n", test_status ? "FAIL" : "PASS", funtab[i].name);
96 if (test_status)
97 r = -1;
99 return r;