Debian Codegraph @

test-@[email protected]

raw symbols SCIP
1 #include <stdbool.h>
2 #include <sys/resource.h>
3 #include <signal.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <errno.h>
8 #include <string.h>
9
10 #include <argp.h>
11
12 #include <sys/auxv.h>
13
14 /* workarround bug on arm see #1086502*/
15 #ifdef __arm__
16 #ifndef HWCAP_CRC32
17 #include <asm/hwcap.h>
18 #endif
19 #endif
20
21 #if defined(__x86_64__) || defined(__i386__)
22 #include <sys/platform/x86.h>
23 #endif
24
25 #if defined(__riscv)
26 #if __riscv_xlen==64
27 #include <sys/hwprobe.h>
28
29 static inline bool risv_test_flag(uint64_t flag)
30 {
31 struct riscv_hwprobe pairs = {
32 .key = RISCV_HWPROBE_KEY_IMA_EXT_0
33 };
34 if(!__riscv_hwprobe(&pairs, 1, 0, NULL, 0) == 0)
35 return false;
36 return !!(pairs.value & flag);
37 }
38 #endif
39 #endif
40
41 const char *argp_program_version = "test-@NAME@ version @VERSION@";
42 static char doc[] = "return success if @NAME@\n"
43 "\n"
44 "@CDESCRIPTION@";
45 static struct argp argp = { 0, 0, 0, doc };
46
47 #ifdef AT_PLATFORM
48 #if defined(__arm__) || defined(__aarch64__)
49 /* detect ARM ABI version will be optimized away if not used */
50 static inline bool need_armv_version(int atleastversion)
51 {
52 int version;
53 const char * platform = (const char *)getauxval(AT_PLATFORM);
54 if (platform == NULL)
55 return false;
56 const size_t len = strnlen(platform, strlen("v10") + 1);
57 /* at least v5 */
58 if (len < strlen("v5"))
59 return false;
60
61 if (len > strlen("v10"))
62 return false;
63
64 if (*(platform++) != 'v')
65 return false;
66
67 char *endstr;
68 errno = 0;
69 version = strtol(platform,&endstr,10);
70 if (errno != 0)
71 return false;
72 if (endstr == platform)
73 return false;
74
75 return (version >= atleastversion);
76
77 }
78 #endif
79
80 #if defined(__s390__) || defined(__s390x__)
81 /* return arch version according to Princople of Operatior
82 off by two compared to product name */
83 static int s390computelevel (void)
84 {
85 const char *platform = (const char *) getauxval (AT_PLATFORM);
86 if(platform == NULL)
87 return 0;
88
89 if(strnlen(platform, strlen("z17") + 1) > strlen("z17"))
90 return 0;
91
92 if (strcmp (platform, "z13") == 0)
93 return 11;
94 if (strcmp (platform, "z14") == 0)
95 return 12;
96 if (strcmp (platform, "z15") == 0)
97 return 13;
98 if (strcmp (platform, "z16") == 0)
99 return 14;
100 if (strcmp (platform, "z17") == 0)
101 return 15;
102 return 0;
103 }
104 #endif
105
106 #if defined(__powerpc__) || defined(__powerpc64__)
107 static int ppcpowerlevel (void)
108 {
109 const char *platform = (const char *) getauxval (AT_PLATFORM);
110 if(platform == NULL)
111 return 0;
112
113 if(strnlen(platform, strlen("power10") + 1) > strlen("power10"))
114 return 0;
115
116 if (strcmp (platform, "power8") == 0)
117 return 8;
118 if (strcmp (platform, "power9") == 0)
119 return 9;
120 if (strcmp (platform, "power10") == 0)
121 return 10;
122 if (strcmp (platform, "power11") == 0)
123 return 11;
124 return 0;
125 }
126 #endif
127
128 #endif
129
130 static const struct rlimit nocore = { 0, 0 };
131
132 /* emulate kill by signal */
133 static void
134 termination_handler (int signum)
135 {
136 _exit(128+signum);
137 }
138
139 static bool test_cpu_feature(void) {
140 /* now test */
141 @TEST@;
142 return false;
143 }
144
145 int main(int argc,char **argv)
146 {
147 /* no core */
148 (void) setrlimit(RLIMIT_CORE, &nocore);
149 /* return instead */
150 struct sigaction new_action;
151 new_action.sa_handler = termination_handler;
152 (void) sigemptyset (&new_action.sa_mask);
153 new_action.sa_flags = 0;
154 (void) sigaction (SIGILL, &new_action, NULL);
155 (void) sigaction (SIGBUS, &new_action, NULL);
156 (void) sigaction (SIGSEGV, &new_action, NULL);
157 argp_parse (&argp, argc, argv, 0, 0, 0);
158 return !test_cpu_feature();
159 }