string test alignment fix by Mahesh Bodapati
[libc-test.git] / src / functional / string_memcpy.c
blob96256a7c7edcbcfcbcb943a227f78f4f2359cff7
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include "test.h"
6 static char buf[512];
8 static void *(*volatile pmemcpy)(void *restrict, const void *restrict, size_t);
10 static void *aligned(void *p) {
11 return (void*)(((uintptr_t)p + 63) & -64);
14 #define N 80
15 static void test_align(int dalign, int salign, int len)
17 char *src = aligned(buf);
18 char *dst = aligned(buf + 128);
19 char *want = aligned(buf + 256);
20 char *p;
21 int i;
23 if (salign + len > N || dalign + len > N)
24 abort();
25 for (i = 0; i < N; i++) {
26 src[i] = '#';
27 dst[i] = want[i] = ' ';
29 for (i = 0; i < len; i++)
30 src[salign+i] = want[dalign+i] = '0'+i;
31 p = pmemcpy(dst+dalign, src+salign, len);
32 if (p != dst+dalign)
33 t_error("memcpy(%p,...) returned %p\n", dst+dalign, p);
34 for (i = 0; i < N; i++)
35 if (dst[i] != want[i]) {
36 t_error("memcpy(align %d, align %d, %d) failed\n", dalign, salign, len);
37 t_printf("got : %.*s\n", dalign+len+1, dst);
38 t_printf("want: %.*s\n", dalign+len+1, want);
39 break;
43 int main(void)
45 int i,j,k;
47 pmemcpy = memcpy;
49 for (i = 0; i < 16; i++)
50 for (j = 0; j < 16; j++)
51 for (k = 0; k < 64; k++)
52 test_align(i,j,k);
54 return t_status;