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