aboutsummaryrefslogtreecommitdiff
path: root/string/test
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2020-05-22 15:29:04 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-05-22 15:30:18 +0100
commitf5edabeba35de2d2550384fa9816d8bc549f90f8 (patch)
tree956382a6a244b0f044e0fb9970577b22586e0acf /string/test
parente3b6fdf148bd001e7ada875361f3851e6460a3f9 (diff)
downloadarm-optimized-routines-f5edabeba35de2d2550384fa9816d8bc549f90f8.tar.gz
string: Cleanup strrchr test
Clean up code and improve test coverage.
Diffstat (limited to 'string/test')
-rw-r--r--string/test/strrchr.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/string/test/strrchr.c b/string/test/strrchr.c
index 29b3945..2ea676c 100644
--- a/string/test/strrchr.c
+++ b/string/test/strrchr.c
@@ -1,7 +1,7 @@
/*
* strrchr 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,56 +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 / 2] = s[seekpos] = seekchar;
- s[seekpos - (seekpos & 15)] = s[seekpos & 7] = seekchar;
- }
+ s[seekpos / 2] = s[seekpos] = seekchar;
+ if (seekpos > 0 && (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;