tests/arch_test is currently being used for two purposes:
- by vg_regtest for determining if a directory name matches an architecture;
- by various .vgtest files for detecting x86/AMD64 features.
This commit splits it in two for the two different purposes, which makes
things clearer.
Specific changes
- Moved the x86/AMD64 feature detection stuff out of arch_test.c, and
into the new x86_amd64_feature.c. Updated the relevant .vgtest files for
the change.
- In vg_regtest, now a prereq command must return 0 (prereq satisfied) or 1
(prereq not satisfied). Anything else makes vg_regtest abort. This
makes obvious any problems with prereq tests rather than just making the
tests skip innocuously. (We previously had exactly such a problem on the
DARWIN branch; the x86 feature detection tests caused segfaults so the
tests were incorrectly skipped. This change will catch any similar future
problem.)
- Changed os_test from a script to a C program, matching cpu_test.
- Removed some unintentional darwin stuff from platform_test.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9316 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/tests/arch_test.c b/tests/arch_test.c
index feeb67e..f6206e3 100644
--- a/tests/arch_test.c
+++ b/tests/arch_test.c
@@ -1,18 +1,19 @@
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
-// This file determines which architectures that this Valgrind installation
-// supports, which depends on the machine's architecture. It also depends
-// on the configuration options; for example, if Valgrind is installed on
-// an AMD64 machine but has been configured with --enable-only32bit then
-// this program will not match "amd64".
+// This program determines which architectures that this Valgrind installation
+// supports, which depends on the what was chosen at configure-time. For
+// example, if Valgrind is installed on an AMD64 machine but has been
+// configured with --enable-only32bit then this program will match "x86" but
+// not "amd64".
//
// We return:
-// - 0 if the machine matches the asked-for cpu
-// - 1 if it didn't match, but did match the name of another arch
-// - 2 otherwise
+// - 0 if the machine matches the asked-for arch
+// - 1 if it doesn't match but does match the name of another arch
+// - 2 if it doesn't match the name of any arch
+// - 3 if there was a usage error (it also prints an error message)
// Nb: When updating this file for a new architecture, add the name to
// 'all_archs' as well as adding go().
@@ -22,138 +23,44 @@
typedef int Bool;
char* all_archs[] = {
+ "x86",
"amd64",
"ppc32",
"ppc64",
- "x86",
NULL
};
-//-----------------------------------------------------------------------------
-// ppc32-linux
-//---------------------------------------------------------------------------
-#if defined(VGP_ppc32_linux)
-static Bool go(char* cpu)
-{
- if ( strcmp( cpu, "ppc32" ) == 0 )
- return True;
- return False;
-}
-#endif // VGP_ppc32_linux
-
-//---------------------------------------------------------------------------
-// ppc64-linux
-//---------------------------------------------------------------------------
-#if defined(VGP_ppc64_linux)
-static Bool go(char* cpu)
-{
- if ( strcmp( cpu, "ppc64" ) == 0 )
- return True;
- if ( strcmp( cpu, "ppc32" ) == 0 )
- return True;
- return False;
-}
-#endif // VGP_ppc64_linux
-
-//---------------------------------------------------------------------------
-// ppc{32,64}-aix
-//---------------------------------------------------------------------------
-#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
-static Bool go(char* cpu)
-{
- if (sizeof(void*) == 8) {
- /* cpu is in 64-bit mode */
- if ( strcmp( cpu, "ppc64" ) == 0 )
- return True;
- if ( strcmp( cpu, "ppc32" ) == 0 )
- return True;
- } else {
- if ( strcmp( cpu, "ppc32" ) == 0 )
- return True;
- }
- return False;
-}
-#endif // VGP_ppc32_aix5 || VGP_ppc64_aix5
-
-//---------------------------------------------------------------------------
-// {x86,amd64}-linux (part 1 of 2)
-//---------------------------------------------------------------------------
-#if defined(VGP_x86_linux) || defined(VGP_amd64_linux)
-static void cpuid ( unsigned int n,
- unsigned int* a, unsigned int* b,
- unsigned int* c, unsigned int* d )
-{
- __asm__ __volatile__ (
- "cpuid"
- : "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) /* output */
- : "0" (n) /* input */
- );
-}
-#endif // VGP_x86_linux || VGP_amd64_linux
-
-//---------------------------------------------------------------------------
-// {x86,amd64}-linux (part 2 of 2)
-//---------------------------------------------------------------------------
-#if defined(VGP_x86_linux) || defined(VGP_amd64_linux)
-static Bool go(char* cpu)
+static Bool go(char* arch)
{
- unsigned int level = 0, cmask = 0, dmask = 0, a, b, c, d;
+#if defined(VGP_x86_linux)
+ if ( 0 == strcmp( arch, "x86" ) ) return True;
- if ( strcmp( cpu, "x86" ) == 0 ) {
- return True;
- } else if ( strcmp( cpu, "x86-fpu" ) == 0 ) {
- level = 1;
- dmask = 1 << 0;
- } else if ( strcmp( cpu, "x86-cmov" ) == 0 ) {
- level = 1;
- dmask = 1 << 15;
- } else if ( strcmp( cpu, "x86-mmx" ) == 0 ) {
- level = 1;
- dmask = 1 << 23;
- } else if ( strcmp( cpu, "x86-mmxext" ) == 0 ) {
- level = 0x80000001;
- dmask = 1 << 22;
- } else if ( strcmp( cpu, "x86-sse" ) == 0 ) {
- level = 1;
- dmask = 1 << 25;
- } else if ( strcmp( cpu, "x86-sse2" ) == 0 ) {
- level = 1;
- dmask = 1 << 26;
- } else if ( strcmp( cpu, "x86-sse3" ) == 0 ) {
- level = 1;
- cmask = 1 << 0;
- } else if ( strcmp( cpu, "x86-ssse3" ) == 0 ) {
- level = 1;
- cmask = 1 << 9;
-#if defined(VGA_amd64)
- } else if ( strcmp( cpu, "amd64" ) == 0 ) {
- return True;
- } else if ( strcmp( cpu, "amd64-sse3" ) == 0 ) {
- level = 1;
- cmask = 1 << 0;
- } else if ( strcmp( cpu, "amd64-ssse3" ) == 0 ) {
- level = 1;
- cmask = 1 << 9;
-#endif
+#elif defined(VGP_amd64_linux)
+ if ( 0 == strcmp( arch, "x86" ) ) return True;
+ if ( 0 == strcmp( arch, "amd64" ) ) return True;
+
+#elif defined(VGP_ppc32_linux)
+ if ( 0 == strcmp( arch, "ppc32" ) ) return True;
+
+#elif defined(VGP_ppc64_linux)
+ if ( 0 == strcmp( arch, "ppc64" ) ) return True;
+ if ( 0 == strcmp( arch, "ppc32" ) ) return True;
+
+#elif defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+ if (sizeof(void*) == 8) {
+ /* CPU is in 64-bit mode */
+ if ( 0 == strcmp( arch, "ppc64" ) ) return True;
+ if ( 0 == strcmp( arch, "ppc32" ) ) return True;
} else {
- return False;
+ if ( 0 == strcmp( arch, "ppc32" ) ) return True;
}
- assert( !(cmask != 0 && dmask != 0) );
- assert( !(cmask == 0 && dmask == 0) );
+#else
+# error Unknown platform
+#endif // VGP_*
- cpuid( level & 0x80000000, &a, &b, &c, &d );
-
- if ( a >= level ) {
- cpuid( level, &a, &b, &c, &d );
-
- if (dmask > 0 && (d & dmask) != 0) return True;
- if (cmask > 0 && (c & cmask) != 0) return True;
- }
return False;
}
-#endif // VGP_x86_linux || VGP_amd64_linux
-
//---------------------------------------------------------------------------
// main
@@ -162,15 +69,15 @@
{
int i;
if ( argc != 2 ) {
- fprintf( stderr, "usage: arch_test <cpu-type>\n" );
- exit( 2 );
+ fprintf( stderr, "usage: arch_test <arch-type>\n" );
+ exit(3); // Usage error.
}
if (go( argv[1] )) {
- return 0; // matched
+ return 0; // Matched.
}
for (i = 0; NULL != all_archs[i]; i++) {
- if ( strcmp( argv[1], all_archs[i] ) == 0 )
- return 1;
+ if ( 0 == strcmp( argv[1], all_archs[i] ) )
+ return 1; // Didn't match, but named another arch.
}
- return 2;
+ return 2; // Didn't match any archs.
}