summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-10-05 13:32:07 -0700
committerH.J. Lu <hjl.tools@gmail.com>2012-10-05 13:32:07 -0700
commit03759f47db62930f2dddf1c9733ef89b9d99e2da (patch)
treeff23ba8b81b00366f0cbc0c890e9e7487b4497ae /string
parentfb228a2d94a130eda38c8794b0f264aa9f0e4714 (diff)
downloadglibc-03759f47db62930f2dddf1c9733ef89b9d99e2da.tar.gz
glibc-03759f47db62930f2dddf1c9733ef89b9d99e2da.tar.xz
glibc-03759f47db62930f2dddf1c9733ef89b9d99e2da.zip
Test strcasestr/strchr/strstr under all implementations
Diffstat (limited to 'string')
-rw-r--r--string/Makefile2
-rw-r--r--string/bug-strcasestr1.c39
-rw-r--r--string/bug-strchr1.c14
-rw-r--r--string/bug-strstr1.c26
-rw-r--r--string/test-strcasestr.c28
-rw-r--r--string/test-strchr.c27
-rw-r--r--string/test-strstr.c30
7 files changed, 77 insertions, 89 deletions
diff --git a/string/Makefile b/string/Makefile
index a1204d9ad0..6f2c6c369b 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -56,7 +56,7 @@ tests		:= tester inl-tester noinl-tester testcopy test-ffs	\
 		   tst-strtok tst-strxfrm bug-strcoll1 tst-strfry	\
 		   bug-strtok1 $(addprefix test-,$(strop-tests))	\
 		   bug-envz1 tst-strxfrm2 tst-endian tst-svc2		\
-		   bug-strstr1 bug-strcasestr1 bug-strchr1 tst-strtok_r
+		   tst-strtok_r
 
 
 include ../Rules
diff --git a/string/bug-strcasestr1.c b/string/bug-strcasestr1.c
deleted file mode 100644
index e8334d7093..0000000000
--- a/string/bug-strcasestr1.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Test for non-submitted strcasestr bug.
-   Copyright (C) 2012 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stdio.h>
-#include <string.h>
-
-#define TEST_FUNCTION do_test ()
-static int
-do_test (void)
-{
-  const char haystack[] = "AOKB";
-  const char needle[] = "OK";
-  const char *sub = strcasestr (haystack, needle);
-
-  if (sub == NULL)
-    {
-      fprintf (stderr, "BUG: didn't find \"%s\" in \"%s\"\n", needle, haystack);
-      return 1;
-    }
-
-  return 0;
-}
-
-#include "../test-skeleton.c"
diff --git a/string/bug-strchr1.c b/string/bug-strchr1.c
deleted file mode 100644
index 21155d8a7f..0000000000
--- a/string/bug-strchr1.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-static int
-do_test (void)
-{
-  char s[] __attribute__((aligned(16))) = "\xff";
-  char *p = strchr (s, '\xfe');
-  printf ("%p\n", p);
-  return p != NULL;
-}
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
diff --git a/string/bug-strstr1.c b/string/bug-strstr1.c
deleted file mode 100644
index 889de12955..0000000000
--- a/string/bug-strstr1.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-int main (int argc, char** argv)
-{
-  const char haystack[] =
-    "F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD_C3_A7_20_EF_BF_BD";
-
-  const char needle[] =
-    "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
-
-  const char* sub = strstr (haystack, needle);
-
-  if (sub != NULL)
-    {
-      int j;
-
-      fprintf (stderr, "BUG: expected NULL, got:\n%s\n%s\n", sub, needle);
-      for (j = 0; needle[j] != '\0'; ++j)
-        putchar (needle[j] == sub[j] ? ' ' : '^');
-      puts ("");
-      return 1;
-    }
-
-  return 0;
-}
diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c
index 6c1a878617..fc01858637 100644
--- a/string/test-strcasestr.c
+++ b/string/test-strcasestr.c
@@ -57,8 +57,9 @@ IMPL (simple_strcasestr, 0)
 IMPL (strcasestr, 1)
 
 
-static void
-do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
+static int
+check_result (impl_t *impl, const char *s1, const char *s2,
+	      char *exp_result)
 {
   char *result = CALL (impl, s1, s2);
   if (result != exp_result)
@@ -66,8 +67,16 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
 	     result, exp_result);
       ret = 1;
