9 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
10 'flags=s' => \$flags, 'cc=s' => \$CC);
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"} = "-D_XOPEN_SOURCE=700";
44 $CFLAGS{"POSIX2008"} = "-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;
88 ($pwname,$pwpasswd,$pwuid,$pwgid,
89 $pwquota,$pwcomment,$pwgcos,$pwdir,$pwshell,$pwexpire) = getpwuid($uid);
100 my($pattern, $string) = @_;
101 my($strlen) = length ($string);
104 if (substr ($pattern, 0, 1) eq '*') {
105 my($patlen) = length ($pattern) - 1;
106 $res = ($strlen >= $patlen
107 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
108 } elsif (substr ($pattern, -1, 1) eq '*') {
109 if (substr ($pattern, -2, 1) eq ']') {
110 my($patlen) = index ($pattern, '[');
111 my($range) = substr ($pattern, $patlen + 1, -2);
112 $res = ($strlen > $patlen
113 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)
114 && index ($range, substr ($string, $patlen, 1)) != -1);
116 my($patlen) = length ($pattern) - 1;
117 $res = ($strlen >= $patlen
118 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
121 $res = $pattern eq $string;
129 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
140 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
142 if ($optional != 0) {
143 printf (" $errmsg\n");
148 printf (" $errmsg Compiler message:\n");
156 if ($verbose > 1 && -s "$fnamebase.out") {
157 # We print all warnings issued.
161 if ($printlog != 0) {
162 printf (" " . "-" x 71 . "\n");
163 open (MESSAGE, "< $fnamebase.out");
168 printf (" " . "-" x 71 . "\n");
171 unlink "$fnamebase.c";
172 unlink "$fnamebase.o";
173 unlink "$fnamebase.out";
181 my($fnamebase, $msg, $errmsg, $skip) = @_;
192 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
196 printf (" $errmsg Compiler message:\n");
202 # Now run the program. If the exit code is not zero something is wrong.
203 $result = system "$fnamebase > $fnamebase.out2 2>&1";
206 if ($verbose > 1 && -s "$fnamebase.out") {
207 # We print all warnings issued.
209 system "cat $fnamebase.out2 >> $fnamebase.out";
215 unlink "$fnamebase.out";
216 rename "$fnamebase.out2", "$fnamebase.out";
219 if ($printlog != 0) {
220 printf (" " . "-" x 71 . "\n");
221 open (MESSAGE, "< $fnamebase.out");
226 printf (" " . "-" x 71 . "\n");
230 unlink "$fnamebase.c";
231 unlink "$fnamebase.o";
232 unlink "$fnamebase.out";
233 unlink "$fnamebase.out2";
240 my($token, @allow) = @_;
243 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
245 for ($idx = 0; $idx <= $#allow; ++$idx) {
246 return if (poorfnmatch ($allow[$idx], $token));
249 unless ($isknown{$token}) {
259 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
261 if (exists $errors{$token}) {
262 undef $errors{$token};
268 my($h, $fnamebase, @allow) = @_;
272 # Generate a program to get the contents of this header.
273 open (TESTFILE, ">$fnamebase.c");
274 print TESTFILE "#include <$h>\n";
279 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
280 loop: while (<CONTENT>) {
282 if (/^#define (.*)/) {
283 newtoken ($1, @allow);
284 } elsif (/^#undef (.*)/) {
287 # We have to tokenize the line.
290 my($len) = length ($str);
292 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
294 newtoken ($token, @allow);
300 unlink "$fnamebase.c";
303 # Sort the output list so it's easier to compare results with diff.
304 foreach $f (sort keys(%errors)) {
305 if ($errors{$f} == 1) {
306 if ($realerror == 0) {
307 printf ("FAIL\n " . "-" x 72 . "\n");
311 printf (" Namespace violation: \"%s\"\n", $f);
314 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
317 if ($realerror == 0) {
323 while ($#headers >= 0) {
324 my($h) = pop (@headers);
327 my($fnamebase) = "$tmpdir/$hf-test";
330 my(@allowheader) = ();
331 my(%seenheader) = ();
332 my($prepend) = $mustprepend{$h};
335 printf ("Testing <$h>\n");
336 printf ("----------" . "-" x length ($h) . "\n");
338 open (CONTROL, "$CC -E -D$standard -x c data/$h-data |");
339 control: while (<CONTROL>) {
341 next control if (/^#/);
342 next control if (/^[ ]*$/);
346 # Generate a program to test for the availability of this header.
347 open (TESTFILE, ">$fnamebase.c");
348 print TESTFILE "$prepend";
349 print TESTFILE "#include <$h>\n";
352 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
353 "Header <$h> not available", 0, 0);
355 last control if ($missing);
358 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
359 my($struct) = "$2$3";
365 # Remember that this name is allowed.
366 push @allow, $member;
368 # Generate a program to test for the availability of this member.
369 open (TESTFILE, ">$fnamebase.c");
370 print TESTFILE "$prepend";
371 print TESTFILE "#include <$h>\n";
372 print TESTFILE "$struct a;\n";
373 print TESTFILE "$struct b;\n";
374 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
375 print TESTFILE "void foobarbaz (void) {\n";
376 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
377 print TESTFILE "}\n";
380 $res = compiletest ($fnamebase, "Testing for member $member",
381 "Member \"$member\" not available.", $res, 0);
384 # Test the types of the members.
385 open (TESTFILE, ">$fnamebase.c");
386 print TESTFILE "$prepend";
387 print TESTFILE "#include <$h>\n";
388 print TESTFILE "$struct a;\n";
389 print TESTFILE "extern $type b$rest;\n";
390 print TESTFILE "extern __typeof__ (a.$member) b;\n";
393 compiletest ($fnamebase, "Testing for type of member $member",
394 "Member \"$member\" does not have the correct type.",
396 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
397 my($struct) = "$2$3";
403 # Remember that this name is allowed.
404 push @allow, $member;
406 # Generate a program to test for the availability of this member.
407 open (TESTFILE, ">$fnamebase.c");
408 print TESTFILE "$prepend";
409 print TESTFILE "#include <$h>\n";
410 print TESTFILE "$struct a;\n";
411 print TESTFILE "$struct b;\n";
412 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
413 print TESTFILE "void foobarbaz (void) {\n";
414 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
415 print TESTFILE "}\n";
418 $res = compiletest ($fnamebase, "Testing for member $member",
419 "NOT AVAILABLE.", $res, 1);
421 if ($res == 0 || $missing != 0) {
422 # Test the types of the members.
423 open (TESTFILE, ">$fnamebase.c");
424 print TESTFILE "$prepend";
425 print TESTFILE "#include <$h>\n";
426 print TESTFILE "$struct a;\n";
427 print TESTFILE "extern $type b$rest;\n";
428 print TESTFILE "extern __typeof__ (a.$member) b;\n";
431 compiletest ($fnamebase, "Testing for type of member $member",
432 "Member \"$member\" does not have the correct type.",
435 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<!]+) ([A-Za-z0-9_-]*)/) {
441 # Remember that this name is allowed.
444 # Generate a program to test for the availability of this constant.
445 open (TESTFILE, ">$fnamebase.c");
446 print TESTFILE "$prepend";
447 print TESTFILE "#include <$h>\n";
448 print TESTFILE "__typeof__ ($const) a = $const;\n";
451 $res = compiletest ($fnamebase, "Testing for constant $const",
452 "NOT PRESENT", $res, 1);
454 if ($value ne "" && $res == 0) {
455 # Generate a program to test for the value of this constant.
456 open (TESTFILE, ">$fnamebase.c");
457 print TESTFILE "$prepend";
458 print TESTFILE "#include <$h>\n";
459 # Negate the value since 0 means ok
460 print TESTFILE "int main (void) { return !($const $op $value); }\n";
463 $res = runtest ($fnamebase, "Testing for value of constant $const",
464 "Constant \"$const\" has not the right value.", $res);
466 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_-]*)/) {
472 # Remember that this name is allowed.
475 # Generate a program to test for the availability of this constant.
476 open (TESTFILE, ">$fnamebase.c");
477 print TESTFILE "$prepend";
478 print TESTFILE "#include <$h>\n";
479 print TESTFILE "__typeof__ ($const) a = $const;\n";
482 $res = compiletest ($fnamebase, "Testing for constant $const",
483 "Constant \"$const\" not available.", $res, 0);
486 # Generate a program to test for the value of this constant.
487 open (TESTFILE, ">$fnamebase.c");
488 print TESTFILE "$prepend";
489 print TESTFILE "#include <$h>\n";
490 # Negate the value since 0 means ok
491 print TESTFILE "int main (void) { return !($const $op $value); }\n";
494 $res = runtest ($fnamebase, "Testing for value of constant $const",
495 "Constant \"$const\" has not the right value.", $res);
497 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_-]*)?/) {
503 # Remember that this name is allowed.
506 # Generate a program to test for the availability of this constant.
507 open (TESTFILE, ">$fnamebase.c");
508 print TESTFILE "$prepend";
509 print TESTFILE "#include <$h>\n";
510 print TESTFILE "__typeof__ ($const) a = $const;\n";
513 $res = compiletest ($fnamebase, "Testing for constant $const",
514 "Constant \"$const\" not available.", $res, 0);
516 # Test the types of the members.
517 open (TESTFILE, ">$fnamebase.c");
518 print TESTFILE "$prepend";
519 print TESTFILE "#include <$h>\n";
520 print TESTFILE "__typeof__ (($type) 0) a;\n";
521 print TESTFILE "extern __typeof__ ($const) a;\n";
524 compiletest ($fnamebase, "Testing for type of constant $const",
525 "Constant \"$const\" does not have the correct type.",
529 # Generate a program to test for the value of this constant.
530 open (TESTFILE, ">$fnamebase.c");
531 print TESTFILE "$prepend";
532 print TESTFILE "#include <$h>\n";
533 print TESTFILE "int main (void) { return $const != $value; }\n";
536 $res = runtest ($fnamebase, "Testing for value of constant $const",
537 "Constant \"$const\" has not the right value.", $res);
539 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
544 # Remember that this name is allowed.
547 # Generate a program to test for the availability of this constant.
548 open (TESTFILE, ">$fnamebase.c");
549 print TESTFILE "$prepend";
550 print TESTFILE "#include <$h>\n";
551 print TESTFILE "__typeof__ ($const) a = $const;\n";
554 $res = compiletest ($fnamebase, "Testing for constant $const",
555 "NOT PRESENT", $res, 1);
557 if ($value ne "" && $res == 0) {
558 # Generate a program to test for the value of this constant.
559 open (TESTFILE, ">$fnamebase.c");
560 print TESTFILE "$prepend";
561 print TESTFILE "#include <$h>\n";
562 print TESTFILE "int main (void) { return $const != $value; }\n";
565 $res = runtest ($fnamebase, "Testing for value of constant $const",
566 "Constant \"$const\" has not the right value.", $res);
568 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
573 # Remember that this name is allowed.
576 # Generate a program to test for the availability of this constant.
577 open (TESTFILE, ">$fnamebase.c");
578 print TESTFILE "$prepend";
579 print TESTFILE "#include <$h>\n";
580 print TESTFILE "__typeof__ ($const) a = $const;\n";
583 $res = compiletest ($fnamebase, "Testing for constant $const",
584 "Constant \"$const\" not available.", $res, 0);
587 # Generate a program to test for the value of this constant.
588 open (TESTFILE, ">$fnamebase.c");
589 print TESTFILE "$prepend";
590 print TESTFILE "#include <$h>\n";
591 print TESTFILE "int main (void) { return $const != $value; }\n";
594 $res = runtest ($fnamebase, "Testing for value of constant $const",
595 "Constant \"$const\" has not the right value.", $res);
597 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
602 # Remember that this name is allowed.
603 push @allow, $symbol;
605 # Generate a program to test for the availability of this constant.
606 open (TESTFILE, ">$fnamebase.c");
607 print TESTFILE "$prepend";
608 print TESTFILE "#include <$h>\n";
609 print TESTFILE "void foobarbaz (void) {\n";
610 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
611 print TESTFILE "}\n";
614 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
615 "Symbol \"$symbol\" not available.", $res, 0);
618 # Generate a program to test for the value of this constant.
619 open (TESTFILE, ">$fnamebase.c");
620 print TESTFILE "$prepend";
621 print TESTFILE "#include <$h>\n";
622 print TESTFILE "int main (void) { return $symbol != $value; }\n";
625 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
626 "Symbol \"$symbol\" has not the right value.", $res);
628 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_-]*)?/) {
634 # Remember that this name is allowed.
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 print TESTFILE "__typeof__ ($const) a = $const;\n";
644 $res = compiletest ($fnamebase, "Testing for constant $const",
645 "Constant \"$const\" not available.", $res, 0);
647 # Test the types of the members.
648 open (TESTFILE, ">$fnamebase.c");
649 print TESTFILE "$prepend";
650 print TESTFILE "#include <$h>\n";
651 print TESTFILE "__typeof__ (($type) 0) a;\n";
652 print TESTFILE "extern __typeof__ ($const) a;\n";
655 compiletest ($fnamebase, "Testing for type of constant $const",
656 "Constant \"$const\" does not have the correct type.",
660 # Generate a program to test for the value of this constant.
661 open (TESTFILE, ">$fnamebase.c");
662 print TESTFILE "$prepend";
663 print TESTFILE "#include <$h>\n";
664 print TESTFILE "int main (void) { return $const != $value; }\n";
667 $res = runtest ($fnamebase, "Testing for value of constant $const",
668 "Constant \"$const\" has not the right value.", $res);
670 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
672 my($maybe_opaque) = 0;
674 # Remember that this name is allowed.
675 if ($type =~ /^struct *(.*)/) {
677 } elsif ($type =~ /^union *(.*)/) {
684 # Generate a program to test for the availability of this constant.
685 open (TESTFILE, ">$fnamebase.c");
686 print TESTFILE "$prepend";
687 print TESTFILE "#include <$h>\n";
688 if ($maybe_opaque == 1) {
689 print TESTFILE "$type *a;\n";
691 print TESTFILE "$type a;\n";
695 compiletest ($fnamebase, "Testing for type $type",
696 "NOT AVAILABLE", $missing, 1);
697 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
699 my($maybe_opaque) = 0;
701 # Remember that this name is allowed.
702 if ($type =~ /^struct *(.*)/) {
704 } elsif ($type =~ /^union *(.*)/) {
711 # Generate a program to test for the availability of this type.
712 open (TESTFILE, ">$fnamebase.c");
713 print TESTFILE "$prepend";
714 print TESTFILE "#include <$h>\n";
715 if ($maybe_opaque == 1) {
716 print TESTFILE "$type *a;\n";
718 print TESTFILE "$type a;\n";
722 compiletest ($fnamebase, "Testing for type $type",
723 "Type \"$type\" not available.", $missing, 0);
724 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
727 # Remember that this name is allowed.
728 if ($type =~ /^struct *(.*)/) {
730 } elsif ($type =~ /^union *(.*)/) {
736 # Generate a program to test for the availability of this type.
737 open (TESTFILE, ">$fnamebase.c");
738 print TESTFILE "$prepend";
739 print TESTFILE "#include <$h>\n";
740 print TESTFILE "$type;\n";
743 compiletest ($fnamebase, "Testing for type $type",
744 "Type \"$type\" not available.", $missing, 0);
745 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
746 my($rettype) = "$2$3";
751 # Remember that this name is allowed.
754 # Generate a program to test for availability of this function.
755 open (TESTFILE, ">$fnamebase.c");
756 print TESTFILE "$prepend";
757 print TESTFILE "#include <$h>\n";
758 # print TESTFILE "#undef $fname\n";
759 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
762 $res = compiletest ($fnamebase, "Test availability of function $fname",
763 "NOT AVAILABLE", $res, 1);
765 if ($res == 0 || $missing == 1) {
766 # Generate a program to test for the type of this function.
767 open (TESTFILE, ">$fnamebase.c");
768 print TESTFILE "$prepend";
769 print TESTFILE "#include <$h>\n";
770 # print TESTFILE "#undef $fname\n";
771 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
772 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
775 compiletest ($fnamebase, "Test for type of function $fname",
776 "Function \"$fname\" has incorrect type.", $res, 0);
778 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
779 my($rettype) = "$2$3";
784 # Remember that this name is allowed.
787 # Generate a program to test for availability of this function.
788 open (TESTFILE, ">$fnamebase.c");
789 print TESTFILE "$prepend";
790 print TESTFILE "#include <$h>\n";
791 # print TESTFILE "#undef $fname\n";
792 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
795 $res = compiletest ($fnamebase, "Test availability of function $fname",
796 "Function \"$fname\" is not available.", $res, 0);
798 # Generate a program to test for the type of this function.
799 open (TESTFILE, ">$fnamebase.c");
800 print TESTFILE "$prepend";
801 print TESTFILE "#include <$h>\n";
802 # print TESTFILE "#undef $fname\n";
803 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
804 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
807 compiletest ($fnamebase, "Test for type of function $fname",
808 "Function \"$fname\" has incorrect type.", $res, 0);
809 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
810 my($rettype) = "$2$3";
815 # Remember that this name is allowed.
818 # Generate a program to test for availability of this function.
819 open (TESTFILE, ">$fnamebase.c");
820 print TESTFILE "$prepend";
821 print TESTFILE "#include <$h>\n";
822 # print TESTFILE "#undef $fname\n";
823 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
826 $res = compiletest ($fnamebase, "Test availability of function $fname",
827 "NOT AVAILABLE", $res, 1);
829 if ($res == 0 || $missing != 0) {
830 # Generate a program to test for the type of this function.
831 open (TESTFILE, ">$fnamebase.c");
832 print TESTFILE "$prepend";
833 print TESTFILE "#include <$h>\n";
834 # print TESTFILE "#undef $fname\n";
835 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
836 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
839 compiletest ($fnamebase, "Test for type of function $fname",
840 "Function \"$fname\" has incorrect type.", $res, 0);
842 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
843 my($rettype) = "$2$3";
848 # Remember that this name is allowed.
851 # Generate a program to test for availability of this function.
852 open (TESTFILE, ">$fnamebase.c");
853 print TESTFILE "$prepend";
854 print TESTFILE "#include <$h>\n";
855 # print TESTFILE "#undef $fname\n";
856 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
859 $res = compiletest ($fnamebase, "Test availability of function $fname",
860 "Function \"$fname\" is not available.", $res, 0);
862 # Generate a program to test for the type of this function.
863 open (TESTFILE, ">$fnamebase.c");
864 print TESTFILE "$prepend";
865 print TESTFILE "#include <$h>\n";
866 # print TESTFILE "#undef $fname\n";
867 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
868 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
871 compiletest ($fnamebase, "Test for type of function $fname",
872 "Function \"$fname\" has incorrect type.", $res, 0);
873 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
879 # Remember that this name is allowed.
882 # Generate a program to test for availability of this function.
883 open (TESTFILE, ">$fnamebase.c");
884 print TESTFILE "$prepend";
885 print TESTFILE "#include <$h>\n";
886 # print TESTFILE "#undef $fname\n";
887 print TESTFILE "typedef $type xyzzy$rest;\n";
888 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
891 $res = compiletest ($fnamebase, "Test availability of variable $vname",
892 "Variable \"$vname\" is not available.", $res, 0);
894 # Generate a program to test for the type of this function.
895 open (TESTFILE, ">$fnamebase.c");
896 print TESTFILE "$prepend";
897 print TESTFILE "#include <$h>\n";
898 # print TESTFILE "#undef $fname\n";
899 print TESTFILE "extern $type $vname$rest;\n";
902 compiletest ($fnamebase, "Test for type of variable $fname",
903 "Variable \"$vname\" has incorrect type.", $res, 0);
904 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
905 my($rettype) = "$2$3";
910 # Remember that this name is allowed.
913 # Generate a program to test for availability of this function.
914 open (TESTFILE, ">$fnamebase.c");
915 print TESTFILE "$prepend";
916 print TESTFILE "#include <$h>\n";
917 print TESTFILE "#ifndef $fname\n";
918 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
919 print TESTFILE "#endif\n";
922 $res = compiletest ($fnamebase, "Test availability of macro $fname",
923 "Function \"$fname\" is not available.", $res, 0);
925 # Generate a program to test for the type of this function.
926 open (TESTFILE, ">$fnamebase.c");
927 print TESTFILE "$prepend";
928 print TESTFILE "#include <$h>\n";
929 print TESTFILE "#ifndef $fname\n";
930 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
931 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
932 print TESTFILE "#endif\n";
935 compiletest ($fnamebase, "Test for type of macro $fname",
936 "Function \"$fname\" has incorrect type.", $res, 0);
937 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
938 # The above regex doesn't handle a \" in a string.
943 # Remember that this name is allowed.
946 # Generate a program to test for availability of this macro.
947 open (TESTFILE, ">$fnamebase.c");
948 print TESTFILE "$prepend";
949 print TESTFILE "#include <$h>\n";
950 print TESTFILE "#ifndef $macro\n";
951 print TESTFILE "# error \"Macro $macro not defined\"\n";
952 print TESTFILE "#endif\n";
955 compiletest ($fnamebase, "Test availability of macro $macro",
956 "Macro \"$macro\" is not available.", $missing, 0);
958 # Generate a program to test for the value of this macro.
959 open (TESTFILE, ">$fnamebase.c");
960 print TESTFILE "$prepend";
961 print TESTFILE "#include <$h>\n";
962 # We can't include <string.h> here.
963 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
964 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
967 $res = runtest ($fnamebase, "Testing for value of macro $macro",
968 "Macro \"$macro\" has not the right value.", $res);
969 } elsif (/^optional-macro *([^ ]*)/) {
972 # Remember that this name is allowed.
975 # Generate a program to test for availability of this macro.
976 open (TESTFILE, ">$fnamebase.c");
977 print TESTFILE "$prepend";
978 print TESTFILE "#include <$h>\n";
979 print TESTFILE "#ifndef $macro\n";
980 print TESTFILE "# error \"Macro $macro not defined\"\n";
981 print TESTFILE "#endif\n";
984 compiletest ($fnamebase, "Test availability of macro $macro",
985 "NOT PRESENT", $missing, 1);
986 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_]*)/) {
992 # Remember that this name is allowed.
995 # Generate a program to test for availability of this macro.
996 open (TESTFILE, ">$fnamebase.c");
997 print TESTFILE "$prepend";
998 print TESTFILE "#include <$h>\n";
999 print TESTFILE "#ifndef $macro\n";
1000 print TESTFILE "# error \"Macro $macro not defined\"\n";
1001 print TESTFILE "#endif\n";
1004 $res = compiletest ($fnamebase, "Test availability of macro $macro",
1005 "Macro \"$macro\" is not available.", $res, 0);
1008 # Generate a program to test for the value of this constant.
1009 open (TESTFILE, ">$fnamebase.c");
1010 print TESTFILE "$prepend";
1011 print TESTFILE "#include <$h>\n";
1012 # Negate the value since 0 means ok
1013 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
1016 $res = runtest ($fnamebase, "Testing for value of macro $macro",
1017 "Macro \"$macro\" has not the right value.", $res);
1019 } elsif (/^macro *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)/) {
1022 my($res) = $missing;
1024 # Remember that this name is allowed.
1025 push @allow, $macro;
1027 # Generate a program to test for availability of this macro.
1028 open (TESTFILE, ">$fnamebase.c");
1029 print TESTFILE "$prepend";
1030 print TESTFILE "#include <$h>\n";
1031 print TESTFILE "#ifndef $macro\n";
1032 print TESTFILE "# error \"Macro $macro not defined\"\n";
1033 print TESTFILE "#endif\n";
1036 $res = compiletest ($fnamebase, "Test availability of macro $macro",
1037 "Macro \"$macro\" is not available.", $res, 0);
1040 # Generate a program to test for the value of this constant.
1041 open (TESTFILE, ">$fnamebase.c");
1042 print TESTFILE "$prepend";
1043 print TESTFILE "#include <$h>\n";
1044 # Negate the value since 0 means ok
1045 print TESTFILE "int main (void) { return !($macro == $value); }\n";
1048 $res = runtest ($fnamebase, "Testing for value of macro $macro",
1049 "Macro \"$macro\" has not the right value.", $res);
1051 } elsif (/^macro *([^ ]*)/) {
1054 # Remember that this name is allowed.
1055 push @allow, $macro;
1057 # Generate a program to test for availability of this macro.
1058 open (TESTFILE, ">$fnamebase.c");
1059 print TESTFILE "$prepend";
1060 print TESTFILE "#include <$h>\n";
1061 print TESTFILE "#ifndef $macro\n";
1062 print TESTFILE "# error \"Macro $macro not defined\"\n";
1063 print TESTFILE "#endif\n";
1066 compiletest ($fnamebase, "Test availability of macro $macro",
1067 "Macro \"$macro\" is not available.", $missing, 0);
1068 } elsif (/^allow-header *(.*)/) {
1070 if ($seenheader{$pattern} != 1) {
1071 push @allowheader, $pattern;
1072 $seenheader{$pattern} = 1;
1075 } elsif (/^allow *(.*)/) {
1077 push @allow, $pattern;
1080 # printf ("line is `%s'\n", $_);
1088 # Read the data files for the header files which are allowed to be included.
1089 while ($#allowheader >= 0) {
1090 my($ah) = pop @allowheader;
1092 open (ALLOW, "$CC -E -D$standard - < data/$ah-data |");
1093 acontrol: while (<ALLOW>) {
1095 next acontrol if (/^#/);
1096 next acontrol if (/^[ ]*$/);
1098 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1100 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1102 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1104 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
1107 # Remember that this name is allowed.
1108 if ($type =~ /^struct *(.*)/) {
1110 } elsif ($type =~ /^union *(.*)/) {
1115 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1117 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1119 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1121 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1123 } elsif (/^macro *([^ ]*)/) {
1125 } elsif (/^allow-header *(.*)/) {
1126 if ($seenheader{$1} != 1) {
1127 push @allowheader, $1;
1128 $seenheader{$1} = 1;
1130 } elsif (/^allow *(.*)/) {
1138 printf (" Not defined\n");
1140 # Now check the namespace.
1141 printf (" Checking the namespace of \"%s\"... ", $h);
1146 checknamespace ($h, $fnamebase, @allow);
1153 printf "-" x 76 . "\n";
1154 printf (" Total number of tests : %4d\n", $total);
1156 printf (" Number of failed tests : %4d (", $errors);
1157 $percent = ($errors * 100) / $total;
1158 if ($errors > 0 && $percent < 1.0) {
1159 printf (" <1%%)\n");
1161 printf ("%3d%%)\n", $percent);
1164 printf (" Number of skipped tests : %4d (", $skipped);
1165 $percent = ($skipped * 100) / $total;
1166 if ($skipped > 0 && $percent < 1.0) {
1167 printf (" <1%%)\n");
1169 printf ("%3d%%)\n", $percent);
1174 # perl-indent-level: 2