Remove support in configure for unsupported architectures
[glibc.git] / string / test-strlen.c
blobf12d3ba9d306807d0b54fb8c389031eff243b6e2
1 /* Test and measure STRLEN functions.
2 Copyright (C) 1999, 2002, 2003, 2005, 2011 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Jakub Jelinek <jakub@redhat.com>, 1999.
5 Added wcslen support by Liubov Dmitrieva <liubov.dmitrieva@gmail.com>, 2011
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #define TEST_MAIN
23 #include "test-string.h"
25 #ifndef WIDE
26 # define STRLEN strlen
27 # define CHAR char
28 # define MAX_CHAR CHAR_MAX
29 #else
30 # include <wchar.h>
31 # define STRLEN wcslen
32 # define CHAR wchar_t
33 # define MAX_CHAR WCHAR_MAX
34 #endif
36 typedef size_t (*proto_t) (const CHAR *);
38 size_t
39 simple_STRLEN (const CHAR *s)
41 const CHAR *p;
43 for (p = s; *p; ++p);
44 return p - s;
47 #ifndef WIDE
48 size_t
49 builtin_strlen (const CHAR *p)
51 return __builtin_strlen (p);
53 IMPL (builtin_strlen, 0)
54 #endif
56 IMPL (simple_STRLEN, 0)
57 IMPL (STRLEN, 1)
60 static void
61 do_one_test (impl_t *impl, const CHAR *s, size_t exp_len)
63 size_t len = CALL (impl, s);
64 if (len != exp_len)
66 error (0, 0, "Wrong result in function %s %zd %zd", impl->name,
67 len, exp_len);
68 ret = 1;
69 return;
72 if (HP_TIMING_AVAIL)
74 hp_timing_t start __attribute ((unused));
75 hp_timing_t stop __attribute ((unused));
76 hp_timing_t best_time = ~ (hp_timing_t) 0;
77 size_t i;
79 for (i = 0; i < 32; ++i)
81 HP_TIMING_NOW (start);
82 CALL (impl, s);
83 HP_TIMING_NOW (stop);
84 HP_TIMING_BEST (best_time, start, stop);
87 printf ("\t%zd", (size_t) best_time);
91 static void
92 do_test (size_t align, size_t len)
94 size_t i;
96 align &= 63;
97 if (align + sizeof(CHAR) * len >= page_size)
98 return;
100 CHAR *buf = (CHAR *) (buf1);
102 for (i = 0; i < len; ++i)
103 buf[align + i] = 1 + 11111 * i % MAX_CHAR;
104 buf[align + len] = 0;
106 if (HP_TIMING_AVAIL)
107 printf ("Length %4zd, alignment %2zd:", len, align);
109 FOR_EACH_IMPL (impl, 0)
110 do_one_test (impl, (CHAR *) (buf + align), len);
112 if (HP_TIMING_AVAIL)
113 putchar ('\n');
116 static void
117 do_random_tests (void)
119 size_t i, j, n, align, len;
120 CHAR *p = (CHAR *) (buf1 + page_size - 512 * sizeof(CHAR));
122 for (n = 0; n < ITERATIONS; n++)
124 align = random () & 15;
125 len = random () & 511;
126 if (len + align > 510)
127 len = 511 - align - (random () & 7);
128 j = len + align + 64;
129 if (j > 512)
130 j = 512;
132 for (i = 0; i < j; i++)
134 if (i == len + align)
135 p[i] = 0;
136 else
138 p[i] = random () & 255;
139 if (i >= align && i < len + align && !p[i])
140 p[i] = (random () & 127) + 1;
144 FOR_EACH_IMPL (impl, 1)
145 if (CALL (impl, (CHAR *) (p + align)) != len)
147 error (0, 0, "Iteration %zd - wrong result in function %s (%zd) %zd != %zd, p %p",
148 n, impl->name, align, CALL (impl, (CHAR *) (p + align)),
149 len, p);
150 ret = 1;
156 test_main (void)
158 size_t i;
160 test_init ();
162 printf ("%20s", "");
163 FOR_EACH_IMPL (impl, 0)
164 printf ("\t%s", impl->name);
165 putchar ('\n');
167 /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
169 for (i = 1; i < 8; ++i)
171 do_test (sizeof(CHAR) * i, i);
172 do_test (0, i);
175 for (i = 2; i <= 12; ++i)
177 do_test (0, 1 << i);
178 do_test (sizeof(CHAR) * 7, 1 << i);
179 do_test (sizeof(CHAR) * i, 1 << i);
180 do_test (sizeof(CHAR) * i, (size_t)((1 << i) / 1.5));
183 do_random_tests ();
184 return ret;
187 #include "../test-skeleton.c"