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 # Sort the output list so it's easier to compare results with diff.
282 foreach $f (sort keys(%errors)) {
283 if ($errors{$f} == 1) {
284 if ($realerror == 0) {
285 printf ("FAIL\n " . "-" x
72 . "\n");
289 printf (" Namespace violation: \"%s\"\n", $f);
292 printf (" " . "-" x
72 . "\n") if ($realerror != 0);
295 if ($realerror == 0) {
297 printf ("EXPECTED FAILURES\n");
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};
317 printf ("Testing <$h>\n");
318 printf ("----------" . "-" x
length ($h) . "\n");
320 # Generate a program to test for the availability of this header.
321 open (TESTFILE
, ">$fnamebase.c");
322 print TESTFILE
"$prepend";
323 print TESTFILE
"#include <$h>\n";
326 $missing = compiletest
($fnamebase, "Checking whether <$h> is available",
327 "Header <$h> not available", 0, 0);
331 open (CONTROL
, "$CC -E -D$dialect - < data/$h-data |");
332 control
: while (<CONTROL
>) {
334 next control
if (/^#/);
335 next control
if (/^[ ]*$/);
337 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
338 my($struct) = "$2$3";
344 # Remember that this name is allowed.
345 push @allow, $member;
347 # Generate a program to test for the availability of this member.
348 open (TESTFILE
, ">$fnamebase.c");
349 print TESTFILE
"$prepend";
350 print TESTFILE
"#include <$h>\n";
351 print TESTFILE
"$struct a;\n";
352 print TESTFILE
"$struct b;\n";
353 print TESTFILE
"extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
354 print TESTFILE
"void foobarbaz (void) {\n";
355 print TESTFILE
" xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
356 print TESTFILE
"}\n";
359 $res = compiletest
($fnamebase, "Testing for member $member",
360 "Member \"$member\" not available.", $res, 0);
363 # Test the types of the members.
364 open (TESTFILE
, ">$fnamebase.c");
365 print TESTFILE
"$prepend";
366 print TESTFILE
"#include <$h>\n";
367 print TESTFILE
"$struct a;\n";
368 print TESTFILE
"extern $type b$rest;\n";
369 print TESTFILE
"extern __typeof__ (a.$member) b;\n";
372 compiletest
($fnamebase, "Testing for type of member $member",
373 "Member \"$member\" does not have the correct type.",
375 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
376 my($struct) = "$2$3";
382 # Remember that this name is allowed.
383 push @allow, $member;
385 # Generate a program to test for the availability of this member.
386 open (TESTFILE
, ">$fnamebase.c");
387 print TESTFILE
"$prepend";
388 print TESTFILE
"#include <$h>\n";
389 print TESTFILE
"$struct a;\n";
390 print TESTFILE
"$struct b;\n";
391 print TESTFILE
"extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
392 print TESTFILE
"void foobarbaz (void) {\n";
393 print TESTFILE
" xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
394 print TESTFILE
"}\n";
397 $res = compiletest
($fnamebase, "Testing for member $member",
398 "NOT AVAILABLE.", $res, 1);
400 if ($res == 0 || $missing != 0) {
401 # Test the types of the members.
402 open (TESTFILE
, ">$fnamebase.c");
403 print TESTFILE
"$prepend";
404 print TESTFILE
"#include <$h>\n";
405 print TESTFILE
"$struct a;\n";
406 print TESTFILE
"extern $type b$rest;\n";
407 print TESTFILE
"extern __typeof__ (a.$member) b;\n";
410 compiletest
($fnamebase, "Testing for type of member $member",
411 "Member \"$member\" does not have the correct type.",
414 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
420 # Remember that this name is allowed.
423 # Generate a program to test for the availability of this constant.
424 open (TESTFILE
, ">$fnamebase.c");
425 print TESTFILE
"$prepend";
426 print TESTFILE
"#include <$h>\n";
427 print TESTFILE
"__typeof__ ($const) a = $const;\n";
430 $res = compiletest
($fnamebase, "Testing for constant $const",
431 "NOT PRESENT", $res, 1);
433 if ($value ne "" && $res == 0) {
434 # Generate a program to test for the value of this constant.
435 open (TESTFILE
, ">$fnamebase.c");
436 print TESTFILE
"$prepend";
437 print TESTFILE
"#include <$h>\n";
438 # Negate the value since 0 means ok
439 print TESTFILE
"int main (void) { return !($const $op $value); }\n";
442 $res = runtest
($fnamebase, "Testing for value of constant $const",
443 "Constant \"$const\" has not the right value.", $res);
445 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
451 # Remember that this name is allowed.
454 # Generate a program to test for the availability of this constant.
455 open (TESTFILE
, ">$fnamebase.c");
456 print TESTFILE
"$prepend";
457 print TESTFILE
"#include <$h>\n";
458 print TESTFILE
"__typeof__ ($const) a = $const;\n";
461 $res = compiletest
($fnamebase, "Testing for constant $const",
462 "Constant \"$const\" not available.", $res, 0);
465 # Generate a program to test for the value of this constant.
466 open (TESTFILE
, ">$fnamebase.c");
467 print TESTFILE
"$prepend";
468 print TESTFILE
"#include <$h>\n";
469 # Negate the value since 0 means ok
470 print TESTFILE
"int main (void) { return !($const $op $value); }\n";
473 $res = runtest
($fnamebase, "Testing for value of constant $const",
474 "Constant \"$const\" has not the right value.", $res);
476 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
482 # Remember that this name is allowed.
485 # Generate a program to test for the availability of this constant.
486 open (TESTFILE
, ">$fnamebase.c");
487 print TESTFILE
"$prepend";
488 print TESTFILE
"#include <$h>\n";
489 print TESTFILE
"__typeof__ ($const) a = $const;\n";
492 $res = compiletest
($fnamebase, "Testing for constant $const",
493 "Constant \"$const\" not available.", $res, 0);
495 # Test the types of the members.
496 open (TESTFILE
, ">$fnamebase.c");
497 print TESTFILE
"$prepend";
498 print TESTFILE
"#include <$h>\n";
499 print TESTFILE
"__typeof__ (($type) 0) a;\n";
500 print TESTFILE
"extern __typeof__ ($const) a;\n";
503 compiletest
($fnamebase, "Testing for type of constant $const",
504 "Constant \"$const\" does not have the correct type.",
508 # Generate a program to test for the value of this constant.
509 open (TESTFILE
, ">$fnamebase.c");
510 print TESTFILE
"$prepend";
511 print TESTFILE
"#include <$h>\n";
512 print TESTFILE
"int main (void) { return $const != $value; }\n";
515 $res = runtest
($fnamebase, "Testing for value of constant $const",
516 "Constant \"$const\" has not the right value.", $res);
518 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
523 # Remember that this name is allowed.
526 # Generate a program to test for the availability of this constant.
527 open (TESTFILE
, ">$fnamebase.c");
528 print TESTFILE
"$prepend";
529 print TESTFILE
"#include <$h>\n";
530 print TESTFILE
"__typeof__ ($const) a = $const;\n";
533 $res = compiletest
($fnamebase, "Testing for constant $const",
534 "NOT PRESENT", $res, 1);
536 if ($value ne "" && $res == 0) {
537 # Generate a program to test for the value of this constant.
538 open (TESTFILE
, ">$fnamebase.c");
539 print TESTFILE
"$prepend";
540 print TESTFILE
"#include <$h>\n";
541 print TESTFILE
"int main (void) { return $const != $value; }\n";
544 $res = runtest
($fnamebase, "Testing for value of constant $const",
545 "Constant \"$const\" has not the right value.", $res);
547 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
552 # Remember that this name is allowed.
555 # Generate a program to test for the availability of this constant.
556 open (TESTFILE
, ">$fnamebase.c");
557 print TESTFILE
"$prepend";
558 print TESTFILE
"#include <$h>\n";
559 print TESTFILE
"__typeof__ ($const) a = $const;\n";
562 $res = compiletest
($fnamebase, "Testing for constant $const",
563 "Constant \"$const\" not available.", $res, 0);
566 # Generate a program to test for the value of this constant.
567 open (TESTFILE
, ">$fnamebase.c");
568 print TESTFILE
"$prepend";
569 print TESTFILE
"#include <$h>\n";
570 print TESTFILE
"int main (void) { return $const != $value; }\n";
573 $res = runtest
($fnamebase, "Testing for value of constant $const",
574 "Constant \"$const\" has not the right value.", $res);
576 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
581 # Remember that this name is allowed.
582 push @allow, $symbol;
584 # Generate a program to test for the availability of this constant.
585 open (TESTFILE
, ">$fnamebase.c");
586 print TESTFILE
"$prepend";
587 print TESTFILE
"#include <$h>\n";
588 print TESTFILE
"void foobarbaz (void) {\n";
589 print TESTFILE
"__typeof__ ($symbol) a = $symbol;\n";
590 print TESTFILE
"}\n";
593 $res = compiletest
($fnamebase, "Testing for symbol $symbol",
594 "Symbol \"$symbol\" not available.", $res, 0);
597 # Generate a program to test for the value of this constant.
598 open (TESTFILE
, ">$fnamebase.c");
599 print TESTFILE
"$prepend";
600 print TESTFILE
"#include <$h>\n";
601 print TESTFILE
"int main (void) { return $symbol != $value; }\n";
604 $res = runtest
($fnamebase, "Testing for value of symbol $symbol",
605 "Symbol \"$symbol\" has not the right value.", $res);
607 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
613 # Remember that this name is allowed.
616 # Generate a program to test for the availability of this constant.
617 open (TESTFILE
, ">$fnamebase.c");
618 print TESTFILE
"$prepend";
619 print TESTFILE
"#include <$h>\n";
620 print TESTFILE
"__typeof__ ($const) a = $const;\n";
623 $res = compiletest
($fnamebase, "Testing for constant $const",
624 "Constant \"$const\" not available.", $res, 0);
626 # Test the types of the members.
627 open (TESTFILE
, ">$fnamebase.c");
628 print TESTFILE
"$prepend";
629 print TESTFILE
"#include <$h>\n";
630 print TESTFILE
"__typeof__ (($type) 0) a;\n";
631 print TESTFILE
"extern __typeof__ ($const) a;\n";
634 compiletest
($fnamebase, "Testing for type of constant $const",
635 "Constant \"$const\" does not have the correct type.",
639 # Generate a program to test for the value of this constant.
640 open (TESTFILE
, ">$fnamebase.c");
641 print TESTFILE
"$prepend";
642 print TESTFILE
"#include <$h>\n";
643 print TESTFILE
"int main (void) { return $const != $value; }\n";
646 $res = runtest
($fnamebase, "Testing for value of constant $const",
647 "Constant \"$const\" has not the right value.", $res);
649 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
651 my($maybe_opaque) = 0;
653 # Remember that this name is allowed.
654 if ($type =~ /^struct *(.*)/) {
656 } elsif ($type =~ /^union *(.*)/) {
663 # Remember that this name is allowed.
666 # Generate a program to test for the availability of this constant.
667 open (TESTFILE
, ">$fnamebase.c");
668 print TESTFILE
"$prepend";
669 print TESTFILE
"#include <$h>\n";
670 if ($maybe_opaque == 1) {
671 print TESTFILE
"$type *a;\n";
673 print TESTFILE
"$type a;\n";
677 compiletest
($fnamebase, "Testing for type $type",
678 "NOT AVAILABLE", $missing, 1);
679 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
681 my($maybe_opaque) = 0;
683 # Remember that this name is allowed.
684 if ($type =~ /^struct *(.*)/) {
686 } elsif ($type =~ /^union *(.*)/) {
693 # Remember that this name is allowed.
696 # Generate a program to test for the availability of this type.
697 open (TESTFILE
, ">$fnamebase.c");
698 print TESTFILE
"$prepend";
699 print TESTFILE
"#include <$h>\n";
700 if ($maybe_opaque == 1) {
701 print TESTFILE
"$type *a;\n";
703 print TESTFILE
"$type a;\n";
707 compiletest
($fnamebase, "Testing for type $type",
708 "Type \"$type\" not available.", $missing, 0);
709 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
710 my($rettype) = "$2$3";
715 # Remember that this name is allowed.
718 # Generate a program to test for availability of this function.
719 open (TESTFILE
, ">$fnamebase.c");
720 print TESTFILE
"$prepend";
721 print TESTFILE
"#include <$h>\n";
722 # print TESTFILE "#undef $fname\n";
723 print TESTFILE
"$rettype (*(*foobarbaz) $args = $fname;\n";
726 $res = compiletest
($fnamebase, "Test availability of function $fname",
727 "NOT AVAILABLE", $res, 1);
729 if ($res == 0 || $missing == 1) {
730 # Generate a program to test for the type of this function.
731 open (TESTFILE
, ">$fnamebase.c");
732 print TESTFILE
"$prepend";
733 print TESTFILE
"#include <$h>\n";
734 # print TESTFILE "#undef $fname\n";
735 print TESTFILE
"extern $rettype (*(*foobarbaz) $args;\n";
736 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
739 compiletest
($fnamebase, "Test for type of function $fname",
740 "Function \"$fname\" has incorrect type.", $res, 0);
742 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
743 my($rettype) = "$2$3";
748 # Remember that this name is allowed.
751 # Generate a program to test for availability of this function.
752 open (TESTFILE
, ">$fnamebase.c");
753 print TESTFILE
"$prepend";
754 print TESTFILE
"#include <$h>\n";
755 # print TESTFILE "#undef $fname\n";
756 print TESTFILE
"$rettype (*(*foobarbaz) $args = $fname;\n";
759 $res = compiletest
($fnamebase, "Test availability of function $fname",
760 "Function \"$fname\" is not available.", $res, 0);
762 # Generate a program to test for the type of this function.
763 open (TESTFILE
, ">$fnamebase.c");
764 print TESTFILE
"$prepend";
765 print TESTFILE
"#include <$h>\n";
766 # print TESTFILE "#undef $fname\n";
767 print TESTFILE
"extern $rettype (*(*foobarbaz) $args;\n";
768 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
771 compiletest
($fnamebase, "Test for type of function $fname",
772 "Function \"$fname\" has incorrect type.", $res, 0);
773 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
774 my($rettype) = "$2$3";
779 # Remember that this name is allowed.
782 # Generate a program to test for availability of this function.
783 open (TESTFILE
, ">$fnamebase.c");
784 print TESTFILE
"$prepend";
785 print TESTFILE
"#include <$h>\n";
786 # print TESTFILE "#undef $fname\n";
787 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
790 $res = compiletest
($fnamebase, "Test availability of function $fname",
791 "NOT AVAILABLE", $res, 1);
793 if ($res == 0 || $missing != 0) {
794 # Generate a program to test for the type of this function.
795 open (TESTFILE
, ">$fnamebase.c");
796 print TESTFILE
"$prepend";
797 print TESTFILE
"#include <$h>\n";
798 # print TESTFILE "#undef $fname\n";
799 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
800 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
803 compiletest
($fnamebase, "Test for type of function $fname",
804 "Function \"$fname\" has incorrect type.", $res, 0);
806 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
807 my($rettype) = "$2$3";
812 # Remember that this name is allowed.
815 # Generate a program to test for availability of this function.
816 open (TESTFILE
, ">$fnamebase.c");
817 print TESTFILE
"$prepend";
818 print TESTFILE
"#include <$h>\n";
819 # print TESTFILE "#undef $fname\n";
820 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
823 $res = compiletest
($fnamebase, "Test availability of function $fname",
824 "Function \"$fname\" is not available.", $res, 0);
826 # Generate a program to test for the type of this function.
827 open (TESTFILE
, ">$fnamebase.c");
828 print TESTFILE
"$prepend";
829 print TESTFILE
"#include <$h>\n";
830 # print TESTFILE "#undef $fname\n";
831 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
832 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
835 compiletest
($fnamebase, "Test for type of function $fname",
836 "Function \"$fname\" has incorrect type.", $res, 0);
837 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
843 # Remember that this name is allowed.
846 # Generate a program to test for availability of this function.
847 open (TESTFILE
, ">$fnamebase.c");
848 print TESTFILE
"$prepend";
849 print TESTFILE
"#include <$h>\n";
850 # print TESTFILE "#undef $fname\n";
851 print TESTFILE
"typedef $type xyzzy$rest;\n";
852 print TESTFILE
"$xyzzy *foobarbaz = &$vname;\n";
855 $res = compiletest
($fnamebase, "Test availability of variable $vname",
856 "Variable \"$vname\" is not available.", $res, 0);
858 # Generate a program to test for the type of this function.
859 open (TESTFILE
, ">$fnamebase.c");
860 print TESTFILE
"$prepend";
861 print TESTFILE
"#include <$h>\n";
862 # print TESTFILE "#undef $fname\n";
863 print TESTFILE
"extern $type $vname$rest;\n";
866 compiletest
($fnamebase, "Test for type of variable $fname",
867 "Variable \"$vname\" has incorrect type.", $res, 0);
868 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
869 my($rettype) = "$2$3";
874 # Remember that this name is allowed.
877 # Generate a program to test for availability of this function.
878 open (TESTFILE
, ">$fnamebase.c");
879 print TESTFILE
"$prepend";
880 print TESTFILE
"#include <$h>\n";
881 print TESTFILE
"#ifndef $fname\n";
882 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
883 print TESTFILE
"#endif\n";
886 $res = compiletest
($fnamebase, "Test availability of function $fname",
887 "Function \"$fname\" is not available.", $res, 0);
889 # Generate a program to test for the type of this function.
890 open (TESTFILE
, ">$fnamebase.c");
891 print TESTFILE
"$prepend";
892 print TESTFILE
"#include <$h>\n";
893 print TESTFILE
"#ifndef $fname\n";
894 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
895 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
896 print TESTFILE
"#endif\n";
899 compiletest
($fnamebase, "Test for type of function $fname",
900 "Function \"$fname\" has incorrect type.", $res, 0);
901 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
902 # The above regex doesn't handle a \" in a string.
907 # Remember that this name is allowed.
910 # Generate a program to test for availability of this macro.
911 open (TESTFILE
, ">$fnamebase.c");
912 print TESTFILE
"$prepend";
913 print TESTFILE
"#include <$h>\n";
914 print TESTFILE
"#ifndef $macro\n";
915 print TESTFILE
"# error \"Macro $macro not defined\"\n";
916 print TESTFILE
"#endif\n";
919 compiletest
($fnamebase, "Test availability of macro $macro",
920 "Macro \"$macro\" is not available.", $missing, 0);
922 # Generate a program to test for the value of this macro.
923 open (TESTFILE
, ">$fnamebase.c");
924 print TESTFILE
"$prepend";
925 print TESTFILE
"#include <$h>\n";
926 # We can't include <string.h> here.
927 print TESTFILE
"extern int (strcmp)(const char *, const char *);\n";
928 print TESTFILE
"int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
931 $res = runtest
($fnamebase, "Testing for value of macro $macro",
932 "Macro \"$macro\" has not the right value.", $res);
933 } elsif (/^optional-macro *([^ ]*)/) {
936 # Remember that this name is allowed.
939 # Generate a program to test for availability of this macro.
940 open (TESTFILE
, ">$fnamebase.c");
941 print TESTFILE
"$prepend";
942 print TESTFILE
"#include <$h>\n";
943 print TESTFILE
"#ifndef $macro\n";
944 print TESTFILE
"# error \"Macro $macro not defined\"\n";
945 print TESTFILE
"#endif\n";
948 compiletest
($fnamebase, "Test availability of macro $macro",
949 "NOT PRESENT", $missing, 1);
950 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
956 # Remember that this name is allowed.
959 # Generate a program to test for availability of this macro.
960 open (TESTFILE
, ">$fnamebase.c");
961 print TESTFILE
"$prepend";
962 print TESTFILE
"#include <$h>\n";
963 print TESTFILE
"#ifndef $macro\n";
964 print TESTFILE
"# error \"Macro $macro not defined\"\n";
965 print TESTFILE
"#endif\n";
968 $res = compiletest
($fnamebase, "Test availability of macro $macro",
969 "Macro \"$macro\" is not available.", $res, 0);
972 # Generate a program to test for the value of this constant.
973 open (TESTFILE
, ">$fnamebase.c");
974 print TESTFILE
"$prepend";
975 print TESTFILE
"#include <$h>\n";
976 # Negate the value since 0 means ok
977 print TESTFILE
"int main (void) { return !($macro $op $value); }\n";
980 $res = runtest
($fnamebase, "Testing for value of constant $macro",
981 "Macro \"$macro\" has not the right value.", $res);
983 } elsif (/^macro *([^ ]*)/) {
986 # Remember that this name is allowed.
989 # Generate a program to test for availability of this macro.
990 open (TESTFILE
, ">$fnamebase.c");
991 print TESTFILE
"$prepend";
992 print TESTFILE
"#include <$h>\n";
993 print TESTFILE
"#ifndef $macro\n";
994 print TESTFILE
"# error \"Macro $macro not defined\"\n";
995 print TESTFILE
"#endif\n";
998 compiletest
($fnamebase, "Test availability of macro $macro",
999 "Macro \"$macro\" is not available.", $missing, 0);
1000 } elsif (/^allow-header *(.*)/) {
1002 if ($seenheader{$pattern} != 1) {
1003 push @allowheader, $pattern;
1004 $seenheader{$pattern} = 1;
1007 } elsif (/^allow *(.*)/) {
1009 push @allow, $pattern;
1012 # printf ("line is `%s'\n", $_);
1020 # Read the data files for the header files which are allowed to be included.
1021 while ($#allowheader >= 0) {
1022 my($ah) = pop @allowheader;
1024 open (ALLOW
, "$CC -E -D$dialect - < data/$ah-data |");
1025 acontrol
: while (<ALLOW
>) {
1026 next acontrol
if (/^#/);
1027 next acontrol
if (/^[ ]*$/);
1029 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1031 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1033 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1035 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1038 # Remember that this name is allowed.
1039 if ($type =~ /^struct *(.*)/) {
1041 } elsif ($type =~ /^union *(.*)/) {
1046 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1048 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1050 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1052 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1054 } elsif (/^macro *([^ ]*)/) {
1056 } elsif (/^allow-header *(.*)/) {
1057 if ($seenheader{$1} != 1) {
1058 push @allowheader, $1;
1059 $seenheader{$1} = 1;
1061 } elsif (/^allow *(.*)/) {
1068 # Now check the namespace.
1069 printf (" Checking the namespace of \"%s\"... ", $h);
1074 checknamespace
($h, $fnamebase, @allow);
1080 printf "-" x
76 . "\n";
1081 printf (" Total number of tests : %4d\n", $total);
1083 printf (" Number of known failures: %4d (", $known);
1084 $percent = ($known * 100) / $total;
1085 if ($known > 0 && $percent < 1.0) {
1086 printf (" <1%%)\n");
1088 printf ("%3d%%)\n", $percent);
1091 printf (" Number of failed tests : %4d (", $errors);
1092 $percent = ($errors * 100) / $total;
1093 if ($errors > 0 && $percent < 1.0) {
1094 printf (" <1%%)\n");
1096 printf ("%3d%%)\n", $percent);
1099 printf (" Number of skipped tests : %4d (", $skipped);
1100 $percent = ($skipped * 100) / $total;
1101 if ($skipped > 0 && $percent < 1.0) {
1102 printf (" <1%%)\n");
1104 printf ("%3d%%)\n", $percent);