aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/ltp/ltp/0008-Check-if-__GLIBC_PREREQ-is-defined-before-using-it.patch
blob: d1230742070e028fe8f28abd421dba7571aa1ecf (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
From a3cbee31daae2466bc8dcac36b33a01352693346 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 7 Jan 2016 19:40:08 +0000
Subject: [PATCH 01/26] Check if __GLIBC_PREREQ is defined before using it

__GLIBC_PREREQ is specific to glibc so it should be checked if it is
defined or not.

Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 testcases/kernel/syscalls/accept4/accept4_01.c     |  9 ++++-
 testcases/kernel/syscalls/getcpu/getcpu01.c        | 40 +++++++++++++++++++++-
 .../sched_getaffinity/sched_getaffinity01.c        | 26 ++++++++++++++
 3 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index 6072bfa..2b090cb 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -64,6 +64,7 @@ static void cleanup(void)
 	tst_rmdir();
 }
 
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if !(__GLIBC_PREREQ(2, 10))
 static int
 accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
@@ -82,7 +83,6 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
 	}
 	tst_resm(TINFO, "\n");
 #endif
-
 #if USE_SOCKETCALL
 	long args[6];
 
@@ -97,6 +97,7 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
 #endif
 }
 #endif
+#endif
 
 static void
 do_test(int lfd, struct sockaddr_in *conn_addr,
@@ -119,9 +120,15 @@ do_test(int lfd, struct sockaddr_in *conn_addr,
 		die("Connect Error");
 
 	addrlen = sizeof(struct sockaddr_in);
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if !(__GLIBC_PREREQ(2, 10))
 	acceptfd = accept4_01(lfd, (struct sockaddr *)&claddr, &addrlen,
 			      closeonexec_flag | nonblock_flag);
+
+#else
+	acceptfd = accept4(lfd, (struct sockaddr *)&claddr, &addrlen,
+			   closeonexec_flag | nonblock_flag);
+#endif
 #else
 	acceptfd = accept4(lfd, (struct sockaddr *)&claddr, &addrlen,
 			   closeonexec_flag | nonblock_flag);
diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
index c927512..921b107 100644
--- a/testcases/kernel/syscalls/getcpu/getcpu01.c
+++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
@@ -62,6 +62,7 @@
 #include <dirent.h>
 
 #if defined(__i386__) || defined(__x86_64__)
+#if defined(__GLIBC__)
 #if __GLIBC_PREREQ(2,6)
 #if defined(__x86_64__)
 #include <utmpx.h>
@@ -75,10 +76,17 @@ int sys_support = 0;
 #else
 int sys_support = 0;
 #endif
+#else
+int sys_support = 0;
+#endif
 
+#if defined(__GLIBC__)
 #if !(__GLIBC_PREREQ(2, 7))
 #define CPU_FREE(ptr) free(ptr)
 #endif
+#else
+#define CPU_FREE(ptr) free(ptr)
+#endif
 
 void cleanup(void);
 void setup(void);
@@ -164,9 +172,14 @@ static inline int getcpu(unsigned *cpu_id, unsigned *node_id,
 {
 #if defined(__i386__)
 	return syscall(318, cpu_id, node_id, cache_struct);
-#elif __GLIBC_PREREQ(2,6)
+#if defined(__GLIBC__)
+#if __GLIBC_PREREQ(2,6)
+	*cpu_id = sched_getcpu();
+#endif
+#else
 	*cpu_id = sched_getcpu();
 #endif
+#endif
 	return 0;
 }
 
@@ -191,15 +204,20 @@ unsigned int set_cpu_affinity(void)
 	cpu_set_t *set;
 	size_t size;
 	int nrcpus = 1024;
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 realloc:
 	set = CPU_ALLOC(nrcpus);
 #else
 	set = malloc(sizeof(cpu_set_t));
 #endif
+#else
+	set = malloc(sizeof(cpu_set_t));
+#endif
 	if (set == NULL) {
 		tst_brkm(TFAIL, NULL, "CPU_ALLOC:errno:%d", errno);
 	}
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 	size = CPU_ALLOC_SIZE(nrcpus);
 	CPU_ZERO_S(size, set);
@@ -207,8 +225,13 @@ realloc:
 	size = sizeof(cpu_set_t);
 	CPU_ZERO(set);
 #endif
+#else
+	size = sizeof(cpu_set_t);
+	CPU_ZERO(set);
+#endif
 	if (sched_getaffinity(0, size, set) < 0) {
 		CPU_FREE(set);
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 		if (errno == EINVAL && nrcpus < (1024 << 8)) {
 			nrcpus = nrcpus << 2;
@@ -220,10 +243,17 @@ realloc:
 				 "NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)");
 		else
 #endif
+#else
+		if (errno == EINVAL)
+			tst_resm(TFAIL,
+				 "NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)");
+		else
+#endif
 			tst_resm(TFAIL, "sched_getaffinity:errno:%d", errno);
 		tst_exit();
 	}
 	cpu_max = max_cpuid(size, set);
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 	CPU_ZERO_S(size, set);
 	CPU_SET_S(cpu_max, size, set);
@@ -231,6 +261,10 @@ realloc:
 	CPU_ZERO(set);
 	CPU_SET(cpu_max, set);
 #endif
+#else
+	CPU_ZERO(set);
+	CPU_SET(cpu_max, set);
+#endif
 	if (sched_setaffinity(0, size, set) < 0) {
 		CPU_FREE(set);
 		tst_brkm(TFAIL, NULL, "sched_setaffinity:errno:%d", errno);
@@ -247,11 +281,15 @@ unsigned int max_cpuid(size_t size, cpu_set_t * set)
 {
 	unsigned int index, max = 0;
 	for (index = 0; index < size * BITS_PER_BYTE; index++)
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 		if (CPU_ISSET_S(index, size, set))
 #else
 		if (CPU_ISSET(index, set))
 #endif
+#else
+		if (CPU_ISSET(index, set))
+#endif
 			max = index;
 	return max;
 }
diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 9d6a81a..4ed13b2 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -66,9 +66,11 @@ do { \
 	tst_resm((TEST_RETURN == -1 ? TPASS : TFAIL) | TTERRNO, #t); \
 } while (0)
 
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if !(__GLIBC_PREREQ(2, 7))
 #define CPU_FREE(ptr)	free(ptr)
 #endif
+#endif
 
 int main(int ac, char **av)
 {
@@ -95,14 +97,19 @@ static void do_test(void)
 	pid_t unused_pid;
 	unsigned len;
 
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 realloc:
 	mask = CPU_ALLOC(nrcpus);
 #else
 	mask = malloc(sizeof(cpu_set_t));
 #endif
+#else
+	mask = malloc(sizeof(cpu_set_t));
+#endif
 	if (mask == NULL)
 		tst_brkm(TFAIL | TTERRNO, cleanup, "fail to get enough memory");
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 	len = CPU_ALLOC_SIZE(nrcpus);
 	CPU_ZERO_S(len, mask);
@@ -110,10 +117,15 @@ realloc:
 	len = sizeof(cpu_set_t);
 	CPU_ZERO(mask);
 #endif
+#else
+	len = sizeof(cpu_set_t);
+	CPU_ZERO(mask);
+#endif
 	/* positive test */
 	TEST(sched_getaffinity(0, len, mask));
 	if (TEST_RETURN == -1) {
 		CPU_FREE(mask);
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 		if (errno == EINVAL && nrcpus < (1024 << 8)) {
 			nrcpus = nrcpus << 2;
@@ -125,17 +137,27 @@ realloc:
 				 "newer glibc(>= 2.7)");
 		else
 #endif
+#else
+		if (errno == EINVAL)
+			tst_resm(TFAIL, "NR_CPUS > 1024, we'd better use a "
+				 "newer glibc(>= 2.7)");
+		else
+#endif
 			tst_resm(TFAIL | TTERRNO, "fail to get cpu affinity");
 		cleanup();
 	} else {
 		tst_resm(TINFO, "cpusetsize is %d", len);
 		tst_resm(TINFO, "mask.__bits[0] = %lu ", mask->__bits[0]);
 		for (i = 0; i < num; i++) {
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 			TEST(CPU_ISSET_S(i, len, mask));
 #else
 			TEST(CPU_ISSET(i, mask));
 #endif
+#else
+			TEST(CPU_ISSET(i, mask));
+#endif
 			if (TEST_RETURN != -1)
 				tst_resm(TPASS, "sched_getaffinity() succeed, "
 					 "this process %d is running "
@@ -143,11 +165,15 @@ realloc:
 		}
 	}
 
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
 #if __GLIBC_PREREQ(2, 7)
 	CPU_ZERO_S(len, mask);
 #else
 	CPU_ZERO(mask);
 #endif
+#else
+	CPU_ZERO(mask);
+#endif
 	/* negative tests */
 	QUICK_TEST(sched_getaffinity(0, len, (cpu_set_t *) - 1));
 	QUICK_TEST(sched_getaffinity(0, 0, mask));
-- 
1.9.1