[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / AOR_v20.02 / string / test / memchr.c
blobee7f2131a458e5c77e2ebaccc574f629b2102a73
1 /*
2 * memchr 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 void *(*fun)(const void *, int c, size_t n);
20 } funtab[] = {
21 #define F(x) {#x, x},
22 F(memchr)
23 #if __aarch64__
24 F(__memchr_aarch64)
25 # if __ARM_FEATURE_SVE
26 F(__memchr_aarch64_sve)
27 # endif
28 #elif __arm__
29 F(__memchr_arm)
30 #endif
31 #undef F
32 {0, 0}
35 static int test_status;
36 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
38 #define A 32
39 #define SP 512
40 #define LEN 250000
41 static unsigned 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 unsigned char *src = alignup(sbuf);
51 unsigned char *s = src + align;
52 unsigned char *f = len ? s + seekpos : 0;
53 int seekchar = 0x1;
54 int i;
55 void *p;
57 if (len > LEN || seekpos >= len || align >= A)
58 abort();
60 for (i = 0; i < seekpos; i++)
61 s[i] = 'a' + i%23;
62 s[i++] = seekchar;
63 for (; i < len; i++)
64 s[i] = 'a' + i%23;
66 p = fun->fun(s, seekchar, len);
68 if (p != f) {
69 ERR("%s(%p,0x%02x,%d) returned %p\n", fun->name, s, seekchar, len, p);
70 ERR("expected: %p\n", f);
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 for (int n = 0; n < 100; n++)
82 for (int sp = 0; sp < n-1; sp++)
83 test(funtab+i, a, sp, n);
84 for (int n = 100; n < LEN; n *= 2) {
85 test(funtab+i, a, n-1, n);
86 test(funtab+i, a, n/2, n);
89 printf("%s %s\n", test_status ? "FAIL" : "PASS", funtab[i].name);
90 if (test_status)
91 r = -1;
93 return r;