|
From: Nicholas N. <nj...@ca...> - 2004-11-18 18:22:02
|
CVS commit by nethercote:
Arch-abstraction:
- Added a hacky mechanism which prevents the regtest script from entering
directories for other architectures. (Eg. when running on x86/, it won't enter
a ppc/ subdir.)
M +36 -12 cputest.c 1.6
M +7 -1 vg_regtest.in 1.26
--- valgrind/tests/cputest.c #1.5:1.6
@@ -3,5 +3,22 @@
#include <string.h>
-// We return 0 if the machine matches the asked-for cpu, 1 otherwise.
+// 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
+
+// When updating this file for a new architecture, add the name to
+// 'all_archs' as well as adding go().
+
+#define False 0
+#define True 1
+typedef int Bool;
+
+char* all_archs[] = {
+ "x86",
+ "ppc",
+ "amd64",
+ NULL
+};
#ifdef __x86__
@@ -17,10 +34,10 @@ static __inline__ void cpuid(unsigned in
}
-static int go(char* cpu)
+static Bool go(char* cpu)
{
unsigned int level = 0, mask = 0, a, b, c, d;
if ( strcmp( cpu, "x86" ) == 0 ) {
- return 0;
+ return True;
} else if ( strcmp( cpu, "x86-fpu" ) == 0 ) {
level = 1;
@@ -42,5 +59,5 @@ static int go(char* cpu)
mask = 1 << 26;
} else {
- return 1;
+ return False;
}
@@ -50,7 +67,7 @@ static int go(char* cpu)
cpuid( level, &a, &b, &c, &d );
- if ( ( d & mask ) != 0 ) return 0;
+ if ( ( d & mask ) != 0 ) return True;
}
- return 1;
+ return False;
}
#endif // __x86__
@@ -58,10 +75,10 @@ static int go(char* cpu)
#ifdef __ppc__
-static int go(char* cpu)
+static Bool go(char* cpu)
{
if ( strcmp( cpu, "ppc" ) == 0 )
- return 0;
+ return True;
else
- return 1;
+ return False;
}
#endif // __ppc__
@@ -70,8 +86,16 @@ static int go(char* cpu)
int main(int argc, char **argv)
{
+ int i;
if ( argc != 2 ) {
fprintf( stderr, "usage: cputest <cpu-type>\n" );
- exit( 1 );
+ exit( 2 );
}
- return go( argv[1] );
+ if (go( argv[1] )) {
+ return 0; // matched
+ }
+ for (i = 0; NULL != all_archs[i]; i++) {
+ if ( strcmp( argv[1], all_archs[i] ) == 0 )
+ return 1;
+ }
+ return 2;
}
--- valgrind/tests/vg_regtest.in #1.25:1.26
@@ -319,7 +319,13 @@
$dir =~ s/\/$//; # trim a trailing '/'
- # ignore dirs into which we should not recurse
+ # Ignore dirs into which we should not recurse.
if ($dir =~ /^(BitKeeper|CVS|SCCS|docs|doc)$/) { return; }
+ # 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).
+ # Nb: weird Perl-ism -- exit code of '1' is seen by Perl as 256...
+ if (256 == system("$tests_dir/tests/cputest $dir")) { return; }
+
chdir($dir) or die "Could not change into $dir\n";
|