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