[v2] Add page tests to string/test-strnlen.

Submitted by Wainer dos Santos Moschetta on March 15, 2017, 6 p.m.

Details

Message ID 20170315180012.6170-1-wainersm@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wainer dos Santos Moschetta March 15, 2017, 6 p.m.
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-15  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 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Zack Weinberg March 15, 2017, 8:40 p.m.
On Wed, Mar 15, 2017 at 2:00 PM, Wainer dos Santos Moschetta
<wainersm@linux.vnet.ibm.com> wrote:
> 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.

Please check you aren't duplicating tests done by string/stratcliff.c.

zw
Mike Frysinger March 17, 2017, 2:59 a.m.
On 15 Mar 2017 15:00, Wainer dos Santos Moschetta wrote:
> +  for (i = 0; i < last_offset; i++)
> +    s[i] = 65;

memset ?

> +      FOR_EACH_IMPL (impl, 0)
> +          /* Checks only for maxlen larger than length because other cases are
> +             already covered in do_random_tests.  */
> +          do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len);

incorrect indent.  but please use braces as it'll be less confusing
(especially with that comment in there).
-mike

Patch hide | download patch | download mbox

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index 7059669..b628176 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -143,6 +143,58 @@  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;
+  for (i = 0; i < last_offset; i++)
+    s[i] = 65;
+  s[i] = 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 larger than length because other cases are
+             already covered in do_random_tests.  */
+          do_one_test (impl, (CHAR *) (s + offset), page_size, exp_len);
+    }
+}
+
 int
 test_main (void)
 {
@@ -188,6 +240,7 @@  test_main (void)
     }
 
   do_random_tests ();
+  do_page_tests ();
   return ret;
 }