Increase test coverage on OS X, by re-enabling the memcheck/tests/amd64/xsave-avx regression tests with a handy memalign() shim.
n-i-bz

(Unfortunately I don’t have right here the hw support, but build environment works)

$ perl tests/vg_regtest memcheck/tests/amd64/xsave-avx
xsave-avx:       (skipping, prereq failed: test -x xsave-avx && ../../../tests/x86_amd64_features amd64-avx)

== 0 tests, 0 stderr failures, 0 stdout failures, 0 stderrB failures, 0 stdoutB failures, 0 post failures ==


On OS X 10.10

Before:

== 594 tests, 215 stderr failures, 9 stdout failures, 0 stderrB failures, 0 stdoutB failures, 30 post failures ==

After:

== 594 tests, 215 stderr failures, 9 stdout failures, 0 stderrB failures, 0 stdoutB failures, 30 post failures ==


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15551 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/tests/amd64/Makefile.am b/memcheck/tests/amd64/Makefile.am
index 11381be..dc48f41 100644
--- a/memcheck/tests/amd64/Makefile.am
+++ b/memcheck/tests/amd64/Makefile.am
@@ -46,10 +46,7 @@
 	sse_memory \
 	xor-undef-amd64
 if BUILD_AVX_TESTS
- check_PROGRAMS += sh-mem-vec256
-if !VGCONF_OS_IS_DARWIN
- check_PROGRAMS += xsave-avx
-endif
+ check_PROGRAMS += sh-mem-vec256 xsave-avx
 endif
 if HAVE_ASM_CONSTRAINT_P
  check_PROGRAMS += insn-pcmpistri
diff --git a/memcheck/tests/amd64/xsave-avx.c b/memcheck/tests/amd64/xsave-avx.c
index 0c896fe..9a32389 100644
--- a/memcheck/tests/amd64/xsave-avx.c
+++ b/memcheck/tests/amd64/xsave-avx.c
@@ -54,9 +54,9 @@
    return dest;
 }
 
-static void* memalign_zeroed(size_t alignment, size_t size)
+static void* memalign_zeroed64(size_t size)
 {
-   char* p = memalign(alignment, size);
+   char* p = memalign64(size);
    if (p && size > 0) {
       my_memset(p, 0, size);
    }
@@ -203,7 +203,7 @@
 
    UInt rfbm;
    for (rfbm = 0; rfbm <= 7; rfbm++) {
-      UChar* saved_img = memalign_zeroed(64, XSAVE_AREA_SIZE);
+      UChar* saved_img = memalign_zeroed64(XSAVE_AREA_SIZE);
 
       my_memset(saved_img, 0xAA, XSAVE_AREA_SIZE);
       saved_img[512] = 0;
@@ -236,7 +236,7 @@
       neither zero nor the data to be loaded.  We choose to use 0x55
       where possible. */
 
-   UChar* fives = memalign_zeroed(64, XSAVE_AREA_SIZE);
+   UChar* fives = memalign_zeroed64(XSAVE_AREA_SIZE);
    my_memset(fives, 0x55, XSAVE_AREA_SIZE);
    /* Set MXCSR so that the insn doesn't fault */
    fives[24] = 0x80;
@@ -259,7 +259,7 @@
    fives[4/*FTW*/] = 0xFF;
 
    /* (1) (see comment in loop below) */
-   UChar* standard_test_data = memalign_zeroed(64, XSAVE_AREA_SIZE);
+   UChar* standard_test_data = memalign_zeroed64(XSAVE_AREA_SIZE);
    do_setup_then_xsave(standard_test_data, 7);
 
    UInt xstate_bv, rfbm;
@@ -283,12 +283,12 @@
          /* (3a).  We can't use |standard_test_data| directly, since we
             need to put in the required |xstate_bv| value.  So make a
             copy and modify that instead. */
-         UChar* img_to_restore_from = memalign_zeroed(64, XSAVE_AREA_SIZE);
+         UChar* img_to_restore_from = memalign_zeroed64(XSAVE_AREA_SIZE);
          my_memcpy(img_to_restore_from, standard_test_data, XSAVE_AREA_SIZE);
          img_to_restore_from[512] = xstate_bv;
 
          /* (4a) */
-         UChar* saved_img = memalign_zeroed(64, XSAVE_AREA_SIZE);
+         UChar* saved_img = memalign_zeroed64(XSAVE_AREA_SIZE);
          my_memset(saved_img, 0xAA, XSAVE_AREA_SIZE);
          saved_img[512] = 0;
 
diff --git a/tests/malloc.h b/tests/malloc.h
index 6a73dde..12afdf4 100644
--- a/tests/malloc.h
+++ b/tests/malloc.h
@@ -41,3 +41,19 @@
    return x;
 }
 
+// Allocates a 64-aligned block.  Asserts if the allocation fails.
+__attribute__((unused))
+static void* memalign64(size_t szB)
+{
+   void* x;
+#if defined(VGO_darwin)
+   // Darwin lacks memalign
+   posix_memalign((void **)&x, 64, szB);
+#else
+   x = memalign(64, szB);
+#endif
+   assert(x);
+   assert(0 == ((64-1) & (unsigned long)x));
+   return x;
+}
+