diff mbox series

[v2] Improve test coverage of strlen function

Message ID 20210531155938.421952-1-skpgkp2@gmail.com
State New
Headers show
Series [v2] Improve test coverage of strlen function | expand

Commit Message

Sunil Pandey May 31, 2021, 3:59 p.m. UTC
This patch covers following conditions.

- String starts with different alignments and ends at the page boundary
  with less than 64 byte length.
- String starts with different alignments and cross page boundary with
  fixed length.
---
 string/test-strlen.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

H.J. Lu May 31, 2021, 4:02 p.m. UTC | #1
On Mon, May 31, 2021 at 8:59 AM Sunil K Pandey <skpgkp2@gmail.com> wrote:
>
> This patch covers following conditions.

"the following conditions:"

> - String starts with different alignments and ends at the page boundary
Strings start ... and end
>   with less than 64 byte length.
> - String starts with different alignments and cross page boundary with
 Strings starts
>   fixed length.
> ---
>  string/test-strlen.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/string/test-strlen.c b/string/test-strlen.c
> index 6e67d1f1f1..c9a7afb339 100644
> --- a/string/test-strlen.c
> +++ b/string/test-strlen.c
> @@ -79,7 +79,7 @@ do_test (size_t align, size_t len)
>  {
>    size_t i;
>
> -  align &= 63;
> +  align &= (getpagesize () / sizeof (CHAR)) - 1;
>    if (align + sizeof (CHAR) * len >= page_size)
>      return;
>
> @@ -160,6 +160,19 @@ test_main (void)
>        do_test (sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
>      }
>
> +  /* Test strings near page boundary */
> +
> +  size_t maxlength = 64 / sizeof (CHAR) - 1;
> +  size_t pagesize = getpagesize () / sizeof (CHAR);
> +
> +  for (i = maxlength ; i > 1; --i)
> +    {
> +      /* String stays on the same page.  */
> +      do_test (pagesize - i, i - 1);
> +      /* String crosses page boundary.  */
> +      do_test (pagesize - i, maxlength);
> +    }
> +
>    do_random_tests ();
>    return ret;
>  }
> --
> 2.31.1
>
diff mbox series

Patch

diff --git a/string/test-strlen.c b/string/test-strlen.c
index 6e67d1f1f1..c9a7afb339 100644
--- a/string/test-strlen.c
+++ b/string/test-strlen.c
@@ -79,7 +79,7 @@  do_test (size_t align, size_t len)
 {
   size_t i;
 
-  align &= 63;
+  align &= (getpagesize () / sizeof (CHAR)) - 1;
   if (align + sizeof (CHAR) * len >= page_size)
     return;
 
@@ -160,6 +160,19 @@  test_main (void)
       do_test (sizeof (CHAR) * i, (size_t)((1 << i) / 1.5));
     }
 
+  /* Test strings near page boundary */
+
+  size_t maxlength = 64 / sizeof (CHAR) - 1;
+  size_t pagesize = getpagesize () / sizeof (CHAR);
+
+  for (i = maxlength ; i > 1; --i)
+    {
+      /* String stays on the same page.  */
+      do_test (pagesize - i, i - 1);
+      /* String crosses page boundary.  */
+      do_test (pagesize - i, maxlength);
+    }
+
   do_random_tests ();
   return ret;
 }