Test strcasestr/strchr/strstr under all implementations

This commit is contained in:
H.J. Lu 2012-10-05 13:32:07 -07:00
parent fb228a2d94
commit 03759f47db
8 changed files with 101 additions and 89 deletions

View File

@ -1,5 +1,29 @@
2012-10-05 H.J. Lu <hongjiu.lu@intel.com>
* 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.
* elf/Makefile (dl-routines): Add hwcaps.
* elf/dl-support.c (_dl_important_hwcaps): Removed.
* elf/dl-sysdep.c (_DL_FIRST_EXTRA): Likewise.

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);