mirror of
git://sourceware.org/git/glibc.git
synced 2024-11-27 03:41:23 +08:00
String: Add tests for __memcmpeq
No bug. This commit adds tests for the new function __memcmpeq. The new tests use the existing tests in 'test-memcmp.c' but relax the result requirement to only check for zero or non-zero returns. All string tests include test-memcmpeq are passing.
This commit is contained in:
parent
9894127d20
commit
d9283b71ac
@ -48,8 +48,8 @@ routines := strcat strchr strcmp strcoll strcpy strcspn \
|
|||||||
sigdescr_np sigabbrev_np strerrorname_np \
|
sigdescr_np sigabbrev_np strerrorname_np \
|
||||||
strerrordesc_np
|
strerrordesc_np
|
||||||
|
|
||||||
strop-tests := memchr memcmp memcpy memmove mempcpy memset memccpy \
|
strop-tests := memchr memcmp memcpy memcmpeq memmove mempcpy memset \
|
||||||
stpcpy stpncpy strcat strchr strcmp strcpy strcspn \
|
memccpy stpcpy stpncpy strcat strchr strcmp strcpy strcspn \
|
||||||
strlen strncmp strncpy strpbrk strrchr strspn memmem \
|
strlen strncmp strncpy strpbrk strrchr strspn memmem \
|
||||||
strstr strcasestr strnlen strcasecmp strncasecmp \
|
strstr strcasestr strnlen strcasecmp strncasecmp \
|
||||||
strncat rawmemchr strchrnul bcopy bzero memrchr \
|
strncat rawmemchr strchrnul bcopy bzero memrchr \
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#define TEST_MAIN
|
#define TEST_MAIN
|
||||||
#ifdef WIDE
|
#ifdef TEST_MEMCMPEQ
|
||||||
|
# define TEST_NAME "__memcmpeq"
|
||||||
|
#elif defined WIDE
|
||||||
# define TEST_NAME "wmemcmp"
|
# define TEST_NAME "wmemcmp"
|
||||||
#else
|
#else
|
||||||
# define TEST_NAME "memcmp"
|
# define TEST_NAME "memcmp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "test-string.h"
|
#include "test-string.h"
|
||||||
#ifdef WIDE
|
#ifdef WIDE
|
||||||
# include <inttypes.h>
|
# include <inttypes.h>
|
||||||
@ -35,8 +38,9 @@
|
|||||||
# define CHARBYTES 4
|
# define CHARBYTES 4
|
||||||
# define CHAR__MIN WCHAR_MIN
|
# define CHAR__MIN WCHAR_MIN
|
||||||
# define CHAR__MAX WCHAR_MAX
|
# define CHAR__MAX WCHAR_MAX
|
||||||
|
|
||||||
int
|
int
|
||||||
simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
|
SIMPLE_MEMCMP (const wchar_t *s1, const wchar_t *s2, size_t n)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
/* Warning!
|
/* Warning!
|
||||||
@ -48,10 +52,14 @@ simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
|
# ifdef TEST_MEMCMPEQ
|
||||||
# define MEMCMP memcmp
|
# define MEMCMP __memcmpeq
|
||||||
|
# define SIMPLE_MEMCMP simple_memcmpeq
|
||||||
|
# else
|
||||||
|
# define MEMCMP memcmp
|
||||||
|
# define SIMPLE_MEMCMP simple_memcmp
|
||||||
|
# endif
|
||||||
# define MEMCPY memcpy
|
# define MEMCPY memcpy
|
||||||
# define SIMPLE_MEMCMP simple_memcmp
|
|
||||||
# define CHAR char
|
# define CHAR char
|
||||||
# define MAX_CHAR 255
|
# define MAX_CHAR 255
|
||||||
# define UCHAR unsigned char
|
# define UCHAR unsigned char
|
||||||
@ -60,7 +68,7 @@ simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
|
|||||||
# define CHAR__MAX CHAR_MAX
|
# define CHAR__MAX CHAR_MAX
|
||||||
|
|
||||||
int
|
int
|
||||||
simple_memcmp (const char *s1, const char *s2, size_t n)
|
SIMPLE_MEMCMP (const char *s1, const char *s2, size_t n)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@ -69,6 +77,12 @@ simple_memcmp (const char *s1, const char *s2, size_t n)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef BAD_RESULT
|
||||||
|
# define BAD_RESULT(result, expec) \
|
||||||
|
(((result) == 0 && (expec)) || ((result) < 0 && (expec) >= 0) || \
|
||||||
|
((result) > 0 && (expec) <= 0))
|
||||||
|
# endif
|
||||||
|
|
||||||
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
|
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
|
||||||
|
|
||||||
IMPL (SIMPLE_MEMCMP, 0)
|
IMPL (SIMPLE_MEMCMP, 0)
|
||||||
@ -79,9 +93,7 @@ check_result (impl_t *impl, const CHAR *s1, const CHAR *s2, size_t len,
|
|||||||
int exp_result)
|
int exp_result)
|
||||||
{
|
{
|
||||||
int result = CALL (impl, s1, s2, len);
|
int result = CALL (impl, s1, s2, len);
|
||||||
if ((exp_result == 0 && result != 0)
|
if (BAD_RESULT(result, exp_result))
|
||||||
|| (exp_result < 0 && result >= 0)
|
|
||||||
|| (exp_result > 0 && result <= 0))
|
|
||||||
{
|
{
|
||||||
error (0, 0, "Wrong result in function %s %d %d", impl->name,
|
error (0, 0, "Wrong result in function %s %d %d", impl->name,
|
||||||
result, exp_result);
|
result, exp_result);
|
||||||
@ -186,9 +198,7 @@ do_random_tests (void)
|
|||||||
{
|
{
|
||||||
r = CALL (impl, (CHAR *) p1 + align1, (const CHAR *) p2 + align2,
|
r = CALL (impl, (CHAR *) p1 + align1, (const CHAR *) p2 + align2,
|
||||||
len);
|
len);
|
||||||
if ((r == 0 && result)
|
if (BAD_RESULT(r, result))
|
||||||
|| (r < 0 && result >= 0)
|
|
||||||
|| (r > 0 && result <= 0))
|
|
||||||
{
|
{
|
||||||
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd) %ld != %d, p1 %p p2 %p",
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd) %ld != %d, p1 %p p2 %p",
|
||||||
n, impl->name, align1 * CHARBYTES & 63, align2 * CHARBYTES & 63, len, pos, r, result, p1, p2);
|
n, impl->name, align1 * CHARBYTES & 63, align2 * CHARBYTES & 63, len, pos, r, result, p1, p2);
|
||||||
|
21
string/test-memcmpeq.c
Normal file
21
string/test-memcmpeq.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* Test and measure __memcmpeq functions.
|
||||||
|
Copyright (C) 2012-2021 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
|
||||||
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#define BAD_RESULT(result, expec) ((!(result)) != (!(expec)))
|
||||||
|
#define TEST_MEMCMPEQ 1
|
||||||
|
#include "test-memcmp.c"
|
Loading…
Reference in New Issue
Block a user