aboutsummaryrefslogtreecommitdiff
path: root/tests/arch_test.c
blob: 6771f4a6a6eb326124e0316623f023b72d85dc00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 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 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().

#define False  0
#define True   1
typedef int    Bool;

char* all_archs[] = {
   "x86",
   "amd64",
   "ppc32",
   "ppc64",
   NULL
};

static Bool go(char* arch)
{ 
#if defined(VGP_x86_linux) || defined(VGP_x86_darwin)
   if ( 0 == strcmp( arch, "x86"   ) ) return True;

#elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin)
   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 {
      if ( 0 == strcmp( arch, "ppc32" ) ) return True;
   }

#else
#  error Unknown platform
#endif   // VGP_*

   return False;
}

//---------------------------------------------------------------------------
// main
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
   int i;
   if ( argc != 2 ) {
      fprintf( stderr, "usage: arch_test <arch-type>\n" );
      exit(3);             // Usage error.
   }
   if (go( argv[1] )) {
      return 0;            // Matched.
   }
   for (i = 0; NULL != all_archs[i]; i++) {
      if ( 0 == strcmp( argv[1], all_archs[i] ) )
         return 1;         // Didn't match, but named another arch.
   }
   return 2;               // Didn't match any archs.
}