]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/tests/arch_test.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / tests / arch_test.c
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 // This program determines which architectures that this Valgrind installation
7 // supports, which depends on the what was chosen at configure-time.  For
8 // example, if Valgrind is installed on an AMD64 machine but has been
9 // configured with --enable-only32bit then this program will match "x86" but
10 // not "amd64".
11 //
12 // We return:
13 // - 0 if the machine matches the asked-for arch
14 // - 1 if it doesn't match but does match the name of another arch
15 // - 2 if it doesn't match the name of any arch
16 // - 3 if there was a usage error (it also prints an error message)
17
18 // Nb: When updating this file for a new architecture, add the name to
19 // 'all_archs' as well as adding go().
20
21 #define False  0
22 #define True   1
23 typedef int    Bool;
24
25 char* all_archs[] = {
26    "x86",
27    "amd64",
28    "ppc32",
29    "ppc64",
30    "arm",
31    "s390x",
32    NULL
33 };
34
35 static Bool go(char* arch)
36
37 #if defined(VGP_x86_linux) || defined(VGP_x86_darwin)
38    if ( 0 == strcmp( arch, "x86"   ) ) return True;
39
40 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin)
41    if ( 0 == strcmp( arch, "x86"   ) ) return True;
42    if ( 0 == strcmp( arch, "amd64" ) ) return True;
43
44 #elif defined(VGP_ppc32_linux)
45    if ( 0 == strcmp( arch, "ppc32" ) ) return True;
46
47 #elif defined(VGP_ppc64_linux)
48    if ( 0 == strcmp( arch, "ppc64" ) ) return True;
49    if ( 0 == strcmp( arch, "ppc32" ) ) return True;
50
51 #elif defined(VGP_s390x_linux)
52    if ( 0 == strcmp( arch, "s390x" ) ) return True;
53
54 #elif defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
55    if (sizeof(void*) == 8) {
56       /* CPU is in 64-bit mode */
57       if ( 0 == strcmp( arch, "ppc64" ) ) return True;
58       if ( 0 == strcmp( arch, "ppc32" ) ) return True;
59    } else {
60       if ( 0 == strcmp( arch, "ppc32" ) ) return True;
61    }
62
63 #elif defined(VGP_arm_linux)
64    if ( 0 == strcmp( arch, "arm" ) ) return True;
65
66 #else
67 #  error Unknown platform
68 #endif   // VGP_*
69
70    return False;
71 }
72
73 //---------------------------------------------------------------------------
74 // main
75 //---------------------------------------------------------------------------
76 int main(int argc, char **argv)
77 {
78    int i;
79    if ( argc != 2 ) {
80       fprintf( stderr, "usage: arch_test <arch-type>\n" );
81       exit(3);             // Usage error.
82    }
83    if (go( argv[1] )) {
84       return 0;            // Matched.
85    }
86    for (i = 0; NULL != all_archs[i]; i++) {
87       if ( 0 == strcmp( argv[1], all_archs[i] ) )
88          return 1;         // Didn't match, but named another arch.
89    }
90    return 2;               // Didn't match any archs.
91 }