Commit 349a6770 authored by Eric Blake's avatar Eric Blake

test-rawmemchr: make more robust

* modules/rawmemchr-tests (Files): Add zerosize-ptr.h, mmap-anon.m4.
(Depends-on, configure.ac): Add needed prerequisites to use it.
* modules/memchr-tests (Files, Depends-on, configure.ac):
Likewise, to avoid implicit reliance on memchr module prereqs.
* tests/test-memchr.c (main): Ensure proper masking.
* tests/test-rawmemchr.c (main): Likewise.  Detect oversized
reads.
Signed-off-by: 's avatarEric Blake <eblake@redhat.com>
parent 017b0b20
2010-09-14 Eric Blake <eblake@redhat.com>
test-rawmemchr: make more robust
* modules/rawmemchr-tests (Files): Add zerosize-ptr.h, mmap-anon.m4.
(Depends-on, configure.ac): Add needed prerequisites to use it.
* modules/memchr-tests (Files, Depends-on, configure.ac):
Likewise, to avoid implicit reliance on memchr module prereqs.
* tests/test-memchr.c (main): Ensure proper masking.
* tests/test-rawmemchr.c (main): Likewise. Detect oversized
reads.
memchr: detect glibc Alpha bug
Avoids http://sourceware.org/bugzilla/show_bug.cgi?id=12019.
* m4/memchr.m4 (gl_FUNC_MEMCHR): Detect glibc 2.11.2 failure on
......@@ -3,10 +3,17 @@ tests/test-memchr.c
tests/zerosize-ptr.h
tests/signature.h
tests/macros.h
m4/mmap-anon.m4
Depends-on:
extensions
getpagesize
configure.ac:
dnl Check for prerequisites for memory fence checks.
gl_FUNC_MMAP_ANON
AC_CHECK_HEADERS_ONCE([sys/mman.h])
AC_CHECK_FUNCS_ONCE([mprotect])
Makefile.am:
TESTS += test-memchr
......
Files:
tests/test-rawmemchr.c
tests/zerosize-ptr.h
tests/signature.h
tests/macros.h
m4/mmap-anon.m4
Depends-on:
extensions
getpagesize
configure.ac:
dnl Check for prerequisites for memory fence checks.
gl_FUNC_MMAP_ANON
AC_CHECK_HEADERS_ONCE([sys/mman.h])
AC_CHECK_FUNCS_ONCE([mprotect])
Makefile.am:
TESTS += test-rawmemchr
......
......@@ -57,6 +57,7 @@ main (void)
ASSERT (MEMCHR (input + 1, 'a', n - 1) == input + n - 1);
ASSERT (MEMCHR (input + 1, 'e', n - 1) == input + n - 2);
ASSERT (MEMCHR (input + 1, 0x789abc00 | 'e', n - 1) == input + n - 2);
ASSERT (MEMCHR (input, 'f', n) == NULL);
ASSERT (MEMCHR (input, '\0', n) == NULL);
......
......@@ -24,6 +24,7 @@ SIGNATURE_CHECK (rawmemchr, void *, (void const *, int));
#include <stdlib.h>
#include "zerosize-ptr.h"
#include "macros.h"
/* Calculating void * + int is not portable, so this wrapper converts
......@@ -53,6 +54,7 @@ main (void)
ASSERT (RAWMEMCHR (input + 1, 'a') == input + n - 1);
ASSERT (RAWMEMCHR (input + 1, 'e') == input + n - 2);
ASSERT (RAWMEMCHR (input + 1, 0x789abc00 | 'e') == input + n - 2);
ASSERT (RAWMEMCHR (input, '\0') == input + n);
......@@ -70,6 +72,20 @@ main (void)
}
}
/* Ensure that no unaligned oversized reads occur. */
{
char *page_boundary = (char *) zerosize_ptr ();
size_t i;
if (!page_boundary)
page_boundary = input + 4096;
memset (page_boundary - 512, '1', 511);
page_boundary[-1] = '2';
for (i = 1; i <= 512; i++)
ASSERT (RAWMEMCHR (page_boundary - i, (i * 0x01010100) | '2')
== page_boundary - 1);
}
free (input);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment