8 GetOptions ('headers=s' => \@headers, 'dialect=s' => \$dialect);
9 @headers = split(/,/,join(',',@headers));
11 # List of the headers we are testing.
13 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
14 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "time.h",
15 "tgmath.h", "termios.h", "tar.h", "sys/wait.h", "sys/utsname.h",
16 "sys/un.h", "sys/uio.h", "sys/types.h", "sys/times.h",
17 "sys/timeb.h", "sys/time.h", "sys/statvfs.h", "sys/stat.h",
18 "sys/socket.h", "sys/shm.h", "sys/sem.h", "sys/select.h",
19 "sys/resource.h", "sys/msg.h", "sys/mman.h", "sys/ipc.h",
20 "syslog.h", "stropts.h", "strings.h", "string.h", "stdlib.h",
21 "stdio.h", "stdint.h", "stddef.h", "stdarg.h", "spawn.h",
22 "signal.h", "setjmp.h", "semaphore.h", "search.h", "sched.h",
23 "regex.h", "pwd.h", "pthread.h", "poll.h", "nl_types.h",
24 "netinet/tcp.h", "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h",
25 "mqueue.h", "monetary.h", "math.h", "locale.h", "libgen.h",
26 "limits.h", "langinfo.h", "iso646.h", "inttypes.h", "iconv.h",
27 "grp.h", "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h",
28 "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
29 "complex.h", "assert.h", "arpa/inet.h", "aio.h");
32 if ($dialect ne "ISO" && $dialect ne "POSIX" && $dialect ne "XPG3"
33 && $dialect ne "XPG4" && $dialect ne "UNIX98" && $dialect ne "XOPEN2K") {
34 die "unknown dialect \"$dialect\"";
37 $CFLAGS{"ISO"} = "-I. -fno-builtin '-D__attribute__(x)=' -ansi";
38 $CFLAGS{"POSIX"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_POSIX_C_SOURCE=199912";
39 $CFLAGS{"XPG3"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE";
40 $CFLAGS{"XPG4"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE_EXTENDED";
41 $CFLAGS{"UNIX98"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
42 $CFLAGS{"XOPEN2K"} = "-I. -fno-builtin '-D__attribute__(x)=' -D_XOPEN_SOURCE=600";
45 # These are the ISO C99 keywords.
46 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
47 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
48 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
49 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
50 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
52 # These are symbols which are known to pollute the namespace.
53 @knownproblems = ('unix', 'linux', 'i386');
55 # Some headers need a bit more attention.
56 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
57 $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
58 $mustprepend{'signal.h'} = "#include <pthread.h>\n";
59 $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
60 $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
61 $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
63 # Make a hash table from this information.
64 while ($#keywords >= 0) {
65 $iskeyword{pop (@keywords)} = 1;
68 # Make a hash table from the known problems.
69 while ($#knownproblems >= 0) {
70 $isknown{pop (@knownproblems)} = 1;
83 my($pattern, $string) = @_;
84 my($strlen) = length ($string);
87 if (substr ($pattern, 0, 1) eq '*') {
88 my($patlen) = length ($pattern) - 1;
89 $res = ($strlen >= $patlen
90 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
91 } elsif (substr ($pattern, -1, 1) eq '*') {
92 my($patlen) = length ($pattern) - 1;
93 $res = ($strlen >= $patlen
94 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
96 $res = $pattern eq $string;
104 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
115 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
117 if ($optional != 0) {
118 printf (" $errmsg\n");
123 printf (" $errmsg Compiler message:\n");
131 if ($verbose > 1 && -s "$fnamebase.out") {
132 # We print all warnings issued.
136 if ($printlog != 0) {
137 printf (" " . "-" x 71 . "\n");
138 open (MESSAGE, "< $fnamebase.out");
143 printf (" " . "-" x 71 . "\n");
146 unlink "$fnamebase.c";
147 unlink "$fnamebase.o";
148 unlink "$fnamebase.out";
156 my($fnamebase, $msg, $errmsg, $skip) = @_;
167 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
171 printf (" $errmsg Compiler message:\n");
177 # Now run the program. If the exit code is not zero something is wrong.
178 $result = system "$fnamebase > $fnamebase.out2 2>&1";
181 if ($verbose > 1 && -s "$fnamebase.out") {
182 # We print all warnings issued.
184 system "cat $fnamebase.out2 >> $fnamebase.out";
190 unlink "$fnamebase.out";
191 rename "$fnamebase.out2", "$fnamebase.out";
194 if ($printlog != 0) {
195 printf (" " . "-" x 71 . "\n");
196 open (MESSAGE, "< $fnamebase.out");
201 printf (" " . "-" x 71 . "\n");
205 unlink "$fnamebase.c";
206 unlink "$fnamebase.o";
207 unlink "$fnamebase.out";
208 unlink "$fnamebase.out2";
215 my($token, @allow) = @_;
218 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
220 for ($idx = 0; $idx <= $#allow; ++$idx) {
221 return if (poorfnmatch ($allow[$idx], $token));
224 if ($isknown{$token}) {
236 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
238 if (exists $errors{$token}) {
239 undef $errors{$token};
245 my($h, $fnamebase, @allow) = @_;
249 # Generate a program to get the contents of this header.
250 open (TESTFILE, ">$fnamebase.c");
251 print TESTFILE "#include <$h>\n";
256 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
257 loop: while (<CONTENT>) {
259 if (/^#define (.*)/) {
260 newtoken ($1, @allow);
261 } elsif (/^#undef (.*)/) {
264 # We have to tokenize the line.
267 my($len) = length ($str);
269 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
271 newtoken ($token, @allow);
277 unlink "$fnamebase.c";
280 foreach $f (%errors) {
281 if ($errors{$f} == 1) {
282 if ($realerror == 0) {
283 printf ("FAIL\n " . "-" x 72 . "\n");
287 printf (" Namespace violation: \"%s\"\n", $f);
290 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
293 if ($realerror == 0) {
295 printf ("EXPECTED FAILURES\n");
304 while ($#headers >= 0) {
305 my($h) = pop (@headers);
308 my($fnamebase) = "$tmpdir/$hf-test";
311 my(@allowheader) = ();
312 my(%seenheader) = ();
313 my($prepend) = $mustprepend{$h};
315 printf ("Testing <$h>\n");
316 printf ("----------" . "-" x length ($h) . "\n");
318 # Generate a program to test for the availability of this header.
319 open (TESTFILE, ">$fnamebase.c");
320 print TESTFILE "$prepend";
321 print TESTFILE "#include <$h>\n";
324 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
325 "Header <$h> not available", 0, 0);
329 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
330 control: while (<CONTROL>) {
332 next control if (/^#/);
333 next control if (/^[ ]*$/);
335 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
336 my($struct) = "$2$3";
342 # Remember that this name is allowed.
343 push @allow, $member;
345 # Generate a program to test for the availability of this member.
346 open (TESTFILE, ">$fnamebase.c");
347 print TESTFILE "$prepend";
348 print TESTFILE "#include <$h>\n";
349 print TESTFILE "$struct a;\n";
350 print TESTFILE "$struct b;\n";
351 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
352 print TESTFILE "void foobarbaz (void) {\n";
353 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
354 print TESTFILE "}\n";
357 $res = compiletest ($fnamebase, "Testing for member $member",
358 "Member \"$member\" not available.", $res, 0);
361 # Test the types of the members.
362 open (TESTFILE, ">$fnamebase.c");
363 print TESTFILE "$prepend";
364 print TESTFILE "#include <$h>\n";
365 print TESTFILE "$struct a;\n";
366 print TESTFILE "extern $type b$rest;\n";
367 print TESTFILE "extern __typeof__ (a.$member) b;\n";
370 compiletest ($fnamebase, "Testing for type of member $member",
371 "Member \"$member\" does not have the correct type.",
373 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
374 my($struct) = "$2$3";
380 # Remember that this name is allowed.
381 push @allow, $member;
383 # Generate a program to test for the availability of this member.
384 open (TESTFILE, ">$fnamebase.c");
385 print TESTFILE "$prepend";
386 print TESTFILE "#include <$h>\n";
387 print TESTFILE "$struct a;\n";
388 print TESTFILE "$struct b;\n";
389 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
390 print TESTFILE "void foobarbaz (void) {\n";
391 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
392 print TESTFILE "}\n";
395 $res = compiletest ($fnamebase, "Testing for member $member",
396 "NOT AVAILABLE.", $res, 1);
398 if ($res == 0 || $missing != 0) {
399 # Test the types of the members.
400 open (TESTFILE, ">$fnamebase.c");
401 print TESTFILE "$prepend";
402 print TESTFILE "#include <$h>\n";
403 print TESTFILE "$struct a;\n";
404 print TESTFILE "extern $type b$rest;\n";
405 print TESTFILE "extern __typeof__ (a.$member) b;\n";
408 compiletest ($fnamebase, "Testing for type of member $member",
409 "Member \"$member\" does not have the correct type.",
412 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
418 # Remember that this name is allowed.
421 # Generate a program to test for the availability of this constant.
422 open (TESTFILE, ">$fnamebase.c");
423 print TESTFILE "$prepend";
424 print TESTFILE "#include <$h>\n";
425 print TESTFILE "__typeof__ ($const) a = $const;\n";
428 $res = compiletest ($fnamebase, "Testing for constant $const",
429 "NOT PRESENT", $res, 1);
431 if ($value ne "" && $res == 0) {
432 # Generate a program to test for the value of this constant.
433 open (TESTFILE, ">$fnamebase.c");
434 print TESTFILE "$prepend";
435 print TESTFILE "#include <$h>\n";
436 # Negate the value since 0 means ok
437 print TESTFILE "int main (void) { return !($const $op $value); }\n";
440 $res = runtest ($fnamebase, "Testing for value of constant $const",
441 "Constant \"$const\" has not the right value.", $res);
443 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
449 # Remember that this name is allowed.
452 # Generate a program to test for the availability of this constant.
453 open (TESTFILE, ">$fnamebase.c");
454 print TESTFILE "$prepend";
455 print TESTFILE "#include <$h>\n";
456 print TESTFILE "__typeof__ ($const) a = $const;\n";
459 $res = compiletest ($fnamebase, "Testing for constant $const",
460 "Constant \"$const\" not available.", $res, 0);
463 # Generate a program to test for the value of this constant.
464 open (TESTFILE, ">$fnamebase.c");
465 print TESTFILE "$prepend";
466 print TESTFILE "#include <$h>\n";
467 # Negate the value since 0 means ok
468 print TESTFILE "int main (void) { return !($const $op $value); }\n";
471 $res = runtest ($fnamebase, "Testing for value of constant $const",
472 "Constant \"$const\" has not the right value.", $res);
474 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
480 # Remember that this name is allowed.
483 # Generate a program to test for the availability of this constant.
484 open (TESTFILE, ">$fnamebase.c");
485 print TESTFILE "$prepend";
486 print TESTFILE "#include <$h>\n";
487 print TESTFILE "__typeof__ ($const) a = $const;\n";
490 $res = compiletest ($fnamebase, "Testing for constant $const",
491 "Constant \"$const\" not available.", $res, 0);
493 # Test the types of the members.
494 open (TESTFILE, ">$fnamebase.c");
495 print TESTFILE "$prepend";
496 print TESTFILE "#include <$h>\n";
497 print TESTFILE "__typeof__ (($type) 0) a;\n";
498 print TESTFILE "extern __typeof__ ($const) a;\n";
501 compiletest ($fnamebase, "Testing for type of constant $const",
502 "Constant \"$const\" does not have the correct type.",
506 # Generate a program to test for the value of this constant.
507 open (TESTFILE, ">$fnamebase.c");
508 print TESTFILE "$prepend";
509 print TESTFILE "#include <$h>\n";
510 print TESTFILE "int main (void) { return $const != $value; }\n";
513 $res = runtest ($fnamebase, "Testing for value of constant $const",
514 "Constant \"$const\" has not the right value.", $res);
516 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
521 # Remember that this name is allowed.
524 # Generate a program to test for the availability of this constant.
525 open (TESTFILE, ">$fnamebase.c");
526 print TESTFILE "$prepend";
527 print TESTFILE "#include <$h>\n";
528 print TESTFILE "__typeof__ ($const) a = $const;\n";
531 $res = compiletest ($fnamebase, "Testing for constant $const",
532 "NOT PRESENT", $res, 1);
534 if ($value ne "" && $res == 0) {
535 # Generate a program to test for the value of this constant.
536 open (TESTFILE, ">$fnamebase.c");
537 print TESTFILE "$prepend";
538 print TESTFILE "#include <$h>\n";
539 print TESTFILE "int main (void) { return $const != $value; }\n";
542 $res = runtest ($fnamebase, "Testing for value of constant $const",
543 "Constant \"$const\" has not the right value.", $res);
545 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
550 # Remember that this name is allowed.
553 # Generate a program to test for the availability of this constant.
554 open (TESTFILE, ">$fnamebase.c");
555 print TESTFILE "$prepend";
556 print TESTFILE "#include <$h>\n";
557 print TESTFILE "__typeof__ ($const) a = $const;\n";
560 $res = compiletest ($fnamebase, "Testing for constant $const",
561 "Constant \"$const\" not available.", $res, 0);
564 # Generate a program to test for the value of this constant.
565 open (TESTFILE, ">$fnamebase.c");
566 print TESTFILE "$prepend";
567 print TESTFILE "#include <$h>\n";
568 print TESTFILE "int main (void) { return $const != $value; }\n";
571 $res = runtest ($fnamebase, "Testing for value of constant $const",
572 "Constant \"$const\" has not the right value.", $res);
574 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
579 # Remember that this name is allowed.
580 push @allow, $symbol;
582 # Generate a program to test for the availability of this constant.
583 open (TESTFILE, ">$fnamebase.c");
584 print TESTFILE "$prepend";
585 print TESTFILE "#include <$h>\n";
586 print TESTFILE "void foobarbaz (void) {\n";
587 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
588 print TESTFILE "}\n";
591 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
592 "Symbol \"$symbol\" not available.", $res, 0);
595 # Generate a program to test for the value of this constant.
596 open (TESTFILE, ">$fnamebase.c");
597 print TESTFILE "$prepend";
598 print TESTFILE "#include <$h>\n";
599 print TESTFILE "int main (void) { return $symbol != $value; }\n";
602 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
603 "Symbol \"$symbol\" has not the right value.", $res);
605 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
611 # Remember that this name is allowed.
614 # Generate a program to test for the availability of this constant.
615 open (TESTFILE, ">$fnamebase.c");
616 print TESTFILE "$prepend";
617 print TESTFILE "#include <$h>\n";
618 print TESTFILE "__typeof__ ($const) a = $const;\n";
621 $res = compiletest ($fnamebase, "Testing for constant $const",
622 "Constant \"$const\" not available.", $res, 0);
624 # Test the types of the members.
625 open (TESTFILE, ">$fnamebase.c");
626 print TESTFILE "$prepend";
627 print TESTFILE "#include <$h>\n";
628 print TESTFILE "__typeof__ (($type) 0) a;\n";
629 print TESTFILE "extern __typeof__ ($const) a;\n";
632 compiletest ($fnamebase, "Testing for type of constant $const",
633 "Constant \"$const\" does not have the correct type.",
637 # Generate a program to test for the value of this constant.
638 open (TESTFILE, ">$fnamebase.c");
639 print TESTFILE "$prepend";
640 print TESTFILE "#include <$h>\n";
641 print TESTFILE "int main (void) { return $const != $value; }\n";
644 $res = runtest ($fnamebase, "Testing for value of constant $const",
645 "Constant \"$const\" has not the right value.", $res);
647 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
649 my($maybe_opaque) = 0;
651 # Remember that this name is allowed.
652 if ($type =~ /^struct *(.*)/) {
654 } elsif ($type =~ /^union *(.*)/) {
661 # Remember that this name is allowed.
664 # Generate a program to test for the availability of this constant.
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 "NOT AVAILABLE", $missing, 1);
677 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
679 my($maybe_opaque) = 0;
681 # Remember that this name is allowed.
682 if ($type =~ /^struct *(.*)/) {
684 } elsif ($type =~ /^union *(.*)/) {
691 # Remember that this name is allowed.
694 # Generate a program to test for the availability of this type.
695 open (TESTFILE, ">$fnamebase.c");
696 print TESTFILE "$prepend";
697 print TESTFILE "#include <$h>\n";
698 if ($maybe_opaque == 1) {
699 print TESTFILE "$type *a;\n";
701 print TESTFILE "$type a;\n";
705 compiletest ($fnamebase, "Testing for type $type",
706 "Type \"$type\" not available.", $missing, 0);
707 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
708 my($rettype) = "$2$3";
713 # Remember that this name is allowed.
716 # Generate a program to test for availability of this function.
717 open (TESTFILE, ">$fnamebase.c");
718 print TESTFILE "$prepend";
719 print TESTFILE "#include <$h>\n";
720 # print TESTFILE "#undef $fname\n";
721 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
724 $res = compiletest ($fnamebase, "Test availability of function $fname",
725 "NOT AVAILABLE", $res, 1);
727 if ($res == 0 || $missing == 1) {
728 # Generate a program to test for the type of this function.
729 open (TESTFILE, ">$fnamebase.c");
730 print TESTFILE "$prepend";
731 print TESTFILE "#include <$h>\n";
732 # print TESTFILE "#undef $fname\n";
733 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
734 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
737 compiletest ($fnamebase, "Test for type of function $fname",
738 "Function \"$fname\" has incorrect type.", $res, 0);
740 } elsif (/^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 "Function \"$fname\" is not available.", $res, 0);
760 # Generate a program to test for the type of this function.
761 open (TESTFILE, ">$fnamebase.c");
762 print TESTFILE "$prepend";
763 print TESTFILE "#include <$h>\n";
764 # print TESTFILE "#undef $fname\n";
765 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
766 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
769 compiletest ($fnamebase, "Test for type of function $fname",
770 "Function \"$fname\" has incorrect type.", $res, 0);
771 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
772 my($rettype) = "$2$3";
777 # Remember that this name is allowed.
780 # Generate a program to test for availability of this function.
781 open (TESTFILE, ">$fnamebase.c");
782 print TESTFILE "$prepend";
783 print TESTFILE "#include <$h>\n";
784 # print TESTFILE "#undef $fname\n";
785 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
788 $res = compiletest ($fnamebase, "Test availability of function $fname",
789 "NOT AVAILABLE", $res, 1);
791 if ($res == 0 || $missing != 0) {
792 # Generate a program to test for the type of this function.
793 open (TESTFILE, ">$fnamebase.c");
794 print TESTFILE "$prepend";
795 print TESTFILE "#include <$h>\n";
796 # print TESTFILE "#undef $fname\n";
797 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
798 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
801 compiletest ($fnamebase, "Test for type of function $fname",
802 "Function \"$fname\" has incorrect type.", $res, 0);
804 } elsif (/^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 "Function \"$fname\" is not available.", $res, 0);
824 # Generate a program to test for the type of this function.
825 open (TESTFILE, ">$fnamebase.c");
826 print TESTFILE "$prepend";
827 print TESTFILE "#include <$h>\n";
828 # print TESTFILE "#undef $fname\n";
829 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
830 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
833 compiletest ($fnamebase, "Test for type of function $fname",
834 "Function \"$fname\" has incorrect type.", $res, 0);
835 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
841 # Remember that this name is allowed.
844 # Generate a program to test for availability of this function.
845 open (TESTFILE, ">$fnamebase.c");
846 print TESTFILE "$prepend";
847 print TESTFILE "#include <$h>\n";
848 # print TESTFILE "#undef $fname\n";
849 print TESTFILE "typedef $type xyzzy$rest;\n";
850 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
853 $res = compiletest ($fnamebase, "Test availability of variable $vname",
854 "Variable \"$vname\" is not available.", $res, 0);
856 # Generate a program to test for the type of this function.
857 open (TESTFILE, ">$fnamebase.c");
858 print TESTFILE "$prepend";
859 print TESTFILE "#include <$h>\n";
860 # print TESTFILE "#undef $fname\n";
861 print TESTFILE "extern $type $vname$rest;\n";
864 compiletest ($fnamebase, "Test for type of variable $fname",
865 "Variable \"$vname\" has incorrect type.", $res, 0);
866 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
867 my($rettype) = "$2$3";
872 # Remember that this name is allowed.
875 # Generate a program to test for availability of this function.
876 open (TESTFILE, ">$fnamebase.c");
877 print TESTFILE "$prepend";
878 print TESTFILE "#include <$h>\n";
879 print TESTFILE "#ifndef $fname\n";
880 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
881 print TESTFILE "#endif\n";
884 $res = compiletest ($fnamebase, "Test availability of function $fname",
885 "Function \"$fname\" is not available.", $res, 0);
887 # Generate a program to test for the type of this function.
888 open (TESTFILE, ">$fnamebase.c");
889 print TESTFILE "$prepend";
890 print TESTFILE "#include <$h>\n";
891 print TESTFILE "#ifndef $fname\n";
892 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
893 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
894 print TESTFILE "#endif\n";
897 compiletest ($fnamebase, "Test for type of function $fname",
898 "Function \"$fname\" has incorrect type.", $res, 0);
899 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
900 # The above regex doesn't handle a \" in a string.
905 # Remember that this name is allowed.
908 # Generate a program to test for availability of this macro.
909 open (TESTFILE, ">$fnamebase.c");
910 print TESTFILE "$prepend";
911 print TESTFILE "#include <$h>\n";
912 print TESTFILE "#ifndef $macro\n";
913 print TESTFILE "# error \"Macro $macro not defined\"\n";
914 print TESTFILE "#endif\n";
917 compiletest ($fnamebase, "Test availability of macro $macro",
918 "Macro \"$macro\" is not available.", $missing, 0);
920 # Generate a program to test for the value of this macro.
921 open (TESTFILE, ">$fnamebase.c");
922 print TESTFILE "$prepend";
923 print TESTFILE "#include <$h>\n";
924 # We can't include <string.h> here.
925 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
926 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
929 $res = runtest ($fnamebase, "Testing for value of macro $macro",
930 "Macro \"$macro\" has not the right value.", $res);
931 } elsif (/^optional-macro *([^ ]*)/) {
934 # Remember that this name is allowed.
937 # Generate a program to test for availability of this macro.
938 open (TESTFILE, ">$fnamebase.c");
939 print TESTFILE "$prepend";
940 print TESTFILE "#include <$h>\n";
941 print TESTFILE "#ifndef $macro\n";
942 print TESTFILE "# error \"Macro $macro not defined\"\n";
943 print TESTFILE "#endif\n";
946 compiletest ($fnamebase, "Test availability of macro $macro",
947 "NOT PRESENT", $missing, 1);
948 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
954 # Remember that this name is allowed.
957 # Generate a program to test for availability of this macro.
958 open (TESTFILE, ">$fnamebase.c");
959 print TESTFILE "$prepend";
960 print TESTFILE "#include <$h>\n";
961 print TESTFILE "#ifndef $macro\n";
962 print TESTFILE "# error \"Macro $macro not defined\"\n";
963 print TESTFILE "#endif\n";
966 $res = compiletest ($fnamebase, "Test availability of macro $macro",
967 "Macro \"$macro\" is not available.", $res, 0);
970 # Generate a program to test for the value of this constant.
971 open (TESTFILE, ">$fnamebase.c");
972 print TESTFILE "$prepend";
973 print TESTFILE "#include <$h>\n";
974 # Negate the value since 0 means ok
975 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
978 $res = runtest ($fnamebase, "Testing for value of constant $macro",
979 "Macro \"$macro\" has not the right value.", $res);
981 } elsif (/^macro *([^ ]*)/) {
984 # Remember that this name is allowed.
987 # Generate a program to test for availability of this macro.
988 open (TESTFILE, ">$fnamebase.c");
989 print TESTFILE "$prepend";
990 print TESTFILE "#include <$h>\n";
991 print TESTFILE "#ifndef $macro\n";
992 print TESTFILE "# error \"Macro $macro not defined\"\n";
993 print TESTFILE "#endif\n";
996 compiletest ($fnamebase, "Test availability of macro $macro",
997 "Macro \"$macro\" is not available.", $missing, 0);
998 } elsif (/^allow-header *(.*)/) {
1000 if ($seenheader{$pattern} != 1) {
1001 push @allowheader, $pattern;
1002 $seenheader{$pattern} = 1;
1005 } elsif (/^allow *(.*)/) {
1007 push @allow, $pattern;
1010 # printf ("line is `%s'\n", $_);
1018 # Read the data files for the header files which are allowed to be included.
1019 while ($#allowheader >= 0) {
1020 my($ah) = pop @allowheader;
1022 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
1023 acontrol: while (<ALLOW>) {
1024 next acontrol if (/^#/);
1025 next acontrol if (/^[ ]*$/);
1027 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1029 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1031 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1033 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1036 # Remember that this name is allowed.
1037 if ($type =~ /^struct *(.*)/) {
1039 } elsif ($type =~ /^union *(.*)/) {
1044 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1046 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1048 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1050 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1052 } elsif (/^macro *([^ ]*)/) {
1054 } elsif (/^allow-header *(.*)/) {
1055 if ($seenheader{$1} != 1) {
1056 push @allowheader, $1;
1057 $seenheader{$1} = 1;
1059 } elsif (/^allow *(.*)/) {
1066 # Now check the namespace.
1067 printf (" Checking the namespace of \"%s\"... ", $h);
1072 checknamespace ($h, $fnamebase, @allow);
1078 printf "-" x 76 . "\n";
1079 printf (" Total number of tests : %4d\n", $total);
1081 printf (" Number of known failures: %4d (", $known);
1082 $percent = ($known * 100) / $total;
1083 if ($known > 0 && $percent < 1.0) {
1084 printf (" <1%%)\n");
1086 printf ("%3d%%)\n", $percent);
1089 printf (" Number of failed tests : %4d (", $errors);
1090 $percent = ($errors * 100) / $total;
1091 if ($errors > 0 && $percent < 1.0) {
1092 printf (" <1%%)\n");
1094 printf ("%3d%%)\n", $percent);
1097 printf (" Number of skipped tests : %4d (", $skipped);
1098 $percent = ($skipped * 100) / $total;
1099 if ($skipped > 0 && $percent < 1.0) {
1100 printf (" <1%%)\n");
1102 printf ("%3d%%)\n", $percent);