[2/4] strcmp: Add a testcase for page boundary

Message ID 20200612201056.228614-2-hjl.tools@gmail.com
State Committed
Headers
Series [1/4] strncmp: Add a testcase for page boundary [BZ #25933] |

Commit Message

H.J. Lu June 12, 2020, 8:10 p.m. UTC
  Add a strncmp testcase to cover cases where both strings end on the
page boundary.
---
 string/test-strcmp.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
  

Comments

Carlos O'Donell Sept. 24, 2020, 12:46 a.m. UTC | #1
On 6/12/20 4:10 PM, H.J. Lu via Libc-alpha wrote:
> Add a strncmp testcase to cover cases where both strings end on the
> page boundary.
> ---
>  string/test-strcmp.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 

OK to commit if you:
- Add all the comments.
- s1a iterates over [30,32).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> diff --git a/string/test-strcmp.c b/string/test-strcmp.c
> index 8d4784de80..41d95567c7 100644
> --- a/string/test-strcmp.c
> +++ b/string/test-strcmp.c
> @@ -359,6 +359,30 @@ check (void)
>      }
>  }
>  

Add a comment:

/* To trigger bug 25933 we need a size that is equal to the
   vector length times 4. In the case of AVX2 for Intel we
   need 32 * 4. We make this test generic and run it for all
   architectures as additional boundary testing for such
   related algorithms.  */

> +static void
> +check2 (void)
> +{
> +  size_t size = 32 * 4;
> +  CHAR *s1 = (CHAR *) (buf1 + (BUF1PAGES - 1) * page_size);
> +  CHAR *s2 = (CHAR *) (buf2 + (BUF1PAGES - 1) * page_size);
> +  int exp_result;
> +
> +  memset (s1, 'a', page_size);
> +  memset (s2, 'a', page_size);
> +  s1[(page_size / CHARBYTES) - 1] = (CHAR) 0;
> +  s2[(page_size / CHARBYTES) - 1] = (CHAR) 0;
> +

Add comment:

/* Iterate over a size that is just below where we expect
   the bug to trigger up to the size we expect will trigger
   the bug e.g. [99-128].  Likewise iterate the start of
   two strings between 30 and 31 bytes away from the
   boundary to simulate alignment changes.  */

> +  for (size_t s = 99; s <= size; s++)
> +    for (size_t s1a = 31; s1a < 32; s1a++)

Please make s1a iterate over [30,32) like s2a.

> +      for (size_t s2a = 30; s2a < 32; s2a++)
> +	{
> +	  CHAR *s1p = s1 + (page_size / CHARBYTES - s) - s1a;
> +	  CHAR *s2p = s2 + (page_size / CHARBYTES - s) - s2a;
> +	  exp_result = SIMPLE_STRCMP (s1p, s2p);
> +	  FOR_EACH_IMPL (impl, 0)
> +	    check_result (impl, s1p, s2p, exp_result);
> +	}
> +}
>  
>  int
>  test_main (void)
> @@ -367,6 +391,7 @@ test_main (void)
>  
>    test_init ();
>    check();
> +  check2 ();
>  
>    printf ("%23s", "");
>    FOR_EACH_IMPL (impl, 0)
>
  
