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 (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
625 my($maybe_opaque) = 0;
627 # Remember that this name is allowed.
628 if ($type =~ /^struct *(.*)/) {
630 } elsif ($type =~ /^union *(.*)/) {
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";
641 if ($maybe_opaque == 1) {
642 print TESTFILE "$type *a;\n";
644 print TESTFILE "$type a;\n";
648 compiletest ($fnamebase, "Testing for type $type",
649 "NOT AVAILABLE", $missing, 1);
650 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
652 my($maybe_opaque) = 0;
654 # Remember that this name is allowed.
655 if ($type =~ /^struct *(.*)/) {
657 } elsif ($type =~ /^union *(.*)/) {
664 # Generate a program to test for the availability of this type.
665 open (TESTFILE, ">$fnamebase.c");
666 print TESTFILE "$prepend";
667 print TESTFILE "#include <$h>\n";
668 if ($maybe_opaque == 1) {
669 print TESTFILE "$type *a;\n";
671 print TESTFILE "$type a;\n";
675 compiletest ($fnamebase, "Testing for type $type",
676 "Type \"$type\" not available.", $missing, 0);
677 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
680 # Remember that this name is allowed.
681 if ($type =~ /^struct *(.*)/) {
683 } elsif ($type =~ /^union *(.*)/) {
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";
696 compiletest ($fnamebase, "Testing for type $type",
697 "Type \"$type\" not available.", $missing, 0);
698 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
699 my($rettype) = "$2$3";
704 # Remember that this name is allowed.
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";
715 $res = compiletest ($fnamebase, "Test availability of function $fname",
716 "NOT AVAILABLE", $res, 1);
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";
728 compiletest ($fnamebase, "Test for type of function $fname",
729 "Function \"$fname\" has incorrect type.", $res, 0);
731 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
732 my($rettype) = "$2$3";
737 # Remember that this name is allowed.
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";
748 $res = compiletest ($fnamebase, "Test availability of function $fname",
749 "Function \"$fname\" is not available.", $res, 0);
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";
760 compiletest ($fnamebase, "Test for type of function $fname",
761 "Function \"$fname\" has incorrect type.", $res, 0);
762 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
763 my($rettype) = "$2$3";
768 # Remember that this name is allowed.
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";
779 $res = compiletest ($fnamebase, "Test availability of function $fname",
780 "NOT AVAILABLE", $res, 1);
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";
792 compiletest ($fnamebase, "Test for type of function $fname",
793 "Function \"$fname\" has incorrect type.", $res, 0);
795 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
796 my($rettype) = "$2$3";
801 # Remember that this name is allowed.
804 # Generate a program to test for availability of this function.
805 open (TESTFILE, ">$fnamebase.c");
806 print TESTFILE "$prepend";
807 print TESTFILE "#include <$h>\n";
808 # print TESTFILE "#undef $fname\n";
809 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
812 $res = compiletest ($fnamebase, "Test availability of function $fname",
813 "Function \"$fname\" is not available.", $res, 0);
815 # Generate a program to test for the type of this function.
816 open (TESTFILE, ">$fnamebase.c");
817 print TESTFILE "$prepend";
818 print TESTFILE "#include <$h>\n";
819 # print TESTFILE "#undef $fname\n";
820 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
821 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
824 compiletest ($fnamebase, "Test for type of function $fname",
825 "Function \"$fname\" has incorrect type.", $res, 0);
826 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
832 # Remember that this name is allowed.
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";
840 print TESTFILE "typedef $type xyzzy$rest;\n";
841 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
844 $res = compiletest ($fnamebase, "Test availability of variable $vname",
845 "Variable \"$vname\" is not available.", $res, 0);
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";
852 print TESTFILE "extern $type $vname$rest;\n";
855 compiletest ($fnamebase, "Test for type of variable $fname",
856 "Variable \"$vname\" has incorrect type.", $res, 0);
857 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
858 my($rettype) = "$2$3";
863 # Remember that this name is allowed.
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";
875 $res = compiletest ($fnamebase, "Test availability of macro $fname",
876 "Function \"$fname\" is not available.", $res, 0);
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";
888 compiletest ($fnamebase, "Test for type of macro $fname",
889 "Function \"$fname\" has incorrect type.", $res, 0);
890 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
891 # The above regex doesn't handle a \" in a string.
896 # Remember that this name is allowed.
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";
908 compiletest ($fnamebase, "Test availability of macro $macro",
909 "Macro \"$macro\" is not available.", $missing, 0);
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";
917 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
920 $res = runtest ($fnamebase, "Testing for value of macro $macro",
921 "Macro \"$macro\" has not the right value.", $res);
922 } elsif (/^optional-macro *([^ ]*)/) {
925 # Remember that this name is allowed.
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";
937 compiletest ($fnamebase, "Test availability of macro $macro",
938 "NOT PRESENT", $missing, 1);
939 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_]*)/) {
945 # Remember that this name is allowed.
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";
957 $res = compiletest ($fnamebase, "Test availability of macro $macro",
958 "Macro \"$macro\" is not available.", $res, 0);
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";
969 $res = runtest ($fnamebase, "Testing for value of macro $macro",
970 "Macro \"$macro\" has not the right value.", $res);
972 } elsif (/^macro *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)/) {
977 # Remember that this name is allowed.
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";
989 $res = compiletest ($fnamebase, "Test availability of macro $macro",
990 "Macro \"$macro\" is not available.", $res, 0);
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";
1001 $res = runtest ($fnamebase, "Testing for value of macro $macro",
1002 "Macro \"$macro\" has not the right value.", $res);
1004 } elsif (/^macro *([^ ]*)/) {
1007 # Remember that this name is allowed.
1008 push @allow, $macro;
1010 # Generate a program to test for availability of this macro.
1011 open (TESTFILE, ">$fnamebase.c");
1012 print TESTFILE "$prepend";
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";
1019 compiletest ($fnamebase, "Test availability of macro $macro",
1020 "Macro \"$macro\" is not available.", $missing, 0);
1021 } elsif (/^allow-header *(.*)/) {
1023 if ($seenheader{$pattern} != 1) {
1024 push @allowheader, $pattern;
1025 $seenheader{$pattern} = 1;
1028 } elsif (/^allow *(.*)/) {
1030 push @allow, $pattern;
1033 # printf ("line is `%s'\n", $_);
1041 # Read the data files for the header files which are allowed to be included.
1042 while ($#allowheader >= 0) {
1043 my($ah) = pop @allowheader;
1045 open (ALLOW, "$CC -E -D$standard - < data/$ah-data |");
1046 acontrol: while (<ALLOW>) {
1048 next acontrol if (/^#/);
1049 next acontrol if (/^[ ]*$/);
1051 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1053 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1055 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1057 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
1060 # Remember that this name is allowed.
1061 if ($type =~ /^struct *(.*)/) {
1063 } elsif ($type =~ /^union *(.*)/) {
1068 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1070 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1072 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1074 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1076 } elsif (/^macro *([^ ]*)/) {
1078 } elsif (/^allow-header *(.*)/) {
1079 if ($seenheader{$1} != 1) {
1080 push @allowheader, $1;
1081 $seenheader{$1} = 1;
1083 } elsif (/^allow *(.*)/) {
1091 printf (" Not defined\n");
1093 # Now check the namespace.
1094 printf (" Checking the namespace of \"%s\"... ", $h);
1099 checknamespace ($h, $fnamebase, @allow);
1106 printf "-" x 76 . "\n";
1107 printf (" Total number of tests : %4d\n", $total);
1109 printf (" Number of failed tests : %4d (", $errors);
1110 $percent = ($errors * 100) / $total;
1111 if ($errors > 0 && $percent < 1.0) {
1112 printf (" <1%%)\n");
1114 printf ("%3d%%)\n", $percent);
1117 printf (" Number of skipped tests : %4d (", $skipped);
1118 $percent = ($skipped * 100) / $total;
1119 if ($skipped > 0 && $percent < 1.0) {
1120 printf (" <1%%)\n");
1122 printf ("%3d%%)\n", $percent);
1127 # perl-indent-level: 2