[v3] Improve test coverage of strnlen function

Message ID 20210602222914.1298371-1-skpgkp2@gmail.com
State New
Headers show
Series
  • [v3] Improve test coverage of strnlen function
Related show

Commit Message

Szabolcs Nagy via Libc-alpha June 2, 2021, 10:29 p.m.
This patch covers the following condition:

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

-- 
2.31.1

Comments

Szabolcs Nagy via Libc-alpha June 2, 2021, 11:14 p.m. | #1
On Wed, Jun 2, 2021 at 6:30 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 length less than or

> equal to 512 byte.

> ---

>  string/test-strnlen.c | 11 ++++++++++-

>  1 file changed, 10 insertions(+), 1 deletion(-)

>

> diff --git a/string/test-strnlen.c b/string/test-strnlen.c

> index d70faa26ab..920f58e97b 100644

> --- a/string/test-strnlen.c

> +++ b/string/test-strnlen.c

> @@ -230,7 +230,7 @@ do_page_2_tests (void)

>  int

>  test_main (void)

>  {

> -  size_t i;

> +  size_t i, length, char_per_page;

>

>    test_init ();

>

> @@ -271,6 +271,15 @@ test_main (void)

>        do_test (1, 1 << i, 5000, BIG_CHAR);

>      }

>

> +  char_per_page = getpagesize () / sizeof (CHAR);

> +

> +  for (i = 0; i <= 127; i++)

> +    for (length = i; length <= 512; length++)

> +      {

> +       do_test (i, length, 512, BIG_CHAR);

> +       do_test (char_per_page - i, length, 512, BIG_CHAR);

> +      }

> +

>    do_random_tests ();

>    do_page_tests ();

>    do_page_2_tests ();

> --

> 2.31.1

>


LGTM. Think a maintainer needs to make the final call
though.
Szabolcs Nagy via Libc-alpha June 3, 2021, 4:58 p.m. | #2
On Wed, Jun 2, 2021 at 3:29 PM Sunil K Pandey <skpgkp2@gmail.com> wrote:
>

> This patch covers the following condition:

>

> Strings start with different alignments and end with length less than or

> equal to 512 byte.

> ---

>  string/test-strnlen.c | 11 ++++++++++-

>  1 file changed, 10 insertions(+), 1 deletion(-)

>

> diff --git a/string/test-strnlen.c b/string/test-strnlen.c

> index d70faa26ab..920f58e97b 100644

> --- a/string/test-strnlen.c

> +++ b/string/test-strnlen.c

> @@ -230,7 +230,7 @@ do_page_2_tests (void)

>  int

>  test_main (void)

>  {

> -  size_t i;

> +  size_t i, length, char_per_page;

>

>    test_init ();

>

> @@ -271,6 +271,15 @@ test_main (void)

>        do_test (1, 1 << i, 5000, BIG_CHAR);

>      }

>

> +  char_per_page = getpagesize () / sizeof (CHAR);

> +

> +  for (i = 0; i <= 127; i++)

> +    for (length = i; length <= 512; length++)

> +      {

> +       do_test (i, length, 512, BIG_CHAR);

> +       do_test (char_per_page - i, length, 512, BIG_CHAR);

> +      }

> +

>    do_random_tests ();

>    do_page_tests ();

>    do_page_2_tests ();

> --

> 2.31.1

>


LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>


Thanks.

-- 
H.J.

Patch

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index d70faa26ab..920f58e97b 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -230,7 +230,7 @@  do_page_2_tests (void)
 int
 test_main (void)
 {
-  size_t i;
+  size_t i, length, char_per_page;
 
   test_init ();
 
@@ -271,6 +271,15 @@  test_main (void)
       do_test (1, 1 << i, 5000, BIG_CHAR);
     }
 
+  char_per_page = getpagesize () / sizeof (CHAR);
+
+  for (i = 0; i <= 127; i++)
+    for (length = i; length <= 512; length++)
+      {
+	do_test (i, length, 512, BIG_CHAR);
+	do_test (char_per_page - i, length, 512, BIG_CHAR);
+      }
+
   do_random_tests ();
   do_page_tests ();
   do_page_2_tests ();