Arch-abstraction:
- Rewrote tests/cputest.c so that it can apply to different kinds of
  processors.  The idea being that any arch-specific tests have a cpu_test:
  label in their .vgtest file, so they'll only get executed if the right
  machine is being used.
- Rewrote a bunch of .vgtest files accordingly.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2802 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/tests/cputest.c b/tests/cputest.c
index 40e9c2f..4ccbee3 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -2,6 +2,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+// We return 0 if the machine matches the asked-for cpu, 1 otherwise.
+
+#ifdef __x86__
 static __inline__ void cpuid(unsigned int n,
                              unsigned int *a, unsigned int *b,
                              unsigned int *c, unsigned int *d)
@@ -13,49 +16,63 @@
    );
 }
 
-int main(int argc, char **argv)
-{
-   unsigned int level = 0;
-   unsigned int mask = 0;
-   unsigned int a;
-   unsigned int b;
-   unsigned int c;
-   unsigned int d;
+static int go(char* cpu)
+{ 
+   unsigned int level = 0, mask = 0, a, b, c, d;
 
-   if ( argc == 2 ) {
-      if ( strcmp( argv[1], "fpu" ) == 0 ) {
-        level = 1;
-        mask = 1 << 0;
-      } else if ( strcmp( argv[1], "cmov" ) == 0 ) {
-        level = 1;
-        mask = 1 << 15;
-      } else if ( strcmp( argv[1], "mmx" ) == 0 ) {
-        level = 1;
-        mask = 1 << 23;
-      } else if ( strcmp( argv[1], "mmxext" ) == 0 ) {
-        level = 0x80000001;
-        mask = 1 << 22;
-      } else if ( strcmp( argv[1], "sse" ) == 0 ) {
-        level = 1;
-        mask = 1 << 25;
-      } else if ( strcmp( argv[1], "sse2" ) == 0 ) {
-        level = 1;
-        mask = 1 << 26;
-      }
+   if ( strcmp( cpu, "x86" ) == 0 ) {
+     level = 1;
+     mask = 1 << 0;
+   } else if ( strcmp( cpu, "x86-fpu" ) == 0 ) {
+     level = 1;
+     mask = 1 << 0;
+   } else if ( strcmp( cpu, "x86-cmov" ) == 0 ) {
+     level = 1;
+     mask = 1 << 15;
+   } else if ( strcmp( cpu, "x86-mmx" ) == 0 ) {
+     level = 1;
+     mask = 1 << 23;
+   } else if ( strcmp( cpu, "x86-mmxext" ) == 0 ) {
+     level = 0x80000001;
+     mask = 1 << 22;
+   } else if ( strcmp( cpu, "x86-sse" ) == 0 ) {
+     level = 1;
+     mask = 1 << 25;
+   } else if ( strcmp( cpu, "x86-sse2" ) == 0 ) {
+     level = 1;
+     mask = 1 << 26;
+   } else {
+     return 1;
    }
 
-   if ( level == 0 || mask == 0 ) {
-      fprintf( stderr, "usage: cputest [cmov|mmx|mmxext|sse|sse2]\n" );
-      exit( 1 );
-   }
-   
    cpuid( level & 0x80000000, &a, &b, &c, &d );
 
    if ( a >= level ) {
       cpuid( level, &a, &b, &c, &d );
 
-      if ( ( d & mask ) != 0 ) exit( 0 );
+      if ( ( d & mask ) != 0 ) return 0;
    }
+   return 1;
+}
+#endif // __x86__
 
-   exit( 1 );
+
+#ifdef __ppc__
+static int go(char* cpu)
+{
+   if ( strcmp( cpu, "ppc" ) == 0 )
+      return 0;
+   else 
+      return 1;
+}
+#endif // __ppc__
+
+
+int main(int argc, char **argv)
+{
+   if ( argc != 2 ) {
+      fprintf( stderr, "usage: cputest <cpu-type>\n" );
+      exit( 1 );
+   }
+   return go( argv[1] );
 }