]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - string/test-strnlen.c
Make mktime etc. compatible with __time64_t
[thirdparty/glibc.git] / string / test-strnlen.c
index 7059669b24163430cda0ca165f5c8c064217495a..8c753382a175b4b90facb85952abbc284d95fa89 100644 (file)
@@ -1,5 +1,5 @@
 /* Test strlen functions.
-   Copyright (C) 1999-2017 Free Software Foundation, Inc.
+   Copyright (C) 1999-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
@@ -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,7 +241,8 @@ test_main (void)
     }
 
   do_random_tests ();
+  do_page_tests ();
   return ret;
 }
 
-#include "../test-skeleton.c"
+#include <support/test-driver.c>