6 $standard = "XOPEN2K8";
9 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
10 'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir);
11 @headers = split(/,/,join(',',@headers));
13 # List of the headers we are testing.
15 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
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");
35 $CFLAGS{"ISO"} = "-ansi";
36 $CFLAGS{"ISO99"} = "-std=c99";
37 $CFLAGS{"ISO11"} = "-std=c1x -D_ISOC11_SOURCE";
38 $CFLAGS{"POSIX"} = "-D_POSIX_C_SOURCE=199912 -ansi";
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";
43 $CFLAGS{"XOPEN2K8"} = "-std=c99 -D_XOPEN_SOURCE=700";
44 $CFLAGS{"POSIX2008"} = "-std=c99 -D_POSIX_C_SOURCE=200809L";
46 $CFLAGS = "$flags -fno-builtin '-D__attribute__(x)=' $CFLAGS{$standard} -D_ISOMAC";
48 # Check standard name for validity.
49 die "unknown standard \"$standard\"" if ($CFLAGS{$standard} eq "");
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";
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');
74 # Make a hash table from this information.
75 while ($#keywords >= 0) {
76 $iskeyword{pop (@keywords)} = 1;
79 # These are symbols which are known to pollute the namespace.
80 @knownproblems = ('unix', 'linux', 'i386');
82 # Make a hash table from the known problems.
83 while ($#knownproblems >= 0) {
84 $isknown{pop (@knownproblems)} = 1;
95 my($pattern, $string) = @_;
96 my($strlen) = length ($string);
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 '*') {
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);
111 my($patlen) = length ($pattern) - 1;
112 $res = ($strlen >= $patlen
113 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
116 $res = $pattern eq $string;
124 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
135 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
137 if ($optional != 0) {
138 printf (" $errmsg\n");
143 printf (" $errmsg Compiler message:\n");
151 if ($verbose > 1 && -s "$fnamebase.out") {
152 # We print all warnings issued.
156 if ($printlog != 0) {
157 printf (" " . "-" x 71 . "\n");
158 open (MESSAGE, "< $fnamebase.out");
163 printf (" " . "-" x 71 . "\n");
166 unlink "$fnamebase.c";
167 unlink "$fnamebase.o";
168 unlink "$fnamebase.out";
176 my($fnamebase, $msg, $errmsg, $skip) = @_;
187 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
191 printf (" $errmsg Compiler message:\n");
197 # Now run the program. If the exit code is not zero something is wrong.
198 $result = system "$fnamebase > $fnamebase.out2 2>&1";
201 if ($verbose > 1 && -s "$fnamebase.out") {
202 # We print all warnings issued.
204 system "cat $fnamebase.out2 >> $fnamebase.out";
210 unlink "$fnamebase.out";
211 rename "$fnamebase.out2", "$fnamebase.out";
214 if ($printlog != 0) {
215 printf (" " . "-" x 71 . "\n");
216 open (MESSAGE, "< $fnamebase.out");
221 printf (" " . "-" x 71 . "\n");
225 unlink "$fnamebase.c";
226 unlink "$fnamebase.o";
227 unlink "$fnamebase.out";
228 unlink "$fnamebase.out2";
235 my($token, @allow) = @_;
238 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
240 for ($idx = 0; $idx <= $#allow; ++$idx) {
241 return if (poorfnmatch ($allow[$idx], $token));
244 unless ($isknown{$token}) {
254 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
256 if (exists $errors{$token}) {
257 undef $errors{$token};
263 my($h, $fnamebase, @allow) = @_;
267 # Generate a program to get the contents of this header.
268 open (TESTFILE, ">$fnamebase.c");
269 print TESTFILE "#include <$h>\n";
274 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
275 loop: while (<CONTENT>) {
277 if (/^#define (.*)/) {
278 newtoken ($1, @allow);
279 } elsif (/^#undef (.*)/) {
282 # We have to tokenize the line.
285 my($len) = length ($str);
287 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
289 newtoken ($token, @allow);
295 unlink "$fnamebase.c";
298 # Sort the output list so it's easier to compare results with diff.
299 foreach $f (sort keys(%errors)) {
300 if ($errors{$f} == 1) {
301 if ($realerror == 0) {
302 printf ("FAIL\n " . "-" x 72 . "\n");
306 printf (" Namespace violation: \"%s\"\n", $f);
309 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
312 if ($realerror == 0) {
318 while ($#headers >= 0) {
319 my($h) = pop (@headers);
322 my($fnamebase) = "$tmpdir/$hf-test";
325 my(@allowheader) = ();
326 my(%seenheader) = ();
327 my($prepend) = $mustprepend{$h};
330 printf ("Testing <$h>\n");
331 printf ("----------" . "-" x length ($h) . "\n");
333 open (CONTROL, "$CC -E -D$standard -x c data/$h-data |");
334 control: while (<CONTROL>) {
336 next control if (/^#/);
337 next control if (/^[ ]*$/);
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";
347 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
348 "Header <$h> not available", 0, 0);
350 last control if ($missing);
353 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
354 my($struct) = "$2$3";
360 # Remember that this name is allowed.
361 push @allow, $member;
363 # Generate a program to test for the availability of this member.
364 open (TESTFILE, ">$fnamebase.c");
365 print TESTFILE "$prepend";
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";
375 $res = compiletest ($fnamebase, "Testing for member $member",
376 "Member \"$member\" not available.", $res, 0);
379 # Test the types of the members.
380 open (TESTFILE, ">$fnamebase.c");
381 print TESTFILE "$prepend";
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";
388 compiletest ($fnamebase, "Testing for type of member $member",
389 "Member \"$member\" does not have the correct type.",
391 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
392 my($struct) = "$2$3";
398 # Remember that this name is allowed.
399 push @allow, $member;
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";
413 $res = compiletest ($fnamebase, "Testing for member $member",
414 "NOT AVAILABLE.", $res, 1);
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";
426 compiletest ($fnamebase, "Testing for type of member $member",
427 "Member \"$member\" does not have the correct type.",
430 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<!]+) ([A-Za-z0-9_-]*)/) {
436 # Remember that this name is allowed.
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";
446 $res = compiletest ($fnamebase, "Testing for constant $const",
447 "NOT PRESENT", $res, 1);
449 if ($value ne "" && $res == 0) {
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";
458 $res = runtest ($fnamebase, "Testing for value of constant $const",
459 "Constant \"$const\" has not the right value.", $res);
461 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_-]*)/) {
467 # Remember that this name is allowed.
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";
477 $res = compiletest ($fnamebase, "Testing for constant $const",
478 "Constant \"$const\" not available.", $res, 0);
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";
489 $res = runtest ($fnamebase, "Testing for value of constant $const",
490 "Constant \"$const\" has not the right value.", $res);
492 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_-]*)?/) {
498 # Remember that this name is allowed.
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";
508 $res = compiletest ($fnamebase, "Testing for constant $const",
509 "Constant \"$const\" not available.", $res, 0);
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";
519 compiletest ($fnamebase, "Testing for type of constant $const",
520 "Constant \"$const\" does not have the correct type.",
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";
531 $res = runtest ($fnamebase, "Testing for value of constant $const",
532 "Constant \"$const\" has not the right value.", $res);
534 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
539 # Remember that this name is allowed.
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";
549 $res = compiletest ($fnamebase, "Testing for constant $const",
550 "NOT PRESENT", $res, 1);
552 if ($value ne "" && $res == 0) {
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";
560 $res = runtest ($fnamebase, "Testing for value of constant $const",
561 "Constant \"$const\" has not the right value.", $res);
563 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
568 # Remember that this name is allowed.
571 # Generate a program to test for the availability of this constant.
572 open (TESTFILE, ">$fnamebase.c");
573 print TESTFILE "$prepend";
574 print TESTFILE "#include <$h>\n";
575 print TESTFILE "__typeof__ ($const) a = $const;\n";
578 $res = compiletest ($fnamebase, "Testing for constant $const",
579 "Constant \"$const\" not available.", $res, 0);
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";
589 $res = runtest ($fnamebase, "Testing for value of constant $const",
590 "Constant \"$const\" has not the right value.", $res);
592 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
597 # Remember that this name is allowed.
598 push @allow, $symbol;
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";
609 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
610 "Symbol \"$symbol\" not available.", $res, 0);
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";
620 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
621 "Symbol \"$symbol\" has not the right value.", $res);
623 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_-]*)?/) {
629 # Remember that this name is allowed.
632 # Generate a program to test for the availability of this constant.
633 open (TESTFILE, ">$fnamebase.c");
634 print TESTFILE "$prepend";
635 print TESTFILE "#include <$h>\n";
636 print TESTFILE "__typeof__ ($const) a = $const;\n";
639 $res = compiletest ($fnamebase, "Testing for constant $const",
640 "Constant \"$const\" not available.", $res, 0);
642 # Test the types of the members.
643 open (TESTFILE, ">$fnamebase.c");
644 print TESTFILE "$prepend";
645 print TESTFILE "#include <$h>\n";
646 print TESTFILE "__typeof__ (($type) 0) a;\n";
647 print TESTFILE "extern __typeof__ ($const) a;\n";
650 compiletest ($fnamebase, "Testing for type of constant $const",
651 "Constant \"$const\" does not have the correct type.",
655 # Generate a program to test for the value of this constant.
656 open (TESTFILE, ">$fnamebase.c");
657 print TESTFILE "$prepend";
658 print TESTFILE "#include <$h>\n";
659 print TESTFILE "int main (void) { return $const != $value; }\n";
662 $res = runtest ($fnamebase, "Testing for value of constant $const",
663 "Constant \"$const\" has not the right value.", $res);
665 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
667 my($maybe_opaque) = 0;
669 # Remember that this name is allowed.
670 if ($type =~ /^struct *(.*)/) {
672 } elsif ($type =~ /^union *(.*)/) {
679 # Generate a program to test for the availability of this constant.
680 open (TESTFILE, ">$fnamebase.c");
681 print TESTFILE "$prepend";
682 print TESTFILE "#include <$h>\n";
683 if ($maybe_opaque == 1) {
684 print TESTFILE "$type *a;\n";
686 print TESTFILE "$type a;\n";
690 compiletest ($fnamebase, "Testing for type $type",
691 "NOT AVAILABLE", $missing, 1);
692 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
694 my($maybe_opaque) = 0;
696 # Remember that this name is allowed.
697 if ($type =~ /^struct *(.*)/) {
699 } elsif ($type =~ /^union *(.*)/) {
706 # Generate a program to test for the availability of this type.
707 open (TESTFILE, ">$fnamebase.c");
708 print TESTFILE "$prepend";
709 print TESTFILE "#include <$h>\n";
710 if ($maybe_opaque == 1) {
711 print TESTFILE "$type *a;\n";
713 print TESTFILE "$type a;\n";
717 compiletest ($fnamebase, "Testing for type $type",
718 "Type \"$type\" not available.", $missing, 0);
719 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
722 # Remember that this name is allowed.
723 if ($type =~ /^struct *(.*)/) {
725 } elsif ($type =~ /^union *(.*)/) {
731 # Generate a program to test for the availability of this type.
732 open (TESTFILE, ">$fnamebase.c");
733 print TESTFILE "$prepend";
734 print TESTFILE "#include <$h>\n";
735 print TESTFILE "$type;\n";
738 compiletest ($fnamebase, "Testing for type $type",
739 "Type \"$type\" not available.", $missing, 0);
740 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
741 my($rettype) = "$2$3";
746 # Remember that this name is allowed.
749 # Generate a program to test for availability of this function.
750 open (TESTFILE, ">$fnamebase.c");
751 print TESTFILE "$prepend";
752 print TESTFILE "#include <$h>\n";
753 # print TESTFILE "#undef $fname\n";
754 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
757 $res = compiletest ($fnamebase, "Test availability of function $fname",
758 "NOT AVAILABLE", $res, 1);
760 if ($res == 0 || $missing == 1) {
761 # Generate a program to test for the type of this function.
762 open (TESTFILE, ">$fnamebase.c");
763 print TESTFILE "$prepend";
764 print TESTFILE "#include <$h>\n";
765 # print TESTFILE "#undef $fname\n";
766 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
767 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
770 compiletest ($fnamebase, "Test for type of function $fname",
771 "Function \"$fname\" has incorrect type.", $res, 0);
773 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
774 my($rettype) = "$2$3";
779 # Remember that this name is allowed.
782 # Generate a program to test for availability of this function.
783 open (TESTFILE, ">$fnamebase.c");
784 print TESTFILE "$prepend";
785 print TESTFILE "#include <$h>\n";
786 # print TESTFILE "#undef $fname\n";
787 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
790 $res = compiletest ($fnamebase, "Test availability of function $fname",
791 "Function \"$fname\" is not available.", $res, 0);
793 # Generate a program to test for the type of this function.
794 open (TESTFILE, ">$fnamebase.c");
795 print TESTFILE "$prepend";
796 print TESTFILE "#include <$h>\n";
797 # print TESTFILE "#undef $fname\n";
798 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
799 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
802 compiletest ($fnamebase, "Test for type of function $fname",
803 "Function \"$fname\" has incorrect type.", $res, 0);
804 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
805 my($rettype) = "$2$3";
810 # Remember that this name is allowed.
813 # Generate a program to test for availability of this function.
814 open (TESTFILE, ">$fnamebase.c");
815 print TESTFILE "$prepend";
816 print TESTFILE "#include <$h>\n";
817 # print TESTFILE "#undef $fname\n";
818 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
821 $res = compiletest ($fnamebase, "Test availability of function $fname",
822 "NOT AVAILABLE", $res, 1);
824 if ($res == 0 || $missing != 0) {
825 # Generate a program to test for the type of this function.
826 open (TESTFILE, ">$fnamebase.c");
827 print TESTFILE "$prepend";
828 print TESTFILE "#include <$h>\n";
829 # print TESTFILE "#undef $fname\n";
830 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
831 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
834 compiletest ($fnamebase, "Test for type of function $fname",
835 "Function \"$fname\" has incorrect type.", $res, 0);
837 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
838 my($rettype) = "$2$3";
843 # Remember that this name is allowed.
846 # Generate a program to test for availability of this function.
847 open (TESTFILE, ">$fnamebase.c");
848 print TESTFILE "$prepend";
849 print TESTFILE "#include <$h>\n";
850 # print TESTFILE "#undef $fname\n";
851 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
854 $res = compiletest ($fnamebase, "Test availability of function $fname",
855 "Function \"$fname\" is not available.", $res, 0);
857 # Generate a program to test for the type of this function.
858 open (TESTFILE, ">$fnamebase.c");
859 print TESTFILE "$prepend";
860 print TESTFILE "#include <$h>\n";
861 # print TESTFILE "#undef $fname\n";
862 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
863 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
866 compiletest ($fnamebase, "Test for type of function $fname",
867 "Function \"$fname\" has incorrect type.", $res, 0);
868 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
874 # Remember that this name is allowed.
877 # Generate a program to test for availability of this function.
878 open (TESTFILE, ">$fnamebase.c");
879 print TESTFILE "$prepend";
880 print TESTFILE "#include <$h>\n";
881 # print TESTFILE "#undef $fname\n";
882 print TESTFILE "typedef $type xyzzy$rest;\n";
883 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
886 $res = compiletest ($fnamebase, "Test availability of variable $vname",
887 "Variable \"$vname\" is not available.", $res, 0);
889 # Generate a program to test for the type of this function.
890 open (TESTFILE, ">$fnamebase.c");
891 print TESTFILE "$prepend";
892 print TESTFILE "#include <$h>\n";
893 # print TESTFILE "#undef $fname\n";
894 print TESTFILE "extern $type $vname$rest;\n";
897 compiletest ($fnamebase, "Test for type of variable $fname",
898 "Variable \"$vname\" has incorrect type.", $res, 0);
899 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
900 my($rettype) = "$2$3";
905 # Remember that this name is allowed.
908 # Generate a program to test for availability of this function.
909 open (TESTFILE, ">$fnamebase.c");
910 print TESTFILE "$prepend";
911 print TESTFILE "#include <$h>\n";
912 print TESTFILE "#ifndef $fname\n";
913 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
914 print TESTFILE "#endif\n";
917 $res = compiletest ($fnamebase, "Test availability of macro $fname",
918 "Function \"$fname\" is not available.", $res, 0);
920 # Generate a program to test for the type of this function.
921 open (TESTFILE, ">$fnamebase.c");
922 print TESTFILE "$prepend";
923 print TESTFILE "#include <$h>\n";
924 print TESTFILE "#ifndef $fname\n";
925 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
926 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
927 print TESTFILE "#endif\n";
930 compiletest ($fnamebase, "Test for type of macro $fname",
931 "Function \"$fname\" has incorrect type.", $res, 0);
932 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
933 # The above regex doesn't handle a \" in a string.
938 # Remember that this name is allowed.
941 # Generate a program to test for availability of this macro.
942 open (TESTFILE, ">$fnamebase.c");
943 print TESTFILE "$prepend";
944 print TESTFILE "#include <$h>\n";
945 print TESTFILE "#ifndef $macro\n";
946 print TESTFILE "# error \"Macro $macro not defined\"\n";
947 print TESTFILE "#endif\n";
950 compiletest ($fnamebase, "Test availability of macro $macro",
951 "Macro \"$macro\" is not available.", $missing, 0);
953 # Generate a program to test for the value of this macro.
954 open (TESTFILE, ">$fnamebase.c");
955 print TESTFILE "$prepend";
956 print TESTFILE "#include <$h>\n";
957 # We can't include <string.h> here.
958 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
959 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
962 $res = runtest ($fnamebase, "Testing for value of macro $macro",
963 "Macro \"$macro\" has not the right value.", $res);
964 } elsif (/^optional-macro *([^ ]*)/) {
967 # Remember that this name is allowed.
970 # Generate a program to test for availability of this macro.
971 open (TESTFILE, ">$fnamebase.c");
972 print TESTFILE "$prepend";
973 print TESTFILE "#include <$h>\n";
974 print TESTFILE "#ifndef $macro\n";
975 print TESTFILE "# error \"Macro $macro not defined\"\n";
976 print TESTFILE "#endif\n";
979 compiletest ($fnamebase, "Test availability of macro $macro",
980 "NOT PRESENT", $missing, 1);
981 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_]*)/) {
987 # Remember that this name is allowed.
990 # Generate a program to test for availability of this macro.
991 open (TESTFILE, ">$fnamebase.c");
992 print TESTFILE "$prepend";
993 print TESTFILE "#include <$h>\n";
994 print TESTFILE "#ifndef $macro\n";
995 print TESTFILE "# error \"Macro $macro not defined\"\n";
996 print TESTFILE "#endif\n";
999 $res = compiletest ($fnamebase, "Test availability of macro $macro",
1000 "Macro \"$macro\" is not available.", $res, 0);
1003 # Generate a program to test for the value of this constant.
1004 open (TESTFILE, ">$fnamebase.c");
1005 print TESTFILE "$prepend";
1006 print TESTFILE "#include <$h>\n";
1007 # Negate the value since 0 means ok
1008 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
1011 $res = runtest ($fnamebase, "Testing for value of macro $macro",
1012 "Macro \"$macro\" has not the right value.", $res);
1014 } elsif (/^macro *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)/) {
1017 my($res) = $missing;
1019 # Remember that this name is allowed.
1020 push @allow, $macro;
1022 # Generate a program to test for availability of this macro.
1023 open (TESTFILE, ">$fnamebase.c");
1024 print TESTFILE "$prepend";
1025 print TESTFILE "#include <$h>\n";
1026 print TESTFILE "#ifndef $macro\n";
1027 print TESTFILE "# error \"Macro $macro not defined\"\n";
1028 print TESTFILE "#endif\n";
1031 $res = compiletest ($fnamebase, "Test availability of macro $macro",
1032 "Macro \"$macro\" is not available.", $res, 0);
1035 # Generate a program to test for the value of this constant.
1036 open (TESTFILE, ">$fnamebase.c");
1037 print TESTFILE "$prepend";
1038 print TESTFILE "#include <$h>\n";
1039 # Negate the value since 0 means ok
1040 print TESTFILE "int main (void) { return !($macro == $value); }\n";
1043 $res = runtest ($fnamebase, "Testing for value of macro $macro",
1044 "Macro \"$macro\" has not the right value.", $res);
1046 } elsif (/^macro *([^ ]*)/) {
1049 # Remember that this name is allowed.
1050 push @allow, $macro;
1052 # Generate a program to test for availability of this macro.
1053 open (TESTFILE, ">$fnamebase.c");
1054 print TESTFILE "$prepend";
1055 print TESTFILE "#include <$h>\n";
1056 print TESTFILE "#ifndef $macro\n";
1057 print TESTFILE "# error \"Macro $macro not defined\"\n";
1058 print TESTFILE "#endif\n";
1061 compiletest ($fnamebase, "Test availability of macro $macro",
1062 "Macro \"$macro\" is not available.", $missing, 0);
1063 } elsif (/^allow-header *(.*)/) {
1065 if ($seenheader{$pattern} != 1) {
1066 push @allowheader, $pattern;
1067 $seenheader{$pattern} = 1;
1070 } elsif (/^allow *(.*)/) {
1072 push @allow, $pattern;
1075 # printf ("line is `%s'\n", $_);
1083 # Read the data files for the header files which are allowed to be included.
1084 while ($#allowheader >= 0) {
1085 my($ah) = pop @allowheader;
1087 open (ALLOW, "$CC -E -D$standard - < data/$ah-data |");
1088 acontrol: while (<ALLOW>) {
1090 next acontrol if (/^#/);
1091 next acontrol if (/^[ ]*$/);
1093 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1095 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1097 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1099 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
1102 # Remember that this name is allowed.
1103 if ($type =~ /^struct *(.*)/) {
1105 } elsif ($type =~ /^union *(.*)/) {
1110 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1112 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1114 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1116 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1118 } elsif (/^macro *([^ ]*)/) {
1120 } elsif (/^allow-header *(.*)/) {
1121 if ($seenheader{$1} != 1) {
1122 push @allowheader, $1;
1123 $seenheader{$1} = 1;
1125 } elsif (/^allow *(.*)/) {
1133 printf (" Not defined\n");
1135 # Now check the namespace.
1136 printf (" Checking the namespace of \"%s\"... ", $h);
1141 checknamespace ($h, $fnamebase, @allow);
1148 printf "-" x 76 . "\n";
1149 printf (" Total number of tests : %4d\n", $total);
1151 printf (" Number of failed tests : %4d (", $errors);
1152 $percent = ($errors * 100) / $total;
1153 if ($errors > 0 && $percent < 1.0) {
1154 printf (" <1%%)\n");
1156 printf ("%3d%%)\n", $percent);
1159 printf (" Number of skipped tests : %4d (", $skipped);
1160 $percent = ($skipped * 100) / $total;
1161 if ($skipped > 0 && $percent < 1.0) {
1162 printf (" <1%%)\n");
1164 printf ("%3d%%)\n", $percent);
1169 # perl-indent-level: 2