Linux 4.8-rc8
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / copyloops / validate.c
blob1750ff57ee583839ab658a13a61f0e089b4460a9
1 #include <malloc.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdbool.h>
6 #include "../utils.h"
8 #define MAX_LEN 8192
9 #define MAX_OFFSET 16
10 #define MIN_REDZONE 128
11 #define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE)
12 #define POISON 0xa5
14 unsigned long COPY_LOOP(void *to, const void *from, unsigned long size);
16 static void do_one(char *src, char *dst, unsigned long src_off,
17 unsigned long dst_off, unsigned long len, void *redzone,
18 void *fill)
20 char *srcp, *dstp;
21 unsigned long ret;
22 unsigned long i;
24 srcp = src + MIN_REDZONE + src_off;
25 dstp = dst + MIN_REDZONE + dst_off;
27 memset(src, POISON, BUFLEN);
28 memset(dst, POISON, BUFLEN);
29 memcpy(srcp, fill, len);
31 ret = COPY_LOOP(dstp, srcp, len);
32 if (ret && ret != (unsigned long)dstp) {
33 printf("(%p,%p,%ld) returned %ld\n", dstp, srcp, len, ret);
34 abort();
37 if (memcmp(dstp, srcp, len)) {
38 printf("(%p,%p,%ld) miscompare\n", dstp, srcp, len);
39 printf("src: ");
40 for (i = 0; i < len; i++)
41 printf("%02x ", srcp[i]);
42 printf("\ndst: ");
43 for (i = 0; i < len; i++)
44 printf("%02x ", dstp[i]);
45 printf("\n");
46 abort();
49 if (memcmp(dst, redzone, dstp - dst)) {
50 printf("(%p,%p,%ld) redzone before corrupted\n",
51 dstp, srcp, len);
52 abort();
55 if (memcmp(dstp+len, redzone, dst+BUFLEN-(dstp+len))) {
56 printf("(%p,%p,%ld) redzone after corrupted\n",
57 dstp, srcp, len);
58 abort();
62 int test_copy_loop(void)
64 char *src, *dst, *redzone, *fill;
65 unsigned long len, src_off, dst_off;
66 unsigned long i;
68 src = memalign(BUFLEN, BUFLEN);
69 dst = memalign(BUFLEN, BUFLEN);
70 redzone = malloc(BUFLEN);
71 fill = malloc(BUFLEN);
73 if (!src || !dst || !redzone || !fill) {
74 fprintf(stderr, "malloc failed\n");
75 exit(1);
78 memset(redzone, POISON, BUFLEN);
80 /* Fill with sequential bytes */
81 for (i = 0; i < BUFLEN; i++)
82 fill[i] = i & 0xff;
84 for (len = 1; len < MAX_LEN; len++) {
85 for (src_off = 0; src_off < MAX_OFFSET; src_off++) {
86 for (dst_off = 0; dst_off < MAX_OFFSET; dst_off++) {
87 do_one(src, dst, src_off, dst_off, len,
88 redzone, fill);
93 return 0;
96 int main(void)
98 return test_harness(test_copy_loop, str(COPY_LOOP));