mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
x86: Expand test-memset.c and bench-memset.c
No bug. This commit adds tests cases and benchmarks for page cross and for memset to the end of the page without crossing. As well in test-memset.c this commit adds sentinel on start/end of tstbuf to test for overwrites Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
This commit is contained in:
@ -61,7 +61,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
|
|||||||
static void
|
static void
|
||||||
do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
|
do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
|
||||||
{
|
{
|
||||||
align &= 63;
|
align &= 4095;
|
||||||
if ((align + len) * sizeof (CHAR) > page_size)
|
if ((align + len) * sizeof (CHAR) > page_size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -110,9 +110,11 @@ test_main (void)
|
|||||||
{
|
{
|
||||||
for (i = 0; i < 18; ++i)
|
for (i = 0; i < 18; ++i)
|
||||||
do_test (&json_ctx, 0, c, 1 << i);
|
do_test (&json_ctx, 0, c, 1 << i);
|
||||||
for (i = 1; i < 32; ++i)
|
for (i = 1; i < 64; ++i)
|
||||||
{
|
{
|
||||||
do_test (&json_ctx, i, c, i);
|
do_test (&json_ctx, i, c, i);
|
||||||
|
do_test (&json_ctx, 4096 - i, c, i);
|
||||||
|
do_test (&json_ctx, 4095, c, i);
|
||||||
if (i & (i - 1))
|
if (i & (i - 1))
|
||||||
do_test (&json_ctx, 0, c, i);
|
do_test (&json_ctx, 0, c, i);
|
||||||
}
|
}
|
||||||
|
@ -109,16 +109,24 @@ SIMPLE_MEMSET (CHAR *s, int c, size_t n)
|
|||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
|
do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
|
||||||
{
|
{
|
||||||
CHAR tstbuf[n];
|
CHAR buf[n + 2];
|
||||||
|
CHAR *tstbuf = buf + 1;
|
||||||
|
CHAR sentinel = c - 1;
|
||||||
|
buf[0] = sentinel;
|
||||||
|
buf[n + 1] = sentinel;
|
||||||
#ifdef TEST_BZERO
|
#ifdef TEST_BZERO
|
||||||
simple_bzero (tstbuf, n);
|
simple_bzero (tstbuf, n);
|
||||||
CALL (impl, s, n);
|
CALL (impl, s, n);
|
||||||
if (memcmp (s, tstbuf, n) != 0)
|
if (memcmp (s, tstbuf, n) != 0
|
||||||
|
|| buf[0] != sentinel
|
||||||
|
|| buf[n + 1] != sentinel)
|
||||||
#else
|
#else
|
||||||
CHAR *res = CALL (impl, s, c, n);
|
CHAR *res = CALL (impl, s, c, n);
|
||||||
if (res != s
|
if (res != s
|
||||||
|| SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
|
|| SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
|
||||||
|| MEMCMP (s, tstbuf, n) != 0)
|
|| MEMCMP (s, tstbuf, n) != 0
|
||||||
|
|| buf[0] != sentinel
|
||||||
|
|| buf[n + 1] != sentinel)
|
||||||
#endif /* !TEST_BZERO */
|
#endif /* !TEST_BZERO */
|
||||||
{
|
{
|
||||||
error (0, 0, "Wrong result in function %s", impl->name);
|
error (0, 0, "Wrong result in function %s", impl->name);
|
||||||
@ -130,7 +138,7 @@ do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
|
|||||||
static void
|
static void
|
||||||
do_test (size_t align, int c, size_t len)
|
do_test (size_t align, int c, size_t len)
|
||||||
{
|
{
|
||||||
align &= 7;
|
align &= 4095;
|
||||||
if ((align + len) * sizeof (CHAR) > page_size)
|
if ((align + len) * sizeof (CHAR) > page_size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -245,9 +253,11 @@ test_main (void)
|
|||||||
{
|
{
|
||||||
for (i = 0; i < 18; ++i)
|
for (i = 0; i < 18; ++i)
|
||||||
do_test (0, c, 1 << i);
|
do_test (0, c, 1 << i);
|
||||||
for (i = 1; i < 32; ++i)
|
for (i = 1; i < 64; ++i)
|
||||||
{
|
{
|
||||||
do_test (i, c, i);
|
do_test (i, c, i);
|
||||||
|
do_test (4096 - i, c, i);
|
||||||
|
do_test (4095, c, i);
|
||||||
if (i & (i - 1))
|
if (i & (i - 1))
|
||||||
do_test (0, c, i);
|
do_test (0, c, i);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user