FreeBSD: add common failure causes to README.freebsd
[valgrind.git] / tests / arch_test.c
blob37cc1bc76d62ad89ae467e066ba3651666881dde
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
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".
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)
18 // Nb: When updating this file for a new architecture, add the name to
19 // 'all_archs' as well as adding go().
21 #define False 0
22 #define True 1
23 typedef int Bool;
25 char* all_archs[] = {
26 "x86",
27 "amd64",
28 "ppc32",
29 "ppc64",
30 "ppc64le",
31 "arm",
32 "arm64",
33 "s390x",
34 "mips32",
35 "mips64",
36 "nanomips",
37 NULL
40 static Bool go(char* arch)
42 #if defined(VGP_x86_linux) || defined(VGP_x86_darwin) \
43 || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd)
44 if ( 0 == strcmp( arch, "x86" ) ) return True;
46 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) \
47 || defined(VGP_amd64_solaris) || defined(VGP_amd64_freebsd)
48 #if defined(VGA_SEC_x86)
49 if ( 0 == strcmp( arch, "x86" ) ) return True;
50 #endif
51 if ( 0 == strcmp( arch, "amd64" ) ) return True;
53 #elif defined(VGP_ppc32_linux)
54 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
56 #elif defined(VGP_ppc64be_linux)
57 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
58 #if defined(VGA_SEC_ppc32)
59 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
60 #endif
62 #elif defined(VGP_ppc64le_linux)
63 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
65 #elif defined(VGP_s390x_linux)
66 if ( 0 == strcmp( arch, "s390x" ) ) return True;
68 #elif defined(VGP_arm_linux)
69 if ( 0 == strcmp( arch, "arm" ) ) return True;
71 #elif defined(VGP_arm64_linux)
72 if ( 0 == strcmp( arch, "arm64" ) ) return True;
74 #elif defined(VGP_mips32_linux)
75 if ( 0 == strcmp( arch, "mips32" ) ) return True;
77 #elif defined(VGP_mips64_linux)
78 if ( 0 == strcmp( arch, "mips64" ) ) return True;
80 #elif defined(VGP_nanomips_linux)
81 if ( 0 == strcmp( arch, "nanomips" ) ) return True;
82 #else
83 # error Unknown platform
84 #endif // VGP_*
86 return False;
89 //---------------------------------------------------------------------------
90 // main
91 //---------------------------------------------------------------------------
92 int main(int argc, char **argv)
94 int i;
95 if ( argc != 2 ) {
96 fprintf( stderr, "usage: arch_test <arch-type>\n" );
97 exit(3); // Usage error.
99 if (go( argv[1] )) {
100 return 0; // Matched.
102 for (i = 0; NULL != all_archs[i]; i++) {
103 if ( 0 == strcmp( argv[1], all_archs[i] ) )
104 return 1; // Didn't match, but named another arch.
106 return 2; // Didn't match any archs.