This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Test strcasestr/strchr/strstr under all implementations
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 5 Oct 2012 13:02:20 -0700
- Subject: [PATCH] Test strcasestr/strchr/strstr under all implementations
Hi,
This patch runs strcasestr/strchr/strstr test under all implementations.
Tested on x86-64 and i686. OK to install?
Thanks.
H.J.
---
string/Makefile | 2 +-
string/bug-strcasestr1.c | 39 ---------------------------------------
string/bug-strchr1.c | 14 --------------
string/bug-strstr1.c | 26 --------------------------
string/test-strcasestr.c | 28 +++++++++++++++++++++++++---
string/test-strchr.c | 27 ++++++++++++++++++++++++---
string/test-strstr.c | 30 +++++++++++++++++++++++++++---
8 files changed, 102 insertions(+), 89 deletions(-)
create mode 100644 ChangeLog.pr14602
delete mode 100644 string/bug-strcasestr1.c
delete mode 100644 string/bug-strchr1.c
delete mode 100644 string/bug-strstr1.c
* string/Makefile (tests): Remove bug-strstr1, bug-strcasestr1
and bug-strchr1.
* string/bug-strcasestr1.c (do_test): Moved to ...
* string/test-strcasestr.c (check1): Here. New function.
(do_one_test): Break out result checking code into ...
(check_result): This. New function.
(do_one_test): Call check_result.
(test_main): Call check1.
* string/bug-strchr1.c (do_test): Moved to ...
* string/test-strchr.c (check1): Here. New function.
(do_one_test): Break out result checking code into ...
(check_result): This. New function.
(do_one_test): Call check_result.
(test_main): Call check1.
* string/bug-strstr1.c (main): Moved to ...
* string/test-strchr.c (check1): Here. New function.
(do_one_test): Break out result checking code into ...
(check_result): This. New function.
(do_one_test): Call check_result.
(test_main): Call check1.
* string/bug-strcasestr1.c: Removed.
* string/bug-strchr1.c: Likewise.
* string/bug-strstr1.c: Likewise.
diff --git a/string/Makefile b/string/Makefile
index 51e9fde..ce2446b 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -62,7 +62,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
ifunc-tests = $(addprefix test-,$(strop-tests))
tests-ifunc = $(addsuffix -ifunc,$(ifunc-tests))
diff --git a/string/bug-strcasestr1.c b/string/bug-strcasestr1.c
deleted file mode 100644
index e8334d7..0000000
--- 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 21155d8..0000000
--- 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 889de12..0000000
--- 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 650b865..9a0f30c 100644
--- a/string/test-strcasestr.c
+++ b/string/test-strcasestr.c
@@ -58,8 +58,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)
@@ -67,8 +68,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)
{
@@ -137,12 +146,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 e7c5298..1ed6966 100644
--- a/string/test-strchr.c
+++ b/string/test-strchr.c
@@ -88,8 +88,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)
@@ -97,8 +97,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)
{
@@ -233,6 +241,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)
{
@@ -240,6 +259,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 c2c6705..24f3eb5 100644
--- a/string/test-strstr.c
+++ b/string/test-strstr.c
@@ -56,8 +56,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)
@@ -65,8 +66,17 @@ 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)
{
@@ -134,12 +144,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);
--
1.7.11.4