]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/tst-strlen.c
nptl/tst-cancel25 needs to be an internal test
[thirdparty/glibc.git] / string / tst-strlen.c
CommitLineData
9a0a462c
UD
1/* Make sure we don't test the optimized inline functions if we want to
2 test the real implementation. */
3#undef __USE_STRING_INLINES
4
7a12c6bb
RM
5#include <stdio.h>
6#include <string.h>
7
fb82116f 8int
c1f41083 9do_test (void)
7a12c6bb 10{
68dbb3a6
UD
11 static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
12 0, 1, 0, 2, 0, 1, 0, 4 };
5929563f
UD
13 char basebuf[24 + 32];
14 size_t base;
7a12c6bb 15
5929563f 16 for (base = 0; base < 32; ++base)
7a12c6bb 17 {
5929563f
UD
18 char *buf = basebuf + base;
19 size_t words;
7a12c6bb 20
5929563f
UD
21 for (words = 0; words < 4; ++words)
22 {
23 size_t last;
24 memset (buf, 'a', words * 4);
7a12c6bb 25
5929563f 26 for (last = 0; last < 16; ++last)
7a12c6bb 27 {
5929563f
UD
28 buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
29 buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
30 buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
31 buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
32 buf[words * 4 + 4] = '\0';
33
24fb0f88 34 if (strlen (buf) != words * 4 + lens[last])
5929563f 35 {
24fb0f88
UD
36 printf ("\
37strlen failed for base=%Zu, words=%Zu, and last=%Zu (is %zd, expected %zd)\n",
38 base, words, last,
39 strlen (buf), words * 4 + lens[last]);
40 return 1;
41 }
42
43 if (strnlen (buf, -1) != words * 4 + lens[last])
44 {
45 printf ("\
46strnlen failed for base=%Zu, words=%Zu, and last=%Zu (is %zd, expected %zd)\n",
47 base, words, last,
48 strnlen (buf, -1), words * 4 + lens[last]);
5929563f
UD
49 return 1;
50 }
7a12c6bb 51 }
1f205a47 52 }
7a12c6bb
RM
53 }
54 return 0;
55}
c1f41083 56
fb82116f 57#include <support/test-driver.c>