Mercurial > hg > octave-nkf > gnulib-hg
changeset 13678:794abd047acd
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: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Tue, 14 Sep 2010 16:42:39 -0600 |
parents | 8ac4aae842ca |
children | f4c397f20139 |
files | ChangeLog modules/memchr-tests modules/rawmemchr-tests tests/test-memchr.c tests/test-rawmemchr.c |
diffstat | 5 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 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
--- a/modules/memchr-tests +++ b/modules/memchr-tests @@ -3,10 +3,17 @@ 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
--- a/modules/rawmemchr-tests +++ b/modules/rawmemchr-tests @@ -1,11 +1,19 @@ 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
--- a/tests/test-memchr.c +++ b/tests/test-memchr.c @@ -57,6 +57,7 @@ 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);
--- a/tests/test-rawmemchr.c +++ b/tests/test-rawmemchr.c @@ -24,6 +24,7 @@ #include <stdlib.h> +#include "zerosize-ptr.h" #include "macros.h" /* Calculating void * + int is not portable, so this wrapper converts @@ -53,6 +54,7 @@ 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 @@ } } + /* 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;