1 /* Test and measure strlen functions.
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Jakub Jelinek <jakub@redhat.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include "test-string.h"
24 typedef size_t (*proto_t
) (const char *);
25 size_t simple_strlen (const char *);
26 size_t builtin_strlen (const char *);
28 IMPL (simple_strlen
, 0)
29 IMPL (builtin_strlen
, 0)
33 simple_strlen (const char *s
)
42 builtin_strlen (const char *p
)
44 return __builtin_strlen (p
);
48 do_one_test (impl_t
*impl
, const char *s
, size_t exp_len
)
50 size_t len
= CALL (impl
, s
);
53 error (0, 0, "Wrong result in function %s %zd %zd", impl
->name
,
61 hp_timing_t start
, stop
, best_time
= ~ (hp_timing_t
) 0;
64 for (i
= 0; i
< 32; ++i
)
66 HP_TIMING_NOW (start
);
69 HP_TIMING_BEST (best_time
, start
, stop
);
72 printf ("\t%zd", (size_t) best_time
);
77 do_test (size_t align
, size_t len
, int max_char
)
82 if (align
+ len
>= page_size
)
85 for (i
= 0; i
< len
; ++i
)
86 buf1
[align
+ i
] = 1 + 7 * i
% max_char
;
87 buf1
[align
+ len
] = 0;
90 printf ("Length %4zd, alignment %2zd:", len
, align
);
92 FOR_EACH_IMPL (impl
, 0)
93 do_one_test (impl
, buf1
+ align
, len
);
100 do_random_tests (void)
102 size_t i
, j
, n
, align
, len
;
103 unsigned char *p
= buf1
+ page_size
- 512;
105 for (n
= 0; n
< ITERATIONS
; n
++)
107 align
= random () & 15;
108 len
= random () & 511;
109 if (len
+ align
> 510)
110 len
= 511 - align
- (random () & 7);
111 j
= len
+ align
+ 64;
115 for (i
= 0; i
< j
; i
++)
117 if (i
== len
+ align
)
121 p
[i
] = random () & 255;
122 if (i
>= align
&& i
< len
+ align
&& !p
[i
])
123 p
[i
] = (random () & 127) + 1;
127 FOR_EACH_IMPL (impl
, 1)
128 if (CALL (impl
, p
+ align
) != len
)
130 error (0, 0, "Iteration %zd - wrong result in function %s (%zd) %zd != %zd, p %p",
131 n
, impl
->name
, align
, CALL (impl
, p
+ align
), len
, p
);
145 FOR_EACH_IMPL (impl
, 0)
146 printf ("\t%s", impl
->name
);
149 for (i
= 1; i
< 8; ++i
)
152 for (i
= 1; i
< 8; ++i
)
155 for (i
= 2; i
<= 10; ++i
)
157 do_test (0, 1 << i
, 127);
158 do_test (1, 1 << i
, 127);
161 for (i
= 1; i
< 8; ++i
)
164 for (i
= 1; i
< 8; ++i
)
167 for (i
= 2; i
<= 10; ++i
)
169 do_test (0, 1 << i
, 255);
170 do_test (1, 1 << i
, 255);
177 #include "../test-skeleton.c"