* 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>
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
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
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);
#include <stdlib.h>
+#include "zerosize-ptr.h"
#include "macros.h"
/* Calculating void * + int is not portable, so this wrapper converts
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);
}
}
+ /* 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;