(Normalization Functions): Remove duplicated description of logb.
[glibc.git] / conform / conformtest.pl
blob5ae1cea45a5f7eb60851df7c7708f08863c17a3f
1 #! /usr/bin/perl
3 use Getopt::Long;
5 $CC = "gcc";
7 $dialect="XOPEN2K";
8 GetOptions ('headers=s' => \@headers, 'dialect=s' => \$dialect);
9 @headers = split(/,/,join(',',@headers));
11 # List of the headers we are testing.
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",
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");
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\"";
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";
45 # These are the ISO C99 keywords.
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');
52 # These are symbols which are known to pollute the namespace.
53 @knownproblems = ('unix', 'linux', 'i386');
55 # Some headers need a bit more attention.
56 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
57 $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
58 $mustprepend{'signal.h'} = "#include <pthread.h>\n";
59 $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
60 $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
61 $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
63 # Make a hash table from this information.
64 while ($#keywords >= 0) {
65 $iskeyword{pop (@keywords)} = 1;
68 # Make a hash table from the known problems.
69 while ($#knownproblems >= 0) {
70 $isknown{pop (@knownproblems)} = 1;
73 $tmpdir = "/tmp";
75 $verbose = 1;
77 $total = 0;
78 $skipped = 0;
79 $errors = 0;
82 sub poorfnmatch {
83 my($pattern, $string) = @_;
84 my($strlen) = length ($string);
85 my($res);
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;
98 return $res;
102 sub compiletest
104 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
105 my($result) = $skip;
106 my($printlog) = 0;
108 ++$total;
109 printf (" $msg...");
111 if ($skip != 0) {
112 ++$skipped;
113 printf (" SKIP\n");
114 } else {
115 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
116 if ($ret != 0) {
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;
126 ++$errors;
127 $result = 1;
129 } else {
130 printf (" OK\n");
131 if ($verbose > 1 && -s "$fnamebase.out") {
132 # We print all warnings issued.
133 $printlog = 1;
136 if ($printlog != 0) {
137 printf (" " . "-" x 71 . "\n");
138 open (MESSAGE, "< $fnamebase.out");
139 while (<MESSAGE>) {
140 printf (" %s", $_);
142 close (MESSAGE);
143 printf (" " . "-" x 71 . "\n");
146 unlink "$fnamebase.c";
147 unlink "$fnamebase.o";
148 unlink "$fnamebase.out";
150 $result;
154 sub runtest
156 my($fnamebase, $msg, $errmsg, $skip) = @_;
157 my($result) = $skip;
158 my($printlog) = 0;
160 ++$total;
161 printf (" $msg...");
163 if ($skip != 0) {
164 ++$skipped;
165 printf (" SKIP\n");
166 } else {
167 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
168 if ($ret != 0) {
169 printf (" FAIL\n");
170 if ($verbose != 0) {
171 printf (" $errmsg Compiler message:\n");
172 $printlog = 1;
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";
186 } else {
187 printf (" FAIL\n");
188 ++$errors;
189 $printlog = 1;
190 unlink "$fnamebase.out";
191 rename "$fnamebase.out2", "$fnamebase.out";
194 if ($printlog != 0) {
195 printf (" " . "-" x 71 . "\n");
196 open (MESSAGE, "< $fnamebase.out");
197 while (<MESSAGE>) {
198 printf (" %s", $_);
200 close (MESSAGE);
201 printf (" " . "-" x 71 . "\n");
204 unlink "$fnamebase";
205 unlink "$fnamebase.c";
206 unlink "$fnamebase.o";
207 unlink "$fnamebase.out";
208 unlink "$fnamebase.out2";
210 $result;
214 sub newtoken {
215 my($token, @allow) = @_;
216 my($idx);
218 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
220 for ($idx = 0; $idx <= $#allow; ++$idx) {
221 return if (poorfnmatch ($allow[$idx], $token));
224 if ($isknown{$token}) {
225 ++$nknown;
226 } else {
227 ++$nerrors;
228 if ($nerrors == 1) {
229 printf ("FAIL\n " . "-" x 72 . "\n");
231 printf (" Namespace violation: \"%s\"\n", $token);
236 sub checknamespace {
237 my($h, $fnamebase, @allow) = @_;
239 ++$total;
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);
246 $nerrors = 0;
247 $nknown = 0;
248 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
249 loop: while (<CONTENT>) {
250 next loop if (/^#undef /);
251 chop;
252 if (/^#define (.*)/) {
253 newtoken ($1, @allow);
254 } else {
255 # We have to tokenize the line.
256 my($str) = $_;
257 my($index) = 0;
258 my($len) = length ($str);
260 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
261 if ($token ne "") {
262 newtoken ($token, @allow);
267 close (CONTENT);
268 unlink "$fnamebase.c";
269 if ($nerrors != 0) {
270 printf (" " . "-" x 72 . "\n");
271 ++$errors;
272 } elsif ($nknown > 0) {
273 printf ("EXPECTED FAILURES\n");
274 ++$known;
275 } else {
276 printf ("OK\n");
281 while ($#headers >= 0) {
282 my($h) = pop (@headers);
283 my($hf) = $h;
284 $hf =~ s|/|-|;
285 my($fnamebase) = "$tmpdir/$hf-test";
286 my($missing);
287 my(@allow) = ();
288 my(@allowheader) = ();
289 my(%seenheader) = ();
290 my($prepend) = $mustprepend{$h};
292 printf ("Testing <$h>\n");
293 printf ("----------" . "-" x length ($h) . "\n");
295 # Generate a program to test for the availability of this header.
296 open (TESTFILE, ">$fnamebase.c");
297 print TESTFILE "$prepend";
298 print TESTFILE "#include <$h>\n";
299 close (TESTFILE);
301 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
302 "Header <$h> not available", 0, 0);
304 printf ("\n");
306 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
307 control: while (<CONTROL>) {
308 chop;
309 next control if (/^#/);
310 next control if (/^[ ]*$/);
312 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
313 my($struct) = "$2$3";
314 my($type) = "$5$6";
315 my($member) = "$7";
316 my($rest) = "$8";
317 my($res) = $missing;
319 # Remember that this name is allowed.
320 push @allow, $member;
322 # Generate a program to test for the availability of this member.
323 open (TESTFILE, ">$fnamebase.c");
324 print TESTFILE "$prepend";
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);
334 $res = compiletest ($fnamebase, "Testing for member $member",
335 "Member \"$member\" not available.", $res, 0);
338 # Test the types of the members.
339 open (TESTFILE, ">$fnamebase.c");
340 print TESTFILE "$prepend";
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);
347 compiletest ($fnamebase, "Testing for type of member $member",
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;
357 # Remember that this name is allowed.
358 push @allow, $member;
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);
372 $res = compiletest ($fnamebase, "Testing for member $member",
373 "NOT AVAILABLE.", $res, 1);
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);
385 compiletest ($fnamebase, "Testing for type of member $member",
386 "Member \"$member\" does not have the correct type.",
387 $res, 0);
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;
395 # Remember that this name is allowed.
396 push @allow, $const;
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);
405 $res = compiletest ($fnamebase, "Testing for constant $const",
406 "NOT PRESENT", $res, 1);
408 if ($value ne "" && $res == 0) {
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);
417 $res = runtest ($fnamebase, "Testing for value of constant $const",
418 "Constant \"$const\" has not the right value.", $res);
420 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
421 my($const) = $1;
422 my($op) = $2;
423 my($value) = $3;
424 my($res) = $missing;
426 # Remember that this name is allowed.
427 push @allow, $const;
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);
436 $res = compiletest ($fnamebase, "Testing for constant $const",
437 "Constant \"$const\" not available.", $res, 0);
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);
448 $res = runtest ($fnamebase, "Testing for value of constant $const",
449 "Constant \"$const\" has not the right value.", $res);
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;
457 # Remember that this name is allowed.
458 push @allow, $const;
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);
467 $res = compiletest ($fnamebase, "Testing for constant $const",
468 "Constant \"$const\" not available.", $res, 0);
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);
478 compiletest ($fnamebase, "Testing for type of constant $const",
479 "Constant \"$const\" does not have the correct type.",
480 $res, 0);
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);
490 $res = runtest ($fnamebase, "Testing for value of constant $const",
491 "Constant \"$const\" has not the right value.", $res);
493 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
494 my($const) = $1;
495 my($value) = $2;
496 my($res) = $missing;
498 # Remember that this name is allowed.
499 push @allow, $const;
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);
508 $res = compiletest ($fnamebase, "Testing for constant $const",
509 "NOT PRESENT", $res, 1);
511 if ($value ne "" && $res == 0) {
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);
519 $res = runtest ($fnamebase, "Testing for value of constant $const",
520 "Constant \"$const\" has not the right value.", $res);
522 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
523 my($const) = $1;
524 my($value) = $2;
525 my($res) = $missing;
527 # Remember that this name is allowed.
528 push @allow, $const;
530 # Generate a program to test for the availability of this constant.
531 open (TESTFILE, ">$fnamebase.c");
532 print TESTFILE "$prepend";
533 print TESTFILE "#include <$h>\n";
534 print TESTFILE "__typeof__ ($const) a = $const;\n";
535 close (TESTFILE);
537 $res = compiletest ($fnamebase, "Testing for constant $const",
538 "Constant \"$const\" not available.", $res, 0);
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);
548 $res = runtest ($fnamebase, "Testing for value of constant $const",
549 "Constant \"$const\" has not the right value.", $res);
551 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
552 my($symbol) = $1;
553 my($value) = $2;
554 my($res) = $missing;
556 # Remember that this name is allowed.
557 push @allow, $symbol;
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);
568 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
569 "Symbol \"$symbol\" not available.", $res, 0);
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);
579 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
580 "Symbol \"$symbol\" has not the right value.", $res);
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;
588 # Remember that this name is allowed.
589 push @allow, $const;
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);
598 $res = compiletest ($fnamebase, "Testing for constant $const",
599 "Constant \"$const\" not available.", $res, 0);
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);
609 compiletest ($fnamebase, "Testing for type of constant $const",
610 "Constant \"$const\" does not have the correct type.",
611 $res, 0);
613 if ($value ne "") {
614 # Generate a program to test for the value of this constant.
615 open (TESTFILE, ">$fnamebase.c");
616 print TESTFILE "$prepend";
617 print TESTFILE "#include <$h>\n";
618 print TESTFILE "int main (void) { return $const != $value; }\n";
619 close (TESTFILE);
621 $res = runtest ($fnamebase, "Testing for value of constant $const",
622 "Constant \"$const\" has not the right value.", $res);
624 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
625 my($type) = "$2$3";
626 my($maybe_opaque) = 0;
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;
635 $maybe_opaque = 1;
638 # Remember that this name is allowed.
639 push @allow, $type;
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";
645 if ($maybe_opaque == 1) {
646 print TESTFILE "$type *a;\n";
647 } else {
648 print TESTFILE "$type a;\n";
650 close (TESTFILE);
652 compiletest ($fnamebase, "Testing for type $type",
653 "NOT AVAILABLE", $missing, 1);
654 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
655 my($type) = "$2$3";
656 my($maybe_opaque) = 0;
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;
665 $maybe_opaque = 1;
668 # Remember that this name is allowed.
669 push @allow, $type;
671 # Generate a program to test for the availability of this type.
672 open (TESTFILE, ">$fnamebase.c");
673 print TESTFILE "$prepend";
674 print TESTFILE "#include <$h>\n";
675 if ($maybe_opaque == 1) {
676 print TESTFILE "$type *a;\n";
677 } else {
678 print TESTFILE "$type a;\n";
680 close (TESTFILE);
682 compiletest ($fnamebase, "Testing for type $type",
683 "Type \"$type\" not available.", $missing, 0);
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;
690 # Remember that this name is allowed.
691 push @allow, $fname;
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);
701 $res = compiletest ($fnamebase, "Test availability of function $fname",
702 "NOT AVAILABLE", $res, 1);
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);
714 compiletest ($fnamebase, "Test for type of function $fname",
715 "Function \"$fname\" has incorrect type.", $res, 0);
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;
723 # Remember that this name is allowed.
724 push @allow, $fname;
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);
734 $res = compiletest ($fnamebase, "Test availability of function $fname",
735 "Function \"$fname\" is not available.", $res, 0);
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);
746 compiletest ($fnamebase, "Test for type of function $fname",
747 "Function \"$fname\" has incorrect type.", $res, 0);
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;
754 # Remember that this name is allowed.
755 push @allow, $fname;
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);
765 $res = compiletest ($fnamebase, "Test availability of function $fname",
766 "NOT AVAILABLE", $res, 1);
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);
778 compiletest ($fnamebase, "Test for type of function $fname",
779 "Function \"$fname\" has incorrect type.", $res, 0);
781 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
782 my($rettype) = "$2$3";
783 my($fname) = "$4";
784 my($args) = "$5";
785 my($res) = $missing;
787 # Remember that this name is allowed.
788 push @allow, $fname;
790 # Generate a program to test for availability of this function.
791 open (TESTFILE, ">$fnamebase.c");
792 print TESTFILE "$prepend";
793 print TESTFILE "#include <$h>\n";
794 # print TESTFILE "#undef $fname\n";
795 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
796 close (TESTFILE);
798 $res = compiletest ($fnamebase, "Test availability of function $fname",
799 "Function \"$fname\" is not available.", $res, 0);
801 # Generate a program to test for the type of this function.
802 open (TESTFILE, ">$fnamebase.c");
803 print TESTFILE "$prepend";
804 print TESTFILE "#include <$h>\n";
805 # print TESTFILE "#undef $fname\n";
806 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
807 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
808 close (TESTFILE);
810 compiletest ($fnamebase, "Test for type of function $fname",
811 "Function \"$fname\" has incorrect type.", $res, 0);
812 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
813 my($type) = "$2$3";
814 my($vname) = "$4";
815 my($rest) = "$5";
816 my($res) = $missing;
818 # Remember that this name is allowed.
819 push @allow, $vname;
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";
826 print TESTFILE "typedef $type xyzzy$rest;\n";
827 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
828 close (TESTFILE);
830 $res = compiletest ($fnamebase, "Test availability of variable $vname",
831 "Variable \"$vname\" is not available.", $res, 0);
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";
838 print TESTFILE "extern $type $vname$rest;\n";
839 close (TESTFILE);
841 compiletest ($fnamebase, "Test for type of variable $fname",
842 "Variable \"$vname\" has incorrect type.", $res, 0);
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;
849 # Remember that this name is allowed.
850 push @allow, $fname;
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);
861 $res = compiletest ($fnamebase, "Test availability of function $fname",
862 "Function \"$fname\" is not available.", $res, 0);
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);
874 compiletest ($fnamebase, "Test for type of function $fname",
875 "Function \"$fname\" has incorrect type.", $res, 0);
876 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
877 # The above regex doesn't handle a \" in a string.
878 my($macro) = "$1";
879 my($string) = "$2";
880 my($res) = $missing;
882 # Remember that this name is allowed.
883 push @allow, $macro;
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);
894 compiletest ($fnamebase, "Test availability of macro $macro",
895 "Macro \"$macro\" is not available.", $missing, 0);
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";
903 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
904 close (TESTFILE);
906 $res = runtest ($fnamebase, "Testing for value of macro $macro",
907 "Macro \"$macro\" has not the right value.", $res);
908 } elsif (/^optional-macro *([^ ]*)/) {
909 my($macro) = "$1";
911 # Remember that this name is allowed.
912 push @allow, $macro;
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);
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;
931 # Remember that this name is allowed.
932 push @allow, $macro;
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);
943 $res = compiletest ($fnamebase, "Test availability of macro $macro",
944 "Macro \"$macro\" is not available.", $res, 0);
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);
955 $res = runtest ($fnamebase, "Testing for value of constant $macro",
956 "Macro \"$macro\" has not the right value.", $res);
958 } elsif (/^macro *([^ ]*)/) {
959 my($macro) = "$1";
961 # Remember that this name is allowed.
962 push @allow, $macro;
964 # Generate a program to test for availability of this macro.
965 open (TESTFILE, ">$fnamebase.c");
966 print TESTFILE "$prepend";
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);
973 compiletest ($fnamebase, "Test availability of macro $macro",
974 "Macro \"$macro\" is not available.", $missing, 0);
975 } elsif (/^allow-header *(.*)/) {
976 my($pattern) = $1;
977 if ($seenheader{$pattern} != 1) {
978 push @allowheader, $pattern;
979 $seenheader{$pattern} = 1;
981 next control;
982 } elsif (/^allow *(.*)/) {
983 my($pattern) = $1;
984 push @allow, $pattern;
985 next control;
986 } else {
987 # printf ("line is `%s'\n", $_);
988 next control;
991 printf ("\n");
993 close (CONTROL);
995 # Read the data files for the header files which are allowed to be included.
996 while ($#allowheader >= 0) {
997 my($ah) = pop @allowheader;
999 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
1000 acontrol: while (<ALLOW>) {
1001 next acontrol if (/^#/);
1002 next acontrol if (/^[ ]*$/);
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";
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;
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;
1029 } elsif (/^macro *([^ ]*)/) {
1030 push @allow, $1;
1031 } elsif (/^allow-header *(.*)/) {
1032 if ($seenheader{$1} != 1) {
1033 push @allowheader, $1;
1034 $seenheader{$1} = 1;
1036 } elsif (/^allow *(.*)/) {
1037 push @allow, $1;
1040 close (ALLOW);
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);
1052 printf ("\n\n");
1055 printf "-" x 76 . "\n";
1056 printf (" Total number of tests : %4d\n", $total);
1058 printf (" Number of known failures: %4d (", $known);
1059 $percent = ($known * 100) / $total;
1060 if ($known > 0 && $percent < 1.0) {
1061 printf (" <1%%)\n");
1062 } else {
1063 printf ("%3d%%)\n", $percent);
1066 printf (" Number of failed tests : %4d (", $errors);
1067 $percent = ($errors * 100) / $total;
1068 if ($errors > 0 && $percent < 1.0) {
1069 printf (" <1%%)\n");
1070 } else {
1071 printf ("%3d%%)\n", $percent);
1074 printf (" Number of skipped tests : %4d (", $skipped);
1075 $percent = ($skipped * 100) / $total;
1076 if ($skipped > 0 && $percent < 1.0) {
1077 printf (" <1%%)\n");
1078 } else {
1079 printf ("%3d%%)\n", $percent);
1082 exit $errors != 0;