aboutsummaryrefslogtreecommitdiff
path: root/string/test
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-04-29 17:04:10 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-04-29 17:34:41 +0100
commit9bd3b27776d8d56ebac9f5f511bbf7c12e639de5 (patch)
treeb01f4efba38d5b561ea8817f9529fc3b4b52e6c4 /string/test
parent22fd93176f9eca0ee38954e233826d05fdb31b0f (diff)
downloadarm-optimized-routines-9bd3b27776d8d56ebac9f5f511bbf7c12e639de5.tar.gz
string: more strchr, strrchr, strchrnul test improvements
Use matching and null characters in the padding area around the string. Remove large input tests.
Diffstat (limited to 'string/test')
-rw-r--r--string/test/strchr.c40
-rw-r--r--string/test/strchrnul.c39
-rw-r--r--string/test/strrchr.c37
3 files changed, 60 insertions, 56 deletions
diff --git a/string/test/strchr.c b/string/test/strchr.c
index d6ed39a..1d90c85 100644
--- a/string/test/strchr.c
+++ b/string/test/strchr.c
@@ -32,9 +32,8 @@ F(__strchr_aarch64_sve)
};
#define A 32
-#define SP 512
-#define LEN 250000
-static char sbuf[LEN+2*A+1];
+#define LEN 512
+static char sbuf[LEN+3*A];
static void *alignup(void *p)
{
@@ -53,24 +52,29 @@ static void test(const struct fun *fun, int align, int seekpos, int len)
return;
if (len > LEN || seekpos >= len || align >= A)
abort();
- if (seekchar >= 'a' && seekchar <= 'a' + 23)
- abort();
- for (int i = 0; i < len + A; i++)
- src[i] = '?';
+ 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;
for (int i = 0; i < len; i++)
- s[i] = 'a' + i%23;
+ s[i] = 'a' + i%32;
if (seekpos != -1)
- s[seekpos] = seekchar;
+ s[seekpos] = s[seekpos+2] = seekchar;
s[len] = '\0';
p = fun->fun(s, seekchar);
-
if (p != f) {
- ERR("%s(%p,0x%02x,%d) returned %p\n", fun->name, s, seekchar, len, p);
- quoteat("input", s, len+A, seekpos);
- printf("expected: %p\n", f);
- abort();
+ 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);
+ quote("input", s, len);
}
}
@@ -81,15 +85,11 @@ int main()
err_count = 0;
for (int a = 0; a < A; a++) {
int n;
- for (n = 1; n < 100; n++) {
- for (int sp = 0; sp < n - 1; sp++)
+ 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 (; n < LEN; n *= 2) {
- test(funtab+i, a, -1, n);
- test(funtab+i, a, n / 2, n);
- }
}
printf("%s %s\n", err_count ? "FAIL" : "PASS", funtab[i].name);
if (err_count)
diff --git a/string/test/strchrnul.c b/string/test/strchrnul.c
index 78192c4..b103568 100644
--- a/string/test/strchrnul.c
+++ b/string/test/strchrnul.c
@@ -34,9 +34,8 @@ F(__strchrnul_aarch64_sve)
};
#define A 32
-#define SP 512
-#define LEN 250000
-static char sbuf[LEN+2*A+1];
+#define LEN 512
+static char sbuf[LEN+3*A];
static void *alignup(void *p)
{
@@ -55,23 +54,29 @@ static void test(const struct fun *fun, int align, int seekpos, int len)
return;
if (len > LEN || seekpos >= len || align >= A)
abort();
- if (seekchar >= 'a' && seekchar <= 'a' + 23)
- abort();
- for (int i = 0; i < len + A; i++)
- src[i] = '?';
+ 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;
for (int i = 0; i < len; i++)
- s[i] = 'a' + i%23;
+ s[i] = 'a' + i%32;
if (seekpos != -1)
- s[seekpos] = seekchar;
+ s[seekpos] = s[seekpos+2] = seekchar;
s[len] = '\0';
p = fun->fun(s, seekchar);
-
if (p != f) {
- ERR("%s(%p,0x%02x,%d) returned %p\n", fun->name, s, seekchar, len, p);
- quoteat("input", s, len+A, seekpos);
- printf("expected: %p\n", f);
+ 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);
+ quote("input", s, len);
}
}
@@ -82,15 +87,11 @@ int main()
err_count = 0;
for (int a = 0; a < A; a++) {
int n;
- for (n = 1; n < 100; n++) {
- for (int sp = 0; sp < n - 1; sp++)
+ 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 (; n < LEN; n *= 2) {
- test(funtab+i, a, -1, n);
- test(funtab+i, a, n / 2, n);
- }
}
printf("%s %s\n", err_count ? "FAIL" : "PASS", funtab[i].name);
if (err_count)
diff --git a/string/test/strrchr.c b/string/test/strrchr.c
index d3d0bc5..8bc47f3 100644
--- a/string/test/strrchr.c
+++ b/string/test/strrchr.c
@@ -31,9 +31,8 @@ F(__strrchr_aarch64_sve)
};
#define A 32
-#define SP 512
-#define LEN 250000
-static char sbuf[LEN+2*A+1];
+#define LEN 512
+static char sbuf[LEN+3*A];
static void *alignup(void *p)
{
@@ -52,23 +51,31 @@ static void test(const struct fun *fun, int align, int seekpos, int len)
return;
if (len > LEN || seekpos >= len || align >= A)
abort();
- if (seekchar >= 'a' && seekchar <= 'a' + 23)
- abort();
- for (int i = 0; i < len + A; i++)
- src[i] = '?';
+ 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;
for (int i = 0; i < len; i++)
- s[i] = 'a' + i%23;
- if (seekpos != -1)
+ s[i] = 'a' + i%32;
+ if (seekpos != -1) {
s[seekpos/2] = s[seekpos] = seekchar;
+ s[seekpos - (seekpos & 15)] = s[seekpos & 7] = seekchar;
+ }
s[len] = '\0';
p = fun->fun(s, seekchar);
-
if (p != f) {
- ERR("%s(%p,0x%02x,%d) returned %p\n", fun->name, s, seekchar, len, p);
+ 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);
quote("input", s, len);
- printf("expected: %p\n", f);
}
}
@@ -79,15 +86,11 @@ int main()
err_count = 0;
for (int a = 0; a < A; a++) {
int n;
- for (n = 1; n < 100; 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 (; n < LEN; n *= 2) {
- test(funtab+i, a, -1, n);
- test(funtab+i, a, n / 2, n);
- }
}
printf("%s %s\n", err_count ? "FAIL" : "PASS", funtab[i].name);
if (err_count)