Merge r9175 (don't run inappropriate OS- and platform-specific tests) from
the DARWIN branch.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9176 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.in b/configure.in
index 3e9e76c..63fa8e4 100644
--- a/configure.in
+++ b/configure.in
@@ -1690,6 +1690,7 @@
    docs/xml/Makefile
    tests/Makefile 
    tests/vg_regtest 
+   tests/os_test 
    perf/Makefile 
    perf/vg_perf
    include/Makefile 
diff --git a/docs/internals/porting-HOWTO.txt b/docs/internals/porting-HOWTO.txt
index 121e39c..abc9a97 100644
--- a/docs/internals/porting-HOWTO.txt
+++ b/docs/internals/porting-HOWTO.txt
@@ -68,8 +68,9 @@
 
 Once it runs ok:
 
-- Add the cpu to the tests/cputest.c file so the reg test script will work.
-  (Don't forget to add it to all_archs[].)
+- Add the arch to the tests/arch_test.c file so the reg test script will work.
+  (Don't forget to add it to all_archs[].)  Likewise for os_test.in and
+  platform_test.
 
 - Ensure the regression tests work, and add some arch-specific tests to
   none/tests directory.
diff --git a/docs/internals/porting-to-ARM.txt b/docs/internals/porting-to-ARM.txt
index d99f9ad..4e54d24 100644
--- a/docs/internals/porting-to-ARM.txt
+++ b/docs/internals/porting-to-ARM.txt
@@ -156,7 +156,7 @@
 #  error VG_UCONTEXT_SYSCALL_RET undefined for ARM/Linux
 
 =============================================================================
-From tests/cputest.c
+From tests/arch_test.c
 =============================================================================
 - You'll need to add "arm" to all_archs[].
 
diff --git a/memcheck/tests/x86/fxsave.vgtest b/memcheck/tests/x86/fxsave.vgtest
index 1049e63..93a87a9 100644
--- a/memcheck/tests/x86/fxsave.vgtest
+++ b/memcheck/tests/x86/fxsave.vgtest
@@ -1,4 +1,4 @@
 prog: fxsave
-prereq: ../../../tests/cputest x86-sse
+prereq: ../../../tests/arch_test x86-sse
 vgopts: -q
 args: x
diff --git a/memcheck/tests/x86/sse1_memory.vgtest b/memcheck/tests/x86/sse1_memory.vgtest
index 5134ea9..cf6cd55 100644
--- a/memcheck/tests/x86/sse1_memory.vgtest
+++ b/memcheck/tests/x86/sse1_memory.vgtest
@@ -1,4 +1,4 @@
 prog: sse_memory
 vgopts: -q
 args: sse1
-prereq: ../../../tests/cputest x86-sse
+prereq: ../../../tests/arch_test x86-sse
diff --git a/memcheck/tests/x86/sse2_memory.vgtest b/memcheck/tests/x86/sse2_memory.vgtest
index 8eaeca6..1fe8856 100644
--- a/memcheck/tests/x86/sse2_memory.vgtest
+++ b/memcheck/tests/x86/sse2_memory.vgtest
@@ -1,4 +1,4 @@
 prog: sse_memory
 vgopts: -q
 args: sse2
-prereq: ../../../tests/cputest x86-sse2
+prereq: ../../../tests/arch_test x86-sse2
diff --git a/memcheck/tests/x86/xor-undef-x86.vgtest b/memcheck/tests/x86/xor-undef-x86.vgtest
index daa648b..495a57c 100644
--- a/memcheck/tests/x86/xor-undef-x86.vgtest
+++ b/memcheck/tests/x86/xor-undef-x86.vgtest
@@ -1,2 +1,2 @@
 prog: xor-undef-x86
-prereq: ../../../tests/cputest x86-sse
+prereq: ../../../tests/arch_test x86-sse
diff --git a/none/tests/amd64/insn_sse3.vgtest b/none/tests/amd64/insn_sse3.vgtest
index af3d9c6..ccf6cff 100644
--- a/none/tests/amd64/insn_sse3.vgtest
+++ b/none/tests/amd64/insn_sse3.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/amd64/insn_sse3
-prereq: ../../../tests/cputest amd64-sse3
+prereq: ../../../tests/arch_test amd64-sse3
 vgopts: -q
diff --git a/none/tests/amd64/insn_ssse3.vgtest b/none/tests/amd64/insn_ssse3.vgtest
index 311d8f2..d08dc3d 100644
--- a/none/tests/amd64/insn_ssse3.vgtest
+++ b/none/tests/amd64/insn_ssse3.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/amd64/insn_ssse3
-prereq: ../../../tests/cputest amd64-ssse3
+prereq: ../../../tests/arch_test amd64-ssse3
 vgopts: -q
diff --git a/none/tests/amd64/ssse3_misaligned.vgtest b/none/tests/amd64/ssse3_misaligned.vgtest
index ba76568..76255d9 100644
--- a/none/tests/amd64/ssse3_misaligned.vgtest
+++ b/none/tests/amd64/ssse3_misaligned.vgtest
@@ -1,3 +1,3 @@
 prog: ssse3_misaligned
-prereq: ../../../tests/cputest amd64-ssse3
+prereq: ../../../tests/arch_test amd64-ssse3
 vgopts: -q
diff --git a/none/tests/x86/bug137714-x86.vgtest b/none/tests/x86/bug137714-x86.vgtest
index 35bd7df..ab1560e 100644
--- a/none/tests/x86/bug137714-x86.vgtest
+++ b/none/tests/x86/bug137714-x86.vgtest
@@ -1,3 +1,3 @@
 prog: bug137714-x86
-prereq: ../../../tests/cputest x86-sse2
+prereq: ../../../tests/arch_test x86-sse2
 vgopts: -q
diff --git a/none/tests/x86/cse_fail.vgtest b/none/tests/x86/cse_fail.vgtest
index 13e64bd..6c0092c 100644
--- a/none/tests/x86/cse_fail.vgtest
+++ b/none/tests/x86/cse_fail.vgtest
@@ -1,3 +1,3 @@
 prog: cse_fail
-prereq: ../../../tests/cputest x86-sse
+prereq: ../../../tests/arch_test x86-sse
 vgopts: -q
diff --git a/none/tests/x86/insn_cmov.vgtest b/none/tests/x86/insn_cmov.vgtest
index e4cf756..42b44b9 100644
--- a/none/tests/x86/insn_cmov.vgtest
+++ b/none/tests/x86/insn_cmov.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_cmov
-prereq: ../../../tests/cputest x86-cmov
+prereq: ../../../tests/arch_test x86-cmov
 vgopts: -q
diff --git a/none/tests/x86/insn_fpu.vgtest b/none/tests/x86/insn_fpu.vgtest
index cb7cb8b..01e514a 100644
--- a/none/tests/x86/insn_fpu.vgtest
+++ b/none/tests/x86/insn_fpu.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_fpu
-prereq: ../../../tests/cputest x86-fpu
+prereq: ../../../tests/arch_test x86-fpu
 vgopts: -q
diff --git a/none/tests/x86/insn_mmx.vgtest b/none/tests/x86/insn_mmx.vgtest
index 301f38a..88adf5b 100644
--- a/none/tests/x86/insn_mmx.vgtest
+++ b/none/tests/x86/insn_mmx.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_mmx
-prereq: ../../../tests/cputest x86-mmx
+prereq: ../../../tests/arch_test x86-mmx
 vgopts: -q
diff --git a/none/tests/x86/insn_mmxext.vgtest b/none/tests/x86/insn_mmxext.vgtest
index 42dc0e1..2b42ff4 100644
--- a/none/tests/x86/insn_mmxext.vgtest
+++ b/none/tests/x86/insn_mmxext.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_mmxext
-prereq: ../../../tests/cputest x86-mmxext
+prereq: ../../../tests/arch_test x86-mmxext
 vgopts: -q
diff --git a/none/tests/x86/insn_sse.vgtest b/none/tests/x86/insn_sse.vgtest
index 731dae8..24a7f06 100644
--- a/none/tests/x86/insn_sse.vgtest
+++ b/none/tests/x86/insn_sse.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_sse
-prereq: ../../../tests/cputest x86-sse
+prereq: ../../../tests/arch_test x86-sse
 vgopts: -q
diff --git a/none/tests/x86/insn_sse2.vgtest b/none/tests/x86/insn_sse2.vgtest
index 7f4bbaf..a13a51d 100644
--- a/none/tests/x86/insn_sse2.vgtest
+++ b/none/tests/x86/insn_sse2.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_sse2
-prereq: ../../../tests/cputest x86-sse2
+prereq: ../../../tests/arch_test x86-sse2
 vgopts: -q
diff --git a/none/tests/x86/insn_sse3.vgtest b/none/tests/x86/insn_sse3.vgtest
index c471163..6c67999 100644
--- a/none/tests/x86/insn_sse3.vgtest
+++ b/none/tests/x86/insn_sse3.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_sse3
-prereq: ../../../tests/cputest x86-sse3
+prereq: ../../../tests/arch_test x86-sse3
 vgopts: -q
diff --git a/none/tests/x86/insn_ssse3.vgtest b/none/tests/x86/insn_ssse3.vgtest
index 10c976c..c9b5a61 100644
--- a/none/tests/x86/insn_ssse3.vgtest
+++ b/none/tests/x86/insn_ssse3.vgtest
@@ -1,3 +1,3 @@
 prog: ../../../none/tests/x86/insn_ssse3
-prereq: ../../../tests/cputest x86-ssse3
+prereq: ../../../tests/arch_test x86-ssse3
 vgopts: -q
diff --git a/none/tests/x86/ssse3_misaligned.vgtest b/none/tests/x86/ssse3_misaligned.vgtest
index 15e8324..bd570b6 100644
--- a/none/tests/x86/ssse3_misaligned.vgtest
+++ b/none/tests/x86/ssse3_misaligned.vgtest
@@ -1,3 +1,3 @@
 prog: ssse3_misaligned
-prereq: ../../../tests/cputest x86-ssse3
+prereq: ../../../tests/arch_test x86-ssse3
 vgopts: -q
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bb46703..9109378 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,19 +3,21 @@
 include $(top_srcdir)/Makefile.flags.am
 
 noinst_SCRIPTS = \
-	vg_regtest \
 	filter_addresses \
 	filter_discards \
 	filter_libc \
 	filter_numbers \
 	filter_stderr_basic \
 	filter_sink \
-	filter_test_paths
+	filter_test_paths \
+	os_test \
+	platform_test \
+	vg_regtest
 
 EXTRA_DIST = $(noinst_SCRIPTS)
 
 check_PROGRAMS = \
-	cputest \
+	arch_test \
 	toobig-allocs \
 	true
 
@@ -23,7 +25,7 @@
 AM_CXXFLAGS = $(AM_CFLAGS)
 
 # generic C ones
-cputest_CFLAGS  	= $(AM_CFLAGS) \
+arch_test_CFLAGS  	= $(AM_CFLAGS) \
 				-DVGA_$(VGCONF_ARCH_PRI)=1 \
 				-DVGO_$(VGCONF_OS)=1 \
 				-DVGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS)=1
diff --git a/tests/cputest.c b/tests/arch_test.c
similarity index 79%
rename from tests/cputest.c
rename to tests/arch_test.c
index fc82b73..398cb67 100644
--- a/tests/cputest.c
+++ b/tests/arch_test.c
@@ -92,9 +92,39 @@
 #endif   // VGP_x86_linux || VGP_amd64_linux
 
 //---------------------------------------------------------------------------
-// {x86,amd64}-{linux} (part 2 of 2)
+// {x86,amd64}-darwin (part 1 of 2)
 //---------------------------------------------------------------------------
-#if defined(VGP_x86_linux)  || defined(VGP_amd64_linux)
+#if defined(VGP_x86_darwin) || defined(VGP_amd64_darwin)
+static void cpuid ( unsigned int n,
+                    unsigned int* a, unsigned int* b,
+                    unsigned int* c, unsigned int* d )
+{
+   __asm__ __volatile__ (
+       "pushl %%eax\n\t"
+       "pushl %%ebx\n\t"
+       "pushl %%ecx\n\t"
+       "pushl %%edx\n\t"
+       "movl %4, %%eax\n\t"
+       "cpuid\n\t"
+       "movl %%eax,%0\n\t"
+       "movl %%ebx,%1\n\t"
+       "movl %%ecx,%2\n\t"
+       "movl %%edx,%3\n\t"
+       "popl %%edx\n\t"
+       "popl %%ecx\n\t"
+       "popl %%ebx\n\t"
+       "popl %%eax\n\t"
+       : "=m" (*a), "=m" (*b), "=m" (*c), "=m" (*d)
+       : "mr" (n)
+       );
+}
+#endif   // VGP_x86_darwin || VGP_amd64_darwin
+
+//---------------------------------------------------------------------------
+// {x86,amd64}-{linux,darwin} (part 2 of 2)
+//---------------------------------------------------------------------------
+#if defined(VGP_x86_linux)  || defined(VGP_amd64_linux) || \
+    defined(VGP_x86_darwin) || defined(VGP_amd64_darwin)
 static Bool go(char* cpu)
 { 
    unsigned int level = 0, cmask = 0, dmask = 0, a, b, c, d;
@@ -152,7 +182,8 @@
    }
    return False;
 }
-#endif   // VGP_x86_linux  || VGP_amd64_linux
+#endif   // VGP_x86_linux  || VGP_amd64_linux ||
+         // VGP_x86_darwin || VGP_amd64_darwin
 
 
 //---------------------------------------------------------------------------
@@ -162,7 +193,7 @@
 {
    int i;
    if ( argc != 2 ) {
-      fprintf( stderr, "usage: cputest <cpu-type>\n" );
+      fprintf( stderr, "usage: arch_test <cpu-type>\n" );
       exit( 2 );
    }
    if (go( argv[1] )) {
diff --git a/tests/os_test.in b/tests/os_test.in
new file mode 100644
index 0000000..27410dd
--- /dev/null
+++ b/tests/os_test.in
@@ -0,0 +1,29 @@
+#! /bin/sh
+
+# This script determines which OSes that this Valgrind installation
+# supports, which depends on the machine's OS.
+# We return:
+# - 0 if the machine matches the asked-for OS
+# - 1 if it didn't match, but did match the name of another OS
+# - 2 otherwise
+
+# Nb: When updating this file for a new OS, add the name to 'all_OSes'.
+
+all_OSes="linux aix5 darwin"
+
+if [ $# -ne 1 ] ; then
+    echo "usage: os_test <os-type>"
+    exit 2;
+fi
+
+if [ $1 = @VGCONF_OS@ ] ; then
+    exit 0;         # Matches this OS.
+fi
+
+for os in $all_OSes ; do
+    if [ $1 = $os ] ; then
+        exit 1;     # Matches another Valgrind-supported OS.
+    fi
+done
+
+exit 2;             # Doesn't match any Valgrind-supported OS.
diff --git a/tests/platform_test b/tests/platform_test
new file mode 100644
index 0000000..e11d5d8
--- /dev/null
+++ b/tests/platform_test
@@ -0,0 +1,37 @@
+#! /bin/sh
+
+# This script determines which platforms that this Valgrind installation
+# supports.
+# We return:
+# - 0 if the machine matches the asked-for platform
+# - 1 if it didn't match, but did match the name of another platform
+# - 2 otherwise
+
+# Nb: When updating this file for a new platform, add the name to
+# 'all_platforms'.
+
+all_platforms=
+all_platforms="$all_platforms x86-linux amd64-linux ppc32-linux ppc64-linux"
+all_platforms="$all_platforms ppc32-aix5 ppc64-aix5"
+all_platforms="$all_platforms x86-darwin amd64-darwin"
+
+if [ $# -ne 2 ] ; then
+    echo "usage: platform_test <arch-type> <OS-type>"
+    exit 2;
+fi
+
+# Get the directory holding the arch_test and os_test, which will be the same
+# as the one holding this script.
+dir=`dirname $0`
+
+if $dir/arch_test $1 && sh $dir/os_test $2 ; then
+    exit 0;         # Matches this platform.
+fi
+
+for p in $all_platforms ; do
+    if [ $1-$2 = $p ] ; then
+        exit 1;     # Matches another Valgrind-supported platform.
+    fi
+done
+
+exit 2;             # Doesn't match any Valgrind-supported platform.
diff --git a/tests/vg_regtest.in b/tests/vg_regtest.in
index bc065da..1d397a6 100755
--- a/tests/vg_regtest.in
+++ b/tests/vg_regtest.in
@@ -378,14 +378,18 @@
     # Ignore dirs into which we should not recurse.
     if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; }
 
-    (-x "$tests_dir/tests/cputest") or die 
-        "vg_regtest: 'cputest' is missing.  Did you forget to 'make check'?\n";
+    (-x "$tests_dir/tests/arch_test") or die 
+        "vg_regtest: 'arch_test' is missing.  Did you forget to 'make check'?\n";
     
     # Ignore any dir whose name matches that of an architecture which is not
-    # the architecture we are running on (eg. when running on x86, ignore ppc/
-    # directories).
+    # the architecture we are running on.  Eg. when running on x86, ignore
+    # ppc/ directories ('arch_test' returns 1 for this case).  Likewise for
+    # the OS and platform.
     # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
-    if (256 == system("$tests_dir/tests/cputest $dir")) { return; }
+    if (256 == system(   "$tests_dir/tests/arch_test     $dir"))  { return; }
+    if (256 == system("sh $tests_dir/tests/os_test       $dir"))  { return; }
+    if ($dir =~ /(\w+)-(\w+)/ &&
+        256 == system("sh $tests_dir/tests/platform_test $1 $2")) { return; }
     
     chdir($dir) or die "Could not change into $dir\n";