public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3] Add page tests to string/test-strnlen.
@ 2017-03-31 20:37 Wainer dos Santos Moschetta
  2017-04-01  7:32 ` Rajalakshmi Srinivasaraghavan
  2017-04-05 14:52 ` Tulio Magno Quites Machado Filho
  0 siblings, 2 replies; 3+ messages in thread
From: Wainer dos Santos Moschetta @ 2017-03-31 20:37 UTC (permalink / raw)
  To: libc-alpha

I checked following the new cases aren't duplicated of string/stratcliff.c
tests.

Changes since v2:
- Now using memset to initialize the string.
- Fixed indent of 2nd FOR_EACH_IMPL statement in do_page_test(), also
improved its explanation.
 
--- >8 ---
May be tricky for otimized implementations to handle strings around
page boundary once, for instance, it is performed unaligned loads or
when maxlen is used as a hint for vectorized loops. The test cases
should unveil regression bugs on these cases.

To some extend do_random_tests in string/test-strnlen tests strings
placed at page end but it does not cover all cases. So this change
adds tests which consists of placing strings of varying sizes ending
at the page boundary. It also combines with different values of maxlen.

Tested on ppc64le and x86_64.

2017-03-31  Wainer dos Santos Moschetta  <wainersm@linux.vnet.ibm.com>

	* string/test-strnlen.c (do_page_tests): New function
	to check length of strings ending at the page boundary.
	(test_main): Added call to the do_page_tests function.
---
 string/test-strnlen.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index 277146f..e56cdb6 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -143,6 +143,59 @@ do_random_tests (void)
     }
 }
 
+/* Tests meant to unveil fail on implementation that does not access bytes
+   around the page boundary accordingly.  */
+static void
+do_page_tests (void)
+{
+  size_t i, exp_len, start_offset, offset;
+  /* Calculate the null character offset.  */
+  size_t last_offset = (page_size / sizeof (CHAR)) - 1;
+
+  CHAR *s = (CHAR *) buf2;
+  memset (s, 65, (last_offset - 1));
+  s[last_offset] = 0;
+
+  /* Place short strings ending at page boundary.  */
+  offset = last_offset;
+  for (i = 0; i < 128; i++)
+    {
+      /* Decrease offset to stress several sizes and alignments.  */
+      offset--;
+      exp_len = last_offset - offset;
+      FOR_EACH_IMPL (impl, 0)
+        {
+          /* Varies maxlen value to cover the cases where it is:
+               - larger than length;
+               - slightly greater than length;
+               - equal to length;
+               - slightly less than length.  */
+          do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len);
+          do_one_test (impl, (CHAR *) (s + offset), exp_len + 1, exp_len);
+          do_one_test (impl, (CHAR *) (s + offset), exp_len, exp_len);
+          if (exp_len > 0)
+            do_one_test (impl, (CHAR *) (s + offset), exp_len - 1, exp_len - 1);
+        }
+    }
+
+  /* Place long strings ending at page boundary.  */
+  start_offset = (last_offset + 1) / 2;
+  for (i = 0; i < 64; ++i)
+    {
+      /* Increase offset to stress several alignments.  */
+      offset = start_offset + i;
+      if (offset >= (last_offset + 1))
+        break;
+      exp_len = last_offset - offset;
+      FOR_EACH_IMPL (impl, 0)
+        {
+          /* Checks only for maxlen much larger than length because smaller
+             values are already covered in do_random_tests function.  */
+          do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len);
+        }
+    }
+}
+
 int
 test_main (void)
 {
@@ -188,6 +241,7 @@ test_main (void)
     }
 
   do_random_tests ();
+  do_page_tests ();
   return ret;
 }
 
-- 
2.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] Add page tests to string/test-strnlen.
  2017-03-31 20:37 [PATCH v3] Add page tests to string/test-strnlen Wainer dos Santos Moschetta
@ 2017-04-01  7:32 ` Rajalakshmi Srinivasaraghavan
  2017-04-05 14:52 ` Tulio Magno Quites Machado Filho
  1 sibling, 0 replies; 3+ messages in thread
From: Rajalakshmi Srinivasaraghavan @ 2017-04-01  7:32 UTC (permalink / raw)
  To: libc-alpha, wainersm



On 04/01/2017 02:07 AM, Wainer dos Santos Moschetta wrote:
> I checked following the new cases aren't duplicated of string/stratcliff.c
> tests.
>
> Changes since v2:
> - Now using memset to initialize the string.
> - Fixed indent of 2nd FOR_EACH_IMPL statement in do_page_test(), also
> improved its explanation.
>
> --- >8 ---
> May be tricky for otimized implementations to handle strings around
> page boundary once, for instance, it is performed unaligned loads or
> when maxlen is used as a hint for vectorized loops. The test cases
> should unveil regression bugs on these cases.
>
> To some extend do_random_tests in string/test-strnlen tests strings
> placed at page end but it does not cover all cases. So this change
> adds tests which consists of placing strings of varying sizes ending
> at the page boundary. It also combines with different values of maxlen.
>
> Tested on ppc64le and x86_64.
>
> 2017-03-31  Wainer dos Santos Moschetta  <wainersm@linux.vnet.ibm.com>
>
> 	* string/test-strnlen.c (do_page_tests): New function
> 	to check length of strings ending at the page boundary.
> 	(test_main): Added call to the do_page_tests function.

LGTM
-- 
Thanks
Rajalakshmi S

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] Add page tests to string/test-strnlen.
  2017-03-31 20:37 [PATCH v3] Add page tests to string/test-strnlen Wainer dos Santos Moschetta
  2017-04-01  7:32 ` Rajalakshmi Srinivasaraghavan
@ 2017-04-05 14:52 ` Tulio Magno Quites Machado Filho
  1 sibling, 0 replies; 3+ messages in thread
From: Tulio Magno Quites Machado Filho @ 2017-04-05 14:52 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta, libc-alpha

Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com> writes:

> May be tricky for otimized implementations to handle strings around
> page boundary once, for instance, it is performed unaligned loads or
> when maxlen is used as a hint for vectorized loops. The test cases
> should unveil regression bugs on these cases.
>
> To some extend do_random_tests in string/test-strnlen tests strings
> placed at page end but it does not cover all cases. So this change
> adds tests which consists of placing strings of varying sizes ending
> at the page boundary. It also combines with different values of maxlen.
>
> Tested on ppc64le and x86_64.
>
> 2017-03-31  Wainer dos Santos Moschetta  <wainersm@linux.vnet.ibm.com>
>
> 	* string/test-strnlen.c (do_page_tests): New function
> 	to check length of strings ending at the page boundary.
> 	(test_main): Added call to the do_page_tests function.

LGTM too.
Pushed as ff65c87.

-- 
Tulio Magno

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-05 14:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 20:37 [PATCH v3] Add page tests to string/test-strnlen Wainer dos Santos Moschetta
2017-04-01  7:32 ` Rajalakshmi Srinivasaraghavan
2017-04-05 14:52 ` Tulio Magno Quites Machado Filho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).