diff options
author | Christophe Leroy <christophe.leroy@c-s.fr> | 2018-08-01 09:01:12 +0000 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2018-08-07 21:49:30 +1000 |
commit | f0abbfd89fed4abd8301b35fbf65a26d85b16e7f (patch) | |
tree | 408b80cf6f30bac7f4723a8ce30a3bc5ae5e215c /tools/testing/selftests/powerpc/stringloops/string.c | |
parent | 1bb07b593adc1934a526eb04acfe8bf786decfd2 (diff) |
selftests/powerpc: Add test for strlen()
This patch adds a test for strlen()
string.c contains a copy of strlen() from lib/string.c
The test first tests the correctness of strlen() by comparing
the result with libc strlen(). It tests all cases of alignment.
It them tests the duration of an aligned strlen() on a 4 bytes string,
on a 16 bytes string and on a 256 bytes string.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
[mpe: Drop change log from copy of string.c]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing/selftests/powerpc/stringloops/string.c')
-rw-r--r-- | tools/testing/selftests/powerpc/stringloops/string.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/stringloops/string.c b/tools/testing/selftests/powerpc/stringloops/string.c new file mode 100644 index 000000000000..45e7775415c7 --- /dev/null +++ b/tools/testing/selftests/powerpc/stringloops/string.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copied from linux/lib/string.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +#include <stddef.h> + +/** + * strlen - Find the length of a string + * @s: The string to be sized + */ +size_t test_strlen(const char *s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} |