c6d234
commit ed983107bbc62245b06b99f02e69acf36a0baa3e
c6d234
Author: H.J. Lu <hjl.tools@gmail.com>
c6d234
Date:   Wed May 23 03:59:56 2018 -0700
c6d234
c6d234
    Add a test case for [BZ #23196]
c6d234
    
c6d234
            [BZ #23196]
c6d234
            * string/test-memcpy.c (do_test1): New function.
c6d234
            (test_main): Call it.
c6d234
c6d234
diff --git a/string/test-memcpy.c b/string/test-memcpy.c
c6d234
index d252400bf5254eee..10a09d0b0fb50dc5 100644
c6d234
--- a/string/test-memcpy.c
c6d234
+++ b/string/test-memcpy.c
c6d234
@@ -206,6 +206,50 @@ do_random_tests (void)
c6d234
     }
c6d234
 }
c6d234
 
c6d234
+static void
c6d234
+do_test1 (void)
c6d234
+{
c6d234
+  size_t size = 0x100000;
c6d234
+  void *large_buf;
c6d234
+
c6d234
+  large_buf = mmap (NULL, size * 2 + page_size, PROT_READ | PROT_WRITE,
c6d234
+		    MAP_PRIVATE | MAP_ANON, -1, 0);
c6d234
+  if (large_buf == MAP_FAILED)
c6d234
+    {
c6d234
+      puts ("Failed to allocat large_buf, skipping do_test1");
c6d234
+      return;
c6d234
+    }
c6d234
+
c6d234
+  if (mprotect (large_buf + size, page_size, PROT_NONE))
c6d234
+    error (EXIT_FAILURE, errno, "mprotect failed");
c6d234
+
c6d234
+  size_t arrary_size = size / sizeof (uint32_t);
c6d234
+  uint32_t *dest = large_buf;
c6d234
+  uint32_t *src = large_buf + size + page_size;
c6d234
+  size_t i;
c6d234
+
c6d234
+  for (i = 0; i < arrary_size; i++)
c6d234
+    src[i] = (uint32_t) i;
c6d234
+
c6d234
+  FOR_EACH_IMPL (impl, 0)
c6d234
+    {
c6d234
+      memset (dest, -1, size);
c6d234
+      CALL (impl, (char *) dest, (char *) src, size);
c6d234
+      for (i = 0; i < arrary_size; i++)
c6d234
+	if (dest[i] != src[i])
c6d234
+	  {
c6d234
+	    error (0, 0,
c6d234
+		   "Wrong result in function %s dst \"%p\" src \"%p\" offset \"%zd\"",
c6d234
+		   impl->name, dest, src, i);
c6d234
+	    ret = 1;
c6d234
+	    break;
c6d234
+	  }
c6d234
+    }
c6d234
+
c6d234
+  munmap ((void *) dest, size);
c6d234
+  munmap ((void *) src, size);
c6d234
+}
c6d234
+
c6d234
 int
c6d234
 test_main (void)
c6d234
 {
c6d234
@@ -247,6 +291,9 @@ test_main (void)
c6d234
   do_test (0, 0, getpagesize ());
c6d234
 
c6d234
   do_random_tests ();
c6d234
+
c6d234
+  do_test1 ();
c6d234
+
c6d234
   return ret;
c6d234
 }
c6d234