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