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. '-D__attribute__(x)=' -ansi";
38 $CFLAGS{"POSIX"} = "-I. '-D__attribute__(x)=' -D_POSIX_C_SOURCE=199912";
39 $CFLAGS{"XPG3"} = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE";
40 $CFLAGS{"XPG4"} = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE_EXTENDED";
41 $CFLAGS{"UNIX98"} = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
42 $CFLAGS{"XOPEN2K"} = "-I. '-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 "#include <$h>\n";
674 if ($maybe_opaque == 1) {
675 print TESTFILE "$type *a;\n";
677 print TESTFILE "$type a;\n";
681 compiletest ($fnamebase, "Testing for type $type",
682 "Type \"$type\" not available.", $missing, 0);
683 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
684 my($rettype) = "$2$3";
689 # Remember that this name is allowed.
692 # Generate a program to test for availability of this function.
693 open (TESTFILE, ">$fnamebase.c");
694 print TESTFILE "$prepend";
695 print TESTFILE "#include <$h>\n";
696 # print TESTFILE "#undef $fname\n";
697 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
700 $res = compiletest ($fnamebase, "Test availability of function $fname",
701 "NOT AVAILABLE", $res, 1);
703 if ($res == 0 || $missing == 1) {
704 # Generate a program to test for the type of this function.
705 open (TESTFILE, ">$fnamebase.c");
706 print TESTFILE "$prepend";
707 print TESTFILE "#include <$h>\n";
708 # print TESTFILE "#undef $fname\n";
709 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
710 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
713 compiletest ($fnamebase, "Test for type of function $fname",
714 "Function \"$fname\" has incorrect type.", $res, 0);
716 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
717 my($rettype) = "$2$3";
722 # Remember that this name is allowed.
725 # Generate a program to test for availability of this function.
726 open (TESTFILE, ">$fnamebase.c");
727 print TESTFILE "$prepend";
728 print TESTFILE "#include <$h>\n";
729 # print TESTFILE "#undef $fname\n";
730 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
733 $res = compiletest ($fnamebase, "Test availability of function $fname",
734 "Function \"$fname\" is not available.", $res, 0);
736 # Generate a program to test for the type of this function.
737 open (TESTFILE, ">$fnamebase.c");
738 print TESTFILE "$prepend";
739 print TESTFILE "#include <$h>\n";
740 # print TESTFILE "#undef $fname\n";
741 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
742 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
745 compiletest ($fnamebase, "Test for type of function $fname",
746 "Function \"$fname\" has incorrect type.", $res, 0);
747 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
748 my($rettype) = "$2$3";
753 # Remember that this name is allowed.
756 # Generate a program to test for availability of this function.
757 open (TESTFILE, ">$fnamebase.c");
758 print TESTFILE "$prepend";
759 print TESTFILE "#include <$h>\n";
760 # print TESTFILE "#undef $fname\n";
761 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
764 $res = compiletest ($fnamebase, "Test availability of function $fname",
765 "NOT AVAILABLE", $res, 1);
767 if ($res == 0 || $missing != 0) {
768 # Generate a program to test for the type of this function.
769 open (TESTFILE, ">$fnamebase.c");
770 print TESTFILE "$prepend";
771 print TESTFILE "#include <$h>\n";
772 # print TESTFILE "#undef $fname\n";
773 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
774 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
777 compiletest ($fnamebase, "Test for type of function $fname",
778 "Function \"$fname\" has incorrect type.", $res, 0);
780 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
781 my($rettype) = "$2$3";
786 # Remember that this name is allowed.
789 # Generate a program to test for availability of this function.
790 open (TESTFILE, ">$fnamebase.c");
791 print TESTFILE "$prepend";
792 print TESTFILE "#include <$h>\n";
793 # print TESTFILE "#undef $fname\n";
794 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
797 $res = compiletest ($fnamebase, "Test availability of function $fname",
798 "Function \"$fname\" is not available.", $res, 0);
800 # Generate a program to test for the type of this function.
801 open (TESTFILE, ">$fnamebase.c");
802 print TESTFILE "$prepend";
803 print TESTFILE "#include <$h>\n";
804 # print TESTFILE "#undef $fname\n";
805 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
806 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
809 compiletest ($fnamebase, "Test for type of function $fname",
810 "Function \"$fname\" has incorrect type.", $res, 0);
811 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
817 # Remember that this name is allowed.
820 # Generate a program to test for availability of this function.
821 open (TESTFILE, ">$fnamebase.c");
822 print TESTFILE "$prepend";
823 print TESTFILE "#include <$h>\n";
824 # print TESTFILE "#undef $fname\n";
825 print TESTFILE "typedef $type xyzzy$rest;\n";
826 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
829 $res = compiletest ($fnamebase, "Test availability of variable $vname",
830 "Variable \"$vname\" is not available.", $res, 0);
832 # Generate a program to test for the type of this function.
833 open (TESTFILE, ">$fnamebase.c");
834 print TESTFILE "$prepend";
835 print TESTFILE "#include <$h>\n";
836 # print TESTFILE "#undef $fname\n";
837 print TESTFILE "extern $type $vname$rest;\n";
840 compiletest ($fnamebase, "Test for type of variable $fname",
841 "Variable \"$vname\" has incorrect type.", $res, 0);
842 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
843 my($rettype) = "$2$3";
848 # Remember that this name is allowed.
851 # Generate a program to test for availability of this function.
852 open (TESTFILE, ">$fnamebase.c");
853 print TESTFILE "$prepend";
854 print TESTFILE "#include <$h>\n";
855 print TESTFILE "#ifndef $fname\n";
856 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
857 print TESTFILE "#endif\n";
860 $res = compiletest ($fnamebase, "Test availability of function $fname",
861 "Function \"$fname\" is not available.", $res, 0);
863 # Generate a program to test for the type of this function.
864 open (TESTFILE, ">$fnamebase.c");
865 print TESTFILE "$prepend";
866 print TESTFILE "#include <$h>\n";
867 print TESTFILE "#ifndef $fname\n";
868 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
869 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
870 print TESTFILE "#endif\n";
873 compiletest ($fnamebase, "Test for type of function $fname",
874 "Function \"$fname\" has incorrect type.", $res, 0);
875 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
876 # The above regex doesn't handle a \" in a string.
881 # Remember that this name is allowed.
884 # Generate a program to test for availability of this macro.
885 open (TESTFILE, ">$fnamebase.c");
886 print TESTFILE "$prepend";
887 print TESTFILE "#include <$h>\n";
888 print TESTFILE "#ifndef $macro\n";
889 print TESTFILE "# error \"Macro $macro not defined\"\n";
890 print TESTFILE "#endif\n";
893 compiletest ($fnamebase, "Test availability of macro $macro",
894 "Macro \"$macro\" is not available.", $missing, 0);
896 # Generate a program to test for the value of this macro.
897 open (TESTFILE, ">$fnamebase.c");
898 print TESTFILE "$prepend";
899 print TESTFILE "#include <$h>\n";
900 # We can't include <string.h> here.
901 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
902 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
905 $res = runtest ($fnamebase, "Testing for value of macro $macro",
906 "Macro \"$macro\" has not the right value.", $res);
907 } elsif (/^optional-macro *([^ ]*)/) {
910 # Remember that this name is allowed.
913 # Generate a program to test for availability of this macro.
914 open (TESTFILE, ">$fnamebase.c");
915 print TESTFILE "$prepend";
916 print TESTFILE "#include <$h>\n";
917 print TESTFILE "#ifndef $macro\n";
918 print TESTFILE "# error \"Macro $macro not defined\"\n";
919 print TESTFILE "#endif\n";
922 compiletest ($fnamebase, "Test availability of macro $macro",
923 "NOT PRESENT", $missing, 1);
924 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
930 # Remember that this name is allowed.
933 # Generate a program to test for availability of this macro.
934 open (TESTFILE, ">$fnamebase.c");
935 print TESTFILE "$prepend";
936 print TESTFILE "#include <$h>\n";
937 print TESTFILE "#ifndef $macro\n";
938 print TESTFILE "# error \"Macro $macro not defined\"\n";
939 print TESTFILE "#endif\n";
942 $res = compiletest ($fnamebase, "Test availability of macro $macro",
943 "Macro \"$macro\" is not available.", $res, 0);
946 # Generate a program to test for the value of this constant.
947 open (TESTFILE, ">$fnamebase.c");
948 print TESTFILE "$prepend";
949 print TESTFILE "#include <$h>\n";
950 # Negate the value since 0 means ok
951 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
954 $res = runtest ($fnamebase, "Testing for value of constant $macro",
955 "Macro \"$macro\" has not the right value.", $res);
957 } elsif (/^macro *([^ ]*)/) {
960 # Remember that this name is allowed.
963 # Generate a program to test for availability of this macro.
964 open (TESTFILE, ">$fnamebase.c");
965 print TESTFILE "$prepend";
966 print TESTFILE "#include <$h>\n";
967 print TESTFILE "#ifndef $macro\n";
968 print TESTFILE "# error \"Macro $macro not defined\"\n";
969 print TESTFILE "#endif\n";
972 compiletest ($fnamebase, "Test availability of macro $macro",
973 "Macro \"$macro\" is not available.", $missing, 0);
974 } elsif (/^allow-header *(.*)/) {
976 if ($seenheader{$pattern} != 1) {
977 push @allowheader, $pattern;
978 $seenheader{$pattern} = 1;
981 } elsif (/^allow *(.*)/) {
983 push @allow, $pattern;
986 # printf ("line is `%s'\n", $_);
994 # Read the data files for the header files which are allowed to be included.
995 while ($#allowheader >= 0) {
996 my($ah) = pop @allowheader;
998 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
999 acontrol: while (<ALLOW>) {
1000 next acontrol if (/^#/);
1001 next acontrol if (/^[ ]*$/);
1003 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1005 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1007 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1009 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1012 # Remember that this name is allowed.
1013 if ($type =~ /^struct *(.*)/) {
1015 } elsif ($type =~ /^union *(.*)/) {
1020 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1022 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1024 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1026 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1028 } elsif (/^macro *([^ ]*)/) {
1030 } elsif (/^allow-header *(.*)/) {
1031 if ($seenheader{$1} != 1) {
1032 push @allowheader, $1;
1033 $seenheader{$1} = 1;
1035 } elsif (/^allow *(.*)/) {
1042 # Now check the namespace.
1043 printf (" Checking the namespace of \"%s\"... ", $h);
1048 checknamespace ($h, $fnamebase, @allow);
1054 printf "-" x 76 . "\n";
1055 printf (" Total number of tests : %4d\n", $total);
1057 printf (" Number of known failures: %4d (", $known);
1058 $percent = ($known * 100) / $total;
1059 if ($known > 0 && $percent < 1.0) {
1060 printf (" <1%%)\n");
1062 printf ("%3d%%)\n", $percent);
1065 printf (" Number of failed tests : %4d (", $errors);
1066 $percent = ($errors * 100) / $total;
1067 if ($errors > 0 && $percent < 1.0) {
1068 printf (" <1%%)\n");
1070 printf ("%3d%%)\n", $percent);
1073 printf (" Number of skipped tests : %4d (", $skipped);
1074 $percent = ($skipped * 100) / $total;
1075 if ($skipped > 0 && $percent < 1.0) {
1076 printf (" <1%%)\n");
1078 printf ("%3d%%)\n", $percent);