~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/copyloops/validate.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <malloc.h>
  3 #include <string.h>
  4 #include <stdlib.h>
  5 #include <stdbool.h>
  6 
  7 #include "utils.h"
  8 
  9 #define MAX_LEN 8192
 10 #define MAX_OFFSET 16
 11 #define MIN_REDZONE 128
 12 #define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE)
 13 #define POISON 0xa5
 14 
 15 unsigned long COPY_LOOP(void *to, const void *from, unsigned long size);
 16 
 17 static void do_one(char *src, char *dst, unsigned long src_off,
 18                    unsigned long dst_off, unsigned long len, void *redzone,
 19                    void *fill)
 20 {
 21         char *srcp, *dstp;
 22         unsigned long ret;
 23         unsigned long i;
 24 
 25         srcp = src + MIN_REDZONE + src_off;
 26         dstp = dst + MIN_REDZONE + dst_off;
 27 
 28         memset(src, POISON, BUFLEN);
 29         memset(dst, POISON, BUFLEN);
 30         memcpy(srcp, fill, len);
 31 
 32         ret = COPY_LOOP(dstp, srcp, len);
 33         if (ret && ret != (unsigned long)dstp) {
 34                 printf("(%p,%p,%ld) returned %ld\n", dstp, srcp, len, ret);
 35                 abort();
 36         }
 37 
 38         if (memcmp(dstp, srcp, len)) {
 39                 printf("(%p,%p,%ld) miscompare\n", dstp, srcp, len);
 40                 printf("src: ");
 41                 for (i = 0; i < len; i++)
 42                         printf("%02x ", srcp[i]);
 43                 printf("\ndst: ");
 44                 for (i = 0; i < len; i++)
 45                         printf("%02x ", dstp[i]);
 46                 printf("\n");
 47                 abort();
 48         }
 49 
 50         if (memcmp(dst, redzone, dstp - dst)) {
 51                 printf("(%p,%p,%ld) redzone before corrupted\n",
 52                        dstp, srcp, len);
 53                 abort();
 54         }
 55 
 56         if (memcmp(dstp+len, redzone, dst+BUFLEN-(dstp+len))) {
 57                 printf("(%p,%p,%ld) redzone after corrupted\n",
 58                        dstp, srcp, len);
 59                 abort();
 60         }
 61 }
 62 
 63 int test_copy_loop(void)
 64 {
 65         char *src, *dst, *redzone, *fill;
 66         unsigned long len, src_off, dst_off;
 67         unsigned long i;
 68 
 69         src = memalign(BUFLEN, BUFLEN);
 70         dst = memalign(BUFLEN, BUFLEN);
 71         redzone = malloc(BUFLEN);
 72         fill = malloc(BUFLEN);
 73 
 74         if (!src || !dst || !redzone || !fill) {
 75                 fprintf(stderr, "malloc failed\n");
 76                 exit(1);
 77         }
 78 
 79         memset(redzone, POISON, BUFLEN);
 80 
 81         /* Fill with sequential bytes */
 82         for (i = 0; i < BUFLEN; i++)
 83                 fill[i] = i & 0xff;
 84 
 85         for (len = 1; len < MAX_LEN; len++) {
 86                 for (src_off = 0; src_off < MAX_OFFSET; src_off++) {
 87                         for (dst_off = 0; dst_off < MAX_OFFSET; dst_off++) {
 88                                 do_one(src, dst, src_off, dst_off, len,
 89                                        redzone, fill);
 90                         }
 91                 }
 92         }
 93 
 94         return 0;
 95 }
 96 
 97 int main(void)
 98 {
 99         return test_harness(test_copy_loop, str(COPY_LOOP));
100 }
101 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php