2015-08-26 16:26:25 +08:00
|
|
|
/* Test memset functions.
|
2017-01-01 08:14:16 +08:00
|
|
|
Copyright (C) 1999-2017 Free Software Foundation, Inc.
|
2002-11-08 03:15:01 +08:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Written by Jakub Jelinek <jakub@redhat.com>, 1999.
|
|
|
|
|
|
|
|
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
|
2012-02-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2002-11-08 03:15:01 +08:00
|
|
|
|
|
|
|
#define TEST_MAIN
|
2012-10-20 13:04:19 +08:00
|
|
|
#ifdef TEST_BZERO
|
New string function explicit_bzero (from OpenBSD).
explicit_bzero(s, n) is the same as memset(s, 0, n), except that the
compiler is not allowed to delete a call to explicit_bzero even if the
memory pointed to by 's' is dead after the call. Right now, this effect
is achieved externally by having explicit_bzero be a function whose
semantics are unknown to the compiler, and internally, with a no-op
asm statement that clobbers memory. This does mean that small
explicit_bzero operations cannot be expanded inline as small memset
operations can, but on the other hand, small memset operations do get
deleted by the compiler. Hopefully full compiler support for
explicit_bzero will happen relatively soon.
There are two new tests: test-explicit_bzero.c verifies the
visible semantics in the same way as the existing test-bzero.c,
and tst-xbzero-opt.c verifies the not-being-optimized-out property.
The latter is conceptually based on a test written by Matthew Dempsky
for the OpenBSD regression suite.
The crypt() implementation has an immediate use for this new feature.
We avoid having to add a GLIBC_PRIVATE alias for explicit_bzero
by running all of libcrypt's calls through the fortified variant,
__explicit_bzero_chk, which is in the impl namespace anyway. Currently
I'm not aware of anything in libc proper that needs this, but the
glue is all in place if it does become necessary. The legacy DES
implementation wasn't bothering to clear its buffers, so I added that,
mostly for consistency's sake.
* string/explicit_bzero.c: New routine.
* string/test-explicit_bzero.c, string/tst-xbzero-opt.c: New tests.
* string/Makefile (routines, strop-tests, tests): Add them.
* string/test-memset.c: Add ifdeffage for testing explicit_bzero.
* string/string.h [__USE_MISC]: Declare explicit_bzero.
* debug/explicit_bzero_chk.c: New routine.
* debug/Makefile (routines): Add it.
* debug/tst-chk1.c: Test fortification of explicit_bzero.
* string/bits/string3.h: Fortify explicit_bzero.
* manual/string.texi: Document explicit_bzero.
* NEWS: Mention addition of explicit_bzero.
* crypt/crypt-entry.c (__crypt_r): Clear key-dependent intermediate
data before returning, using explicit_bzero.
* crypt/md5-crypt.c (__md5_crypt_r): Likewise.
* crypt/sha256-crypt.c (__sha256_crypt_r): Likewise.
* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.
* include/string.h: Redirect internal uses of explicit_bzero
to __explicit_bzero_chk[_internal].
* string/Versions [GLIBC_2.25]: Add explicit_bzero.
* debug/Versions [GLIBC_2.25]: Add __explicit_bzero_chk.
* sysdeps/arm/nacl/libc.abilist
* sysdeps/unix/sysv/linux/aarch64/libc.abilist
* sysdeps/unix/sysv/linux/alpha/libc.abilist
* sysdeps/unix/sysv/linux/arm/libc.abilist
* sysdeps/unix/sysv/linux/hppa/libc.abilist
* sysdeps/unix/sysv/linux/i386/libc.abilist
* sysdeps/unix/sysv/linux/ia64/libc.abilist
* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
* sysdeps/unix/sysv/linux/microblaze/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
* sysdeps/unix/sysv/linux/nios2/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
* sysdeps/unix/sysv/linux/sh/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist:
Add entries for explicit_bzero and __explicit_bzero_chk.
2016-09-15 19:29:44 +08:00
|
|
|
# ifdef TEST_EXPLICIT_BZERO
|
|
|
|
# define TEST_NAME "explicit_bzero"
|
|
|
|
# else
|
|
|
|
# define TEST_NAME "bzero"
|
|
|
|
# endif
|
2012-10-20 13:04:19 +08:00
|
|
|
#else
|
2015-08-26 16:26:25 +08:00
|
|
|
# ifndef WIDE
|
|
|
|
# define TEST_NAME "memset"
|
|
|
|
# else
|
|
|
|
# define TEST_NAME "wmemset"
|
|
|
|
# endif /* WIDE */
|
|
|
|
#endif /* !TEST_BZERO */
|
2002-11-08 03:15:01 +08:00
|
|
|
#define MIN_PAGE_SIZE 131072
|
|
|
|
#include "test-string.h"
|
|
|
|
|
2015-08-26 16:26:25 +08:00
|
|
|
#ifndef WIDE
|
|
|
|
# define MEMSET memset
|
|
|
|
# define CHAR char
|
|
|
|
# define UCHAR unsigned char
|
|
|
|
# define SIMPLE_MEMSET simple_memset
|
|
|
|
# define MEMCMP memcmp
|
|
|
|
# define BIG_CHAR CHAR_MAX
|
|
|
|
#else
|
|
|
|
# include <wchar.h>
|
|
|
|
# define MEMSET wmemset
|
|
|
|
# define CHAR wchar_t
|
|
|
|
# define UCHAR wchar_t
|
|
|
|
# define SIMPLE_MEMSET simple_wmemset
|
|
|
|
# define MEMCMP wmemcmp
|
|
|
|
# define BIG_CHAR WCHAR_MAX
|
|
|
|
#endif /* WIDE */
|
|
|
|
|
|
|
|
CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
|
2012-10-12 04:58:16 +08:00
|
|
|
|
|
|
|
#ifdef TEST_BZERO
|
|
|
|
typedef void (*proto_t) (char *, size_t);
|
|
|
|
void simple_bzero (char *, size_t);
|
|
|
|
void builtin_bzero (char *, size_t);
|
|
|
|
|
|
|
|
IMPL (simple_bzero, 0)
|
|
|
|
IMPL (builtin_bzero, 0)
|
New string function explicit_bzero (from OpenBSD).
explicit_bzero(s, n) is the same as memset(s, 0, n), except that the
compiler is not allowed to delete a call to explicit_bzero even if the
memory pointed to by 's' is dead after the call. Right now, this effect
is achieved externally by having explicit_bzero be a function whose
semantics are unknown to the compiler, and internally, with a no-op
asm statement that clobbers memory. This does mean that small
explicit_bzero operations cannot be expanded inline as small memset
operations can, but on the other hand, small memset operations do get
deleted by the compiler. Hopefully full compiler support for
explicit_bzero will happen relatively soon.
There are two new tests: test-explicit_bzero.c verifies the
visible semantics in the same way as the existing test-bzero.c,
and tst-xbzero-opt.c verifies the not-being-optimized-out property.
The latter is conceptually based on a test written by Matthew Dempsky
for the OpenBSD regression suite.
The crypt() implementation has an immediate use for this new feature.
We avoid having to add a GLIBC_PRIVATE alias for explicit_bzero
by running all of libcrypt's calls through the fortified variant,
__explicit_bzero_chk, which is in the impl namespace anyway. Currently
I'm not aware of anything in libc proper that needs this, but the
glue is all in place if it does become necessary. The legacy DES
implementation wasn't bothering to clear its buffers, so I added that,
mostly for consistency's sake.
* string/explicit_bzero.c: New routine.
* string/test-explicit_bzero.c, string/tst-xbzero-opt.c: New tests.
* string/Makefile (routines, strop-tests, tests): Add them.
* string/test-memset.c: Add ifdeffage for testing explicit_bzero.
* string/string.h [__USE_MISC]: Declare explicit_bzero.
* debug/explicit_bzero_chk.c: New routine.
* debug/Makefile (routines): Add it.
* debug/tst-chk1.c: Test fortification of explicit_bzero.
* string/bits/string3.h: Fortify explicit_bzero.
* manual/string.texi: Document explicit_bzero.
* NEWS: Mention addition of explicit_bzero.
* crypt/crypt-entry.c (__crypt_r): Clear key-dependent intermediate
data before returning, using explicit_bzero.
* crypt/md5-crypt.c (__md5_crypt_r): Likewise.
* crypt/sha256-crypt.c (__sha256_crypt_r): Likewise.
* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.
* include/string.h: Redirect internal uses of explicit_bzero
to __explicit_bzero_chk[_internal].
* string/Versions [GLIBC_2.25]: Add explicit_bzero.
* debug/Versions [GLIBC_2.25]: Add __explicit_bzero_chk.
* sysdeps/arm/nacl/libc.abilist
* sysdeps/unix/sysv/linux/aarch64/libc.abilist
* sysdeps/unix/sysv/linux/alpha/libc.abilist
* sysdeps/unix/sysv/linux/arm/libc.abilist
* sysdeps/unix/sysv/linux/hppa/libc.abilist
* sysdeps/unix/sysv/linux/i386/libc.abilist
* sysdeps/unix/sysv/linux/ia64/libc.abilist
* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
* sysdeps/unix/sysv/linux/microblaze/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
* sysdeps/unix/sysv/linux/nios2/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
* sysdeps/unix/sysv/linux/sh/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist:
Add entries for explicit_bzero and __explicit_bzero_chk.
2016-09-15 19:29:44 +08:00
|
|
|
#ifdef TEST_EXPLICIT_BZERO
|
|
|
|
IMPL (explicit_bzero, 1)
|
|
|
|
#else
|
2012-10-12 04:58:16 +08:00
|
|
|
IMPL (bzero, 1)
|
New string function explicit_bzero (from OpenBSD).
explicit_bzero(s, n) is the same as memset(s, 0, n), except that the
compiler is not allowed to delete a call to explicit_bzero even if the
memory pointed to by 's' is dead after the call. Right now, this effect
is achieved externally by having explicit_bzero be a function whose
semantics are unknown to the compiler, and internally, with a no-op
asm statement that clobbers memory. This does mean that small
explicit_bzero operations cannot be expanded inline as small memset
operations can, but on the other hand, small memset operations do get
deleted by the compiler. Hopefully full compiler support for
explicit_bzero will happen relatively soon.
There are two new tests: test-explicit_bzero.c verifies the
visible semantics in the same way as the existing test-bzero.c,
and tst-xbzero-opt.c verifies the not-being-optimized-out property.
The latter is conceptually based on a test written by Matthew Dempsky
for the OpenBSD regression suite.
The crypt() implementation has an immediate use for this new feature.
We avoid having to add a GLIBC_PRIVATE alias for explicit_bzero
by running all of libcrypt's calls through the fortified variant,
__explicit_bzero_chk, which is in the impl namespace anyway. Currently
I'm not aware of anything in libc proper that needs this, but the
glue is all in place if it does become necessary. The legacy DES
implementation wasn't bothering to clear its buffers, so I added that,
mostly for consistency's sake.
* string/explicit_bzero.c: New routine.
* string/test-explicit_bzero.c, string/tst-xbzero-opt.c: New tests.
* string/Makefile (routines, strop-tests, tests): Add them.
* string/test-memset.c: Add ifdeffage for testing explicit_bzero.
* string/string.h [__USE_MISC]: Declare explicit_bzero.
* debug/explicit_bzero_chk.c: New routine.
* debug/Makefile (routines): Add it.
* debug/tst-chk1.c: Test fortification of explicit_bzero.
* string/bits/string3.h: Fortify explicit_bzero.
* manual/string.texi: Document explicit_bzero.
* NEWS: Mention addition of explicit_bzero.
* crypt/crypt-entry.c (__crypt_r): Clear key-dependent intermediate
data before returning, using explicit_bzero.
* crypt/md5-crypt.c (__md5_crypt_r): Likewise.
* crypt/sha256-crypt.c (__sha256_crypt_r): Likewise.
* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.
* include/string.h: Redirect internal uses of explicit_bzero
to __explicit_bzero_chk[_internal].
* string/Versions [GLIBC_2.25]: Add explicit_bzero.
* debug/Versions [GLIBC_2.25]: Add __explicit_bzero_chk.
* sysdeps/arm/nacl/libc.abilist
* sysdeps/unix/sysv/linux/aarch64/libc.abilist
* sysdeps/unix/sysv/linux/alpha/libc.abilist
* sysdeps/unix/sysv/linux/arm/libc.abilist
* sysdeps/unix/sysv/linux/hppa/libc.abilist
* sysdeps/unix/sysv/linux/i386/libc.abilist
* sysdeps/unix/sysv/linux/ia64/libc.abilist
* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
* sysdeps/unix/sysv/linux/microblaze/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
* sysdeps/unix/sysv/linux/nios2/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
* sysdeps/unix/sysv/linux/sh/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist
* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist:
Add entries for explicit_bzero and __explicit_bzero_chk.
2016-09-15 19:29:44 +08:00
|
|
|
#endif
|
2012-10-12 04:58:16 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
simple_bzero (char *s, size_t n)
|
|
|
|
{
|
2015-08-26 16:26:25 +08:00
|
|
|
SIMPLE_MEMSET (s, 0, n);
|
2012-10-12 04:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
builtin_bzero (char *s, size_t n)
|
|
|
|
{
|
|
|
|
__builtin_bzero (s, n);
|
|
|
|
}
|
|
|
|
#else
|
2015-08-26 16:26:25 +08:00
|
|
|
typedef CHAR *(*proto_t) (CHAR *, int, size_t);
|
2002-11-08 03:15:01 +08:00
|
|
|
|
2015-08-26 16:26:25 +08:00
|
|
|
IMPL (SIMPLE_MEMSET, 0)
|
|
|
|
# ifndef WIDE
|
|
|
|
char *builtin_memset (char *, int, size_t);
|
2002-11-08 03:15:01 +08:00
|
|
|
IMPL (builtin_memset, 0)
|
2015-08-26 16:26:25 +08:00
|
|
|
# endif /* !WIDE */
|
|
|
|
IMPL (MEMSET, 1)
|
2002-11-08 03:15:01 +08:00
|
|
|
|
2015-08-26 16:26:25 +08:00
|
|
|
# ifndef WIDE
|
2012-10-12 04:58:16 +08:00
|
|
|
char *
|
|
|
|
builtin_memset (char *s, int c, size_t n)
|
|
|
|
{
|
|
|
|
return __builtin_memset (s, c, n);
|
|
|
|
}
|
2015-08-26 16:26:25 +08:00
|
|
|
# endif /* !WIDE */
|
|
|
|
#endif /* !TEST_BZERO */
|
2012-10-12 04:58:16 +08:00
|
|
|
|
2015-08-26 16:26:25 +08:00
|
|
|
CHAR *
|
2013-06-21 08:40:55 +08:00
|
|
|
inhibit_loop_to_libcall
|
2015-08-26 16:26:25 +08:00
|
|
|
SIMPLE_MEMSET (CHAR *s, int c, size_t n)
|
2002-11-08 03:15:01 +08:00
|
|
|
{
|
2015-08-26 16:26:25 +08:00
|
|
|
CHAR *r = s, *end = s + n;
|
2002-11-08 03:15:01 +08:00
|
|
|
while (r < end)
|
|
|
|
*r++ = c;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-26 16:26:25 +08:00
|
|
|
do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
|
2002-11-08 03:15:01 +08:00
|
|
|
{
|
2015-08-26 16:26:25 +08:00
|
|
|
CHAR tstbuf[n];
|
2012-10-12 04:58:16 +08:00
|
|
|
#ifdef TEST_BZERO
|
|
|
|
simple_bzero (tstbuf, n);
|
|
|
|
CALL (impl, s, n);
|
|
|
|
if (memcmp (s, tstbuf, n) != 0)
|
|
|
|
#else
|
2015-08-26 16:26:25 +08:00
|
|
|
CHAR *res = CALL (impl, s, c, n);
|
2005-07-25 07:06:44 +08:00
|
|
|
if (res != s
|
2015-08-26 16:26:25 +08:00
|
|
|
|| SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
|
|
|
|
|| MEMCMP (s, tstbuf, n) != 0)
|
|
|
|
#endif /* !TEST_BZERO */
|
2002-11-08 03:15:01 +08:00
|
|
|
{
|
2005-07-25 07:06:44 +08:00
|
|
|
error (0, 0, "Wrong result in function %s", impl->name);
|
2002-11-08 03:15:01 +08:00
|
|
|
ret = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_test (size_t align, int c, size_t len)
|
|
|
|
{
|
|
|
|
align &= 7;
|
2015-08-26 16:26:25 +08:00
|
|
|
if ((align + len) * sizeof (CHAR) > page_size)
|
2002-11-08 03:15:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
FOR_EACH_IMPL (impl, 0)
|
2015-08-26 16:26:25 +08:00
|
|
|
do_one_test (impl, (CHAR *) (buf1) + align, c, len);
|
2002-11-08 03:15:01 +08:00
|
|
|
}
|
|
|
|
|
2012-10-12 04:58:16 +08:00
|
|
|
#ifndef TEST_BZERO
|
2002-11-08 03:15:01 +08:00
|
|
|
static void
|
|
|
|
do_random_tests (void)
|
|
|
|
{
|
|
|
|
size_t i, j, k, n, align, len, size;
|
|
|
|
int c, o;
|
2015-08-26 16:26:25 +08:00
|
|
|
UCHAR *p, *res;
|
|
|
|
UCHAR *p2 = (UCHAR *) buf2;
|
2002-11-08 03:15:01 +08:00
|
|
|
|
2015-08-26 16:26:25 +08:00
|
|
|
for (i = 0; i < 65536 / sizeof (CHAR); ++i)
|
|
|
|
p2[i] = random () & BIG_CHAR;
|
2002-11-08 03:15:01 +08:00
|
|
|
|
|
|
|
for (n = 0; n < ITERATIONS; n++)
|
|
|
|
{
|
|
|
|
if ((random () & 31) == 0)
|
2015-08-26 16:26:25 +08:00
|
|
|
size = 65536 / sizeof (CHAR);
|
2002-11-08 03:15:01 +08:00
|
|
|
else
|
|
|
|
size = 512;
|
2015-08-26 16:26:25 +08:00
|
|
|
p = (UCHAR *) (buf1 + page_size) - size;
|
2002-11-08 03:15:01 +08:00
|
|
|
len = random () & (size - 1);
|
|
|
|
align = size - len - (random () & 31);
|
|
|
|
if (align > size)
|
|
|
|
align = size - len;
|
|
|
|
if ((random () & 7) == 0)
|
|
|
|
align &= ~63;
|
|
|
|
if ((random () & 7) == 0)
|
|
|
|
c = 0;
|
|
|
|
else
|
2015-08-26 16:26:25 +08:00
|
|
|
c = random () & BIG_CHAR;
|
|
|
|
o = random () & BIG_CHAR;
|
2002-11-08 03:15:01 +08:00
|
|
|
if (o == c)
|
2015-08-26 16:26:25 +08:00
|
|
|
o = (c + 1) & BIG_CHAR;
|
2002-11-08 03:15:01 +08:00
|
|
|
j = len + align + 128;
|
|
|
|
if (j > size)
|
|
|
|
j = size;
|
|
|
|
if (align >= 128)
|
|
|
|
k = align - 128;
|
|
|
|
else
|
|
|
|
k = 0;
|
|
|
|
for (i = k; i < align; ++i)
|
|
|
|
p[i] = o;
|
|
|
|
for (i = align + len; i < j; ++i)
|
|
|
|
p[i] = o;
|
|
|
|
|
|
|
|
FOR_EACH_IMPL (impl, 1)
|
|
|
|
{
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
2015-08-26 16:26:25 +08:00
|
|
|
p[i + align] = p2[i];
|
2002-11-08 03:15:01 +08:00
|
|
|
if (p[i + align] == c)
|
|
|
|
p[i + align] = o;
|
|
|
|
}
|
2015-08-26 16:26:25 +08:00
|
|
|
res = (UCHAR *) CALL (impl, (CHAR *) p + align, c, len);
|
2002-11-08 03:15:01 +08:00
|
|
|
if (res != p + align)
|
|
|
|
{
|
|
|
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %d, %zd) %p != %p",
|
|
|
|
n, impl->name, align, c, len, res, p + align);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
for (i = k; i < align; ++i)
|
|
|
|
if (p[i] != o)
|
|
|
|
{
|
|
|
|
error (0, 0, "Iteration %zd - garbage before %s (%zd, %d, %zd)",
|
|
|
|
n, impl->name, align, c, len);
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (; i < align + len; ++i)
|
|
|
|
if (p[i] != c)
|
|
|
|
{
|
|
|
|
error (0, 0, "Iteration %zd - not cleared correctly %s (%zd, %d, %zd)",
|
|
|
|
n, impl->name, align, c, len);
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (; i < j; ++i)
|
|
|
|
if (p[i] != o)
|
|
|
|
{
|
|
|
|
error (0, 0, "Iteration %zd - garbage after %s (%zd, %d, %zd)",
|
|
|
|
n, impl->name, align, c, len);
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 16:26:25 +08:00
|
|
|
#endif /* !TEST_BZERO */
|
2002-11-08 03:15:01 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
test_main (void)
|
|
|
|
{
|
|
|
|
size_t i;
|
2012-10-12 04:58:16 +08:00
|
|
|
int c = 0;
|
2002-11-08 03:15:01 +08:00
|
|
|
|
|
|
|
test_init ();
|
|
|
|
|
|
|
|
printf ("%24s", "");
|
|
|
|
FOR_EACH_IMPL (impl, 0)
|
|
|
|
printf ("\t%s", impl->name);
|
|
|
|
putchar ('\n');
|
|
|
|
|
2012-10-12 04:58:16 +08:00
|
|
|
#ifndef TEST_BZERO
|
2005-07-25 09:40:59 +08:00
|
|
|
for (c = -65; c <= 130; c += 65)
|
2012-10-12 04:58:16 +08:00
|
|
|
#endif
|
2002-11-08 03:15:01 +08:00
|
|
|
{
|
|
|
|
for (i = 0; i < 18; ++i)
|
|
|
|
do_test (0, c, 1 << i);
|
|
|
|
for (i = 1; i < 32; ++i)
|
|
|
|
{
|
|
|
|
do_test (i, c, i);
|
|
|
|
if (i & (i - 1))
|
|
|
|
do_test (0, c, i);
|
|
|
|
}
|
|
|
|
do_test (1, c, 14);
|
|
|
|
do_test (3, c, 1024);
|
|
|
|
do_test (4, c, 64);
|
|
|
|
do_test (2, c, 25);
|
|
|
|
}
|
|
|
|
|
2012-10-12 04:58:16 +08:00
|
|
|
#ifndef TEST_BZERO
|
2002-11-08 03:15:01 +08:00
|
|
|
do_random_tests ();
|
2012-10-12 04:58:16 +08:00
|
|
|
#endif
|
|
|
|
|
2002-11-08 03:15:01 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:32:17 +08:00
|
|
|
#include <support/test-driver.c>
|