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}) {
229 printf ("FAIL\n " . "-" x
72 . "\n");
231 printf (" Namespace violation: \"%s\"\n", $token);
237 my($h, $fnamebase, @allow) = @_;
241 # Generate a program to get the contents of this header.
242 open (TESTFILE
, ">$fnamebase.c");
243 print TESTFILE
"#include <$h>\n";
248 open (CONTENT
, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
249 loop: while (<CONTENT
>) {
250 next loop if (/^#undef /);
252 if (/^#define (.*)/) {
253 newtoken
($1, @allow);
255 # We have to tokenize the line.
258 my($len) = length ($str);
260 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
262 newtoken
($token, @allow);
268 unlink "$fnamebase.c";
270 printf (" " . "-" x
72 . "\n");
272 } elsif ($nknown > 0) {
273 printf ("EXPECTED FAILURES\n");
281 while ($#headers >= 0) {
282 my($h) = pop (@headers);
285 my($fnamebase) = "$tmpdir/$hf-test";
288 my(@allowheader) = ();
289 my(%seenheader) = ();
290 my($prepend) = $mustprepend{$h};
292 printf ("Testing <$h>\n");
293 printf ("----------" . "-" x
length ($h) . "\n");
295 # Generate a program to test for the availability of this header.
296 open (TESTFILE
, ">$fnamebase.c");
297 print TESTFILE
"$prepend";
298 print TESTFILE
"#include <$h>\n";
301 $missing = compiletest
($fnamebase, "Checking whether <$h> is available",
302 "Header <$h> not available", 0, 0);
306 open (CONTROL
, "$CC -E -D$dialect - < data/$h-data |");
307 control
: while (<CONTROL
>) {
309 next control
if (/^#/);
310 next control
if (/^[ ]*$/);
312 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
313 my($struct) = "$2$3";
319 # Remember that this name is allowed.
320 push @allow, $member;
322 # Generate a program to test for the availability of this member.
323 open (TESTFILE
, ">$fnamebase.c");
324 print TESTFILE
"$prepend";
325 print TESTFILE
"#include <$h>\n";
326 print TESTFILE
"$struct a;\n";
327 print TESTFILE
"$struct b;\n";
328 print TESTFILE
"extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
329 print TESTFILE
"void foobarbaz (void) {\n";
330 print TESTFILE
" xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
331 print TESTFILE
"}\n";
334 $res = compiletest
($fnamebase, "Testing for member $member",
335 "Member \"$member\" not available.", $res, 0);
338 # Test the types of the members.
339 open (TESTFILE
, ">$fnamebase.c");
340 print TESTFILE
"$prepend";
341 print TESTFILE
"#include <$h>\n";
342 print TESTFILE
"$struct a;\n";
343 print TESTFILE
"extern $type b$rest;\n";
344 print TESTFILE
"extern __typeof__ (a.$member) b;\n";
347 compiletest
($fnamebase, "Testing for type of member $member",
348 "Member \"$member\" does not have the correct type.",
350 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
351 my($struct) = "$2$3";
357 # Remember that this name is allowed.
358 push @allow, $member;
360 # Generate a program to test for the availability of this member.
361 open (TESTFILE
, ">$fnamebase.c");
362 print TESTFILE
"$prepend";
363 print TESTFILE
"#include <$h>\n";
364 print TESTFILE
"$struct a;\n";
365 print TESTFILE
"$struct b;\n";
366 print TESTFILE
"extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
367 print TESTFILE
"void foobarbaz (void) {\n";
368 print TESTFILE
" xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
369 print TESTFILE
"}\n";
372 $res = compiletest
($fnamebase, "Testing for member $member",
373 "NOT AVAILABLE.", $res, 1);
375 if ($res == 0 || $missing != 0) {
376 # Test the types of the members.
377 open (TESTFILE
, ">$fnamebase.c");
378 print TESTFILE
"$prepend";
379 print TESTFILE
"#include <$h>\n";
380 print TESTFILE
"$struct a;\n";
381 print TESTFILE
"extern $type b$rest;\n";
382 print TESTFILE
"extern __typeof__ (a.$member) b;\n";
385 compiletest
($fnamebase, "Testing for type of member $member",
386 "Member \"$member\" does not have the correct type.",
389 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
395 # Remember that this name is allowed.
398 # Generate a program to test for the availability of this constant.
399 open (TESTFILE
, ">$fnamebase.c");
400 print TESTFILE
"$prepend";
401 print TESTFILE
"#include <$h>\n";
402 print TESTFILE
"__typeof__ ($const) a = $const;\n";
405 $res = compiletest
($fnamebase, "Testing for constant $const",
406 "NOT PRESENT", $res, 1);
408 if ($value ne "" && $res == 0) {
409 # Generate a program to test for the value of this constant.
410 open (TESTFILE
, ">$fnamebase.c");
411 print TESTFILE
"$prepend";
412 print TESTFILE
"#include <$h>\n";
413 # Negate the value since 0 means ok
414 print TESTFILE
"int main (void) { return !($const $op $value); }\n";
417 $res = runtest
($fnamebase, "Testing for value of constant $const",
418 "Constant \"$const\" has not the right value.", $res);
420 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
426 # Remember that this name is allowed.
429 # Generate a program to test for the availability of this constant.
430 open (TESTFILE
, ">$fnamebase.c");
431 print TESTFILE
"$prepend";
432 print TESTFILE
"#include <$h>\n";
433 print TESTFILE
"__typeof__ ($const) a = $const;\n";
436 $res = compiletest
($fnamebase, "Testing for constant $const",
437 "Constant \"$const\" not available.", $res, 0);
440 # Generate a program to test for the value of this constant.
441 open (TESTFILE
, ">$fnamebase.c");
442 print TESTFILE
"$prepend";
443 print TESTFILE
"#include <$h>\n";
444 # Negate the value since 0 means ok
445 print TESTFILE
"int main (void) { return !($const $op $value); }\n";
448 $res = runtest
($fnamebase, "Testing for value of constant $const",
449 "Constant \"$const\" has not the right value.", $res);
451 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
457 # Remember that this name is allowed.
460 # Generate a program to test for the availability of this constant.
461 open (TESTFILE
, ">$fnamebase.c");
462 print TESTFILE
"$prepend";
463 print TESTFILE
"#include <$h>\n";
464 print TESTFILE
"__typeof__ ($const) a = $const;\n";
467 $res = compiletest
($fnamebase, "Testing for constant $const",
468 "Constant \"$const\" not available.", $res, 0);
470 # Test the types of the members.
471 open (TESTFILE
, ">$fnamebase.c");
472 print TESTFILE
"$prepend";
473 print TESTFILE
"#include <$h>\n";
474 print TESTFILE
"__typeof__ (($type) 0) a;\n";
475 print TESTFILE
"extern __typeof__ ($const) a;\n";
478 compiletest
($fnamebase, "Testing for type of constant $const",
479 "Constant \"$const\" does not have the correct type.",
483 # Generate a program to test for the value of this constant.
484 open (TESTFILE
, ">$fnamebase.c");
485 print TESTFILE
"$prepend";
486 print TESTFILE
"#include <$h>\n";
487 print TESTFILE
"int main (void) { return $const != $value; }\n";
490 $res = runtest
($fnamebase, "Testing for value of constant $const",
491 "Constant \"$const\" has not the right value.", $res);
493 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
498 # Remember that this name is allowed.
501 # Generate a program to test for the availability of this constant.
502 open (TESTFILE
, ">$fnamebase.c");
503 print TESTFILE
"$prepend";
504 print TESTFILE
"#include <$h>\n";
505 print TESTFILE
"__typeof__ ($const) a = $const;\n";
508 $res = compiletest
($fnamebase, "Testing for constant $const",
509 "NOT PRESENT", $res, 1);
511 if ($value ne "" && $res == 0) {
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 (/^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 "Constant \"$const\" not available.", $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 (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
556 # Remember that this name is allowed.
557 push @allow, $symbol;
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
"void foobarbaz (void) {\n";
564 print TESTFILE
"__typeof__ ($symbol) a = $symbol;\n";
565 print TESTFILE
"}\n";
568 $res = compiletest
($fnamebase, "Testing for symbol $symbol",
569 "Symbol \"$symbol\" not available.", $res, 0);
572 # Generate a program to test for the value of this constant.
573 open (TESTFILE
, ">$fnamebase.c");
574 print TESTFILE
"$prepend";
575 print TESTFILE
"#include <$h>\n";
576 print TESTFILE
"int main (void) { return $symbol != $value; }\n";
579 $res = runtest
($fnamebase, "Testing for value of symbol $symbol",
580 "Symbol \"$symbol\" has not the right value.", $res);
582 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
588 # Remember that this name is allowed.
591 # Generate a program to test for the availability of this constant.
592 open (TESTFILE
, ">$fnamebase.c");
593 print TESTFILE
"$prepend";
594 print TESTFILE
"#include <$h>\n";
595 print TESTFILE
"__typeof__ ($const) a = $const;\n";
598 $res = compiletest
($fnamebase, "Testing for constant $const",
599 "Constant \"$const\" not available.", $res, 0);
601 # Test the types of the members.
602 open (TESTFILE
, ">$fnamebase.c");
603 print TESTFILE
"$prepend";
604 print TESTFILE
"#include <$h>\n";
605 print TESTFILE
"__typeof__ (($type) 0) a;\n";
606 print TESTFILE
"extern __typeof__ ($const) a;\n";
609 compiletest
($fnamebase, "Testing for type of constant $const",
610 "Constant \"$const\" does not have the correct type.",
614 # Generate a program to test for the value of this constant.
615 open (TESTFILE
, ">$fnamebase.c");
616 print TESTFILE
"$prepend";
617 print TESTFILE
"#include <$h>\n";
618 print TESTFILE
"int main (void) { return $const != $value; }\n";
621 $res = runtest
($fnamebase, "Testing for value of constant $const",
622 "Constant \"$const\" has not the right value.", $res);
624 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
626 my($maybe_opaque) = 0;
628 # Remember that this name is allowed.
629 if ($type =~ /^struct *(.*)/) {
631 } elsif ($type =~ /^union *(.*)/) {
638 # Remember that this name is allowed.
641 # Generate a program to test for the availability of this constant.
642 open (TESTFILE
, ">$fnamebase.c");
643 print TESTFILE
"$prepend";
644 print TESTFILE
"#include <$h>\n";
645 if ($maybe_opaque == 1) {
646 print TESTFILE
"$type *a;\n";
648 print TESTFILE
"$type a;\n";
652 compiletest
($fnamebase, "Testing for type $type",
653 "NOT AVAILABLE", $missing, 1);
654 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
656 my($maybe_opaque) = 0;
658 # Remember that this name is allowed.
659 if ($type =~ /^struct *(.*)/) {
661 } elsif ($type =~ /^union *(.*)/) {
668 # Remember that this name is allowed.
671 # Generate a program to test for the availability of this type.
672 open (TESTFILE
, ">$fnamebase.c");
673 print TESTFILE
"$prepend";
674 print TESTFILE
"#include <$h>\n";
675 if ($maybe_opaque == 1) {
676 print TESTFILE
"$type *a;\n";
678 print TESTFILE
"$type a;\n";
682 compiletest
($fnamebase, "Testing for type $type",
683 "Type \"$type\" not available.", $missing, 0);
684 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
685 my($rettype) = "$2$3";
690 # Remember that this name is allowed.
693 # Generate a program to test for availability of this function.
694 open (TESTFILE
, ">$fnamebase.c");
695 print TESTFILE
"$prepend";
696 print TESTFILE
"#include <$h>\n";
697 # print TESTFILE "#undef $fname\n";
698 print TESTFILE
"$rettype (*(*foobarbaz) $args = $fname;\n";
701 $res = compiletest
($fnamebase, "Test availability of function $fname",
702 "NOT AVAILABLE", $res, 1);
704 if ($res == 0 || $missing == 1) {
705 # Generate a program to test for the type of this function.
706 open (TESTFILE
, ">$fnamebase.c");
707 print TESTFILE
"$prepend";
708 print TESTFILE
"#include <$h>\n";
709 # print TESTFILE "#undef $fname\n";
710 print TESTFILE
"extern $rettype (*(*foobarbaz) $args;\n";
711 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
714 compiletest
($fnamebase, "Test for type of function $fname",
715 "Function \"$fname\" has incorrect type.", $res, 0);
717 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
718 my($rettype) = "$2$3";
723 # Remember that this name is allowed.
726 # Generate a program to test for availability of this function.
727 open (TESTFILE
, ">$fnamebase.c");
728 print TESTFILE
"$prepend";
729 print TESTFILE
"#include <$h>\n";
730 # print TESTFILE "#undef $fname\n";
731 print TESTFILE
"$rettype (*(*foobarbaz) $args = $fname;\n";
734 $res = compiletest
($fnamebase, "Test availability of function $fname",
735 "Function \"$fname\" is not available.", $res, 0);
737 # Generate a program to test for the type of this function.
738 open (TESTFILE
, ">$fnamebase.c");
739 print TESTFILE
"$prepend";
740 print TESTFILE
"#include <$h>\n";
741 # print TESTFILE "#undef $fname\n";
742 print TESTFILE
"extern $rettype (*(*foobarbaz) $args;\n";
743 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
746 compiletest
($fnamebase, "Test for type of function $fname",
747 "Function \"$fname\" has incorrect type.", $res, 0);
748 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
749 my($rettype) = "$2$3";
754 # Remember that this name is allowed.
757 # Generate a program to test for availability of this function.
758 open (TESTFILE
, ">$fnamebase.c");
759 print TESTFILE
"$prepend";
760 print TESTFILE
"#include <$h>\n";
761 # print TESTFILE "#undef $fname\n";
762 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
765 $res = compiletest
($fnamebase, "Test availability of function $fname",
766 "NOT AVAILABLE", $res, 1);
768 if ($res == 0 || $missing != 0) {
769 # Generate a program to test for the type of this function.
770 open (TESTFILE
, ">$fnamebase.c");
771 print TESTFILE
"$prepend";
772 print TESTFILE
"#include <$h>\n";
773 # print TESTFILE "#undef $fname\n";
774 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
775 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
778 compiletest
($fnamebase, "Test for type of function $fname",
779 "Function \"$fname\" has incorrect type.", $res, 0);
781 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
782 my($rettype) = "$2$3";
787 # Remember that this name is allowed.
790 # Generate a program to test for availability of this function.
791 open (TESTFILE
, ">$fnamebase.c");
792 print TESTFILE
"$prepend";
793 print TESTFILE
"#include <$h>\n";
794 # print TESTFILE "#undef $fname\n";
795 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
798 $res = compiletest
($fnamebase, "Test availability of function $fname",
799 "Function \"$fname\" is not available.", $res, 0);
801 # Generate a program to test for the type of this function.
802 open (TESTFILE
, ">$fnamebase.c");
803 print TESTFILE
"$prepend";
804 print TESTFILE
"#include <$h>\n";
805 # print TESTFILE "#undef $fname\n";
806 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
807 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
810 compiletest
($fnamebase, "Test for type of function $fname",
811 "Function \"$fname\" has incorrect type.", $res, 0);
812 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
818 # Remember that this name is allowed.
821 # Generate a program to test for availability of this function.
822 open (TESTFILE
, ">$fnamebase.c");
823 print TESTFILE
"$prepend";
824 print TESTFILE
"#include <$h>\n";
825 # print TESTFILE "#undef $fname\n";
826 print TESTFILE
"typedef $type xyzzy$rest;\n";
827 print TESTFILE
"$xyzzy *foobarbaz = &$vname;\n";
830 $res = compiletest
($fnamebase, "Test availability of variable $vname",
831 "Variable \"$vname\" is not available.", $res, 0);
833 # Generate a program to test for the type of this function.
834 open (TESTFILE
, ">$fnamebase.c");
835 print TESTFILE
"$prepend";
836 print TESTFILE
"#include <$h>\n";
837 # print TESTFILE "#undef $fname\n";
838 print TESTFILE
"extern $type $vname$rest;\n";
841 compiletest
($fnamebase, "Test for type of variable $fname",
842 "Variable \"$vname\" has incorrect type.", $res, 0);
843 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
844 my($rettype) = "$2$3";
849 # Remember that this name is allowed.
852 # Generate a program to test for availability of this function.
853 open (TESTFILE
, ">$fnamebase.c");
854 print TESTFILE
"$prepend";
855 print TESTFILE
"#include <$h>\n";
856 print TESTFILE
"#ifndef $fname\n";
857 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
858 print TESTFILE
"#endif\n";
861 $res = compiletest
($fnamebase, "Test availability of function $fname",
862 "Function \"$fname\" is not available.", $res, 0);
864 # Generate a program to test for the type of this function.
865 open (TESTFILE
, ">$fnamebase.c");
866 print TESTFILE
"$prepend";
867 print TESTFILE
"#include <$h>\n";
868 print TESTFILE
"#ifndef $fname\n";
869 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
870 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
871 print TESTFILE
"#endif\n";
874 compiletest
($fnamebase, "Test for type of function $fname",
875 "Function \"$fname\" has incorrect type.", $res, 0);
876 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
877 # The above regex doesn't handle a \" in a string.
882 # Remember that this name is allowed.
885 # Generate a program to test for availability of this macro.
886 open (TESTFILE
, ">$fnamebase.c");
887 print TESTFILE
"$prepend";
888 print TESTFILE
"#include <$h>\n";
889 print TESTFILE
"#ifndef $macro\n";
890 print TESTFILE
"# error \"Macro $macro not defined\"\n";
891 print TESTFILE
"#endif\n";
894 compiletest
($fnamebase, "Test availability of macro $macro",
895 "Macro \"$macro\" is not available.", $missing, 0);
897 # Generate a program to test for the value of this macro.
898 open (TESTFILE
, ">$fnamebase.c");
899 print TESTFILE
"$prepend";
900 print TESTFILE
"#include <$h>\n";
901 # We can't include <string.h> here.
902 print TESTFILE
"extern int (strcmp)(const char *, const char *);\n";
903 print TESTFILE
"int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
906 $res = runtest
($fnamebase, "Testing for value of macro $macro",
907 "Macro \"$macro\" has not the right value.", $res);
908 } elsif (/^optional-macro *([^ ]*)/) {
911 # Remember that this name is allowed.
914 # Generate a program to test for availability of this macro.
915 open (TESTFILE
, ">$fnamebase.c");
916 print TESTFILE
"$prepend";
917 print TESTFILE
"#include <$h>\n";
918 print TESTFILE
"#ifndef $macro\n";
919 print TESTFILE
"# error \"Macro $macro not defined\"\n";
920 print TESTFILE
"#endif\n";
923 compiletest
($fnamebase, "Test availability of macro $macro",
924 "NOT PRESENT", $missing, 1);
925 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
931 # Remember that this name is allowed.
934 # Generate a program to test for availability of this macro.
935 open (TESTFILE
, ">$fnamebase.c");
936 print TESTFILE
"$prepend";
937 print TESTFILE
"#include <$h>\n";
938 print TESTFILE
"#ifndef $macro\n";
939 print TESTFILE
"# error \"Macro $macro not defined\"\n";
940 print TESTFILE
"#endif\n";
943 $res = compiletest
($fnamebase, "Test availability of macro $macro",
944 "Macro \"$macro\" is not available.", $res, 0);
947 # Generate a program to test for the value of this constant.
948 open (TESTFILE
, ">$fnamebase.c");
949 print TESTFILE
"$prepend";
950 print TESTFILE
"#include <$h>\n";
951 # Negate the value since 0 means ok
952 print TESTFILE
"int main (void) { return !($macro $op $value); }\n";
955 $res = runtest
($fnamebase, "Testing for value of constant $macro",
956 "Macro \"$macro\" has not the right value.", $res);
958 } elsif (/^macro *([^ ]*)/) {
961 # Remember that this name is allowed.
964 # Generate a program to test for availability of this macro.
965 open (TESTFILE
, ">$fnamebase.c");
966 print TESTFILE
"$prepend";
967 print TESTFILE
"#include <$h>\n";
968 print TESTFILE
"#ifndef $macro\n";
969 print TESTFILE
"# error \"Macro $macro not defined\"\n";
970 print TESTFILE
"#endif\n";
973 compiletest
($fnamebase, "Test availability of macro $macro",
974 "Macro \"$macro\" is not available.", $missing, 0);
975 } elsif (/^allow-header *(.*)/) {
977 if ($seenheader{$pattern} != 1) {
978 push @allowheader, $pattern;
979 $seenheader{$pattern} = 1;
982 } elsif (/^allow *(.*)/) {
984 push @allow, $pattern;
987 # printf ("line is `%s'\n", $_);
995 # Read the data files for the header files which are allowed to be included.
996 while ($#allowheader >= 0) {
997 my($ah) = pop @allowheader;
999 open (ALLOW
, "$CC -E -D$dialect - < data/$ah-data |");
1000 acontrol
: while (<ALLOW
>) {
1001 next acontrol
if (/^#/);
1002 next acontrol
if (/^[ ]*$/);
1004 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1006 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1008 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1010 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1013 # Remember that this name is allowed.
1014 if ($type =~ /^struct *(.*)/) {
1016 } elsif ($type =~ /^union *(.*)/) {
1021 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1023 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1025 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1027 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1029 } elsif (/^macro *([^ ]*)/) {
1031 } elsif (/^allow-header *(.*)/) {
1032 if ($seenheader{$1} != 1) {
1033 push @allowheader, $1;
1034 $seenheader{$1} = 1;
1036 } elsif (/^allow *(.*)/) {
1043 # Now check the namespace.
1044 printf (" Checking the namespace of \"%s\"... ", $h);
1049 checknamespace
($h, $fnamebase, @allow);
1055 printf "-" x
76 . "\n";
1056 printf (" Total number of tests : %4d\n", $total);
1058 printf (" Number of known failures: %4d (", $known);
1059 $percent = ($known * 100) / $total;
1060 if ($known > 0 && $percent < 1.0) {
1061 printf (" <1%%)\n");
1063 printf ("%3d%%)\n", $percent);
1066 printf (" Number of failed tests : %4d (", $errors);
1067 $percent = ($errors * 100) / $total;
1068 if ($errors > 0 && $percent < 1.0) {
1069 printf (" <1%%)\n");
1071 printf ("%3d%%)\n", $percent);
1074 printf (" Number of skipped tests : %4d (", $skipped);
1075 $percent = ($skipped * 100) / $total;
1076 if ($skipped > 0 && $percent < 1.0) {
1077 printf (" <1%%)\n");
1079 printf ("%3d%%)\n", $percent);