diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2020-02-25 13:07:46 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-02-25 13:09:29 +0000 |
commit | 9be4a9b833dbdb708f7b9bbd20511ea4b528ccac (patch) | |
tree | 16e31b300b70a86fbc616042f5016b0881f0665d /string/test | |
parent | b09a519ef801ac5ecd29f963764d749b1a7067e4 (diff) | |
download | arm-optimized-routines-9be4a9b833dbdb708f7b9bbd20511ea4b528ccac.tar.gz |
string: Add stpcpy
Add support for stpcpy on AArch64.
Diffstat (limited to 'string/test')
-rw-r--r-- | string/test/stpcpy.c | 98 | ||||
-rw-r--r-- | string/test/strcpy.c | 4 |
2 files changed, 100 insertions, 2 deletions
diff --git a/string/test/stpcpy.c b/string/test/stpcpy.c new file mode 100644 index 0000000..9050227 --- /dev/null +++ b/string/test/stpcpy.c @@ -0,0 +1,98 @@ +/* + * stpcpy test. + * + * Copyright (c) 2019-2020, Arm Limited. + * SPDX-License-Identifier: MIT + */ + +#define _GNU_SOURCE +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "stringlib.h" + +static const struct fun +{ + const char *name; + char *(*fun)(char *dest, const char *src); +} funtab[] = { +#define F(x) {#x, x}, +F(stpcpy) +#if __aarch64__ +F(__stpcpy_aarch64) +# if __ARM_FEATURE_SVE +F(__stpcpy_aarch64_sve) +# endif +#endif +#undef F + {0, 0} +}; + +static int test_status; +#define ERR(...) (test_status=1, printf(__VA_ARGS__)) + +#define A 32 +#define LEN 250000 +static char dbuf[LEN+2*A]; +static char sbuf[LEN+2*A]; +static char wbuf[LEN+2*A]; + +static void *alignup(void *p) +{ + return (void*)(((uintptr_t)p + A-1) & -A); +} + +static void test(const struct fun *fun, int dalign, int salign, int len) +{ + char *src = alignup(sbuf); + char *dst = alignup(dbuf); + char *want = wbuf; + char *s = src + salign; + char *d = dst + dalign; + char *w = want + dalign; + void *p; + int i; + + if (len > LEN || dalign >= A || salign >= A) + abort(); + for (i = 0; i < len+A; i++) { + src[i] = '?'; + want[i] = dst[i] = '*'; + } + for (i = 0; i < len; i++) + s[i] = w[i] = 'a' + i%23; + s[i] = w[i] = '\0'; + + p = fun->fun(d, s); + if (p != d + len) + ERR("%s(%p,..) returned %p\n", fun->name, d, p); + for (i = 0; i < len+A; i++) { + if (dst[i] != want[i]) { + ERR("%s(align %d, align %d, %d) failed\n", fun->name, dalign, salign, len); + ERR("got : %.*s\n", dalign+len+1, dst); + ERR("want: %.*s\n", dalign+len+1, want); + break; + } + } +} + +int main() +{ + int r = 0; + for (int i=0; funtab[i].name; i++) { + test_status = 0; + for (int d = 0; d < A; d++) + for (int s = 0; s < A; s++) { + int n; + for (n = 0; n < 100; n++) + test(funtab+i, d, s, n); + for (; n < LEN; n *= 2) + test(funtab+i, d, s, n); + } + printf("%s %s\n", test_status ? "FAIL" : "PASS", funtab[i].name); + if (test_status) + r = -1; + } + return r; +} diff --git a/string/test/strcpy.c b/string/test/strcpy.c index 4882c9f..ea74c9e 100644 --- a/string/test/strcpy.c +++ b/string/test/strcpy.c @@ -1,7 +1,7 @@ /* * strcpy test. * - * Copyright (c) 2019, Arm Limited. + * Copyright (c) 2019-2020, Arm Limited. * SPDX-License-Identifier: MIT */ @@ -61,7 +61,7 @@ static void test(const struct fun *fun, int dalign, int salign, int len) src[i] = '?'; want[i] = dst[i] = '*'; } - for (i = 0; i < len-1; i++) + for (i = 0; i < len; i++) s[i] = w[i] = 'a' + i%23; s[i] = w[i] = '\0'; |