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{'inttypes.h'} = "#include <stddef.h>\n";
57 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
58 $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
59 $mustprepend{'signal.h'} = "#include <pthread.h>\n";
60 $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
61 $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
62 $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
64 # Make a hash table from this information.
65 while ($#keywords >= 0) {
66 $iskeyword{pop (@keywords)} = 1;
69 # Make a hash table from the known problems.
70 while ($#knownproblems >= 0) {
71 $isknown{pop (@knownproblems)} = 1;
84 my($pattern, $string) = @_;
85 my($strlen) = length ($string);
88 if (substr ($pattern, 0, 1) eq '*') {
89 my($patlen) = length ($pattern) - 1;
90 $res = ($strlen >= $patlen
91 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
92 } elsif (substr ($pattern, -1, 1) eq '*') {
93 my($patlen) = length ($pattern) - 1;
94 $res = ($strlen >= $patlen
95 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
97 $res = $pattern eq $string;
105 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
116 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
118 if ($optional != 0) {
119 printf (" $errmsg\n");
124 printf (" $errmsg Compiler message:\n");
132 if ($verbose > 1 && -s "$fnamebase.out") {
133 # We print all warnings issued.
137 if ($printlog != 0) {
138 printf (" " . "-" x 71 . "\n");
139 open (MESSAGE, "< $fnamebase.out");
144 printf (" " . "-" x 71 . "\n");
147 unlink "$fnamebase.c";
148 unlink "$fnamebase.o";
149 unlink "$fnamebase.out";
157 my($fnamebase, $msg, $errmsg, $skip) = @_;
168 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
172 printf (" $errmsg Compiler message:\n");
178 # Now run the program. If the exit code is not zero something is wrong.
179 $result = system "$fnamebase > $fnamebase.out2 2>&1";
182 if ($verbose > 1 && -s "$fnamebase.out") {
183 # We print all warnings issued.
185 system "cat $fnamebase.out2 >> $fnamebase.out";
191 unlink "$fnamebase.out";
192 rename "$fnamebase.out2", "$fnamebase.out";
195 if ($printlog != 0) {
196 printf (" " . "-" x 71 . "\n");
197 open (MESSAGE, "< $fnamebase.out");
202 printf (" " . "-" x 71 . "\n");
206 unlink "$fnamebase.c";
207 unlink "$fnamebase.o";
208 unlink "$fnamebase.out";
209 unlink "$fnamebase.out2";
216 my($token, @allow) = @_;
219 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
221 for ($idx = 0; $idx <= $#allow; ++$idx) {
222 return if (poorfnmatch ($allow[$idx], $token));
225 if ($isknown{$token}) {
237 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
239 if (exists $errors{$token}) {
240 undef $errors{$token};
246 my($h, $fnamebase, @allow) = @_;
250 # Generate a program to get the contents of this header.
251 open (TESTFILE, ">$fnamebase.c");
252 print TESTFILE "#include <$h>\n";
257 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
258 loop: while (<CONTENT>) {
260 if (/^#define (.*)/) {
261 newtoken ($1, @allow);
262 } elsif (/^#undef (.*)/) {
265 # We have to tokenize the line.
268 my($len) = length ($str);
270 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
272 newtoken ($token, @allow);
278 unlink "$fnamebase.c";
281 foreach $f (%errors) {
282 if ($errors{$f} == 1) {
283 if ($realerror == 0) {
284 printf ("FAIL\n " . "-" x 72 . "\n");
288 printf (" Namespace violation: \"%s\"\n", $f);
291 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
294 if ($realerror == 0) {
296 printf ("EXPECTED FAILURES\n");
305 while ($#headers >= 0) {
306 my($h) = pop (@headers);
309 my($fnamebase) = "$tmpdir/$hf-test";
312 my(@allowheader) = ();
313 my(%seenheader) = ();
314 my($prepend) = $mustprepend{$h};
316 printf ("Testing <$h>\n");
317 printf ("----------" . "-" x length ($h) . "\n");
319 # Generate a program to test for the availability of this header.
320 open (TESTFILE, ">$fnamebase.c");
321 print TESTFILE "$prepend";
322 print TESTFILE "#include <$h>\n";
325 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
326 "Header <$h> not available", 0, 0);
330 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
331 control: while (<CONTROL>) {
333 next control if (/^#/);
334 next control if (/^[ ]*$/);
336 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
337 my($struct) = "$2$3";
343 # Remember that this name is allowed.
344 push @allow, $member;
346 # Generate a program to test for the availability of this member.
347 open (TESTFILE, ">$fnamebase.c");
348 print TESTFILE "$prepend";
349 print TESTFILE "#include <$h>\n";
350 print TESTFILE "$struct a;\n";
351 print TESTFILE "$struct b;\n";
352 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
353 print TESTFILE "void foobarbaz (void) {\n";
354 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
355 print TESTFILE "}\n";
358 $res = compiletest ($fnamebase, "Testing for member $member",
359 "Member \"$member\" not available.", $res, 0);
362 # Test the types of the members.
363 open (TESTFILE, ">$fnamebase.c");
364 print TESTFILE "$prepend";
365 print TESTFILE "#include <$h>\n";
366 print TESTFILE "$struct a;\n";
367 print TESTFILE "extern $type b$rest;\n";
368 print TESTFILE "extern __typeof__ (a.$member) b;\n";
371 compiletest ($fnamebase, "Testing for type of member $member",
372 "Member \"$member\" does not have the correct type.",
374 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
375 my($struct) = "$2$3";
381 # Remember that this name is allowed.
382 push @allow, $member;
384 # Generate a program to test for the availability of this member.
385 open (TESTFILE, ">$fnamebase.c");
386 print TESTFILE "$prepend";
387 print TESTFILE "#include <$h>\n";
388 print TESTFILE "$struct a;\n";
389 print TESTFILE "$struct b;\n";
390 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
391 print TESTFILE "void foobarbaz (void) {\n";
392 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
393 print TESTFILE "}\n";
396 $res = compiletest ($fnamebase, "Testing for member $member",
397 "NOT AVAILABLE.", $res, 1);
399 if ($res == 0 || $missing != 0) {
400 # Test the types of the members.
401 open (TESTFILE, ">$fnamebase.c");
402 print TESTFILE "$prepend";
403 print TESTFILE "#include <$h>\n";
404 print TESTFILE "$struct a;\n";
405 print TESTFILE "extern $type b$rest;\n";
406 print TESTFILE "extern __typeof__ (a.$member) b;\n";
409 compiletest ($fnamebase, "Testing for type of member $member",
410 "Member \"$member\" does not have the correct type.",
413 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
419 # Remember that this name is allowed.
422 # Generate a program to test for the availability of this constant.
423 open (TESTFILE, ">$fnamebase.c");
424 print TESTFILE "$prepend";
425 print TESTFILE "#include <$h>\n";
426 print TESTFILE "__typeof__ ($const) a = $const;\n";
429 $res = compiletest ($fnamebase, "Testing for constant $const",
430 "NOT PRESENT", $res, 1);
432 if ($value ne "" && $res == 0) {
433 # Generate a program to test for the value of this constant.
434 open (TESTFILE, ">$fnamebase.c");
435 print TESTFILE "$prepend";
436 print TESTFILE "#include <$h>\n";
437 # Negate the value since 0 means ok
438 print TESTFILE "int main (void) { return !($const $op $value); }\n";
441 $res = runtest ($fnamebase, "Testing for value of constant $const",
442 "Constant \"$const\" has not the right value.", $res);
444 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
450 # Remember that this name is allowed.
453 # Generate a program to test for the availability of this constant.
454 open (TESTFILE, ">$fnamebase.c");
455 print TESTFILE "$prepend";
456 print TESTFILE "#include <$h>\n";
457 print TESTFILE "__typeof__ ($const) a = $const;\n";
460 $res = compiletest ($fnamebase, "Testing for constant $const",
461 "Constant \"$const\" not available.", $res, 0);
464 # Generate a program to test for the value of this constant.
465 open (TESTFILE, ">$fnamebase.c");
466 print TESTFILE "$prepend";
467 print TESTFILE "#include <$h>\n";
468 # Negate the value since 0 means ok
469 print TESTFILE "int main (void) { return !($const $op $value); }\n";
472 $res = runtest ($fnamebase, "Testing for value of constant $const",
473 "Constant \"$const\" has not the right value.", $res);
475 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
481 # Remember that this name is allowed.
484 # Generate a program to test for the availability of this constant.
485 open (TESTFILE, ">$fnamebase.c");
486 print TESTFILE "$prepend";
487 print TESTFILE "#include <$h>\n";
488 print TESTFILE "__typeof__ ($const) a = $const;\n";
491 $res = compiletest ($fnamebase, "Testing for constant $const",
492 "Constant \"$const\" not available.", $res, 0);
494 # Test the types of the members.
495 open (TESTFILE, ">$fnamebase.c");
496 print TESTFILE "$prepend";
497 print TESTFILE "#include <$h>\n";
498 print TESTFILE "__typeof__ (($type) 0) a;\n";
499 print TESTFILE "extern __typeof__ ($const) a;\n";
502 compiletest ($fnamebase, "Testing for type of constant $const",
503 "Constant \"$const\" does not have the correct type.",
507 # Generate a program to test for the value of this constant.
508 open (TESTFILE, ">$fnamebase.c");
509 print TESTFILE "$prepend";
510 print TESTFILE "#include <$h>\n";
511 print TESTFILE "int main (void) { return $const != $value; }\n";
514 $res = runtest ($fnamebase, "Testing for value of constant $const",
515 "Constant \"$const\" has not the right value.", $res);
517 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
522 # Remember that this name is allowed.
525 # Generate a program to test for the availability of this constant.
526 open (TESTFILE, ">$fnamebase.c");
527 print TESTFILE "$prepend";
528 print TESTFILE "#include <$h>\n";
529 print TESTFILE "__typeof__ ($const) a = $const;\n";
532 $res = compiletest ($fnamebase, "Testing for constant $const",
533 "NOT PRESENT", $res, 1);
535 if ($value ne "" && $res == 0) {
536 # Generate a program to test for the value of this constant.
537 open (TESTFILE, ">$fnamebase.c");
538 print TESTFILE "$prepend";
539 print TESTFILE "#include <$h>\n";
540 print TESTFILE "int main (void) { return $const != $value; }\n";
543 $res = runtest ($fnamebase, "Testing for value of constant $const",
544 "Constant \"$const\" has not the right value.", $res);
546 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
551 # Remember that this name is allowed.
554 # Generate a program to test for the availability of this constant.
555 open (TESTFILE, ">$fnamebase.c");
556 print TESTFILE "$prepend";
557 print TESTFILE "#include <$h>\n";
558 print TESTFILE "__typeof__ ($const) a = $const;\n";
561 $res = compiletest ($fnamebase, "Testing for constant $const",
562 "Constant \"$const\" not available.", $res, 0);
565 # Generate a program to test for the value of this constant.
566 open (TESTFILE, ">$fnamebase.c");
567 print TESTFILE "$prepend";
568 print TESTFILE "#include <$h>\n";
569 print TESTFILE "int main (void) { return $const != $value; }\n";
572 $res = runtest ($fnamebase, "Testing for value of constant $const",
573 "Constant \"$const\" has not the right value.", $res);
575 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
580 # Remember that this name is allowed.
581 push @allow, $symbol;
583 # Generate a program to test for the availability of this constant.
584 open (TESTFILE, ">$fnamebase.c");
585 print TESTFILE "$prepend";
586 print TESTFILE "#include <$h>\n";
587 print TESTFILE "void foobarbaz (void) {\n";
588 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
589 print TESTFILE "}\n";
592 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
593 "Symbol \"$symbol\" not available.", $res, 0);
596 # Generate a program to test for the value of this constant.
597 open (TESTFILE, ">$fnamebase.c");
598 print TESTFILE "$prepend";
599 print TESTFILE "#include <$h>\n";
600 print TESTFILE "int main (void) { return $symbol != $value; }\n";
603 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
604 "Symbol \"$symbol\" has not the right value.", $res);
606 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
612 # Remember that this name is allowed.
615 # Generate a program to test for the availability of this constant.
616 open (TESTFILE, ">$fnamebase.c");
617 print TESTFILE "$prepend";
618 print TESTFILE "#include <$h>\n";
619 print TESTFILE "__typeof__ ($const) a = $const;\n";
622 $res = compiletest ($fnamebase, "Testing for constant $const",
623 "Constant \"$const\" not available.", $res, 0);
625 # Test the types of the members.
626 open (TESTFILE, ">$fnamebase.c");
627 print TESTFILE "$prepend";
628 print TESTFILE "#include <$h>\n";
629 print TESTFILE "__typeof__ (($type) 0) a;\n";
630 print TESTFILE "extern __typeof__ ($const) a;\n";
633 compiletest ($fnamebase, "Testing for type of constant $const",
634 "Constant \"$const\" does not have the correct type.",
638 # Generate a program to test for the value of this constant.
639 open (TESTFILE, ">$fnamebase.c");
640 print TESTFILE "$prepend";
641 print TESTFILE "#include <$h>\n";
642 print TESTFILE "int main (void) { return $const != $value; }\n";
645 $res = runtest ($fnamebase, "Testing for value of constant $const",
646 "Constant \"$const\" has not the right value.", $res);
648 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
650 my($maybe_opaque) = 0;
652 # Remember that this name is allowed.
653 if ($type =~ /^struct *(.*)/) {
655 } elsif ($type =~ /^union *(.*)/) {
662 # Remember that this name is allowed.
665 # Generate a program to test for the availability of this constant.
666 open (TESTFILE, ">$fnamebase.c");
667 print TESTFILE "$prepend";
668 print TESTFILE "#include <$h>\n";
669 if ($maybe_opaque == 1) {
670 print TESTFILE "$type *a;\n";
672 print TESTFILE "$type a;\n";
676 compiletest ($fnamebase, "Testing for type $type",
677 "NOT AVAILABLE", $missing, 1);
678 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
680 my($maybe_opaque) = 0;
682 # Remember that this name is allowed.
683 if ($type =~ /^struct *(.*)/) {
685 } elsif ($type =~ /^union *(.*)/) {
692 # Remember that this name is allowed.
695 # Generate a program to test for the availability of this type.
696 open (TESTFILE, ">$fnamebase.c");
697 print TESTFILE "$prepend";
698 print TESTFILE "#include <$h>\n";
699 if ($maybe_opaque == 1) {
700 print TESTFILE "$type *a;\n";
702 print TESTFILE "$type a;\n";
706 compiletest ($fnamebase, "Testing for type $type",
707 "Type \"$type\" not available.", $missing, 0);
708 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
709 my($rettype) = "$2$3";
714 # Remember that this name is allowed.
717 # Generate a program to test for availability of this function.
718 open (TESTFILE, ">$fnamebase.c");
719 print TESTFILE "$prepend";
720 print TESTFILE "#include <$h>\n";
721 # print TESTFILE "#undef $fname\n";
722 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
725 $res = compiletest ($fnamebase, "Test availability of function $fname",
726 "NOT AVAILABLE", $res, 1);
728 if ($res == 0 || $missing == 1) {
729 # Generate a program to test for the type of this function.
730 open (TESTFILE, ">$fnamebase.c");
731 print TESTFILE "$prepend";
732 print TESTFILE "#include <$h>\n";
733 # print TESTFILE "#undef $fname\n";
734 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
735 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
738 compiletest ($fnamebase, "Test for type of function $fname",
739 "Function \"$fname\" has incorrect type.", $res, 0);
741 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
742 my($rettype) = "$2$3";
747 # Remember that this name is allowed.
750 # Generate a program to test for availability of this function.
751 open (TESTFILE, ">$fnamebase.c");
752 print TESTFILE "$prepend";
753 print TESTFILE "#include <$h>\n";
754 # print TESTFILE "#undef $fname\n";
755 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
758 $res = compiletest ($fnamebase, "Test availability of function $fname",
759 "Function \"$fname\" is not available.", $res, 0);
761 # Generate a program to test for the type of this function.
762 open (TESTFILE, ">$fnamebase.c");
763 print TESTFILE "$prepend";
764 print TESTFILE "#include <$h>\n";
765 # print TESTFILE "#undef $fname\n";
766 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
767 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
770 compiletest ($fnamebase, "Test for type of function $fname",
771 "Function \"$fname\" has incorrect type.", $res, 0);
772 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
773 my($rettype) = "$2$3";
778 # Remember that this name is allowed.
781 # Generate a program to test for availability of this function.
782 open (TESTFILE, ">$fnamebase.c");
783 print TESTFILE "$prepend";
784 print TESTFILE "#include <$h>\n";
785 # print TESTFILE "#undef $fname\n";
786 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
789 $res = compiletest ($fnamebase, "Test availability of function $fname",
790 "NOT AVAILABLE", $res, 1);
792 if ($res == 0 || $missing != 0) {
793 # Generate a program to test for the type of this function.
794 open (TESTFILE, ">$fnamebase.c");
795 print TESTFILE "$prepend";
796 print TESTFILE "#include <$h>\n";
797 # print TESTFILE "#undef $fname\n";
798 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
799 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
802 compiletest ($fnamebase, "Test for type of function $fname",
803 "Function \"$fname\" has incorrect type.", $res, 0);
805 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
806 my($rettype) = "$2$3";
811 # Remember that this name is allowed.
814 # Generate a program to test for availability of this function.
815 open (TESTFILE, ">$fnamebase.c");
816 print TESTFILE "$prepend";
817 print TESTFILE "#include <$h>\n";
818 # print TESTFILE "#undef $fname\n";
819 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
822 $res = compiletest ($fnamebase, "Test availability of function $fname",
823 "Function \"$fname\" is not available.", $res, 0);
825 # Generate a program to test for the type of this function.
826 open (TESTFILE, ">$fnamebase.c");
827 print TESTFILE "$prepend";
828 print TESTFILE "#include <$h>\n";
829 # print TESTFILE "#undef $fname\n";
830 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
831 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
834 compiletest ($fnamebase, "Test for type of function $fname",
835 "Function \"$fname\" has incorrect type.", $res, 0);
836 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
842 # Remember that this name is allowed.
845 # Generate a program to test for availability of this function.
846 open (TESTFILE, ">$fnamebase.c");
847 print TESTFILE "$prepend";
848 print TESTFILE "#include <$h>\n";
849 # print TESTFILE "#undef $fname\n";
850 print TESTFILE "typedef $type xyzzy$rest;\n";
851 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
854 $res = compiletest ($fnamebase, "Test availability of variable $vname",
855 "Variable \"$vname\" is not available.", $res, 0);
857 # Generate a program to test for the type of this function.
858 open (TESTFILE, ">$fnamebase.c");
859 print TESTFILE "$prepend";
860 print TESTFILE "#include <$h>\n";
861 # print TESTFILE "#undef $fname\n";
862 print TESTFILE "extern $type $vname$rest;\n";
865 compiletest ($fnamebase, "Test for type of variable $fname",
866 "Variable \"$vname\" has incorrect type.", $res, 0);
867 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
868 my($rettype) = "$2$3";
873 # Remember that this name is allowed.
876 # Generate a program to test for availability of this function.
877 open (TESTFILE, ">$fnamebase.c");
878 print TESTFILE "$prepend";
879 print TESTFILE "#include <$h>\n";
880 print TESTFILE "#ifndef $fname\n";
881 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
882 print TESTFILE "#endif\n";
885 $res = compiletest ($fnamebase, "Test availability of function $fname",
886 "Function \"$fname\" is not available.", $res, 0);
888 # Generate a program to test for the type of this function.
889 open (TESTFILE, ">$fnamebase.c");
890 print TESTFILE "$prepend";
891 print TESTFILE "#include <$h>\n";
892 print TESTFILE "#ifndef $fname\n";
893 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
894 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
895 print TESTFILE "#endif\n";
898 compiletest ($fnamebase, "Test for type of function $fname",
899 "Function \"$fname\" has incorrect type.", $res, 0);
900 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
901 # The above regex doesn't handle a \" in a string.
906 # Remember that this name is allowed.
909 # Generate a program to test for availability of this macro.
910 open (TESTFILE, ">$fnamebase.c");
911 print TESTFILE "$prepend";
912 print TESTFILE "#include <$h>\n";
913 print TESTFILE "#ifndef $macro\n";
914 print TESTFILE "# error \"Macro $macro not defined\"\n";
915 print TESTFILE "#endif\n";
918 compiletest ($fnamebase, "Test availability of macro $macro",
919 "Macro \"$macro\" is not available.", $missing, 0);
921 # Generate a program to test for the value of this macro.
922 open (TESTFILE, ">$fnamebase.c");
923 print TESTFILE "$prepend";
924 print TESTFILE "#include <$h>\n";
925 # We can't include <string.h> here.
926 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
927 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
930 $res = runtest ($fnamebase, "Testing for value of macro $macro",
931 "Macro \"$macro\" has not the right value.", $res);
932 } elsif (/^optional-macro *([^ ]*)/) {
935 # Remember that this name is allowed.
938 # Generate a program to test for availability of this macro.
939 open (TESTFILE, ">$fnamebase.c");
940 print TESTFILE "$prepend";
941 print TESTFILE "#include <$h>\n";
942 print TESTFILE "#ifndef $macro\n";
943 print TESTFILE "# error \"Macro $macro not defined\"\n";
944 print TESTFILE "#endif\n";
947 compiletest ($fnamebase, "Test availability of macro $macro",
948 "NOT PRESENT", $missing, 1);
949 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
955 # Remember that this name is allowed.
958 # Generate a program to test for availability of this macro.
959 open (TESTFILE, ">$fnamebase.c");
960 print TESTFILE "$prepend";
961 print TESTFILE "#include <$h>\n";
962 print TESTFILE "#ifndef $macro\n";
963 print TESTFILE "# error \"Macro $macro not defined\"\n";
964 print TESTFILE "#endif\n";
967 $res = compiletest ($fnamebase, "Test availability of macro $macro",
968 "Macro \"$macro\" is not available.", $res, 0);
971 # Generate a program to test for the value of this constant.
972 open (TESTFILE, ">$fnamebase.c");
973 print TESTFILE "$prepend";
974 print TESTFILE "#include <$h>\n";
975 # Negate the value since 0 means ok
976 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
979 $res = runtest ($fnamebase, "Testing for value of constant $macro",
980 "Macro \"$macro\" has not the right value.", $res);
982 } elsif (/^macro *([^ ]*)/) {
985 # Remember that this name is allowed.
988 # Generate a program to test for availability of this macro.
989 open (TESTFILE, ">$fnamebase.c");
990 print TESTFILE "$prepend";
991 print TESTFILE "#include <$h>\n";
992 print TESTFILE "#ifndef $macro\n";
993 print TESTFILE "# error \"Macro $macro not defined\"\n";
994 print TESTFILE "#endif\n";
997 compiletest ($fnamebase, "Test availability of macro $macro",
998 "Macro \"$macro\" is not available.", $missing, 0);
999 } elsif (/^allow-header *(.*)/) {
1001 if ($seenheader{$pattern} != 1) {
1002 push @allowheader, $pattern;
1003 $seenheader{$pattern} = 1;
1006 } elsif (/^allow *(.*)/) {
1008 push @allow, $pattern;
1011 # printf ("line is `%s'\n", $_);
1019 # Read the data files for the header files which are allowed to be included.
1020 while ($#allowheader >= 0) {
1021 my($ah) = pop @allowheader;
1023 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
1024 acontrol: while (<ALLOW>) {
1025 next acontrol if (/^#/);
1026 next acontrol if (/^[ ]*$/);
1028 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1030 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1032 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1034 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1037 # Remember that this name is allowed.
1038 if ($type =~ /^struct *(.*)/) {
1040 } elsif ($type =~ /^union *(.*)/) {
1045 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1047 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1049 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1051 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1053 } elsif (/^macro *([^ ]*)/) {
1055 } elsif (/^allow-header *(.*)/) {
1056 if ($seenheader{$1} != 1) {
1057 push @allowheader, $1;
1058 $seenheader{$1} = 1;
1060 } elsif (/^allow *(.*)/) {
1067 # Now check the namespace.
1068 printf (" Checking the namespace of \"%s\"... ", $h);
1073 checknamespace ($h, $fnamebase, @allow);
1079 printf "-" x 76 . "\n";
1080 printf (" Total number of tests : %4d\n", $total);
1082 printf (" Number of known failures: %4d (", $known);
1083 $percent = ($known * 100) / $total;
1084 if ($known > 0 && $percent < 1.0) {
1085 printf (" <1%%)\n");
1087 printf ("%3d%%)\n", $percent);
1090 printf (" Number of failed tests : %4d (", $errors);
1091 $percent = ($errors * 100) / $total;
1092 if ($errors > 0 && $percent < 1.0) {
1093 printf (" <1%%)\n");
1095 printf ("%3d%%)\n", $percent);
1098 printf (" Number of skipped tests : %4d (", $skipped);
1099 $percent = ($skipped * 100) / $total;
1100 if ($skipped > 0 && $percent < 1.0) {
1101 printf (" <1%%)\n");
1103 printf ("%3d%%)\n", $percent);