e354a5
commit f7e3f92b7c45663be808279a43b5221c16001229
e354a5
Author: H.J. Lu <hjl.tools@gmail.com>
e354a5
Date:   Thu May 7 07:29:46 2020 -0700
e354a5
e354a5
    strncmp: Add a testcase for page boundary [BZ #25933]
e354a5
    
e354a5
    Add a strncmp testcase to cover cases where one of strings ends on the
e354a5
    page boundary with the maximum string length less than the number bytes
e354a5
    of each AVX2 loop iteration and different offsets from page boundary.
e354a5
    
e354a5
    The updated string/test-strncmp fails on Intel Core i7-8559U without
e354a5
    
e354a5
    ommit 1c6432316bc434a72108d7b0c7cfbfdde64c3124
e354a5
    Author: Sunil K Pandey <skpgkp1@gmail.com>
e354a5
    Date:   Fri Jun 12 08:57:16 2020 -0700
e354a5
    
e354a5
        Fix avx2 strncmp offset compare condition check [BZ #25933]
e354a5
e354a5
diff --git a/string/test-strncmp.c b/string/test-strncmp.c
e354a5
index d961ac4493..962679b384 100644
e354a5
--- a/string/test-strncmp.c
e354a5
+++ b/string/test-strncmp.c
e354a5
@@ -403,6 +403,38 @@ check2 (void)
e354a5
   free (s2);
e354a5
 }
e354a5
 
e354a5
+static void
e354a5
+check3 (void)
e354a5
+{
e354a5
+  /* To trigger bug 25933, we need a size that is equal to the vector
e354a5
+     length times 4. In the case of AVX2 for Intel, we need 32 * 4.  We
e354a5
+     make this test generic and run it for all architectures as additional
e354a5
+     boundary testing for such related algorithms.  */
e354a5
+  size_t size = 32 * 4;
e354a5
+  CHAR *s1 = (CHAR *) (buf1 + (BUF1PAGES - 1) * page_size);
e354a5
+  CHAR *s2 = (CHAR *) (buf2 + (BUF1PAGES - 1) * page_size);
e354a5
+  int exp_result;
e354a5
+
e354a5
+  memset (s1, 'a', page_size);
e354a5
+  memset (s2, 'a', page_size);
e354a5
+  s1[(page_size / CHARBYTES) - 1] = (CHAR) 0;
e354a5
+
e354a5
+  /* Iterate over a size that is just below where we expect the bug to
e354a5
+     trigger up to the size we expect will trigger the bug e.g. [99-128].
e354a5
+     Likewise iterate the start of two strings between 30 and 31 bytes
e354a5
+     away from the boundary to simulate alignment changes.  */
e354a5
+  for (size_t s = 99; s <= size; s++)
e354a5
+    for (size_t s1a = 30; s1a < 32; s1a++)
e354a5
+      for (size_t s2a = 30; s2a < 32; s2a++)
e354a5
+	{
e354a5
+	  CHAR *s1p = s1 + (page_size / CHARBYTES - s) - s1a;
e354a5
+	  CHAR *s2p = s2 + (page_size / CHARBYTES - s) - s2a;
e354a5
+	  exp_result = SIMPLE_STRNCMP (s1p, s2p, s);
e354a5
+	  FOR_EACH_IMPL (impl, 0)
e354a5
+	    check_result (impl, s1p, s2p, s, exp_result);
e354a5
+	}
e354a5
+}
e354a5
+
e354a5
 int
e354a5
 test_main (void)
e354a5
 {
e354a5
@@ -412,6 +444,7 @@ test_main (void)
e354a5
 
e354a5
   check1 ();
e354a5
   check2 ();
e354a5
+  check3 ();
e354a5
 
e354a5
   printf ("%23s", "");
e354a5
   FOR_EACH_IMPL (impl, 0)