6 $standard = "XOPEN2K8";
9 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
10 'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir);
11 @headers = split(/,/,join(',',@headers));
13 # List of the headers we are testing.
15 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
16 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "uchar.h",
17 "time.h", "tgmath.h", "termios.h", "tar.h", "sys/wait.h",
18 "sys/utsname.h", "sys/un.h", "sys/uio.h", "sys/types.h",
19 "sys/times.h", "sys/timeb.h", "sys/time.h", "sys/statvfs.h",
20 "sys/stat.h", "sys/socket.h", "sys/shm.h", "sys/sem.h",
21 "sys/select.h", "sys/resource.h", "sys/msg.h", "sys/mman.h",
22 "sys/ipc.h", "syslog.h", "stropts.h", "strings.h", "string.h",
23 "stdlib.h", "stdio.h", "stdint.h", "stddef.h", "stdarg.h",
24 "spawn.h", "signal.h", "setjmp.h", "semaphore.h", "search.h",
25 "sched.h", "regex.h", "pwd.h", "pthread.h", "poll.h",
26 "nl_types.h", "netinet/tcp.h", "netinet/in.h", "net/if.h",
27 "netdb.h", "ndbm.h", "mqueue.h", "monetary.h", "math.h",
28 "locale.h", "libgen.h", "limits.h", "langinfo.h", "iso646.h",
29 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
30 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h",
31 "dirent.h", "ctype.h", "cpio.h", "complex.h", "assert.h",
32 "arpa/inet.h", "aio.h");
35 $CFLAGS{"ISO"} = "-ansi";
36 $CFLAGS{"ISO99"} = "-std=c99";
37 $CFLAGS{"ISO11"} = "-std=c1x -D_ISOC11_SOURCE";
38 $CFLAGS{"POSIX"} = "-D_POSIX_C_SOURCE=199912 -ansi";
39 $CFLAGS{"XPG3"} = "-ansi -D_XOPEN_SOURCE";
40 $CFLAGS{"XPG4"} = "-ansi -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED";
41 $CFLAGS{"UNIX98"} = "-ansi -D_XOPEN_SOURCE=500";
42 $CFLAGS{"XOPEN2K"} = "-std=c99 -D_XOPEN_SOURCE=600";
43 $CFLAGS{"XOPEN2K8"} = "-std=c99 -D_XOPEN_SOURCE=700";
44 $CFLAGS{"POSIX2008"} = "-std=c99 -D_POSIX_C_SOURCE=200809L";
46 $CFLAGS = "$flags -fno-builtin '-D__attribute__(x)=' $CFLAGS{$standard} -D_ISOMAC";
48 # Check standard name for validity.
49 die "unknown standard \"$standard\"" if ($CFLAGS{$standard} eq "");
51 # if ($standard ne "XOPEN2K8" && $standard ne "POSIX2008") {
52 # # Some headers need a bit more attention. At least with XPG7
53 # # all headers should be self-contained.
54 # $mustprepend{'inttypes.h'} = "#include <stddef.h>\n";
55 # $mustprepend{'glob.h'} = "#include <sys/types.h>\n";
56 # $mustprepend{'grp.h'} = "#include <sys/types.h>\n";
57 # $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
58 # $mustprepend{'pwd.h'} = "#include <sys/types.h>\n";
59 # $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
60 # $mustprepend{'signal.h'} = "#include <pthread.h>\n#include <sys/types.h>\n";
61 # $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
62 # $mustprepend{'sys/stat.h'} = "#include <sys/types.h>\n";
63 # $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
64 # $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
67 # These are the ISO C99 keywords.
68 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
69 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
70 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
71 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
72 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
74 # Make a hash table from this information.
75 while ($#keywords >= 0) {
76 $iskeyword{pop (@keywords)} = 1;
87 my($pattern, $string) = @_;
88 my($strlen) = length ($string);
91 if (substr ($pattern, 0, 1) eq '*') {
92 my($patlen) = length ($pattern) - 1;
93 $res = ($strlen >= $patlen
94 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
95 } elsif (substr ($pattern, -1, 1) eq '*') {
96 if (substr ($pattern, -2, 1) eq ']') {
97 my($patlen) = index ($pattern, '[');
98 my($range) = substr ($pattern, $patlen + 1, -2);
99 $res = ($strlen > $patlen
100 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)
101 && index ($range, substr ($string, $patlen, 1)) != -1);
103 my($patlen) = length ($pattern) - 1;
104 $res = ($strlen >= $patlen
105 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
108 $res = $pattern eq $string;
116 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
127 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
129 if ($optional != 0) {
130 printf (" $errmsg\n");
135 printf (" $errmsg Compiler message:\n");
143 if ($verbose > 1 && -s "$fnamebase.out") {
144 # We print all warnings issued.
148 if ($printlog != 0) {
149 printf (" " . "-" x 71 . "\n");
150 open (MESSAGE, "< $fnamebase.out");
155 printf (" " . "-" x 71 . "\n");
158 unlink "$fnamebase.c";
159 unlink "$fnamebase.o";
160 unlink "$fnamebase.out";
168 my($fnamebase, $msg, $errmsg, $skip) = @_;
179 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
183 printf (" $errmsg Compiler message:\n");
189 # Now run the program. If the exit code is not zero something is wrong.
190 $result = system "$fnamebase > $fnamebase.out2 2>&1";
193 if ($verbose > 1 && -s "$fnamebase.out") {
194 # We print all warnings issued.
196 system "cat $fnamebase.out2 >> $fnamebase.out";
202 unlink "$fnamebase.out";
203 rename "$fnamebase.out2", "$fnamebase.out";
206 if ($printlog != 0) {
207 printf (" " . "-" x 71 . "\n");
208 open (MESSAGE, "< $fnamebase.out");
213 printf (" " . "-" x 71 . "\n");
217 unlink "$fnamebase.c";
218 unlink "$fnamebase.o";
219 unlink "$fnamebase.out";
220 unlink "$fnamebase.out2";
227 my($token, @allow) = @_;
230 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
232 for ($idx = 0; $idx <= $#allow; ++$idx) {
233 return if (poorfnmatch ($allow[$idx], $token));
242 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
244 if (exists $errors{$token}) {
245 undef $errors{$token};
251 my($h, $fnamebase, @allow) = @_;
255 # Generate a program to get the contents of this header.
256 open (TESTFILE, ">$fnamebase.c");
257 print TESTFILE "#include <$h>\n";
262 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
263 loop: while (<CONTENT>) {
265 if (/^#define (.*)/) {
266 newtoken ($1, @allow);
267 } elsif (/^#undef (.*)/) {
270 # We have to tokenize the line.
273 my($len) = length ($str);
275 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
277 newtoken ($token, @allow);
283 unlink "$fnamebase.c";
286 # Sort the output list so it's easier to compare results with diff.
287 foreach $f (sort keys(%errors)) {
288 if ($errors{$f} == 1) {
289 if ($realerror == 0) {
290 printf ("FAIL\n " . "-" x 72 . "\n");
294 printf (" Namespace violation: \"%s\"\n", $f);
297 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
300 if ($realerror == 0) {
306 while ($#headers >= 0) {
307 my($h) = pop (@headers);
310 my($fnamebase) = "$tmpdir/$hf-test";
313 my(@allowheader) = ();
314 my(%seenheader) = ();
315 my($prepend) = $mustprepend{$h};
318 printf ("Testing <$h>\n");
319 printf ("----------" . "-" x length ($h) . "\n");
321 open (CONTROL, "$CC -E -D$standard -x c data/$h-data |");
322 control: while (<CONTROL>) {
324 next control if (/^#/);
325 next control if (/^[ ]*$/);
329 # Generate a program to test for the availability of this header.
330 open (TESTFILE, ">$fnamebase.c");
331 print TESTFILE "$prepend";
332 print TESTFILE "#include <$h>\n";
335 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
336 "Header <$h> not available", 0, 0);
338 last control if ($missing);
341 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
342 my($struct) = "$2$3";
348 # Remember that this name is allowed.
349 push @allow, $member;
351 # Generate a program to test for the availability of this member.
352 open (TESTFILE, ">$fnamebase.c");
353 print TESTFILE "$prepend";
354 print TESTFILE "#include <$h>\n";
355 print TESTFILE "$struct a;\n";
356 print TESTFILE "$struct b;\n";
357 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
358 print TESTFILE "void foobarbaz (void) {\n";
359 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
360 print TESTFILE "}\n";
363 $res = compiletest ($fnamebase, "Testing for member $member",
364 "Member \"$member\" not available.", $res, 0);
367 # Test the types of the members.
368 open (TESTFILE, ">$fnamebase.c");
369 print TESTFILE "$prepend";
370 print TESTFILE "#include <$h>\n";
371 print TESTFILE "$struct a;\n";
372 print TESTFILE "extern $type b$rest;\n";
373 print TESTFILE "extern __typeof__ (a.$member) b;\n";
376 compiletest ($fnamebase, "Testing for type of member $member",
377 "Member \"$member\" does not have the correct type.",
379 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
380 my($struct) = "$2$3";
386 # Remember that this name is allowed.
387 push @allow, $member;
389 # Generate a program to test for the availability of this member.
390 open (TESTFILE, ">$fnamebase.c");
391 print TESTFILE "$prepend";
392 print TESTFILE "#include <$h>\n";
393 print TESTFILE "$struct a;\n";
394 print TESTFILE "$struct b;\n";
395 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
396 print TESTFILE "void foobarbaz (void) {\n";
397 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
398 print TESTFILE "}\n";
401 $res = compiletest ($fnamebase, "Testing for member $member",
402 "NOT AVAILABLE.", $res, 1);
404 if ($res == 0 || $missing != 0) {
405 # Test the types of the members.
406 open (TESTFILE, ">$fnamebase.c");
407 print TESTFILE "$prepend";
408 print TESTFILE "#include <$h>\n";
409 print TESTFILE "$struct a;\n";
410 print TESTFILE "extern $type b$rest;\n";
411 print TESTFILE "extern __typeof__ (a.$member) b;\n";
414 compiletest ($fnamebase, "Testing for type of member $member",
415 "Member \"$member\" does not have the correct type.",
418 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<!]+) ([A-Za-z0-9_-]*)/) {
424 # Remember that this name is allowed.
427 # Generate a program to test for the availability of this constant.
428 open (TESTFILE, ">$fnamebase.c");
429 print TESTFILE "$prepend";
430 print TESTFILE "#include <$h>\n";
431 print TESTFILE "__typeof__ ($const) a = $const;\n";
434 $res = compiletest ($fnamebase, "Testing for constant $const",
435 "NOT PRESENT", $res, 1);
437 if ($value ne "" && $res == 0) {
438 # Generate a program to test for the value of this constant.
439 open (TESTFILE, ">$fnamebase.c");
440 print TESTFILE "$prepend";
441 print TESTFILE "#include <$h>\n";
442 # Negate the value since 0 means ok
443 print TESTFILE "int main (void) { return !($const $op $value); }\n";
446 $res = runtest ($fnamebase, "Testing for value of constant $const",
447 "Constant \"$const\" has not the right value.", $res);
449 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_-]*)/) {
455 # Remember that this name is allowed.
458 # Generate a program to test for the availability of this constant.
459 open (TESTFILE, ">$fnamebase.c");
460 print TESTFILE "$prepend";
461 print TESTFILE "#include <$h>\n";
462 print TESTFILE "__typeof__ ($const) a = $const;\n";
465 $res = compiletest ($fnamebase, "Testing for constant $const",
466 "Constant \"$const\" not available.", $res, 0);
469 # Generate a program to test for the value of this constant.
470 open (TESTFILE, ">$fnamebase.c");
471 print TESTFILE "$prepend";
472 print TESTFILE "#include <$h>\n";
473 # Negate the value since 0 means ok
474 print TESTFILE "int main (void) { return !($const $op $value); }\n";
477 $res = runtest ($fnamebase, "Testing for value of constant $const",
478 "Constant \"$const\" has not the right value.", $res);
480 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_-]*)?/) {
486 # Remember that this name is allowed.
489 # Generate a program to test for the availability of this constant.
490 open (TESTFILE, ">$fnamebase.c");
491 print TESTFILE "$prepend";
492 print TESTFILE "#include <$h>\n";
493 print TESTFILE "__typeof__ ($const) a = $const;\n";
496 $res = compiletest ($fnamebase, "Testing for constant $const",
497 "Constant \"$const\" not available.", $res, 0);
499 # Test the types of the members.
500 open (TESTFILE, ">$fnamebase.c");
501 print TESTFILE "$prepend";
502 print TESTFILE "#include <$h>\n";
503 print TESTFILE "__typeof__ (($type) 0) a;\n";
504 print TESTFILE "extern __typeof__ ($const) a;\n";
507 compiletest ($fnamebase, "Testing for type of constant $const",
508 "Constant \"$const\" does not have the correct type.",
512 # Generate a program to test for the value of this constant.
513 open (TESTFILE, ">$fnamebase.c");
514 print TESTFILE "$prepend";
515 print TESTFILE "#include <$h>\n";
516 print TESTFILE "int main (void) { return $const != $value; }\n";
519 $res = runtest ($fnamebase, "Testing for value of constant $const",
520 "Constant \"$const\" has not the right value.", $res);
522 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
527 # Remember that this name is allowed.
530 # Generate a program to test for the availability of this constant.
531 open (TESTFILE, ">$fnamebase.c");
532 print TESTFILE "$prepend";
533 print TESTFILE "#include <$h>\n";
534 print TESTFILE "__typeof__ ($const) a = $const;\n";
537 $res = compiletest ($fnamebase, "Testing for constant $const",
538 "NOT PRESENT", $res, 1);
540 if ($value ne "" && $res == 0) {
541 # Generate a program to test for the value of this constant.
542 open (TESTFILE, ">$fnamebase.c");
543 print TESTFILE "$prepend";
544 print TESTFILE "#include <$h>\n";
545 print TESTFILE "int main (void) { return $const != $value; }\n";
548 $res = runtest ($fnamebase, "Testing for value of constant $const",
549 "Constant \"$const\" has not the right value.", $res);
551 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
556 # Remember that this name is allowed.
559 # Generate a program to test for the availability of this constant.
560 open (TESTFILE, ">$fnamebase.c");
561 print TESTFILE "$prepend";
562 print TESTFILE "#include <$h>\n";
563 print TESTFILE "__typeof__ ($const) a = $const;\n";
566 $res = compiletest ($fnamebase, "Testing for constant $const",
567 "Constant \"$const\" not available.", $res, 0);
570 # Generate a program to test for the value of this constant.
571 open (TESTFILE, ">$fnamebase.c");
572 print TESTFILE "$prepend";
573 print TESTFILE "#include <$h>\n";
574 print TESTFILE "int main (void) { return $const != $value; }\n";
577 $res = runtest ($fnamebase, "Testing for value of constant $const",
578 "Constant \"$const\" has not the right value.", $res);
580 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
585 # Remember that this name is allowed.
586 push @allow, $symbol;
588 # Generate a program to test for the availability of this constant.
589 open (TESTFILE, ">$fnamebase.c");
590 print TESTFILE "$prepend";
591 print TESTFILE "#include <$h>\n";
592 print TESTFILE "void foobarbaz (void) {\n";
593 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
594 print TESTFILE "}\n";
597 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
598 "Symbol \"$symbol\" not available.", $res, 0);
601 # Generate a program to test for the value of this constant.
602 open (TESTFILE, ">$fnamebase.c");
603 print TESTFILE "$prepend";
604 print TESTFILE "#include <$h>\n";
605 print TESTFILE "int main (void) { return $symbol != $value; }\n";
608 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
609 "Symbol \"$symbol\" has not the right value.", $res);
611 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
613 my($maybe_opaque) = 0;
615 # Remember that this name is allowed.
616 if ($type =~ /^struct *(.*)/) {
618 } elsif ($type =~ /^union *(.*)/) {
625 # Generate a program to test for the availability of this constant.
626 open (TESTFILE, ">$fnamebase.c");
627 print TESTFILE "$prepend";
628 print TESTFILE "#include <$h>\n";
629 if ($maybe_opaque == 1) {
630 print TESTFILE "$type *a;\n";
632 print TESTFILE "$type a;\n";
636 compiletest ($fnamebase, "Testing for type $type",
637 "NOT AVAILABLE", $missing, 1);
638 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
640 my($maybe_opaque) = 0;
642 # Remember that this name is allowed.
643 if ($type =~ /^struct *(.*)/) {
645 } elsif ($type =~ /^union *(.*)/) {
652 # Generate a program to test for the availability of this type.
653 open (TESTFILE, ">$fnamebase.c");
654 print TESTFILE "$prepend";
655 print TESTFILE "#include <$h>\n";
656 if ($maybe_opaque == 1) {
657 print TESTFILE "$type *a;\n";
659 print TESTFILE "$type a;\n";
663 compiletest ($fnamebase, "Testing for type $type",
664 "Type \"$type\" not available.", $missing, 0);
665 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
668 # Remember that this name is allowed.
669 if ($type =~ /^struct *(.*)/) {
671 } elsif ($type =~ /^union *(.*)/) {
677 # Generate a program to test for the availability of this type.
678 open (TESTFILE, ">$fnamebase.c");
679 print TESTFILE "$prepend";
680 print TESTFILE "#include <$h>\n";
681 print TESTFILE "$type;\n";
684 compiletest ($fnamebase, "Testing for type $type",
685 "Type \"$type\" not available.", $missing, 0);
686 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
687 my($rettype) = "$2$3";
692 # Remember that this name is allowed.
695 # Generate a program to test for availability of this function.
696 open (TESTFILE, ">$fnamebase.c");
697 print TESTFILE "$prepend";
698 print TESTFILE "#include <$h>\n";
699 # print TESTFILE "#undef $fname\n";
700 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
703 $res = compiletest ($fnamebase, "Test availability of function $fname",
704 "NOT AVAILABLE", $res, 1);
706 if ($res == 0 || $missing == 1) {
707 # Generate a program to test for the type of this function.
708 open (TESTFILE, ">$fnamebase.c");
709 print TESTFILE "$prepend";
710 print TESTFILE "#include <$h>\n";
711 # print TESTFILE "#undef $fname\n";
712 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
713 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
716 compiletest ($fnamebase, "Test for type of function $fname",
717 "Function \"$fname\" has incorrect type.", $res, 0);
719 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
720 my($rettype) = "$2$3";
725 # Remember that this name is allowed.
728 # Generate a program to test for availability 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 "$rettype (*(*foobarbaz) $args = $fname;\n";
736 $res = compiletest ($fnamebase, "Test availability of function $fname",
737 "Function \"$fname\" is not available.", $res, 0);
739 # Generate a program to test for the type of this function.
740 open (TESTFILE, ">$fnamebase.c");
741 print TESTFILE "$prepend";
742 print TESTFILE "#include <$h>\n";
743 # print TESTFILE "#undef $fname\n";
744 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
745 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
748 compiletest ($fnamebase, "Test for type of function $fname",
749 "Function \"$fname\" has incorrect type.", $res, 0);
750 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
751 my($rettype) = "$2$3";
756 # Remember that this name is allowed.
759 # Generate a program to test for availability of this function.
760 open (TESTFILE, ">$fnamebase.c");
761 print TESTFILE "$prepend";
762 print TESTFILE "#include <$h>\n";
763 # print TESTFILE "#undef $fname\n";
764 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
767 $res = compiletest ($fnamebase, "Test availability of function $fname",
768 "NOT AVAILABLE", $res, 1);
770 if ($res == 0 || $missing != 0) {
771 # Generate a program to test for the type of this function.
772 open (TESTFILE, ">$fnamebase.c");
773 print TESTFILE "$prepend";
774 print TESTFILE "#include <$h>\n";
775 # print TESTFILE "#undef $fname\n";
776 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
777 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
780 compiletest ($fnamebase, "Test for type of function $fname",
781 "Function \"$fname\" has incorrect type.", $res, 0);
783 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
784 my($rettype) = "$2$3";
789 # Remember that this name is allowed.
792 # Generate a program to test for availability 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 "$rettype (*foobarbaz) $args = $fname;\n";
800 $res = compiletest ($fnamebase, "Test availability of function $fname",
801 "Function \"$fname\" is not available.", $res, 0);
803 # Generate a program to test for the type of this function.
804 open (TESTFILE, ">$fnamebase.c");
805 print TESTFILE "$prepend";
806 print TESTFILE "#include <$h>\n";
807 # print TESTFILE "#undef $fname\n";
808 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
809 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
812 compiletest ($fnamebase, "Test for type of function $fname",
813 "Function \"$fname\" has incorrect type.", $res, 0);
814 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
820 # Remember that this name is allowed.
823 # Generate a program to test for availability of this function.
824 open (TESTFILE, ">$fnamebase.c");
825 print TESTFILE "$prepend";
826 print TESTFILE "#include <$h>\n";
827 # print TESTFILE "#undef $fname\n";
828 print TESTFILE "typedef $type xyzzy$rest;\n";
829 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
832 $res = compiletest ($fnamebase, "Test availability of variable $vname",
833 "Variable \"$vname\" is not available.", $res, 0);
835 # Generate a program to test for the type of this function.
836 open (TESTFILE, ">$fnamebase.c");
837 print TESTFILE "$prepend";
838 print TESTFILE "#include <$h>\n";
839 # print TESTFILE "#undef $fname\n";
840 print TESTFILE "extern $type $vname$rest;\n";
843 compiletest ($fnamebase, "Test for type of variable $fname",
844 "Variable \"$vname\" has incorrect type.", $res, 0);
845 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
846 my($rettype) = "$2$3";
851 # Remember that this name is allowed.
854 # Generate a program to test for availability of this function.
855 open (TESTFILE, ">$fnamebase.c");
856 print TESTFILE "$prepend";
857 print TESTFILE "#include <$h>\n";
858 print TESTFILE "#ifndef $fname\n";
859 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
860 print TESTFILE "#endif\n";
863 $res = compiletest ($fnamebase, "Test availability of macro $fname",
864 "Function \"$fname\" is not available.", $res, 0);
866 # Generate a program to test for the type of this function.
867 open (TESTFILE, ">$fnamebase.c");
868 print TESTFILE "$prepend";
869 print TESTFILE "#include <$h>\n";
870 print TESTFILE "#ifndef $fname\n";
871 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
872 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
873 print TESTFILE "#endif\n";
876 compiletest ($fnamebase, "Test for type of macro $fname",
877 "Function \"$fname\" has incorrect type.", $res, 0);
878 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
879 # The above regex doesn't handle a \" in a string.
884 # Remember that this name is allowed.
887 # Generate a program to test for availability of this macro.
888 open (TESTFILE, ">$fnamebase.c");
889 print TESTFILE "$prepend";
890 print TESTFILE "#include <$h>\n";
891 print TESTFILE "#ifndef $macro\n";
892 print TESTFILE "# error \"Macro $macro not defined\"\n";
893 print TESTFILE "#endif\n";
896 compiletest ($fnamebase, "Test availability of macro $macro",
897 "Macro \"$macro\" is not available.", $missing, 0);
899 # Generate a program to test for the value of this macro.
900 open (TESTFILE, ">$fnamebase.c");
901 print TESTFILE "$prepend";
902 print TESTFILE "#include <$h>\n";
903 # We can't include <string.h> here.
904 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
905 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
908 $res = runtest ($fnamebase, "Testing for value of macro $macro",
909 "Macro \"$macro\" has not the right value.", $res);
910 } elsif (/^optional-macro *([^ ]*)/) {
913 # Remember that this name is allowed.
916 # Generate a program to test for availability of this macro.
917 open (TESTFILE, ">$fnamebase.c");
918 print TESTFILE "$prepend";
919 print TESTFILE "#include <$h>\n";
920 print TESTFILE "#ifndef $macro\n";
921 print TESTFILE "# error \"Macro $macro not defined\"\n";
922 print TESTFILE "#endif\n";
925 compiletest ($fnamebase, "Test availability of macro $macro",
926 "NOT PRESENT", $missing, 1);
927 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<!]+) ([A-Za-z0-9_]*)/) {
933 # Remember that this name is allowed.
936 # Generate a program to test for availability of this macro.
937 open (TESTFILE, ">$fnamebase.c");
938 print TESTFILE "$prepend";
939 print TESTFILE "#include <$h>\n";
940 print TESTFILE "#ifndef $macro\n";
941 print TESTFILE "# error \"Macro $macro not defined\"\n";
942 print TESTFILE "#endif\n";
945 $res = compiletest ($fnamebase, "Test availability of macro $macro",
946 "Macro \"$macro\" is not available.", $res, 0);
949 # Generate a program to test for the value of this constant.
950 open (TESTFILE, ">$fnamebase.c");
951 print TESTFILE "$prepend";
952 print TESTFILE "#include <$h>\n";
953 # Negate the value since 0 means ok
954 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
957 $res = runtest ($fnamebase, "Testing for value of macro $macro",
958 "Macro \"$macro\" has not the right value.", $res);
960 } elsif (/^macro *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)/) {
965 # Remember that this name is allowed.
968 # Generate a program to test for availability of this macro.
969 open (TESTFILE, ">$fnamebase.c");
970 print TESTFILE "$prepend";
971 print TESTFILE "#include <$h>\n";
972 print TESTFILE "#ifndef $macro\n";
973 print TESTFILE "# error \"Macro $macro not defined\"\n";
974 print TESTFILE "#endif\n";
977 $res = compiletest ($fnamebase, "Test availability of macro $macro",
978 "Macro \"$macro\" is not available.", $res, 0);
981 # Generate a program to test for the value of this constant.
982 open (TESTFILE, ">$fnamebase.c");
983 print TESTFILE "$prepend";
984 print TESTFILE "#include <$h>\n";
985 # Negate the value since 0 means ok
986 print TESTFILE "int main (void) { return !($macro == $value); }\n";
989 $res = runtest ($fnamebase, "Testing for value of macro $macro",
990 "Macro \"$macro\" has not the right value.", $res);
992 } elsif (/^macro *([^ ]*)/) {
995 # Remember that this name is allowed.
998 # Generate a program to test for availability of this macro.
999 open (TESTFILE, ">$fnamebase.c");
1000 print TESTFILE "$prepend";
1001 print TESTFILE "#include <$h>\n";
1002 print TESTFILE "#ifndef $macro\n";
1003 print TESTFILE "# error \"Macro $macro not defined\"\n";
1004 print TESTFILE "#endif\n";
1007 compiletest ($fnamebase, "Test availability of macro $macro",
1008 "Macro \"$macro\" is not available.", $missing, 0);
1009 } elsif (/^allow-header *(.*)/) {
1011 if ($seenheader{$pattern} != 1) {
1012 push @allowheader, $pattern;
1013 $seenheader{$pattern} = 1;
1016 } elsif (/^allow *(.*)/) {
1018 push @allow, $pattern;
1021 # printf ("line is `%s'\n", $_);
1029 # Read the data files for the header files which are allowed to be included.
1030 while ($#allowheader >= 0) {
1031 my($ah) = pop @allowheader;
1033 open (ALLOW, "$CC -E -D$standard - < data/$ah-data |");
1034 acontrol: while (<ALLOW>) {
1036 next acontrol if (/^#/);
1037 next acontrol if (/^[ ]*$/);
1039 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1041 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1043 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1045 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
1048 # Remember that this name is allowed.
1049 if ($type =~ /^struct *(.*)/) {
1051 } elsif ($type =~ /^union *(.*)/) {
1056 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1058 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1060 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1062 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1064 } elsif (/^macro *([^ ]*)/) {
1066 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
1068 } elsif (/^allow-header *(.*)/) {
1069 if ($seenheader{$1} != 1) {
1070 push @allowheader, $1;
1071 $seenheader{$1} = 1;
1073 } elsif (/^allow *(.*)/) {
1081 printf (" Not defined\n");
1083 # Now check the namespace.
1084 printf (" Checking the namespace of \"%s\"... ", $h);
1089 checknamespace ($h, $fnamebase, @allow);
1096 printf "-" x 76 . "\n";
1097 printf (" Total number of tests : %4d\n", $total);
1099 printf (" Number of failed tests : %4d (", $errors);
1100 $percent = ($errors * 100) / $total;
1101 if ($errors > 0 && $percent < 1.0) {
1102 printf (" <1%%)\n");
1104 printf ("%3d%%)\n", $percent);
1107 printf (" Number of skipped tests : %4d (", $skipped);
1108 $percent = ($skipped * 100) / $total;
1109 if ($skipped > 0 && $percent < 1.0) {
1110 printf (" <1%%)\n");
1112 printf ("%3d%%)\n", $percent);
1117 # perl-indent-level: 2