]>
Commit | Line | Data |
---|---|---|
da1067a9 UD |
1 | #! /usr/bin/perl |
2 | ||
ad4f2ebf UD |
3 | use Getopt::Long; |
4 | ||
da1067a9 | 5 | $CC = "gcc"; |
ad4f2ebf UD |
6 | |
7 | $dialect="XOPEN2K"; | |
8 | GetOptions ('headers=s' => \@headers, 'dialect=s' => \$dialect); | |
9 | @headers = split(/,/,join(',',@headers)); | |
da1067a9 UD |
10 | |
11 | # List of the headers we are testing. | |
ad4f2ebf UD |
12 | if (@headers == ()) { |
13 | @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h", | |
14 | "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "time.h", | |
73b6bffc UD |
15 | "tgmath.h", "termios.h", "tar.h", "sys/wait.h", "sys/utsname.h", |
16 | "sys/un.h", "sys/uio.h", "sys/types.h", "sys/times.h", | |
17 | "sys/timeb.h", "sys/time.h", "sys/statvfs.h", "sys/stat.h", | |
18 | "sys/socket.h", "sys/shm.h", "sys/sem.h", "sys/select.h", | |
19 | "sys/resource.h", "sys/msg.h", "sys/mman.h", "sys/ipc.h", | |
20 | "syslog.h", "stropts.h", "strings.h", "string.h", "stdlib.h", | |
21 | "stdio.h", "stdint.h", "stddef.h", "stdarg.h", "spawn.h", | |
22 | "signal.h", "setjmp.h", "semaphore.h", "search.h", "sched.h", | |
23 | "regex.h", "pwd.h", "pthread.h", "poll.h", "nl_types.h", | |
24 | "netinet/tcp.h", "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h", | |
25 | "mqueue.h", "monetary.h", "math.h", "locale.h", "libgen.h", | |
26 | "limits.h", "langinfo.h", "iso646.h", "inttypes.h", "iconv.h", | |
27 | "grp.h", "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h", | |
28 | "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h", | |
29 | "complex.h", "assert.h", "arpa/inet.h", "aio.h"); | |
ad4f2ebf UD |
30 | } |
31 | ||
32 | if ($dialect ne "ISO" && $dialect ne "POSIX" && $dialect ne "XPG3" | |
33 | && $dialect ne "XPG4" && $dialect ne "UNIX98" && $dialect ne "XOPEN2K") { | |
34 | die "unknown dialect \"$dialect\""; | |
35 | } | |
36 | ||
140ec510 UD |
37 | $CFLAGS{"ISO"} = "-I. -fno-builtin '-D__attribute__(x)=' -ansi"; |
38 | $CFLAGS{"POSIX"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_POSIX_C_SOURCE=199912"; | |
39 | $CFLAGS{"XPG3"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE"; | |
40 | $CFLAGS{"XPG4"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE_EXTENDED"; | |
41 | $CFLAGS{"UNIX98"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=500"; | |
42 | $CFLAGS{"XOPEN2K"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=600"; | |
ad4f2ebf | 43 | |
7287c36d | 44 | |
bba09d23 | 45 | # These are the ISO C99 keywords. |
da1067a9 UD |
46 | @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default', |
47 | 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', | |
48 | 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return', | |
49 | 'short', 'signed', 'sizeof', 'static', 'struct', 'switch', | |
50 | 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while'); | |
51 | ||
7287c36d UD |
52 | # These are symbols which are known to pollute the namespace. |
53 | @knownproblems = ('unix', 'linux', 'i386'); | |
54 | ||
77faa354 UD |
55 | # Some headers need a bit more attention. |
56 | $mustprepend{'regex.h'} = "#include <sys/types.h>\n"; | |
da238298 | 57 | $mustprepend{'sched.h'} = "#include <sys/types.h>\n"; |
5a9339d5 | 58 | $mustprepend{'signal.h'} = "#include <pthread.h>\n"; |
3bf3d361 | 59 | $mustprepend{'stdio.h'} = "#include <sys/types.h>\n"; |
73b6bffc | 60 | $mustprepend{'wchar.h'} = "#include <stdarg.h>\n"; |
7287c36d | 61 | $mustprepend{'wordexp.h'} = "#include <stddef.h>\n"; |
77faa354 | 62 | |
7287c36d UD |
63 | # Make a hash table from this information. |
64 | while ($#keywords >= 0) { | |
da1067a9 UD |
65 | $iskeyword{pop (@keywords)} = 1; |
66 | } | |
67 | ||
7287c36d UD |
68 | # Make a hash table from the known problems. |
69 | while ($#knownproblems >= 0) { | |
70 | $isknown{pop (@knownproblems)} = 1; | |
71 | } | |
72 | ||
da1067a9 UD |
73 | $tmpdir = "/tmp"; |
74 | ||
75 | $verbose = 1; | |
76 | ||
77 | $total = 0; | |
78 | $skipped = 0; | |
79 | $errors = 0; | |
80 | ||
da1067a9 UD |
81 | |
82 | sub poorfnmatch { | |
83 | my($pattern, $string) = @_; | |
84 | my($strlen) = length ($string); | |
85 | my($res); | |
86 | ||
87 | if (substr ($pattern, 0, 1) eq '*') { | |
88 | my($patlen) = length ($pattern) - 1; | |
89 | $res = ($strlen >= $patlen | |
90 | && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen)); | |
91 | } elsif (substr ($pattern, -1, 1) eq '*') { | |
92 | my($patlen) = length ($pattern) - 1; | |
93 | $res = ($strlen >= $patlen | |
94 | && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)); | |
95 | } else { | |
96 | $res = $pattern eq $string; | |
97 | } | |
98 | return $res; | |
99 | } | |
100 | ||
101 | ||
102 | sub compiletest | |
103 | { | |
2eba94b2 | 104 | my($fnamebase, $msg, $errmsg, $skip, $optional) = @_; |
da1067a9 UD |
105 | my($result) = $skip; |
106 | my($printlog) = 0; | |
107 | ||
108 | ++$total; | |
109 | printf (" $msg..."); | |
110 | ||
111 | if ($skip != 0) { | |
112 | ++$skipped; | |
113 | printf (" SKIP\n"); | |
114 | } else { | |
ad4f2ebf | 115 | $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1"; |
da1067a9 | 116 | if ($ret != 0) { |
2eba94b2 UD |
117 | if ($optional != 0) { |
118 | printf (" $errmsg\n"); | |
119 | $result = 1; | |
120 | } else { | |
121 | printf (" FAIL\n"); | |
122 | if ($verbose != 0) { | |
123 | printf (" $errmsg Compiler message:\n"); | |
124 | $printlog = 1; | |
125 | } | |
126 | ++$errors; | |
127 | $result = 1; | |
da1067a9 | 128 | } |
da1067a9 UD |
129 | } else { |
130 | printf (" OK\n"); | |
131 | if ($verbose > 1 && -s "$fnamebase.out") { | |
132 | # We print all warnings issued. | |
133 | $printlog = 1; | |
134 | } | |
135 | } | |
136 | if ($printlog != 0) { | |
137 | printf (" " . "-" x 71 . "\n"); | |
138 | open (MESSAGE, "< $fnamebase.out"); | |
139 | while (<MESSAGE>) { | |
140 | printf (" %s", $_); | |
141 | } | |
142 | close (MESSAGE); | |
143 | printf (" " . "-" x 71 . "\n"); | |
144 | } | |
145 | } | |
146 | unlink "$fnamebase.c"; | |
147 | unlink "$fnamebase.o"; | |
148 | unlink "$fnamebase.out"; | |
149 | ||
150 | $result; | |
151 | } | |
152 | ||
153 | ||
154 | sub runtest | |
155 | { | |
156 | my($fnamebase, $msg, $errmsg, $skip) = @_; | |
157 | my($result) = $skip; | |
158 | my($printlog) = 0; | |
159 | ||
160 | ++$total; | |
161 | printf (" $msg..."); | |
162 | ||
163 | if ($skip != 0) { | |
164 | ++$skipped; | |
165 | printf (" SKIP\n"); | |
166 | } else { | |
ad4f2ebf | 167 | $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1"; |
da1067a9 UD |
168 | if ($ret != 0) { |
169 | printf (" FAIL\n"); | |
170 | if ($verbose != 0) { | |
171 | printf (" $errmsg Compiler message:\n"); | |
172 | $printlog = 1; | |
173 | } | |
174 | ++$errors; | |
175 | $result = 1; | |
176 | } else { | |
177 | # Now run the program. If the exit code is not zero something is wrong. | |
178 | $result = system "$fnamebase > $fnamebase.out2 2>&1"; | |
179 | if ($result == 0) { | |
180 | printf (" OK\n"); | |
181 | if ($verbose > 1 && -s "$fnamebase.out") { | |
182 | # We print all warnings issued. | |
183 | $printlog = 1; | |
184 | system "cat $fnamebase.out2 >> $fnamebase.out"; | |
185 | } | |
186 | } else { | |
187 | printf (" FAIL\n"); | |
020275b5 | 188 | ++$errors; |
da1067a9 UD |
189 | $printlog = 1; |
190 | unlink "$fnamebase.out"; | |
191 | rename "$fnamebase.out2", "$fnamebase.out"; | |
192 | } | |
193 | } | |
194 | if ($printlog != 0) { | |
195 | printf (" " . "-" x 71 . "\n"); | |
196 | open (MESSAGE, "< $fnamebase.out"); | |
197 | while (<MESSAGE>) { | |
198 | printf (" %s", $_); | |
199 | } | |
200 | close (MESSAGE); | |
201 | printf (" " . "-" x 71 . "\n"); | |
202 | } | |
203 | } | |
204 | unlink "$fnamebase"; | |
205 | unlink "$fnamebase.c"; | |
206 | unlink "$fnamebase.o"; | |
207 | unlink "$fnamebase.out"; | |
208 | unlink "$fnamebase.out2"; | |
209 | ||
210 | $result; | |
211 | } | |
212 | ||
213 | ||
214 | sub newtoken { | |
7287c36d | 215 | my($token, @allow) = @_; |
da1067a9 UD |
216 | my($idx); |
217 | ||
7287c36d | 218 | return if ($token =~ /^[0-9_]/ || $iskeyword{$token}); |
8ce9ea0c | 219 | |
da1067a9 | 220 | for ($idx = 0; $idx <= $#allow; ++$idx) { |
7287c36d | 221 | return if (poorfnmatch ($allow[$idx], $token)); |
da1067a9 UD |
222 | } |
223 | ||
7287c36d UD |
224 | if ($isknown{$token}) { |
225 | ++$nknown; | |
226 | } else { | |
227 | ++$nerrors; | |
228 | if ($nerrors == 1) { | |
229 | printf ("FAIL\n " . "-" x 72 . "\n"); | |
230 | } | |
231 | printf (" Namespace violation: \"%s\"\n", $token); | |
da1067a9 | 232 | } |
da1067a9 UD |
233 | } |
234 | ||
235 | ||
236 | sub checknamespace { | |
237 | my($h, $fnamebase, @allow) = @_; | |
da1067a9 UD |
238 | |
239 | ++$total; | |
240 | ||
241 | # Generate a program to get the contents of this header. | |
242 | open (TESTFILE, ">$fnamebase.c"); | |
243 | print TESTFILE "#include <$h>\n"; | |
244 | close (TESTFILE); | |
245 | ||
7287c36d UD |
246 | $nerrors = 0; |
247 | $nknown = 0; | |
ad4f2ebf | 248 | open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |"); |
19533127 UD |
249 | loop: while (<CONTENT>) { |
250 | next loop if (/^#undef /); | |
da1067a9 UD |
251 | chop; |
252 | if (/^#define (.*)/) { | |
7287c36d | 253 | newtoken ($1, @allow); |
da1067a9 UD |
254 | } else { |
255 | # We have to tokenize the line. | |
256 | my($str) = $_; | |
257 | my($index) = 0; | |
258 | my($len) = length ($str); | |
259 | ||
260 | foreach $token (split(/[^a-zA-Z0-9_]/, $str)) { | |
261 | if ($token ne "") { | |
7287c36d | 262 | newtoken ($token, @allow); |
da1067a9 UD |
263 | } |
264 | } | |
265 | } | |
266 | } | |
267 | close (CONTENT); | |
268 | unlink "$fnamebase.c"; | |
269 | if ($nerrors != 0) { | |
270 | printf (" " . "-" x 72 . "\n"); | |
271 | ++$errors; | |
7287c36d UD |
272 | } elsif ($nknown > 0) { |
273 | printf ("EXPECTED FAILURES\n"); | |
274 | ++$known; | |
da1067a9 UD |
275 | } else { |
276 | printf ("OK\n"); | |
277 | } | |
278 | } | |
279 | ||
280 | ||
281 | while ($#headers >= 0) { | |
282 | my($h) = pop (@headers); | |
bba09d23 UD |
283 | my($hf) = $h; |
284 | $hf =~ s|/|-|; | |
285 | my($fnamebase) = "$tmpdir/$hf-test"; | |
da1067a9 UD |
286 | my($missing); |
287 | my(@allow) = (); | |
0ed99ce4 | 288 | my(@allowheader) = (); |
9d48fef0 | 289 | my(%seenheader) = (); |
77faa354 | 290 | my($prepend) = $mustprepend{$h}; |
da1067a9 UD |
291 | |
292 | printf ("Testing <$h>\n"); | |
293 | printf ("----------" . "-" x length ($h) . "\n"); | |
294 | ||
295 | # Generate a program to test for the availability of this header. | |
296 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 297 | print TESTFILE "$prepend"; |
da1067a9 UD |
298 | print TESTFILE "#include <$h>\n"; |
299 | close (TESTFILE); | |
300 | ||
301 | $missing = compiletest ($fnamebase, "Checking whether <$h> is available", | |
2eba94b2 | 302 | "Header <$h> not available", 0, 0); |
da1067a9 UD |
303 | |
304 | printf ("\n"); | |
305 | ||
306 | open (CONTROL, "$CC -E -D$dialect - < data/$h-data |"); | |
307 | control: while (<CONTROL>) { | |
308 | chop; | |
309 | next control if (/^#/); | |
20d49639 | 310 | next control if (/^[ ]*$/); |
da1067a9 | 311 | |
7287c36d | 312 | if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) { |
da1067a9 UD |
313 | my($struct) = "$2$3"; |
314 | my($type) = "$5$6"; | |
315 | my($member) = "$7"; | |
316 | my($rest) = "$8"; | |
317 | my($res) = $missing; | |
318 | ||
319 | # Remember that this name is allowed. | |
320 | push @allow, $member; | |
321 | ||
322 | # Generate a program to test for the availability of this member. | |
323 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 324 | print TESTFILE "$prepend"; |
da1067a9 UD |
325 | print TESTFILE "#include <$h>\n"; |
326 | print TESTFILE "$struct a;\n"; | |
327 | print TESTFILE "$struct b;\n"; | |
328 | print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n"; | |
329 | print TESTFILE "void foobarbaz (void) {\n"; | |
330 | print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n"; | |
331 | print TESTFILE "}\n"; | |
332 | close (TESTFILE); | |
333 | ||
334 | $res = compiletest ($fnamebase, "Testing for member $member", | |
2eba94b2 | 335 | "Member \"$member\" not available.", $res, 0); |
da1067a9 UD |
336 | |
337 | ||
338 | # Test the types of the members. | |
339 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 340 | print TESTFILE "$prepend"; |
da1067a9 UD |
341 | print TESTFILE "#include <$h>\n"; |
342 | print TESTFILE "$struct a;\n"; | |
343 | print TESTFILE "extern $type b$rest;\n"; | |
344 | print TESTFILE "extern __typeof__ (a.$member) b;\n"; | |
345 | close (TESTFILE); | |
346 | ||
347 | compiletest ($fnamebase, "Testing for type of member $member", | |
da238298 UD |
348 | "Member \"$member\" does not have the correct type.", |
349 | $res, 0); | |
350 | } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) { | |
351 | my($struct) = "$2$3"; | |
352 | my($type) = "$5$6"; | |
353 | my($member) = "$7"; | |
354 | my($rest) = "$8"; | |
355 | my($res) = $missing; | |
356 | ||
357 | # Remember that this name is allowed. | |
358 | push @allow, $member; | |
359 | ||
360 | # Generate a program to test for the availability of this member. | |
361 | open (TESTFILE, ">$fnamebase.c"); | |
362 | print TESTFILE "$prepend"; | |
363 | print TESTFILE "#include <$h>\n"; | |
364 | print TESTFILE "$struct a;\n"; | |
365 | print TESTFILE "$struct b;\n"; | |
366 | print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n"; | |
367 | print TESTFILE "void foobarbaz (void) {\n"; | |
368 | print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n"; | |
369 | print TESTFILE "}\n"; | |
370 | close (TESTFILE); | |
371 | ||
372 | $res = compiletest ($fnamebase, "Testing for member $member", | |
373 | "NOT AVAILABLE.", $res, 1); | |
374 | ||
375 | if ($res == 0 || $missing != 0) { | |
376 | # Test the types of the members. | |
377 | open (TESTFILE, ">$fnamebase.c"); | |
378 | print TESTFILE "$prepend"; | |
379 | print TESTFILE "#include <$h>\n"; | |
380 | print TESTFILE "$struct a;\n"; | |
381 | print TESTFILE "extern $type b$rest;\n"; | |
382 | print TESTFILE "extern __typeof__ (a.$member) b;\n"; | |
383 | close (TESTFILE); | |
384 | ||
385 | compiletest ($fnamebase, "Testing for type of member $member", | |
386 | "Member \"$member\" does not have the correct type.", | |
387 | $res, 0); | |
388 | } | |
2eba94b2 UD |
389 | } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) { |
390 | my($const) = $1; | |
391 | my($op) = $2; | |
392 | my($value) = $3; | |
393 | my($res) = $missing; | |
394 | ||
395 | # Remember that this name is allowed. | |
396 | push @allow, $const; | |
397 | ||
398 | # Generate a program to test for the availability of this constant. | |
399 | open (TESTFILE, ">$fnamebase.c"); | |
400 | print TESTFILE "$prepend"; | |
401 | print TESTFILE "#include <$h>\n"; | |
402 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
403 | close (TESTFILE); | |
404 | ||
405 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
406 | "NOT PRESENT", $res, 1); | |
407 | ||
12b64309 | 408 | if ($value ne "" && $res == 0) { |
2eba94b2 UD |
409 | # Generate a program to test for the value of this constant. |
410 | open (TESTFILE, ">$fnamebase.c"); | |
411 | print TESTFILE "$prepend"; | |
412 | print TESTFILE "#include <$h>\n"; | |
413 | # Negate the value since 0 means ok | |
414 | print TESTFILE "int main (void) { return !($const $op $value); }\n"; | |
415 | close (TESTFILE); | |
416 | ||
417 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
418 | "Constant \"$const\" has not the right value.", $res); | |
419 | } | |
12b64309 | 420 | } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) { |
20d49639 AJ |
421 | my($const) = $1; |
422 | my($op) = $2; | |
423 | my($value) = $3; | |
424 | my($res) = $missing; | |
425 | ||
426 | # Remember that this name is allowed. | |
427 | push @allow, $const; | |
428 | ||
429 | # Generate a program to test for the availability of this constant. | |
430 | open (TESTFILE, ">$fnamebase.c"); | |
431 | print TESTFILE "$prepend"; | |
432 | print TESTFILE "#include <$h>\n"; | |
433 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
434 | close (TESTFILE); | |
435 | ||
436 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
2eba94b2 | 437 | "Constant \"$const\" not available.", $res, 0); |
20d49639 AJ |
438 | |
439 | if ($value ne "") { | |
440 | # Generate a program to test for the value of this constant. | |
441 | open (TESTFILE, ">$fnamebase.c"); | |
442 | print TESTFILE "$prepend"; | |
443 | print TESTFILE "#include <$h>\n"; | |
444 | # Negate the value since 0 means ok | |
445 | print TESTFILE "int main (void) { return !($const $op $value); }\n"; | |
446 | close (TESTFILE); | |
447 | ||
448 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
449 | "Constant \"$const\" has not the right value.", $res); | |
450 | } | |
451 | } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) { | |
452 | my($const) = $1; | |
453 | my($type) = "$3$4"; | |
454 | my($value) = $5; | |
455 | my($res) = $missing; | |
456 | ||
457 | # Remember that this name is allowed. | |
458 | push @allow, $const; | |
459 | ||
460 | # Generate a program to test for the availability of this constant. | |
461 | open (TESTFILE, ">$fnamebase.c"); | |
462 | print TESTFILE "$prepend"; | |
463 | print TESTFILE "#include <$h>\n"; | |
464 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
465 | close (TESTFILE); | |
466 | ||
467 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
2eba94b2 | 468 | "Constant \"$const\" not available.", $res, 0); |
20d49639 AJ |
469 | |
470 | # Test the types of the members. | |
471 | open (TESTFILE, ">$fnamebase.c"); | |
472 | print TESTFILE "$prepend"; | |
473 | print TESTFILE "#include <$h>\n"; | |
474 | print TESTFILE "__typeof__ (($type) 0) a;\n"; | |
475 | print TESTFILE "extern __typeof__ ($const) a;\n"; | |
476 | close (TESTFILE); | |
477 | ||
478 | compiletest ($fnamebase, "Testing for type of constant $const", | |
479 | "Constant \"$const\" does not have the correct type.", | |
2eba94b2 UD |
480 | $res, 0); |
481 | ||
482 | if ($value ne "") { | |
483 | # Generate a program to test for the value of this constant. | |
484 | open (TESTFILE, ">$fnamebase.c"); | |
485 | print TESTFILE "$prepend"; | |
486 | print TESTFILE "#include <$h>\n"; | |
487 | print TESTFILE "int main (void) { return $const != $value; }\n"; | |
488 | close (TESTFILE); | |
489 | ||
490 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
491 | "Constant \"$const\" has not the right value.", $res); | |
492 | } | |
493 | } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) { | |
494 | my($const) = $1; | |
495 | my($value) = $2; | |
496 | my($res) = $missing; | |
497 | ||
498 | # Remember that this name is allowed. | |
499 | push @allow, $const; | |
500 | ||
501 | # Generate a program to test for the availability of this constant. | |
502 | open (TESTFILE, ">$fnamebase.c"); | |
503 | print TESTFILE "$prepend"; | |
504 | print TESTFILE "#include <$h>\n"; | |
505 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
506 | close (TESTFILE); | |
507 | ||
508 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
509 | "NOT PRESENT", $res, 1); | |
20d49639 | 510 | |
12b64309 | 511 | if ($value ne "" && $res == 0) { |
20d49639 AJ |
512 | # Generate a program to test for the value of this constant. |
513 | open (TESTFILE, ">$fnamebase.c"); | |
514 | print TESTFILE "$prepend"; | |
515 | print TESTFILE "#include <$h>\n"; | |
516 | print TESTFILE "int main (void) { return $const != $value; }\n"; | |
517 | close (TESTFILE); | |
518 | ||
519 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
520 | "Constant \"$const\" has not the right value.", $res); | |
521 | } | |
da1067a9 UD |
522 | } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) { |
523 | my($const) = $1; | |
524 | my($value) = $2; | |
525 | my($res) = $missing; | |
526 | ||
527 | # Remember that this name is allowed. | |
528 | push @allow, $const; | |
529 | ||
530 | # Generate a program to test for the availability of this constant. | |
531 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 532 | print TESTFILE "$prepend"; |
da1067a9 UD |
533 | print TESTFILE "#include <$h>\n"; |
534 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
535 | close (TESTFILE); | |
536 | ||
537 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
2eba94b2 | 538 | "Constant \"$const\" not available.", $res, 0); |
da1067a9 | 539 | |
8ce9ea0c UD |
540 | if ($value ne "") { |
541 | # Generate a program to test for the value of this constant. | |
542 | open (TESTFILE, ">$fnamebase.c"); | |
543 | print TESTFILE "$prepend"; | |
544 | print TESTFILE "#include <$h>\n"; | |
545 | print TESTFILE "int main (void) { return $const != $value; }\n"; | |
546 | close (TESTFILE); | |
547 | ||
548 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
549 | "Constant \"$const\" has not the right value.", $res); | |
550 | } | |
257abbe2 UD |
551 | } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) { |
552 | my($symbol) = $1; | |
553 | my($value) = $2; | |
554 | my($res) = $missing; | |
555 | ||
556 | # Remember that this name is allowed. | |
557 | push @allow, $symbol; | |
558 | ||
559 | # Generate a program to test for the availability of this constant. | |
560 | open (TESTFILE, ">$fnamebase.c"); | |
561 | print TESTFILE "$prepend"; | |
562 | print TESTFILE "#include <$h>\n"; | |
563 | print TESTFILE "void foobarbaz (void) {\n"; | |
564 | print TESTFILE "__typeof__ ($symbol) a = $symbol;\n"; | |
565 | print TESTFILE "}\n"; | |
566 | close (TESTFILE); | |
567 | ||
568 | $res = compiletest ($fnamebase, "Testing for symbol $symbol", | |
569 | "Symbol \"$symbol\" not available.", $res, 0); | |
570 | ||
571 | if ($value ne "") { | |
572 | # Generate a program to test for the value of this constant. | |
573 | open (TESTFILE, ">$fnamebase.c"); | |
574 | print TESTFILE "$prepend"; | |
575 | print TESTFILE "#include <$h>\n"; | |
576 | print TESTFILE "int main (void) { return $symbol != $value; }\n"; | |
577 | close (TESTFILE); | |
578 | ||
579 | $res = runtest ($fnamebase, "Testing for value of symbol $symbol", | |
580 | "Symbol \"$symbol\" has not the right value.", $res); | |
581 | } | |
8ce9ea0c UD |
582 | } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) { |
583 | my($const) = $1; | |
584 | my($type) = "$3$4"; | |
585 | my($value) = $5; | |
586 | my($res) = $missing; | |
587 | ||
588 | # Remember that this name is allowed. | |
589 | push @allow, $const; | |
590 | ||
591 | # Generate a program to test for the availability of this constant. | |
592 | open (TESTFILE, ">$fnamebase.c"); | |
593 | print TESTFILE "$prepend"; | |
594 | print TESTFILE "#include <$h>\n"; | |
595 | print TESTFILE "__typeof__ ($const) a = $const;\n"; | |
596 | close (TESTFILE); | |
597 | ||
598 | $res = compiletest ($fnamebase, "Testing for constant $const", | |
2eba94b2 | 599 | "Constant \"$const\" not available.", $res, 0); |
8ce9ea0c UD |
600 | |
601 | # Test the types of the members. | |
602 | open (TESTFILE, ">$fnamebase.c"); | |
603 | print TESTFILE "$prepend"; | |
604 | print TESTFILE "#include <$h>\n"; | |
605 | print TESTFILE "__typeof__ (($type) 0) a;\n"; | |
606 | print TESTFILE "extern __typeof__ ($const) a;\n"; | |
607 | close (TESTFILE); | |
608 | ||
609 | compiletest ($fnamebase, "Testing for type of constant $const", | |
610 | "Constant \"$const\" does not have the correct type.", | |
2eba94b2 | 611 | $res, 0); |
8ce9ea0c | 612 | |
da1067a9 UD |
613 | if ($value ne "") { |
614 | # Generate a program to test for the value of this constant. | |
615 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 616 | print TESTFILE "$prepend"; |
da1067a9 UD |
617 | print TESTFILE "#include <$h>\n"; |
618 | print TESTFILE "int main (void) { return $const != $value; }\n"; | |
619 | close (TESTFILE); | |
620 | ||
621 | $res = runtest ($fnamebase, "Testing for value of constant $const", | |
622 | "Constant \"$const\" has not the right value.", $res); | |
623 | } | |
ccd4b479 UD |
624 | } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) { |
625 | my($type) = "$2$3"; | |
2ff458eb | 626 | my($maybe_opaque) = 0; |
ccd4b479 UD |
627 | |
628 | # Remember that this name is allowed. | |
629 | if ($type =~ /^struct *(.*)/) { | |
630 | push @allow, $1; | |
631 | } elsif ($type =~ /^union *(.*)/) { | |
632 | push @allow, $1; | |
633 | } else { | |
634 | push @allow, $type; | |
2ff458eb | 635 | $maybe_opaque = 1; |
ccd4b479 UD |
636 | } |
637 | ||
638 | # Remember that this name is allowed. | |
639 | push @allow, $type; | |
640 | ||
641 | # Generate a program to test for the availability of this constant. | |
642 | open (TESTFILE, ">$fnamebase.c"); | |
643 | print TESTFILE "$prepend"; | |
644 | print TESTFILE "#include <$h>\n"; | |
2ff458eb UD |
645 | if ($maybe_opaque == 1) { |
646 | print TESTFILE "$type *a;\n"; | |
647 | } else { | |
648 | print TESTFILE "$type a;\n"; | |
649 | } | |
ccd4b479 UD |
650 | close (TESTFILE); |
651 | ||
652 | compiletest ($fnamebase, "Testing for type $type", | |
2ff458eb | 653 | "NOT AVAILABLE", $missing, 1); |
da1067a9 UD |
654 | } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) { |
655 | my($type) = "$2$3"; | |
2ff458eb | 656 | my($maybe_opaque) = 0; |
da1067a9 UD |
657 | |
658 | # Remember that this name is allowed. | |
659 | if ($type =~ /^struct *(.*)/) { | |
660 | push @allow, $1; | |
661 | } elsif ($type =~ /^union *(.*)/) { | |
662 | push @allow, $1; | |
663 | } else { | |
664 | push @allow, $type; | |
2ff458eb | 665 | $maybe_opaque = 1; |
da1067a9 UD |
666 | } |
667 | ||
668 | # Remember that this name is allowed. | |
669 | push @allow, $type; | |
670 | ||
3bf3d361 | 671 | # Generate a program to test for the availability of this type. |
da1067a9 | 672 | open (TESTFILE, ">$fnamebase.c"); |
5d916713 | 673 | print TESTFILE "$prepend"; |
da1067a9 | 674 | print TESTFILE "#include <$h>\n"; |
2ff458eb UD |
675 | if ($maybe_opaque == 1) { |
676 | print TESTFILE "$type *a;\n"; | |
677 | } else { | |
678 | print TESTFILE "$type a;\n"; | |
679 | } | |
da1067a9 UD |
680 | close (TESTFILE); |
681 | ||
682 | compiletest ($fnamebase, "Testing for type $type", | |
2eba94b2 | 683 | "Type \"$type\" not available.", $missing, 0); |
2ff458eb UD |
684 | } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) { |
685 | my($rettype) = "$2$3"; | |
686 | my($fname) = "$4"; | |
687 | my($args) = "$5"; | |
688 | my($res) = $missing; | |
689 | ||
690 | # Remember that this name is allowed. | |
691 | push @allow, $fname; | |
692 | ||
693 | # Generate a program to test for availability of this function. | |
694 | open (TESTFILE, ">$fnamebase.c"); | |
695 | print TESTFILE "$prepend"; | |
696 | print TESTFILE "#include <$h>\n"; | |
697 | # print TESTFILE "#undef $fname\n"; | |
698 | print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n"; | |
699 | close (TESTFILE); | |
700 | ||
701 | $res = compiletest ($fnamebase, "Test availability of function $fname", | |
702 | "NOT AVAILABLE", $res, 1); | |
703 | ||
704 | if ($res == 0 || $missing == 1) { | |
705 | # Generate a program to test for the type of this function. | |
706 | open (TESTFILE, ">$fnamebase.c"); | |
707 | print TESTFILE "$prepend"; | |
708 | print TESTFILE "#include <$h>\n"; | |
709 | # print TESTFILE "#undef $fname\n"; | |
710 | print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n"; | |
711 | print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n"; | |
712 | close (TESTFILE); | |
713 | ||
714 | compiletest ($fnamebase, "Test for type of function $fname", | |
715 | "Function \"$fname\" has incorrect type.", $res, 0); | |
716 | } | |
8ce9ea0c UD |
717 | } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) { |
718 | my($rettype) = "$2$3"; | |
719 | my($fname) = "$4"; | |
720 | my($args) = "$5"; | |
721 | my($res) = $missing; | |
722 | ||
723 | # Remember that this name is allowed. | |
724 | push @allow, $fname; | |
725 | ||
726 | # Generate a program to test for availability of this function. | |
727 | open (TESTFILE, ">$fnamebase.c"); | |
728 | print TESTFILE "$prepend"; | |
729 | print TESTFILE "#include <$h>\n"; | |
730 | # print TESTFILE "#undef $fname\n"; | |
731 | print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n"; | |
732 | close (TESTFILE); | |
733 | ||
734 | $res = compiletest ($fnamebase, "Test availability of function $fname", | |
2eba94b2 | 735 | "Function \"$fname\" is not available.", $res, 0); |
8ce9ea0c UD |
736 | |
737 | # Generate a program to test for the type of this function. | |
738 | open (TESTFILE, ">$fnamebase.c"); | |
739 | print TESTFILE "$prepend"; | |
740 | print TESTFILE "#include <$h>\n"; | |
741 | # print TESTFILE "#undef $fname\n"; | |
742 | print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n"; | |
743 | print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n"; | |
744 | close (TESTFILE); | |
745 | ||
746 | compiletest ($fnamebase, "Test for type of function $fname", | |
2eba94b2 | 747 | "Function \"$fname\" has incorrect type.", $res, 0); |
2ff458eb UD |
748 | } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { |
749 | my($rettype) = "$2$3"; | |
750 | my($fname) = "$4"; | |
751 | my($args) = "$5"; | |
752 | my($res) = $missing; | |
753 | ||
754 | # Remember that this name is allowed. | |
755 | push @allow, $fname; | |
756 | ||
757 | # Generate a program to test for availability of this function. | |
758 | open (TESTFILE, ">$fnamebase.c"); | |
759 | print TESTFILE "$prepend"; | |
760 | print TESTFILE "#include <$h>\n"; | |
761 | # print TESTFILE "#undef $fname\n"; | |
762 | print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n"; | |
763 | close (TESTFILE); | |
764 | ||
765 | $res = compiletest ($fnamebase, "Test availability of function $fname", | |
766 | "NOT AVAILABLE", $res, 1); | |
767 | ||
768 | if ($res == 0 || $missing != 0) { | |
769 | # Generate a program to test for the type of this function. | |
770 | open (TESTFILE, ">$fnamebase.c"); | |
771 | print TESTFILE "$prepend"; | |
772 | print TESTFILE "#include <$h>\n"; | |
773 | # print TESTFILE "#undef $fname\n"; | |
774 | print TESTFILE "extern $rettype (*foobarbaz) $args;\n"; | |
775 | print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n"; | |
776 | close (TESTFILE); | |
777 | ||
778 | compiletest ($fnamebase, "Test for type of function $fname", | |
779 | "Function \"$fname\" has incorrect type.", $res, 0); | |
780 | } | |
8ce9ea0c | 781 | } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { |
da1067a9 UD |
782 | my($rettype) = "$2$3"; |
783 | my($fname) = "$4"; | |
784 | my($args) = "$5"; | |
785 | my($res) = $missing; | |
786 | ||
787 | # Remember that this name is allowed. | |
788 | push @allow, $fname; | |
789 | ||
790 | # Generate a program to test for availability of this function. | |
791 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 792 | print TESTFILE "$prepend"; |
da1067a9 | 793 | print TESTFILE "#include <$h>\n"; |
52cf7d34 | 794 | # print TESTFILE "#undef $fname\n"; |
da1067a9 UD |
795 | print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n"; |
796 | close (TESTFILE); | |
797 | ||
798 | $res = compiletest ($fnamebase, "Test availability of function $fname", | |
2eba94b2 | 799 | "Function \"$fname\" is not available.", $res, 0); |
da1067a9 UD |
800 | |
801 | # Generate a program to test for the type of this function. | |
802 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 803 | print TESTFILE "$prepend"; |
da1067a9 | 804 | print TESTFILE "#include <$h>\n"; |
52cf7d34 | 805 | # print TESTFILE "#undef $fname\n"; |
da1067a9 UD |
806 | print TESTFILE "extern $rettype (*foobarbaz) $args;\n"; |
807 | print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n"; | |
808 | close (TESTFILE); | |
809 | ||
8ce9ea0c | 810 | compiletest ($fnamebase, "Test for type of function $fname", |
2eba94b2 | 811 | "Function \"$fname\" has incorrect type.", $res, 0); |
73b6bffc | 812 | } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) { |
8ce9ea0c UD |
813 | my($type) = "$2$3"; |
814 | my($vname) = "$4"; | |
73b6bffc | 815 | my($rest) = "$5"; |
8ce9ea0c UD |
816 | my($res) = $missing; |
817 | ||
818 | # Remember that this name is allowed. | |
819 | push @allow, $vname; | |
820 | ||
821 | # Generate a program to test for availability of this function. | |
822 | open (TESTFILE, ">$fnamebase.c"); | |
823 | print TESTFILE "$prepend"; | |
824 | print TESTFILE "#include <$h>\n"; | |
825 | # print TESTFILE "#undef $fname\n"; | |
73b6bffc UD |
826 | print TESTFILE "typedef $type xyzzy$rest;\n"; |
827 | print TESTFILE "$xyzzy *foobarbaz = &$vname;\n"; | |
8ce9ea0c UD |
828 | close (TESTFILE); |
829 | ||
830 | $res = compiletest ($fnamebase, "Test availability of variable $vname", | |
2eba94b2 | 831 | "Variable \"$vname\" is not available.", $res, 0); |
8ce9ea0c UD |
832 | |
833 | # Generate a program to test for the type of this function. | |
834 | open (TESTFILE, ">$fnamebase.c"); | |
835 | print TESTFILE "$prepend"; | |
836 | print TESTFILE "#include <$h>\n"; | |
837 | # print TESTFILE "#undef $fname\n"; | |
73b6bffc | 838 | print TESTFILE "extern $type $vname$rest;\n"; |
8ce9ea0c UD |
839 | close (TESTFILE); |
840 | ||
841 | compiletest ($fnamebase, "Test for type of variable $fname", | |
2eba94b2 | 842 | "Variable \"$vname\" has incorrect type.", $res, 0); |
8ce9ea0c UD |
843 | } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { |
844 | my($rettype) = "$2$3"; | |
845 | my($fname) = "$4"; | |
846 | my($args) = "$5"; | |
847 | my($res) = $missing; | |
848 | ||
849 | # Remember that this name is allowed. | |
850 | push @allow, $fname; | |
851 | ||
852 | # Generate a program to test for availability of this function. | |
853 | open (TESTFILE, ">$fnamebase.c"); | |
854 | print TESTFILE "$prepend"; | |
855 | print TESTFILE "#include <$h>\n"; | |
856 | print TESTFILE "#ifndef $fname\n"; | |
857 | print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n"; | |
858 | print TESTFILE "#endif\n"; | |
859 | close (TESTFILE); | |
860 | ||
861 | $res = compiletest ($fnamebase, "Test availability of function $fname", | |
2eba94b2 | 862 | "Function \"$fname\" is not available.", $res, 0); |
8ce9ea0c UD |
863 | |
864 | # Generate a program to test for the type of this function. | |
865 | open (TESTFILE, ">$fnamebase.c"); | |
866 | print TESTFILE "$prepend"; | |
867 | print TESTFILE "#include <$h>\n"; | |
868 | print TESTFILE "#ifndef $fname\n"; | |
869 | print TESTFILE "extern $rettype (*foobarbaz) $args;\n"; | |
870 | print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n"; | |
871 | print TESTFILE "#endif\n"; | |
872 | close (TESTFILE); | |
873 | ||
da1067a9 | 874 | compiletest ($fnamebase, "Test for type of function $fname", |
2eba94b2 | 875 | "Function \"$fname\" has incorrect type.", $res, 0); |
7cc9fcf4 | 876 | } elsif (/^macro-str *([^ ]*) *(\".*\")/) { |
20d49639 AJ |
877 | # The above regex doesn't handle a \" in a string. |
878 | my($macro) = "$1"; | |
879 | my($string) = "$2"; | |
880 | my($res) = $missing; | |
881 | ||
882 | # Remember that this name is allowed. | |
883 | push @allow, $macro; | |
884 | ||
885 | # Generate a program to test for availability of this macro. | |
886 | open (TESTFILE, ">$fnamebase.c"); | |
887 | print TESTFILE "$prepend"; | |
888 | print TESTFILE "#include <$h>\n"; | |
889 | print TESTFILE "#ifndef $macro\n"; | |
890 | print TESTFILE "# error \"Macro $macro not defined\"\n"; | |
891 | print TESTFILE "#endif\n"; | |
892 | close (TESTFILE); | |
893 | ||
894 | compiletest ($fnamebase, "Test availability of macro $macro", | |
2eba94b2 | 895 | "Macro \"$macro\" is not available.", $missing, 0); |
20d49639 AJ |
896 | |
897 | # Generate a program to test for the value of this macro. | |
898 | open (TESTFILE, ">$fnamebase.c"); | |
899 | print TESTFILE "$prepend"; | |
900 | print TESTFILE "#include <$h>\n"; | |
901 | # We can't include <string.h> here. | |
902 | print TESTFILE "extern int (strcmp)(const char *, const char *);\n"; | |
7cc9fcf4 | 903 | print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n"; |
20d49639 AJ |
904 | close (TESTFILE); |
905 | ||
906 | $res = runtest ($fnamebase, "Testing for value of macro $macro", | |
907 | "Macro \"$macro\" has not the right value.", $res); | |
12b64309 UD |
908 | } elsif (/^optional-macro *([^ ]*)/) { |
909 | my($macro) = "$1"; | |
910 | ||
911 | # Remember that this name is allowed. | |
912 | push @allow, $macro; | |
913 | ||
914 | # Generate a program to test for availability of this macro. | |
915 | open (TESTFILE, ">$fnamebase.c"); | |
916 | print TESTFILE "$prepend"; | |
917 | print TESTFILE "#include <$h>\n"; | |
918 | print TESTFILE "#ifndef $macro\n"; | |
919 | print TESTFILE "# error \"Macro $macro not defined\"\n"; | |
920 | print TESTFILE "#endif\n"; | |
921 | close (TESTFILE); | |
922 | ||
923 | compiletest ($fnamebase, "Test availability of macro $macro", | |
924 | "NOT PRESENT", $missing, 1); | |
925 | } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) { | |
926 | my($macro) = "$1"; | |
927 | my($op) = $2; | |
928 | my($value) = $3; | |
929 | my($res) = $missing; | |
930 | ||
931 | # Remember that this name is allowed. | |
932 | push @allow, $macro; | |
933 | ||
934 | # Generate a program to test for availability of this macro. | |
935 | open (TESTFILE, ">$fnamebase.c"); | |
936 | print TESTFILE "$prepend"; | |
937 | print TESTFILE "#include <$h>\n"; | |
938 | print TESTFILE "#ifndef $macro\n"; | |
939 | print TESTFILE "# error \"Macro $macro not defined\"\n"; | |
940 | print TESTFILE "#endif\n"; | |
941 | close (TESTFILE); | |
942 | ||
943 | $res = compiletest ($fnamebase, "Test availability of macro $macro", | |
944 | "Macro \"$macro\" is not available.", $res, 0); | |
945 | ||
946 | if ($value ne "") { | |
947 | # Generate a program to test for the value of this constant. | |
948 | open (TESTFILE, ">$fnamebase.c"); | |
949 | print TESTFILE "$prepend"; | |
950 | print TESTFILE "#include <$h>\n"; | |
951 | # Negate the value since 0 means ok | |
952 | print TESTFILE "int main (void) { return !($macro $op $value); }\n"; | |
953 | close (TESTFILE); | |
954 | ||
955 | $res = runtest ($fnamebase, "Testing for value of constant $macro", | |
956 | "Macro \"$macro\" has not the right value.", $res); | |
957 | } | |
20d49639 | 958 | } elsif (/^macro *([^ ]*)/) { |
da1067a9 UD |
959 | my($macro) = "$1"; |
960 | ||
961 | # Remember that this name is allowed. | |
962 | push @allow, $macro; | |
963 | ||
964 | # Generate a program to test for availability of this macro. | |
965 | open (TESTFILE, ">$fnamebase.c"); | |
77faa354 | 966 | print TESTFILE "$prepend"; |
da1067a9 UD |
967 | print TESTFILE "#include <$h>\n"; |
968 | print TESTFILE "#ifndef $macro\n"; | |
969 | print TESTFILE "# error \"Macro $macro not defined\"\n"; | |
970 | print TESTFILE "#endif\n"; | |
971 | close (TESTFILE); | |
972 | ||
973 | compiletest ($fnamebase, "Test availability of macro $macro", | |
2eba94b2 | 974 | "Macro \"$macro\" is not available.", $missing, 0); |
0ed99ce4 UD |
975 | } elsif (/^allow-header *(.*)/) { |
976 | my($pattern) = $1; | |
9d48fef0 UD |
977 | if ($seenheader{$pattern} != 1) { |
978 | push @allowheader, $pattern; | |
979 | $seenheader{$pattern} = 1; | |
980 | } | |
0ed99ce4 | 981 | next control; |
d753ffef UD |
982 | } elsif (/^allow *(.*)/) { |
983 | my($pattern) = $1; | |
984 | push @allow, $pattern; | |
985 | next control; | |
da1067a9 UD |
986 | } else { |
987 | # printf ("line is `%s'\n", $_); | |
988 | next control; | |
989 | } | |
990 | ||
991 | printf ("\n"); | |
992 | } | |
993 | close (CONTROL); | |
994 | ||
0ed99ce4 UD |
995 | # Read the data files for the header files which are allowed to be included. |
996 | while ($#allowheader >= 0) { | |
997 | my($ah) = pop @allowheader; | |
998 | ||
999 | open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |"); | |
1000 | acontrol: while (<ALLOW>) { | |
1001 | next acontrol if (/^#/); | |
20d49639 | 1002 | next acontrol if (/^[ ]*$/); |
0ed99ce4 UD |
1003 | |
1004 | if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) { | |
1005 | push @allow, $7; | |
1006 | } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) { | |
1007 | push @allow, $1; | |
1008 | } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) { | |
1009 | push @allow, 1; | |
1010 | } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) { | |
1011 | my($type) = "$2$3"; | |
1012 | ||
1013 | # Remember that this name is allowed. | |
1014 | if ($type =~ /^struct *(.*)/) { | |
1015 | push @allow, $1; | |
1016 | } elsif ($type =~ /^union *(.*)/) { | |
1017 | push @allow, $1; | |
1018 | } else { | |
1019 | push @allow, $type; | |
1020 | } | |
1021 | } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) { | |
1022 | push @allow, $4; | |
1023 | } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { | |
1024 | push @allow, $4; | |
1025 | } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) { | |
1026 | push @allow, $4; | |
1027 | } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { | |
1028 | push @allow, $4; | |
20d49639 | 1029 | } elsif (/^macro *([^ ]*)/) { |
0ed99ce4 | 1030 | push @allow, $1; |
0ed99ce4 | 1031 | } elsif (/^allow-header *(.*)/) { |
9d48fef0 UD |
1032 | if ($seenheader{$1} != 1) { |
1033 | push @allowheader, $1; | |
1034 | $seenheader{$1} = 1; | |
1035 | } | |
bec7805d UD |
1036 | } elsif (/^allow *(.*)/) { |
1037 | push @allow, $1; | |
0ed99ce4 UD |
1038 | } |
1039 | } | |
1040 | close (ALLOW); | |
1041 | } | |
1042 | ||
da1067a9 UD |
1043 | # Now check the namespace. |
1044 | printf (" Checking the namespace of \"%s\"... ", $h); | |
1045 | if ($missing) { | |
1046 | ++$skipped; | |
1047 | printf ("SKIP\n"); | |
1048 | } else { | |
1049 | checknamespace ($h, $fnamebase, @allow); | |
1050 | } | |
1051 | ||
1052 | printf ("\n\n"); | |
1053 | } | |
1054 | ||
1055 | printf "-" x 76 . "\n"; | |
7287c36d UD |
1056 | printf (" Total number of tests : %4d\n", $total); |
1057 | ||
1058 | printf (" Number of known failures: %4d (", $known); | |
1059 | $percent = ($known * 100) / $total; | |
6b3e8333 | 1060 | if ($known > 0 && $percent < 1.0) { |
7287c36d UD |
1061 | printf (" <1%%)\n"); |
1062 | } else { | |
1063 | printf ("%3d%%)\n", $percent); | |
1064 | } | |
1065 | ||
1066 | printf (" Number of failed tests : %4d (", $errors); | |
1067 | $percent = ($errors * 100) / $total; | |
6b3e8333 | 1068 | if ($errors > 0 && $percent < 1.0) { |
7287c36d UD |
1069 | printf (" <1%%)\n"); |
1070 | } else { | |
1071 | printf ("%3d%%)\n", $percent); | |
1072 | } | |
1073 | ||
1074 | printf (" Number of skipped tests : %4d (", $skipped); | |
1075 | $percent = ($skipped * 100) / $total; | |
6b3e8333 | 1076 | if ($skipped > 0 && $percent < 1.0) { |
7287c36d UD |
1077 | printf (" <1%%)\n"); |
1078 | } else { | |
1079 | printf ("%3d%%)\n", $percent); | |
1080 | } | |
da1067a9 UD |
1081 | |
1082 | exit $errors != 0; |