1 /* SPDX-License-Identifier: GPL-2.0-or-later
2 * Copyright (c) 2021 Li Wang <liwang@redhat.com>
3 */
4
5 #include <string.h>
6 #include <stdlib.h>
7
8 #define TST_NO_DEFAULT_MAIN
9 #include "tst_arch.h"
10 #include "tst_test.h"
11
12 const struct tst_arch tst_arch = {
13 #if defined(__x86_64__)
14 .name = "x86_64",
15 .type = TST_X86_64,
16 #elif defined(__i386__) || defined(__i586__) || defined(__i686__)
17 .name = "x86",
18 .type = TST_X86,
19 #elif defined(__ia64__)
20 .name = "ia64",
21 .type = TST_IA64,
22 #elif defined(__powerpc64__) || defined(__ppc64__)
23 .name = "ppc64",
24 .type = TST_PPC64,
25 #elif defined(__powerpc__) || defined(__ppc__)
26 .name = "ppc",
27 .type = TST_PPC,
28 #elif defined(__s390x__)
29 .name = "s390x",
30 .type = TST_S390X,
31 #elif defined(__s390__)
32 .name = "s390",
33 .type = TST_S390,
34 #elif defined(__aarch64__)
35 .name = "aarch64",
36 .type = TST_AARCH64,
37 #elif defined(__arm__)
38 .name = "arm",
39 .type = TST_ARM,
40 #elif defined(__sparc__)
41 .name = "sparc",
42 .type = TST_SPARC,
43 #else
44 .name = "unknown",
45 .type = TST_UNKNOWN,
46 #endif
47 };
48
49 static const char *const arch_type_list[] = {
50 "x86",
51 "x86_64",
52 "ia64",
53 "ppc",
54 "ppc64",
55 "s390",
56 "s390x",
57 "arm",
58 "aarch64",
59 "sparc",
60 NULL
61 };
62
is_valid_arch_name(const char * name)63 static int is_valid_arch_name(const char *name)
64 {
65 unsigned int i;
66
67 for (i = 0; arch_type_list[i]; i++) {
68 if (!strcmp(arch_type_list[i], name))
69 return 1;
70 }
71
72 return 0;
73 }
74
tst_is_on_arch(const char * const * archlist)75 int tst_is_on_arch(const char *const *archlist)
76 {
77 unsigned int i;
78
79 if (!archlist)
80 return 1;
81
82 for (i = 0; archlist[i]; i++) {
83 if (!is_valid_arch_name(archlist[i]))
84 tst_brk(TBROK, "%s is invalid arch, please reset!",
85 archlist[i]);
86 }
87
88 for (i = 0; archlist[i]; i++) {
89 if (!strcmp(tst_arch.name, archlist[i]))
90 return 1;
91 }
92
93 return 0;
94 }
95