9 GetOptions ('headers=s' => \@headers, 'dialect=s' => \$dialect);
10 @headers = split(/,/,join(',',@headers));
12 # List of the headers we are testing.
14 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
15 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "time.h",
16 "tgmath.h", "termios.h", "tar.h", "sys/wait.h", "sys/utsname.h",
17 "sys/un.h", "sys/uio.h", "sys/types.h", "sys/times.h",
18 "sys/timeb.h", "sys/time.h", "sys/statvfs.h", "sys/stat.h",
19 "sys/socket.h", "sys/shm.h", "sys/sem.h", "sys/select.h",
20 "sys/resource.h", "sys/msg.h", "sys/mman.h", "sys/ipc.h",
21 "syslog.h", "stropts.h", "strings.h", "string.h", "stdlib.h",
22 "stdio.h", "stdint.h", "stddef.h", "stdarg.h", "spawn.h",
23 "signal.h", "setjmp.h", "semaphore.h", "search.h", "sched.h",
24 "regex.h", "pwd.h", "pthread.h", "poll.h", "nl_types.h",
25 "netinet/tcp.h", "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h",
26 "mqueue.h", "monetary.h", "math.h", "locale.h", "libgen.h",
27 "limits.h", "langinfo.h", "iso646.h", "inttypes.h", "iconv.h",
28 "grp.h", "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h",
29 "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
30 "complex.h", "assert.h", "arpa/inet.h", "aio.h");
33 if ($dialect ne "ISO" && $dialect ne "POSIX" && $dialect ne "XPG3"
34 && $dialect ne "XPG4" && $dialect ne "UNIX98" && $dialect ne "XOPEN2K"
35 && $dialect ne "XOPEN2K8" && $dialect ne "POSIX2008") {
36 die "unknown dialect \"$dialect\"";
39 $CFLAGS{"ISO"} = "-I. -fno-builtin '-D__attribute__(x)=' -ansi";
40 $CFLAGS{"POSIX"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_POSIX_C_SOURCE=199912";
41 $CFLAGS{"XPG3"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE";
42 $CFLAGS{"XPG4"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE_EXTENDED";
43 $CFLAGS{"UNIX98"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
44 $CFLAGS{"XOPEN2K"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=600";
45 $CFLAGS{"XOPEN2K8"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=700";
46 $CFLAGS{"POSIX2008"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_POSIX_C_SOURCE=200809L";
49 # These are the ISO C99 keywords.
50 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
51 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
52 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
53 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
54 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
56 # These are symbols which are known to pollute the namespace.
57 @knownproblems = ('unix', 'linux', 'i386');
59 # Some headers need a bit more attention.
60 $mustprepend{'inttypes.h'} = "#include <stddef.h>\n";
61 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
62 $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
63 $mustprepend{'signal.h'} = "#include <pthread.h>\n";
64 $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
65 $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
66 $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
68 # Make a hash table from this information.
69 while ($#keywords >= 0) {
70 $iskeyword{pop (@keywords)} = 1;
73 # Make a hash table from the known problems.
74 while ($#knownproblems >= 0) {
75 $isknown{pop (@knownproblems)} = 1;
79 ($pwname,$pwpasswd,$pwuid,$pwgid,
80 $pwquota,$pwcomment,$pwgcos,$pwdir,$pwshell,$pwexpire) = getpwuid($uid);
91 my($pattern, $string) = @_;
92 my($strlen) = length ($string);
95 if (substr ($pattern, 0, 1) eq '*') {
96 my($patlen) = length ($pattern) - 1;
97 $res = ($strlen >= $patlen
98 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
99 } elsif (substr ($pattern, -1, 1) eq '*') {
100 my($patlen) = length ($pattern) - 1;
101 $res = ($strlen >= $patlen
102 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
104 $res = $pattern eq $string;
112 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
123 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
125 if ($optional != 0) {
126 printf (" $errmsg\n");
131 printf (" $errmsg Compiler message:\n");
139 if ($verbose > 1 && -s "$fnamebase.out") {
140 # We print all warnings issued.
144 if ($printlog != 0) {
145 printf (" " . "-" x 71 . "\n");
146 open (MESSAGE, "< $fnamebase.out");
151 printf (" " . "-" x 71 . "\n");
154 unlink "$fnamebase.c";
155 unlink "$fnamebase.o";
156 unlink "$fnamebase.out";
164 my($fnamebase, $msg, $errmsg, $skip) = @_;
175 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
179 printf (" $errmsg Compiler message:\n");
185 # Now run the program. If the exit code is not zero something is wrong.
186 $result = system "$fnamebase > $fnamebase.out2 2>&1";
189 if ($verbose > 1 && -s "$fnamebase.out") {
190 # We print all warnings issued.
192 system "cat $fnamebase.out2 >> $fnamebase.out";
198 unlink "$fnamebase.out";
199 rename "$fnamebase.out2", "$fnamebase.out";
202 if ($printlog != 0) {
203 printf (" " . "-" x 71 . "\n");
204 open (MESSAGE, "< $fnamebase.out");
209 printf (" " . "-" x 71 . "\n");
213 unlink "$fnamebase.c";
214 unlink "$fnamebase.o";
215 unlink "$fnamebase.out";
216 unlink "$fnamebase.out2";
223 my($token, @allow) = @_;
226 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
228 for ($idx = 0; $idx <= $#allow; ++$idx) {
229 return if (poorfnmatch ($allow[$idx], $token));
232 if ($isknown{$token}) {
244 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
246 if (exists $errors{$token}) {
247 undef $errors{$token};
253 my($h, $fnamebase, @allow) = @_;
257 # Generate a program to get the contents of this header.
258 open (TESTFILE, ">$fnamebase.c");
259 print TESTFILE "#include <$h>\n";
264 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
265 loop: while (<CONTENT>) {
267 if (/^#define (.*)/) {
268 newtoken ($1, @allow);
269 } elsif (/^#undef (.*)/) {
272 # We have to tokenize the line.
275 my($len) = length ($str);
277 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
279 newtoken ($token, @allow);
285 unlink "$fnamebase.c";
288 # Sort the output list so it's easier to compare results with diff.
289 foreach $f (sort keys(%errors)) {
290 if ($errors{$f} == 1) {
291 if ($realerror == 0) {
292 printf ("FAIL\n " . "-" x 72 . "\n");
296 printf (" Namespace violation: \"%s\"\n", $f);
299 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
302 if ($realerror == 0) {
304 printf ("EXPECTED FAILURES\n");
313 while ($#headers >= 0) {
314 my($h) = pop (@headers);
317 my($fnamebase) = "$tmpdir/$hf-test";
320 my(@allowheader) = ();
321 my(%seenheader) = ();
322 my($prepend) = $mustprepend{$h};
324 printf ("Testing <$h>\n");
325 printf ("----------" . "-" x length ($h) . "\n");
327 # Generate a program to test for the availability of this header.
328 open (TESTFILE, ">$fnamebase.c");
329 print TESTFILE "$prepend";
330 print TESTFILE "#include <$h>\n";
333 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
334 "Header <$h> not available", 0, 0);
338 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
339 control: while (<CONTROL>) {
341 next control if (/^#/);
342 next control if (/^[ ]*$/);
344 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
345 my($struct) = "$2$3";
351 # Remember that this name is allowed.
352 push @allow, $member;
354 # Generate a program to test for the availability of this member.
355 open (TESTFILE, ">$fnamebase.c");
356 print TESTFILE "$prepend";
357 print TESTFILE "#include <$h>\n";
358 print TESTFILE "$struct a;\n";
359 print TESTFILE "$struct b;\n";
360 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
361 print TESTFILE "void foobarbaz (void) {\n";
362 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
363 print TESTFILE "}\n";
366 $res = compiletest ($fnamebase, "Testing for member $member",
367 "Member \"$member\" not available.", $res, 0);
370 # Test the types of the members.
371 open (TESTFILE, ">$fnamebase.c");
372 print TESTFILE "$prepend";
373 print TESTFILE "#include <$h>\n";
374 print TESTFILE "$struct a;\n";
375 print TESTFILE "extern $type b$rest;\n";
376 print TESTFILE "extern __typeof__ (a.$member) b;\n";
379 compiletest ($fnamebase, "Testing for type of member $member",
380 "Member \"$member\" does not have the correct type.",
382 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
383 my($struct) = "$2$3";
389 # Remember that this name is allowed.
390 push @allow, $member;
392 # Generate a program to test for the availability of this member.
393 open (TESTFILE, ">$fnamebase.c");
394 print TESTFILE "$prepend";
395 print TESTFILE "#include <$h>\n";
396 print TESTFILE "$struct a;\n";
397 print TESTFILE "$struct b;\n";
398 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
399 print TESTFILE "void foobarbaz (void) {\n";
400 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
401 print TESTFILE "}\n";
404 $res = compiletest ($fnamebase, "Testing for member $member",
405 "NOT AVAILABLE.", $res, 1);
407 if ($res == 0 || $missing != 0) {
408 # Test the types of the members.
409 open (TESTFILE, ">$fnamebase.c");
410 print TESTFILE "$prepend";
411 print TESTFILE "#include <$h>\n";
412 print TESTFILE "$struct a;\n";
413 print TESTFILE "extern $type b$rest;\n";
414 print TESTFILE "extern __typeof__ (a.$member) b;\n";
417 compiletest ($fnamebase, "Testing for type of member $member",
418 "Member \"$member\" does not have the correct type.",
421 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
427 # Remember that this name is allowed.
430 # Generate a program to test for the availability of this constant.
431 open (TESTFILE, ">$fnamebase.c");
432 print TESTFILE "$prepend";
433 print TESTFILE "#include <$h>\n";
434 print TESTFILE "__typeof__ ($const) a = $const;\n";
437 $res = compiletest ($fnamebase, "Testing for constant $const",
438 "NOT PRESENT", $res, 1);
440 if ($value ne "" && $res == 0) {
441 # Generate a program to test for the value of this constant.
442 open (TESTFILE, ">$fnamebase.c");
443 print TESTFILE "$prepend";
444 print TESTFILE "#include <$h>\n";
445 # Negate the value since 0 means ok
446 print TESTFILE "int main (void) { return !($const $op $value); }\n";
449 $res = runtest ($fnamebase, "Testing for value of constant $const",
450 "Constant \"$const\" has not the right value.", $res);
452 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
458 # Remember that this name is allowed.
461 # Generate a program to test for the availability of this constant.
462 open (TESTFILE, ">$fnamebase.c");
463 print TESTFILE "$prepend";
464 print TESTFILE "#include <$h>\n";
465 print TESTFILE "__typeof__ ($const) a = $const;\n";
468 $res = compiletest ($fnamebase, "Testing for constant $const",
469 "Constant \"$const\" not available.", $res, 0);
472 # Generate a program to test for the value of this constant.
473 open (TESTFILE, ">$fnamebase.c");
474 print TESTFILE "$prepend";
475 print TESTFILE "#include <$h>\n";
476 # Negate the value since 0 means ok
477 print TESTFILE "int main (void) { return !($const $op $value); }\n";
480 $res = runtest ($fnamebase, "Testing for value of constant $const",
481 "Constant \"$const\" has not the right value.", $res);
483 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
489 # Remember that this name is allowed.
492 # Generate a program to test for the availability of this constant.
493 open (TESTFILE, ">$fnamebase.c");
494 print TESTFILE "$prepend";
495 print TESTFILE "#include <$h>\n";
496 print TESTFILE "__typeof__ ($const) a = $const;\n";
499 $res = compiletest ($fnamebase, "Testing for constant $const",
500 "Constant \"$const\" not available.", $res, 0);
502 # Test the types of the members.
503 open (TESTFILE, ">$fnamebase.c");
504 print TESTFILE "$prepend";
505 print TESTFILE "#include <$h>\n";
506 print TESTFILE "__typeof__ (($type) 0) a;\n";
507 print TESTFILE "extern __typeof__ ($const) a;\n";
510 compiletest ($fnamebase, "Testing for type of constant $const",
511 "Constant \"$const\" does not have the correct type.",
515 # Generate a program to test for the value of this constant.
516 open (TESTFILE, ">$fnamebase.c");
517 print TESTFILE "$prepend";
518 print TESTFILE "#include <$h>\n";
519 print TESTFILE "int main (void) { return $const != $value; }\n";
522 $res = runtest ($fnamebase, "Testing for value of constant $const",
523 "Constant \"$const\" has not the right value.", $res);
525 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
530 # Remember that this name is allowed.
533 # Generate a program to test for the availability of this constant.
534 open (TESTFILE, ">$fnamebase.c");
535 print TESTFILE "$prepend";
536 print TESTFILE "#include <$h>\n";
537 print TESTFILE "__typeof__ ($const) a = $const;\n";
540 $res = compiletest ($fnamebase, "Testing for constant $const",
541 "NOT PRESENT", $res, 1);
543 if ($value ne "" && $res == 0) {
544 # Generate a program to test for the value of this constant.
545 open (TESTFILE, ">$fnamebase.c");
546 print TESTFILE "$prepend";
547 print TESTFILE "#include <$h>\n";
548 print TESTFILE "int main (void) { return $const != $value; }\n";
551 $res = runtest ($fnamebase, "Testing for value of constant $const",
552 "Constant \"$const\" has not the right value.", $res);
554 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
559 # Remember that this name is allowed.
562 # Generate a program to test for the availability of this constant.
563 open (TESTFILE, ">$fnamebase.c");
564 print TESTFILE "$prepend";
565 print TESTFILE "#include <$h>\n";
566 print TESTFILE "__typeof__ ($const) a = $const;\n";
569 $res = compiletest ($fnamebase, "Testing for constant $const",
570 "Constant \"$const\" not available.", $res, 0);
573 # Generate a program to test for the value of this constant.
574 open (TESTFILE, ">$fnamebase.c");
575 print TESTFILE "$prepend";
576 print TESTFILE "#include <$h>\n";
577 print TESTFILE "int main (void) { return $const != $value; }\n";
580 $res = runtest ($fnamebase, "Testing for value of constant $const",
581 "Constant \"$const\" has not the right value.", $res);
583 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
588 # Remember that this name is allowed.
589 push @allow, $symbol;
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 "void foobarbaz (void) {\n";
596 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
597 print TESTFILE "}\n";
600 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
601 "Symbol \"$symbol\" not available.", $res, 0);
604 # Generate a program to test for the value of this constant.
605 open (TESTFILE, ">$fnamebase.c");
606 print TESTFILE "$prepend";
607 print TESTFILE "#include <$h>\n";
608 print TESTFILE "int main (void) { return $symbol != $value; }\n";
611 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
612 "Symbol \"$symbol\" has not the right value.", $res);
614 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
620 # Remember that this name is allowed.
623 # Generate a program to test for the availability of this constant.
624 open (TESTFILE, ">$fnamebase.c");
625 print TESTFILE "$prepend";
626 print TESTFILE "#include <$h>\n";
627 print TESTFILE "__typeof__ ($const) a = $const;\n";
630 $res = compiletest ($fnamebase, "Testing for constant $const",
631 "Constant \"$const\" not available.", $res, 0);
633 # Test the types of the members.
634 open (TESTFILE, ">$fnamebase.c");
635 print TESTFILE "$prepend";
636 print TESTFILE "#include <$h>\n";
637 print TESTFILE "__typeof__ (($type) 0) a;\n";
638 print TESTFILE "extern __typeof__ ($const) a;\n";
641 compiletest ($fnamebase, "Testing for type of constant $const",
642 "Constant \"$const\" does not have the correct type.",
646 # Generate a program to test for the value of this constant.
647 open (TESTFILE, ">$fnamebase.c");
648 print TESTFILE "$prepend";
649 print TESTFILE "#include <$h>\n";
650 print TESTFILE "int main (void) { return $const != $value; }\n";
653 $res = runtest ($fnamebase, "Testing for value of constant $const",
654 "Constant \"$const\" has not the right value.", $res);
656 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
658 my($maybe_opaque) = 0;
660 # Remember that this name is allowed.
661 if ($type =~ /^struct *(.*)/) {
663 } elsif ($type =~ /^union *(.*)/) {
670 # Generate a program to test for the availability of this constant.
671 open (TESTFILE, ">$fnamebase.c");
672 print TESTFILE "$prepend";
673 print TESTFILE "#include <$h>\n";
674 if ($maybe_opaque == 1) {
675 print TESTFILE "$type *a;\n";
677 print TESTFILE "$type a;\n";
681 compiletest ($fnamebase, "Testing for type $type",
682 "NOT AVAILABLE", $missing, 1);
683 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
685 my($maybe_opaque) = 0;
687 # Remember that this name is allowed.
688 if ($type =~ /^struct *(.*)/) {
690 } elsif ($type =~ /^union *(.*)/) {
697 # Generate a program to test for the availability of this type.
698 open (TESTFILE, ">$fnamebase.c");
699 print TESTFILE "$prepend";
700 print TESTFILE "#include <$h>\n";
701 if ($maybe_opaque == 1) {
702 print TESTFILE "$type *a;\n";
704 print TESTFILE "$type a;\n";
708 compiletest ($fnamebase, "Testing for type $type",
709 "Type \"$type\" not available.", $missing, 0);
710 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
713 # Remember that this name is allowed.
714 if ($type =~ /^struct *(.*)/) {
716 } elsif ($type =~ /^union *(.*)/) {
722 # Generate a program to test for the availability of this type.
723 open (TESTFILE, ">$fnamebase.c");
724 print TESTFILE "$prepend";
725 print TESTFILE "#include <$h>\n";
726 print TESTFILE "$type;\n";
729 compiletest ($fnamebase, "Testing for type $type",
730 "Type \"$type\" not available.", $missing, 0);
731 } elsif (/^optional-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 "NOT AVAILABLE", $res, 1);
751 if ($res == 0 || $missing == 1) {
752 # Generate a program to test for the type of this function.
753 open (TESTFILE, ">$fnamebase.c");
754 print TESTFILE "$prepend";
755 print TESTFILE "#include <$h>\n";
756 # print TESTFILE "#undef $fname\n";
757 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
758 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
761 compiletest ($fnamebase, "Test for type of function $fname",
762 "Function \"$fname\" has incorrect type.", $res, 0);
764 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
765 my($rettype) = "$2$3";
770 # Remember that this name is allowed.
773 # Generate a program to test for availability of this function.
774 open (TESTFILE, ">$fnamebase.c");
775 print TESTFILE "$prepend";
776 print TESTFILE "#include <$h>\n";
777 # print TESTFILE "#undef $fname\n";
778 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
781 $res = compiletest ($fnamebase, "Test availability of function $fname",
782 "Function \"$fname\" is not available.", $res, 0);
784 # Generate a program to test for the type of this function.
785 open (TESTFILE, ">$fnamebase.c");
786 print TESTFILE "$prepend";
787 print TESTFILE "#include <$h>\n";
788 # print TESTFILE "#undef $fname\n";
789 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
790 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
793 compiletest ($fnamebase, "Test for type of function $fname",
794 "Function \"$fname\" has incorrect type.", $res, 0);
795 } elsif (/^optional-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 "NOT AVAILABLE", $res, 1);
815 if ($res == 0 || $missing != 0) {
816 # Generate a program to test for the type of this function.
817 open (TESTFILE, ">$fnamebase.c");
818 print TESTFILE "$prepend";
819 print TESTFILE "#include <$h>\n";
820 # print TESTFILE "#undef $fname\n";
821 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
822 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
825 compiletest ($fnamebase, "Test for type of function $fname",
826 "Function \"$fname\" has incorrect type.", $res, 0);
828 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
829 my($rettype) = "$2$3";
834 # Remember that this name is allowed.
837 # Generate a program to test for availability of this function.
838 open (TESTFILE, ">$fnamebase.c");
839 print TESTFILE "$prepend";
840 print TESTFILE "#include <$h>\n";
841 # print TESTFILE "#undef $fname\n";
842 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
845 $res = compiletest ($fnamebase, "Test availability of function $fname",
846 "Function \"$fname\" is not available.", $res, 0);
848 # Generate a program to test for the type of this function.
849 open (TESTFILE, ">$fnamebase.c");
850 print TESTFILE "$prepend";
851 print TESTFILE "#include <$h>\n";
852 # print TESTFILE "#undef $fname\n";
853 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
854 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
857 compiletest ($fnamebase, "Test for type of function $fname",
858 "Function \"$fname\" has incorrect type.", $res, 0);
859 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
865 # Remember that this name is allowed.
868 # Generate a program to test for availability of this function.
869 open (TESTFILE, ">$fnamebase.c");
870 print TESTFILE "$prepend";
871 print TESTFILE "#include <$h>\n";
872 # print TESTFILE "#undef $fname\n";
873 print TESTFILE "typedef $type xyzzy$rest;\n";
874 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
877 $res = compiletest ($fnamebase, "Test availability of variable $vname",
878 "Variable \"$vname\" is not available.", $res, 0);
880 # Generate a program to test for the type of this function.
881 open (TESTFILE, ">$fnamebase.c");
882 print TESTFILE "$prepend";
883 print TESTFILE "#include <$h>\n";
884 # print TESTFILE "#undef $fname\n";
885 print TESTFILE "extern $type $vname$rest;\n";
888 compiletest ($fnamebase, "Test for type of variable $fname",
889 "Variable \"$vname\" has incorrect type.", $res, 0);
890 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
891 my($rettype) = "$2$3";
896 # Remember that this name is allowed.
899 # Generate a program to test for availability of this function.
900 open (TESTFILE, ">$fnamebase.c");
901 print TESTFILE "$prepend";
902 print TESTFILE "#include <$h>\n";
903 print TESTFILE "#ifndef $fname\n";
904 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
905 print TESTFILE "#endif\n";
908 $res = compiletest ($fnamebase, "Test availability of function $fname",
909 "Function \"$fname\" is not available.", $res, 0);
911 # Generate a program to test for the type of this function.
912 open (TESTFILE, ">$fnamebase.c");
913 print TESTFILE "$prepend";
914 print TESTFILE "#include <$h>\n";
915 print TESTFILE "#ifndef $fname\n";
916 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
917 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
918 print TESTFILE "#endif\n";
921 compiletest ($fnamebase, "Test for type of function $fname",
922 "Function \"$fname\" has incorrect type.", $res, 0);
923 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
924 # The above regex doesn't handle a \" in a string.
929 # Remember that this name is allowed.
932 # Generate a program to test for availability of this macro.
933 open (TESTFILE, ">$fnamebase.c");
934 print TESTFILE "$prepend";
935 print TESTFILE "#include <$h>\n";
936 print TESTFILE "#ifndef $macro\n";
937 print TESTFILE "# error \"Macro $macro not defined\"\n";
938 print TESTFILE "#endif\n";
941 compiletest ($fnamebase, "Test availability of macro $macro",
942 "Macro \"$macro\" is not available.", $missing, 0);
944 # Generate a program to test for the value of this macro.
945 open (TESTFILE, ">$fnamebase.c");
946 print TESTFILE "$prepend";
947 print TESTFILE "#include <$h>\n";
948 # We can't include <string.h> here.
949 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
950 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
953 $res = runtest ($fnamebase, "Testing for value of macro $macro",
954 "Macro \"$macro\" has not the right value.", $res);
955 } elsif (/^optional-macro *([^ ]*)/) {
958 # Remember that this name is allowed.
961 # Generate a program to test for availability of this macro.
962 open (TESTFILE, ">$fnamebase.c");
963 print TESTFILE "$prepend";
964 print TESTFILE "#include <$h>\n";
965 print TESTFILE "#ifndef $macro\n";
966 print TESTFILE "# error \"Macro $macro not defined\"\n";
967 print TESTFILE "#endif\n";
970 compiletest ($fnamebase, "Test availability of macro $macro",
971 "NOT PRESENT", $missing, 1);
972 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
978 # Remember that this name is allowed.
981 # Generate a program to test for availability of this macro.
982 open (TESTFILE, ">$fnamebase.c");
983 print TESTFILE "$prepend";
984 print TESTFILE "#include <$h>\n";
985 print TESTFILE "#ifndef $macro\n";
986 print TESTFILE "# error \"Macro $macro not defined\"\n";
987 print TESTFILE "#endif\n";
990 $res = compiletest ($fnamebase, "Test availability of macro $macro",
991 "Macro \"$macro\" is not available.", $res, 0);
994 # Generate a program to test for the value of this constant.
995 open (TESTFILE, ">$fnamebase.c");
996 print TESTFILE "$prepend";
997 print TESTFILE "#include <$h>\n";
998 # Negate the value since 0 means ok
999 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
1002 $res = runtest ($fnamebase, "Testing for value of constant $macro",
1003 "Macro \"$macro\" has not the right value.", $res);
1005 } elsif (/^macro *([^ ]*)/) {
1008 # Remember that this name is allowed.
1009 push @allow, $macro;
1011 # Generate a program to test for availability of this macro.
1012 open (TESTFILE, ">$fnamebase.c");
1013 print TESTFILE "$prepend";
1014 print TESTFILE "#include <$h>\n";
1015 print TESTFILE "#ifndef $macro\n";
1016 print TESTFILE "# error \"Macro $macro not defined\"\n";
1017 print TESTFILE "#endif\n";
1020 compiletest ($fnamebase, "Test availability of macro $macro",
1021 "Macro \"$macro\" is not available.", $missing, 0);
1022 } elsif (/^allow-header *(.*)/) {
1024 if ($seenheader{$pattern} != 1) {
1025 push @allowheader, $pattern;
1026 $seenheader{$pattern} = 1;
1029 } elsif (/^allow *(.*)/) {
1031 push @allow, $pattern;
1034 # printf ("line is `%s'\n", $_);
1042 # Read the data files for the header files which are allowed to be included.
1043 while ($#allowheader >= 0) {
1044 my($ah) = pop @allowheader;
1046 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
1047 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 *({([^}]*)|([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 *(.*)/) {
1090 # Now check the namespace.
1091 printf (" Checking the namespace of \"%s\"... ", $h);
1096 checknamespace ($h, $fnamebase, @allow);
1102 printf "-" x 76 . "\n";
1103 printf (" Total number of tests : %4d\n", $total);
1105 printf (" Number of known failures: %4d (", $known);
1106 $percent = ($known * 100) / $total;
1107 if ($known > 0 && $percent < 1.0) {
1108 printf (" <1%%)\n");
1110 printf ("%3d%%)\n", $percent);
1113 printf (" Number of failed tests : %4d (", $errors);
1114 $percent = ($errors * 100) / $total;
1115 if ($errors > 0 && $percent < 1.0) {
1116 printf (" <1%%)\n");
1118 printf ("%3d%%)\n", $percent);
1121 printf (" Number of skipped tests : %4d (", $skipped);
1122 $percent = ($skipped * 100) / $total;
1123 if ($skipped > 0 && $percent < 1.0) {
1124 printf (" <1%%)\n");
1126 printf ("%3d%%)\n", $percent);