[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / AOR_v20.02 / string / test / stpcpy.c
blobeea9be1cac6ccd0d5a92326d2bdc3a87ca6cdb63
1 /*
2 * stpcpy 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 #define _GNU_SOURCE
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "stringlib.h"
16 static const struct fun
18 const char *name;
19 char *(*fun)(char *dest, const char *src);
20 } funtab[] = {
21 #define F(x) {#x, x},
22 F(stpcpy)
23 #if __aarch64__
24 F(__stpcpy_aarch64)
25 # if __ARM_FEATURE_SVE
26 F(__stpcpy_aarch64_sve)
27 # endif
28 #endif
29 #undef F
30 {0, 0}
33 static int test_status;
34 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
36 #define A 32
37 #define LEN 250000
38 static char dbuf[LEN+2*A];
39 static char sbuf[LEN+2*A];
40 static char wbuf[LEN+2*A];
42 static void *alignup(void *p)
44 return (void*)(((uintptr_t)p + A-1) & -A);
47 static void test(const struct fun *fun, int dalign, int salign, int len)
49 char *src = alignup(sbuf);
50 char *dst = alignup(dbuf);
51 char *want = wbuf;
52 char *s = src + salign;
53 char *d = dst + dalign;
54 char *w = want + dalign;
55 void *p;
56 int i;
58 if (len > LEN || dalign >= A || salign >= A)
59 abort();
60 for (i = 0; i < len+A; i++) {
61 src[i] = '?';
62 want[i] = dst[i] = '*';
64 for (i = 0; i < len; i++)
65 s[i] = w[i] = 'a' + i%23;
66 s[i] = w[i] = '\0';
68 p = fun->fun(d, s);
69 if (p != d + len)
70 ERR("%s(%p,..) returned %p\n", fun->name, d, p);
71 for (i = 0; i < len+A; i++) {
72 if (dst[i] != want[i]) {
73 ERR("%s(align %d, align %d, %d) failed\n", fun->name, dalign, salign, len);
74 ERR("got : %.*s\n", dalign+len+1, dst);
75 ERR("want: %.*s\n", dalign+len+1, want);
76 break;
81 int main()
83 int r = 0;
84 for (int i=0; funtab[i].name; i++) {
85 test_status = 0;
86 for (int d = 0; d < A; d++)
87 for (int s = 0; s < A; s++) {
88 int n;
89 for (n = 0; n < 100; n++)
90 test(funtab+i, d, s, n);
91 for (; n < LEN; n *= 2)
92 test(funtab+i, d, s, n);
94 printf("%s %s\n", test_status ? "FAIL" : "PASS", funtab[i].name);
95 if (test_status)
96 r = -1;
98 return r;