H.J. Lu Sept. 24, 2020, 2:29 p.m. UTC | #2
On Wed, Sep 23, 2020 at 5:46 PM Carlos O'Donell <carlos@redhat.com> wrote:
>
> On 6/12/20 4:10 PM, H.J. Lu via Libc-alpha wrote:
> > Add a strncmp testcase to cover cases where both strings end on the
> > page boundary.
> > ---
> >  string/test-strcmp.c | 25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
> >
>
> OK to commit if you:
> - Add all the comments.
> - s1a iterates over [30,32).
>
> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
>
> > diff --git a/string/test-strcmp.c b/string/test-strcmp.c
> > index 8d4784de80..41d95567c7 100644
> > --- a/string/test-strcmp.c
> > +++ b/string/test-strcmp.c
> > @@ -359,6 +359,30 @@ check (void)
> >      }
> >  }
> >
>
> Add a comment:
>
> /* To trigger bug 25933 we need a size that is equal to the
>    vector length times 4. In the case of AVX2 for Intel we
>    need 32 * 4. We make this test generic and run it for all
>    architectures as additional boundary testing for such
>    related algorithms.  */
>
> > +static void
> > +check2 (void)
> > +{
> > +  size_t size = 32 * 4;
> > +  CHAR *s1 = (CHAR *) (buf1 + (BUF1PAGES - 1) * page_size);
> > +  CHAR *s2 = (CHAR *) (buf2 + (BUF1PAGES - 1) * page_size);
> > +  int exp_result;
> > +
> > +  memset (s1, 'a', page_size);
> > +  memset (s2, 'a', page_size);
> > +  s1[(page_size / CHARBYTES) - 1] = (CHAR) 0;
> > +  s2[(page_size / CHARBYTES) - 1] = (CHAR) 0;
> > +
>
> Add comment:
>
> /* Iterate over a size that is just below where we expect
>    the bug to trigger up to the size we expect will trigger
>    the bug e.g. [99-128].  Likewise iterate the start of
>    two strings between 30 and 31 bytes away from the
>    boundary to simulate alignment changes.  */
>
> > +  for (size_t s = 99; s <= size; s++)
> > +    for (size_t s1a = 31; s1a < 32; s1a++)
>
> Please make s1a iterate over [30,32) like s2a.
>
> > +      for (size_t s2a = 30; s2a < 32; s2a++)
> > +     {
> > +       CHAR *s1p = s1 + (page_size / CHARBYTES - s) - s1a;
> > +       CHAR *s2p = s2 + (page_size / CHARBYTES - s) - s2a;
> > +       exp_result = SIMPLE_STRCMP (s1p, s2p);
> > +       FOR_EACH_IMPL (impl, 0)
> > +         check_result (impl, s1p, s2p, exp_result);
> > +     }
> > +}
> >
> >  int
> >  test_main (void)
> > @@ -367,6 +391,7 @@ test_main (void)
> >
> >    test_init ();
> >    check();
> > +  check2 ();
> >
> >    printf ("%23s", "");
> >    FOR_EACH_IMPL (impl, 0)
> >
>

This is the updated patch I am checking in.

Thanks.
  

Patch

diff --git a/string/test-strcmp.c b/string/test-strcmp.c
index 8d4784de80..41d95567c7 100644
--- a/string/test-strcmp.c
+++ b/string/test-strcmp.c
@@ -359,6 +359,30 @@  check (void)
     }
 }
 
+static void
+check2 (void)
+{
+  size_t size = 32 * 4;
+  CHAR *s1 = (CHAR *) (buf1 + (BUF1PAGES - 1) * page_size);
+  CHAR *s2 = (CHAR *) (buf2 + (BUF1PAGES - 1) * page_size);
+  int exp_result;
+
+  memset (s1, 'a', page_size);
+  memset (s2, 'a', page_size);
+  s1[(page_size / CHARBYTES) - 1] = (CHAR) 0;
+  s2[(page_size / CHARBYTES) - 1] = (CHAR) 0;
+
+  for (size_t s = 99; s <= size; s++)
+    for (size_t s1a = 31; s1a < 32; s1a++)
+      for (size_t s2a = 30; s2a < 32; s2a++)
+	{
+	  CHAR *s1p = s1 + (page_size / CHARBYTES - s) - s1a;
+	  CHAR *s2p = s2 + (page_size / CHARBYTES - s) - s2a;
+	  exp_result = SIMPLE_STRCMP (s1p, s2p);
+	  FOR_EACH_IMPL (impl, 0)
+	    check_result (impl, s1p, s2p, exp_result);
+	}
+}
 
 int
 test_main (void)
@@ -367,6 +391,7 @@  test_main (void)
 
   test_init ();
   check();
+  check2 ();
 
   printf ("%23s", "");
   FOR_EACH_IMPL (impl, 0)