aboutsummaryrefslogtreecommitdiff
path: root/string/test/strchrnul.c
diff options
context:
space:
mode:
authorWilco Dijkstra <wilco.dijkstra@arm.com>2020-05-22 15:32:28 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-05-22 15:32:51 +0100
commit09b21d98a3b4478462f523bfe36b5f334dd1f35f (patch)
tree5b805fe3fcb79059922e64cf9fc2cbd024527a45 /string/test/strchrnul.c
parent620b09f17851741a23f4bbc06c8ab1bf0368e9b7 (diff)
downloadarm-optimized-routines-09b21d98a3b4478462f523bfe36b5f334dd1f35f.tar.gz
string: Cleanup strchrnul test
Clean up code and improve test coverage.
Diffstat (limited to 'string/test/strchrnul.c')
-rw-r--r--string/test/strchrnul.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/string/test/strchrnul.c b/string/test/strchrnul.c
index ca4f753..198c2ad 100644
--- a/string/test/strchrnul.c
+++ b/string/test/strchrnul.c
@@ -1,7 +1,7 @@
/*
* strchrnul test.
*
- * Copyright (c) 2019, Arm Limited.
+ * Copyright (c) 2019-2020, Arm Limited.
* SPDX-License-Identifier: MIT
*/
@@ -36,14 +36,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
@@ -57,53 +57,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;