Improve test coverage of strnlen function

Message ID 20210602161029.799090-1-skpgkp2@gmail.com
State Superseded
Headers
Series Improve test coverage of strnlen function |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Sunil Pandey June 2, 2021, 4:10 p.m. UTC
  This patch covers the following condition:

Strings start with different alignments and end with less than 512 byte
length.
---
 string/test-strnlen.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Noah Goldstein June 2, 2021, 5:26 p.m. UTC | #1
On Wed, Jun 2, 2021 at 12:13 PM Sunil K Pandey via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> This patch covers the following condition:
>
> Strings start with different alignments and end with less than 512 byte
> length.
> ---
>  string/test-strnlen.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/string/test-strnlen.c b/string/test-strnlen.c
> index d70faa26ab..20e645893a 100644
> --- a/string/test-strnlen.c
> +++ b/string/test-strnlen.c
> @@ -271,6 +271,10 @@ test_main (void)
>        do_test (1, 1 << i, 5000, BIG_CHAR);
>      }
>
> +  for (i = 1; i <= 127; i++)

I think it makes sense to either include 0 or 128 for alignments
as in some implementations (x86 avx2/evex for example)
that is a unique case.

> +    for (size_t length = i; length < 512; length++)
> +      do_test (i, length, 512, BIG_CHAR);

Might be strengthened a bit with additional test case
in inner loop:
do_test (getpagesize() - i, length, 512, BIG_CHAR);

> +
>    do_random_tests ();
>    do_page_tests ();
>    do_page_2_tests ();
> --
> 2.31.1
>
  
Noah Goldstein June 2, 2021, 5:33 p.m. UTC | #2
On Wed, Jun 2, 2021 at 1:26 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Wed, Jun 2, 2021 at 12:13 PM Sunil K Pandey via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >
> > This patch covers the following condition:
> >
> > Strings start with different alignments and end with less than 512 byte
> > length.
> > ---
> >  string/test-strnlen.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/string/test-strnlen.c b/string/test-strnlen.c
> > index d70faa26ab..20e645893a 100644
> > --- a/string/test-strnlen.c
> > +++ b/string/test-strnlen.c
> > @@ -271,6 +271,10 @@ test_main (void)
> >        do_test (1, 1 << i, 5000, BIG_CHAR);
> >      }
> >
> > +  for (i = 1; i <= 127; i++)
>
> I think it makes sense to either include 0 or 128 for alignments
> as in some implementations (x86 avx2/evex for example)
> that is a unique case.
>
> > +    for (size_t length = i; length < 512; length++)
> > +      do_test (i, length, 512, BIG_CHAR);
I think it would also make sense to include multiple length.
Again in the x86_64 avx2/evex implementations for example
there are 4 cases for handling remaining length:
 [1,32], [33,64], [65,96], and [97, 128].

As well it might be useful to have tests for position of
null > length as well.

>
> Might be strengthened a bit with additional test case
> in inner loop:
> do_test (getpagesize() - i, length, 512, BIG_CHAR);
>
> > +
> >    do_random_tests ();
> >    do_page_tests ();
> >    do_page_2_tests ();
> > --
> > 2.31.1
> >
  
Sunil Pandey June 2, 2021, 8:57 p.m. UTC | #3
On Wed, Jun 2, 2021 at 10:33 AM Noah Goldstein <goldstein.w.n@gmail.com>
wrote:

> On Wed, Jun 2, 2021 at 1:26 PM Noah Goldstein <goldstein.w.n@gmail.com>
> wrote:
> >
> > On Wed, Jun 2, 2021 at 12:13 PM Sunil K Pandey via Libc-alpha
> > <libc-alpha@sourceware.org> wrote:
> > >
> > > This patch covers the following condition:
> > >
> > > Strings start with different alignments and end with less than 512 byte
> > > length.
> > > ---
> > >  string/test-strnlen.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/string/test-strnlen.c b/string/test-strnlen.c
> > > index d70faa26ab..20e645893a 100644
> > > --- a/string/test-strnlen.c
> > > +++ b/string/test-strnlen.c
> > > @@ -271,6 +271,10 @@ test_main (void)
> > >        do_test (1, 1 << i, 5000, BIG_CHAR);
> > >      }
> > >
> > > +  for (i = 1; i <= 127; i++)
> >
> > I think it makes sense to either include 0 or 128 for alignments
> > as in some implementations (x86 avx2/evex for example)
> > that is a unique case.
> >
> > > +    for (size_t length = i; length < 512; length++)
> > > +      do_test (i, length, 512, BIG_CHAR);
> I think it would also make sense to include multiple length.
> Again in the x86_64 avx2/evex implementations for example
> there are 4 cases for handling remaining length:
>  [1,32], [33,64], [65,96], and [97, 128].
>
> As well it might be useful to have tests for position of
> null > length as well.
>
> >
> > Might be strengthened a bit with additional test case
> > in inner loop:
> > do_test (getpagesize() - i, length, 512, BIG_CHAR);
> >
> > > +
> > >    do_random_tests ();
> > >    do_page_tests ();
> > >    do_page_2_tests ();
> > > --
> > > 2.31.1
> > >
>
Sure, will submit a v2 patch which will incorporate all these cases.
  

Patch

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index d70faa26ab..20e645893a 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -271,6 +271,10 @@  test_main (void)
       do_test (1, 1 << i, 5000, BIG_CHAR);
     }
 
+  for (i = 1; i <= 127; i++)
+    for (size_t length = i; length < 512; length++)
+      do_test (i, length, 512, BIG_CHAR);
+
   do_random_tests ();
   do_page_tests ();
   do_page_2_tests ();