diff options
author | Wilco Dijkstra <wilco.dijkstra@arm.com> | 2020-05-22 15:30:59 +0100 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-05-22 15:31:31 +0100 |
commit | 620b09f17851741a23f4bbc06c8ab1bf0368e9b7 (patch) | |
tree | 61296c29b049ea2502067519dfc3240ff999caae /string/test | |
parent | f5edabeba35de2d2550384fa9816d8bc549f90f8 (diff) | |
download | arm-optimized-routines-620b09f17851741a23f4bbc06c8ab1bf0368e9b7.tar.gz |
string: Cleanup strchr test
Clean up code and improve test coverage.
Diffstat (limited to 'string/test')
-rw-r--r-- | string/test/strchr.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/string/test/strchr.c b/string/test/strchr.c index e6c1e5b..8535686 100644 --- a/string/test/strchr.c +++ b/string/test/strchr.c @@ -1,7 +1,7 @@ /* * strchr test. * - * Copyright (c) 2019, Arm Limited. + * Copyright (c) 2019-2020, Arm Limited. * SPDX-License-Identifier: MIT */ @@ -34,14 +34,14 @@ static const struct fun }; #undef F -#define A 32 +#define ALIGN 32 #define LEN 512 -static char sbuf[LEN + 3 * A]; +static char sbuf[LEN + 3 * ALIGN]; static void * alignup (void *p) { - return (void *) (((uintptr_t) p + A - 1) & -A); + return (void *) (((uintptr_t) p + ALIGN - 1) & -ALIGN); } static void @@ -55,53 +55,53 @@ test (const struct fun *fun, int align, int seekpos, int len) if (err_count >= ERR_LIMIT) return; - if (len > LEN || seekpos >= len || align >= A) + if (len > LEN || seekpos >= len || align >= ALIGN) abort (); for (int i = 0; src + i < s; i++) - src[i] = i & 1 ? seekchar : 0; - for (int i = 1; i < A; i++) - s[len + i] = i & 1 ? seekchar : 0; + src[i] = (i + len) & 1 ? seekchar : 0; + for (int i = 1; i <= ALIGN; i++) + s[len + i] = (i + len) & 1 ? seekchar : 0; for (int i = 0; i < len; i++) - s[i] = 'a' + i % 32; + s[i] = 'a' + (i & 31); if (seekpos != -1) - s[seekpos] = s[seekpos + 2] = seekchar; + s[seekpos] = seekchar; + if (seekpos != -1 && (len + align) & 1) + s[seekpos + 1] = seekchar; s[len] = '\0'; p = fun->fun (s, seekchar); if (p != f) { - ERR ("%s(%p,0x%02x) len %d returned %p, expected %p pos %d\n", fun->name, - s, seekchar, len, p, f, seekpos); + ERR ("%s (%p, 0x%02x) len %d returned %p, expected %p pos %d\n", + fun->name, s, seekchar, len, p, f, seekpos); quote ("input", s, len); } p = fun->fun (s, 0); if (p != s + len) { - ERR ("%s(%p,0x%02x) len %d returned %p, expected %p pos %d\n", fun->name, - s, seekchar, len, p, s + len, len); + ERR ("%s (%p, 0x%02x) len %d returned %p, expected %p pos %d\n", + fun->name, s, 0, len, p, f, len); quote ("input", s, len); } } int -main () +main (void) { int r = 0; for (int i = 0; funtab[i].name; i++) { err_count = 0; - for (int a = 0; a < A; a++) - { - int n; - for (n = 1; n < LEN; n++) - { - for (int sp = 0; sp < n; sp++) - test (funtab + i, a, sp, n); - test (funtab + i, a, -1, n); - } - } + for (int a = 0; a < ALIGN; a++) + for (int n = 0; n < LEN; n++) + { + for (int sp = 0; sp < n; sp++) + test (funtab + i, a, sp, n); + test (funtab + i, a, -1, n); + } + printf ("%s %s\n", err_count ? "FAIL" : "PASS", funtab[i].name); if (err_count) r = -1; |