-      return;
+      return -1;
     }
+  return 0;
+}
+
+static void
+do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
+{
+  if (check_result (impl, s1, s2, exp_result) < 0)
+    return;
 
   if (HP_TIMING_AVAIL)
     {
@@ -136,12 +145,25 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2,
     putchar ('\n');
 }
 
+static void
+check1 (void)
+{
+  const char s1[] = "AOKB";
+  const char s2[] = "OK";
+  char *exp_result;
+
+  exp_result = stupid_strcasestr (s1, s2);
+  FOR_EACH_IMPL (impl, 0)
+    check_result (impl, s1, s2, exp_result);
+}
 
 static int
 test_main (void)
 {
   test_init ();
 
+  check1 ();
+
   printf ("%23s", "");
   FOR_EACH_IMPL (impl, 0)
     printf ("\t%s", impl->name);
diff --git a/string/test-strchr.c b/string/test-strchr.c
index e544aa7158..161ac458c1 100644
--- a/string/test-strchr.c
+++ b/string/test-strchr.c
@@ -79,8 +79,8 @@ IMPL (stupid_STRCHR, 0)
 IMPL (simple_STRCHR, 0)
 IMPL (STRCHR, 1)
 
-static void
-do_one_test (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
+static int
+check_result (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
 {
   CHAR *res = CALL (impl, s, c);
   if (res != exp_res)
@@ -88,8 +88,16 @@ do_one_test (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
       error (0, 0, "Wrong result in function %s %#x %p %p", impl->name,
 	     c, res, exp_res);
       ret = 1;
-      return;
+      return -1;
     }
+  return 0;
+}
+
+static void
+do_one_test (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
+{
+  if (check_result (impl, s, c, exp_res) < 0)
+    return;
 
   if (HP_TIMING_AVAIL)
     {
@@ -224,6 +232,17 @@ do_random_tests (void)
     }
 }
 
+static void
+check1 (void)
+{
+  char s[] __attribute__((aligned(16))) = "\xff";
+  char c = '\xfe';
+  char *exp_result = stupid_STRCHR (s, c);
+
+  FOR_EACH_IMPL (impl, 0)
+    check_result (impl, s, c, exp_result);
+}
+
 int
 test_main (void)
 {
@@ -231,6 +250,8 @@ test_main (void)
 
   test_init ();
 
+  check1 ();
+
   printf ("%20s", "");
   FOR_EACH_IMPL (impl, 0)
     printf ("\t%s", impl->name);
diff --git a/string/test-strstr.c b/string/test-strstr.c
index 6be460168c..e7d8e73ba8 100644
--- a/string/test-strstr.c
+++ b/string/test-strstr.c
@@ -55,8 +55,9 @@ IMPL (simple_strstr, 0)
 IMPL (strstr, 1)
 
 
-static void
-do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
+static int
+check_result (impl_t *impl, const char *s1, const char *s2,
+	      char *exp_result)
 {
   char *result = CALL (impl, s1, s2);
   if (result != exp_result)
@@ -64,9 +65,18 @@ do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
       error (0, 0, "Wrong result in function %s %s %s", impl->name,
 	     result, exp_result);
       ret = 1;
-      return;
+      return -1;
     }
 
+  return 0;
+}
+
+static void
+do_one_test (impl_t *impl, const char *s1, const char *s2, char *exp_result)
+{
+  if (check_result (impl, s1, s2, exp_result) < 0)
+    return;
+
   if (HP_TIMING_AVAIL)
     {
       hp_timing_t start __attribute ((unused));
@@ -133,12 +143,26 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2,
     putchar ('\n');
 }
 
+static void
+check1 (void)
+{
+  const char s1[] =
+    "F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD_C3_A7_20_EF_BF_BD";
+  const char s2[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
+  char *exp_result;
+
+  exp_result = stupid_strstr (s1, s2);
+  FOR_EACH_IMPL (impl, 0)
+    check_result (impl, s1, s2, exp_result);
+}
 
 static int
 test_main (void)
 {
   test_init ();
 
+  check1 ();
+
   printf ("%23s", "");
   FOR_EACH_IMPL (impl, 0)
     printf ("\t%s", impl->name);