summaryrefslogtreecommitdiffstats
path: root/test/string/tst-strlen.c
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2006-08-22 01:56:31 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2006-08-22 01:56:31 +0000
commitc969ef4b8fc1d06c13203b36f8cf5bb61a7730f0 (patch)
treeeb2da173a5661b2b2e615045f26f7b69e774290d /test/string/tst-strlen.c
parentfea84e591f94b025ef7c2da843ae80b809f93dbe (diff)
downloaduClibc-alpine-c969ef4b8fc1d06c13203b36f8cf5bb61a7730f0.tar.bz2
uClibc-alpine-c969ef4b8fc1d06c13203b36f8cf5bb61a7730f0.tar.xz
Merge from trunk. Whoa crap.
Diffstat (limited to 'test/string/tst-strlen.c')
-rw-r--r--test/string/tst-strlen.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/string/tst-strlen.c b/test/string/tst-strlen.c
new file mode 100644
index 000000000..a1e115927
--- /dev/null
+++ b/test/string/tst-strlen.c
@@ -0,0 +1,45 @@
+/* Make sure we don't test the optimized inline functions if we want to
+ test the real implementation. */
+#undef __USE_STRING_INLINES
+
+#include <stdio.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
+ 0, 1, 0, 2, 0, 1, 0, 4 };
+ char basebuf[24 + 32];
+ size_t base;
+
+ for (base = 0; base < 32; ++base)
+ {
+ char *buf = basebuf + base;
+ size_t words;
+
+ for (words = 0; words < 4; ++words)
+ {
+ size_t last;
+ memset (buf, 'a', words * 4);
+
+ for (last = 0; last < 16; ++last)
+ {
+ buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
+ buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
+ buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
+ buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
+ buf[words * 4 + 4] = '\0';
+
+ if (strlen (buf) != words * 4 + lens[last]
+ || strnlen (buf, -1) != words * 4 + lens[last])
+ {
+ printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
+ base, words, last);
+ return 1;
+ }
+ }
+ }
+ }
+ return 0;
+}