about summary refs log tree commit diff
path: root/string/test-strncmp.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /string/test-strncmp.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.xz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip
2.5-18.1
Diffstat (limited to 'string/test-strncmp.c')
-rw-r--r--string/test-strncmp.c85
1 files changed, 81 insertions, 4 deletions
diff --git a/string/test-strncmp.c b/string/test-strncmp.c
index 431b64d6af..5adf0eb311 100644
--- a/string/test-strncmp.c
+++ b/string/test-strncmp.c
@@ -86,6 +86,65 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, size_t n,
 }
 
 static void
+do_test_limit (size_t align1, size_t align2, size_t len, size_t n, int max_char,
+	 int exp_result)
+{
+  size_t i, align_n;
+  char *s1, *s2;
+
+  if (n == 0)
+    {
+      s1 = (char*)(buf1 + page_size);
+      s2 = (char*)(buf2 + page_size);
+      if (HP_TIMING_AVAIL)
+	printf ("Length %4zd/%4zd:", len, n);
+	
+      FOR_EACH_IMPL (impl, 0)
+	do_one_test (impl, s1, s2, n, 0);
+
+      if (HP_TIMING_AVAIL)
+	putchar ('\n');
+	
+      return;
+    }
+
+  align1 &= 15;
+  align2 &= 15;
+  align_n = (page_size - n) & 15;
+
+  s1 = (char*)(buf1 + page_size - n);
+  s2 = (char*)(buf2 + page_size - n);
+  
+  if (align1 < align_n)
+    s1 -= (align_n - align1);
+    
+  if (align2 < align_n)
+    s2 -= (align_n - align2);
+    
+  for (i = 0; i < n; i++)
+    s1[i] = s2[i] = 1 + 23 * i % max_char;
+
+  if (len < n)
+    {
+      s1[len] = 0;
+      s2[len] = 0;
+      if (exp_result < 0)
+	s2[len] = 32;
+      else if (exp_result > 0)
+	s1[len] = 64;
+    }
+
+  if (HP_TIMING_AVAIL)
+    printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len, n, align1, align2);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, s1, s2, n, exp_result);
+
+  if (HP_TIMING_AVAIL)
+    putchar ('\n');
+}
+
+static void
 do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
 	 int exp_result)
 {
@@ -103,8 +162,8 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
   if (align2 + n + 1 >= page_size)
     return;
 
-  s1 = buf1 + align1;
-  s2 = buf2 + align2;
+  s1 = (char*)(buf1 + align1);
+  s2 = (char*)(buf2 + align2);
 
   for (i = 0; i < n; i++)
     s1[i] = s2[i] = 1 + 23 * i % max_char;
@@ -124,7 +183,7 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
     printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len, n, align1, align2);
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, s1, s2, n, exp_result);
+    do_one_test (impl, (char*)s1, (char*)s2, n, exp_result);
 
   if (HP_TIMING_AVAIL)
     putchar ('\n');
@@ -208,7 +267,7 @@ do_random_tests (void)
 
       FOR_EACH_IMPL (impl, 1)
 	{
-	  r = CALL (impl, p1 + align1, p2 + align2, size);
+	  r = CALL (impl, (char*)(p1 + align1), (char*)(p2 + align2), size);
 	  /* Test whether on 64-bit architectures where ABI requires
 	     callee to promote has the promotion been done.  */
 	  asm ("" : "=g" (r) : "0" (r));
@@ -271,6 +330,24 @@ test_main (void)
       do_test (2 * i, i, 8 << i, 16 << i, 255, 0);
       do_test (2 * i, i, 8 << i, 16 << i, 255, 1);
     }
+    
+  do_test_limit (0, 0, 0, 0, 127, 0);
+  do_test_limit (4, 0, 21, 20, 127, 0);
+  do_test_limit (0, 4, 21, 20, 127, 0);
+  do_test_limit (8, 0, 25, 24, 127, 0);
+  do_test_limit (0, 8, 25, 24, 127, 0);
+
+  for (i = 0; i < 8; ++i)
+    {
+      do_test_limit (0, 0, 17 - i, 16 - i, 127, 0);
+      do_test_limit (0, 0, 17 - i, 16 - i, 255, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, 127, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, 127, 1);
+      do_test_limit (0, 0, 15 - i, 16 - i, 127, -1);
+      do_test_limit (0, 0, 15 - i, 16 - i, 255, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, 255, 1);
+      do_test_limit (0, 0, 15 - i, 16 - i, 255, -1);
+    }
 
   do_random_tests ();
   return ret;