x86_64: Fix svml_s_coshf4_core_sse4.S code formatting
[glibc.git] / string / testcopy.c
blob2031d8d9e3b82f9f956d580f54f54719bf06a918
1 /* Copyright (C) 1990-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <support/support.h>
23 static int
24 do_test (void)
26 char *mem, *memp;
27 char *rand_mem;
28 char *lo_around, *hi_around;
29 int size, max_size;
30 int src_off, dst_off;
31 int i;
32 int space_around = 10;
34 max_size = 256;
36 mem = xmalloc (max_size + 2 * max_size + 2 * space_around);
37 rand_mem = xmalloc (max_size);
38 lo_around = xmalloc (space_around);
39 hi_around = xmalloc (space_around);
40 memp = mem + space_around;
42 /* Fill RAND_MEM with random bytes, each non-zero. */
43 for (i = 0; i < max_size; i++)
45 int x;
47 x = random ();
48 while (x == 0);
49 rand_mem[i] = x;
52 for (size = 0; size < max_size; size++)
54 printf("phase %d\n", size);
55 for (src_off = 0; src_off <= 16; src_off++)
57 for (dst_off = 0; dst_off <= 16; dst_off++)
59 /* Put zero around the intended destination, to check
60 that it's not clobbered. */
61 for (i = 1; i < space_around; i++)
63 memp[dst_off - i] = 0;
64 memp[dst_off + size - 1 + i] = 0;
67 /* Fill the source area with known contents. */
68 for (i = 0; i < size; i++)
69 memp[src_off + i] = rand_mem[i];
71 /* Remember the contents around the destination area.
72 (It might not be what we wrote some lines above, since
73 the src area and the dst area overlap.) */
74 for (i = 1; i < space_around; i++)
76 lo_around[i] = memp[dst_off - i];
77 hi_around[i] = memp[dst_off + size - 1 + i];
80 memmove (memp + dst_off, memp + src_off, size);
82 /* Check that the destination area has the same
83 contents we wrote to the source area. */
84 for (i = 0; i < size; i++)
86 if (memp[dst_off + i] != rand_mem[i])
87 abort ();
90 /* Check that the area around the destination is not
91 clobbered. */
92 for (i = 1; i < space_around; i++)
94 if (memp[dst_off - i] != lo_around[i])
95 abort ();
96 if (memp[dst_off + size - 1 + i] != hi_around[i])
97 abort ();
103 puts ("Test succeeded.");
105 return 0;
108 #include <support/test-driver.c>