aboutsummaryrefslogtreecommitdiff
path: root/string/test/strnlen.c
diff options
context:
space:
mode:
authorBranislav Rankov <branislav.rankov@arm.com>2020-05-28 18:11:20 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-05-28 18:11:20 +0100
commit4d55c2d365033a94094cee1d3a704863a2963d38 (patch)
treeeea802b157d515bb33321d1818ed59d708c83542 /string/test/strnlen.c
parent09b21d98a3b4478462f523bfe36b5f334dd1f35f (diff)
downloadarm-optimized-routines-4d55c2d365033a94094cee1d3a704863a2963d38.tar.gz
string: Add MTE support to string tests.
Set taggs for every test case so that boundaries are as narrow as possible. There is no handling of tag faults, so the test will crash if there is a MTE problem. The implementations that are not compatible are excluded, including the standard symbols that may come from an mte incompatible libc.
Diffstat (limited to 'string/test/strnlen.c')
-rw-r--r--string/test/strnlen.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/string/test/strnlen.c b/string/test/strnlen.c
index c838092..0dea00e 100644
--- a/string/test/strnlen.c
+++ b/string/test/strnlen.c
@@ -5,39 +5,43 @@
* SPDX-License-Identifier: MIT
*/
-#define _POSIX_C_SOURCE 200809L
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include "mte.h"
#include "stringlib.h"
#include "stringtest.h"
-#define F(x) {#x, x},
+#define F(x, mte) {#x, x, mte},
static const struct fun
{
const char *name;
size_t (*fun) (const char *s, size_t m);
+ int test_mte;
} funtab[] = {
// clang-format off
- F(strnlen)
+ F(strnlen, 0)
#if __aarch64__
- F(__strnlen_aarch64)
+ F(__strnlen_aarch64, 1)
# if __ARM_FEATURE_SVE
- F(__strnlen_aarch64_sve)
+ F(__strnlen_aarch64_sve, 1)
# endif
#endif
- {0, 0}
+ {0, 0, 0}
// clang-format on
};
#undef F
#define ALIGN 32
#define LEN 512
-static char sbuf[LEN + 3 * ALIGN];
+static char *sbuf;
static void *
alignup (void *p)
@@ -68,7 +72,11 @@ test (const struct fun *fun, int align, size_t maxlen, size_t len)
if ((len + align) & 1)
s[e + 1] = 0;
+ size_t mte_len = maxlen < len + 1 ? maxlen : len + 1;
+ s = tag_buffer (s, mte_len, fun->test_mte);
r = fun->fun (s, maxlen);
+ untag_buffer (s, mte_len, fun->test_mte);
+
if (r != e)
{
ERR ("%s (%p, %zu) len %zu returned %zu, expected %zu\n",
@@ -80,6 +88,7 @@ test (const struct fun *fun, int align, size_t maxlen, size_t len)
int
main (void)
{
+ sbuf = mte_mmap (LEN + 3 * ALIGN);
int r = 0;
for (int i = 0; funtab[i].name; i++)
{
@@ -91,8 +100,8 @@ main (void)
test (funtab + i, a, maxlen, n);
test (funtab + i, a, SIZE_MAX - a, n);
}
-
- printf ("%s %s\n", err_count ? "FAIL" : "PASS", funtab[i].name);
+ char *pass = funtab[i].test_mte && mte_enabled () ? "MTE PASS" : "PASS";
+ printf ("%s %s\n", err_count ? "FAIL" : pass, funtab[i].name);
if (err_count)
r = -1;
}