1 /* Test and measure memcpy functions.
2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* test-memcpy-support.h contains all test functions. */
20 #include "test-memcpy-support.h"
23 do_random_tests (void)
25 size_t i
, j
, n
, align1
, align2
, len
, size1
, size2
, size
;
27 unsigned char *p1
, *p2
;
30 for (n
= 0; n
< ITERATIONS
; n
++)
43 if ((random () & 255) == 0)
60 len
= random () % size
;
61 align1
= size1
- len
- (random () & 31);
62 align2
= size2
- len
- (random () & 31);
70 align1
= random () & 63;
71 align2
= random () & 63;
72 len
= random () % size
;
73 if (align1
+ len
> size1
)
75 if (align2
+ len
> size2
)
79 p1
= buf1
+ page_size
- size1
;
80 p2
= buf2
+ page_size
- size2
;
82 j
= align1
+ len
+ 256;
85 for (i
= 0; i
< j
; ++i
)
86 p1
[i
] = random () & 255;
88 FOR_EACH_IMPL (impl
, 1)
90 j
= align2
+ len
+ 256;
94 res
= (unsigned char *)CALL (impl
, (char *)(p2
+ align2
),
95 (char *)(p1
+ align1
), len
);
96 if (res
!= MEMCPY_RESULT (p2
+ align2
, len
))
99 "Iteration %zd - wrong result in function %s (%zd, %zd, "
101 n
, impl
->name
, align1
, align2
, len
, res
,
102 MEMCPY_RESULT (p2
+ align2
, len
));
105 for (i
= 0; i
< align2
; ++i
)
110 "Iteration %zd - garbage before, %s (%zd, %zd, %zd)", n
,
111 impl
->name
, align1
, align2
, len
);
116 for (i
= align2
+ len
; i
< j
; ++i
)
121 "Iteration %zd - garbage after, %s (%zd, %zd, %zd)", n
,
122 impl
->name
, align1
, align2
, len
);
127 if (memcmp (p1
+ align1
, p2
+ align2
, len
))
130 "Iteration %zd - different strings, %s (%zd, %zd, %zd)", n
,
131 impl
->name
, align1
, align2
, len
);
146 FOR_EACH_IMPL (impl
, 0)
147 printf ("\t%s", impl
->name
);
150 for (i
= 0; i
< 18; ++i
)
152 do_test (0, 0, 1 << i
);
153 do_test (i
, 0, 1 << i
);
154 do_test (0, i
, 1 << i
);
155 do_test (i
, i
, 1 << i
);
157 for (i
= 0; i
< 32; ++i
)
165 for (i
= 3; i
< 32; ++i
)
167 if ((i
& (i
- 1)) == 0)
169 do_test (0, 0, 16 * i
);
170 do_test (i
, 0, 16 * i
);
171 do_test (0, i
, 16 * i
);
172 do_test (i
, i
, 16 * i
);
175 for (i
= 19; i
<= 25; ++i
)
177 do_test (255, 0, 1 << i
);
178 do_test (0, 4000, 1 << i
);
180 do_test (0, 4000, i
);
183 do_test (0, 0, getpagesize ());
186 do_test1 (0, 0, 0x100000);
187 do_test1 (0, 0, 0x2000000);
189 for (i
= 4096; i
< 32768; i
+= 4096)
191 for (j
= 1; j
<= 1024; j
<<= 1)
194 do_test1 (4095, j
, i
);
195 do_test1 (4096 - j
, 0, i
);
197 do_test1 (0, j
- 1, i
);
198 do_test1 (4095, j
- 1, i
);
199 do_test1 (4096 - j
- 1, 0, i
);
201 do_test1 (0, j
+ 1, i
);
202 do_test1 (4095, j
+ 1, i
);
203 do_test1 (4096 - j
, 1, i
);
207 for (i
= 0x300000; i
< 0x2000000; i
+= 0x235689)
209 for (j
= 64; j
<= 1024; j
<<= 1)
212 do_test1 (4095, j
, i
);
213 do_test1 (4096 - j
, 0, i
);
215 do_test1 (0, j
- 1, i
);
216 do_test1 (4095, j
- 1, i
);
217 do_test1 (4096 - j
- 1, 0, i
);
219 do_test1 (0, j
+ 1, i
);
220 do_test1 (4095, j
+ 1, i
);
221 do_test1 (4096 - j
, 1, i
);
228 #include <support/test-driver.c>