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{'wchar.h'} = "#include <stdarg.h>\n";
60 $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
62 # Make a hash table from this information.
63 while ($#keywords >= 0) {
64 $iskeyword{pop (@keywords)} = 1;
67 # Make a hash table from the known problems.
68 while ($#knownproblems >= 0) {
69 $isknown{pop (@knownproblems)} = 1;
82 my($pattern, $string) = @_;
83 my($strlen) = length ($string);
86 if (substr ($pattern, 0, 1) eq '*') {
87 my($patlen) = length ($pattern) - 1;
88 $res = ($strlen >= $patlen
89 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
90 } elsif (substr ($pattern, -1, 1) eq '*') {
91 my($patlen) = length ($pattern) - 1;
92 $res = ($strlen >= $patlen
93 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
95 $res = $pattern eq $string;
103 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
114 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
116 if ($optional != 0) {
117 printf (" $errmsg\n");
122 printf (" $errmsg Compiler message:\n");
130 if ($verbose > 1 && -s "$fnamebase.out") {
131 # We print all warnings issued.
135 if ($printlog != 0) {
136 printf (" " . "-" x 71 . "\n");
137 open (MESSAGE, "< $fnamebase.out");
142 printf (" " . "-" x 71 . "\n");
145 unlink "$fnamebase.c";
146 unlink "$fnamebase.o";
147 unlink "$fnamebase.out";
155 my($fnamebase, $msg, $errmsg, $skip) = @_;
166 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
170 printf (" $errmsg Compiler message:\n");
176 # Now run the program. If the exit code is not zero something is wrong.
177 $result = system "$fnamebase > $fnamebase.out2 2>&1";
180 if ($verbose > 1 && -s "$fnamebase.out") {
181 # We print all warnings issued.
183 system "cat $fnamebase.out2 >> $fnamebase.out";
189 unlink "$fnamebase.out";
190 rename "$fnamebase.out2", "$fnamebase.out";
193 if ($printlog != 0) {
194 printf (" " . "-" x 71 . "\n");
195 open (MESSAGE, "< $fnamebase.out");
200 printf (" " . "-" x 71 . "\n");
204 unlink "$fnamebase.c";
205 unlink "$fnamebase.o";
206 unlink "$fnamebase.out";
207 unlink "$fnamebase.out2";
214 my($token, @allow) = @_;
217 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
219 for ($idx = 0; $idx <= $#allow; ++$idx) {
220 return if (poorfnmatch ($allow[$idx], $token));
223 if ($isknown{$token}) {
228 printf ("FAIL\n " . "-" x 72 . "\n");
230 printf (" Namespace violation: \"%s\"\n", $token);
236 my($h, $fnamebase, @allow) = @_;
240 # Generate a program to get the contents of this header.
241 open (TESTFILE, ">$fnamebase.c");
242 print TESTFILE "#include <$h>\n";
247 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
248 loop: while (<CONTENT>) {
249 next loop if (/^#undef /);
251 if (/^#define (.*)/) {
252 newtoken ($1, @allow);
254 # We have to tokenize the line.
257 my($len) = length ($str);
259 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
261 newtoken ($token, @allow);
267 unlink "$fnamebase.c";
269 printf (" " . "-" x 72 . "\n");
271 } elsif ($nknown > 0) {
272 printf ("EXPECTED FAILURES\n");
280 while ($#headers >= 0) {
281 my($h) = pop (@headers);
284 my($fnamebase) = "$tmpdir/$hf-test";
287 my(@allowheader) = ();
288 my(%seenheader) = ();
289 my($prepend) = $mustprepend{$h};
291 printf ("Testing <$h>\n");
292 printf ("----------" . "-" x length ($h) . "\n");
294 # Generate a program to test for the availability of this header.
295 open (TESTFILE, ">$fnamebase.c");
296 print TESTFILE "$prepend";
297 print TESTFILE "#include <$h>\n";
300 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
301 "Header <$h> not available", 0, 0);
305 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
306 control: while (<CONTROL>) {
308 next control if (/^#/);
309 next control if (/^[ ]*$/);
311 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
312 my($struct) = "$2$3";
318 # Remember that this name is allowed.
319 push @allow, $member;
321 # Generate a program to test for the availability of this member.
322 open (TESTFILE, ">$fnamebase.c");
323 print TESTFILE "$prepend";
324 print TESTFILE "#include <$h>\n";
325 print TESTFILE "$struct a;\n";
326 print TESTFILE "$struct b;\n";
327 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
328 print TESTFILE "void foobarbaz (void) {\n";
329 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
330 print TESTFILE "}\n";
333 $res = compiletest ($fnamebase, "Testing for member $member",
334 "Member \"$member\" not available.", $res, 0);
337 # Test the types of the members.
338 open (TESTFILE, ">$fnamebase.c");
339 print TESTFILE "$prepend";
340 print TESTFILE "#include <$h>\n";
341 print TESTFILE "$struct a;\n";
342 print TESTFILE "extern $type b$rest;\n";
343 print TESTFILE "extern __typeof__ (a.$member) b;\n";
346 compiletest ($fnamebase, "Testing for type of member $member",
347 "Member \"$member\" does not have the correct type.",
349 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
350 my($struct) = "$2$3";
356 # Remember that this name is allowed.
357 push @allow, $member;
359 # Generate a program to test for the availability of this member.
360 open (TESTFILE, ">$fnamebase.c");
361 print TESTFILE "$prepend";
362 print TESTFILE "#include <$h>\n";
363 print TESTFILE "$struct a;\n";
364 print TESTFILE "$struct b;\n";
365 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
366 print TESTFILE "void foobarbaz (void) {\n";
367 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
368 print TESTFILE "}\n";
371 $res = compiletest ($fnamebase, "Testing for member $member",
372 "NOT AVAILABLE.", $res, 1);
374 if ($res == 0 || $missing != 0) {
375 # Test the types of the members.
376 open (TESTFILE, ">$fnamebase.c");
377 print TESTFILE "$prepend";
378 print TESTFILE "#include <$h>\n";
379 print TESTFILE "$struct a;\n";
380 print TESTFILE "extern $type b$rest;\n";
381 print TESTFILE "extern __typeof__ (a.$member) b;\n";
384 compiletest ($fnamebase, "Testing for type of member $member",
385 "Member \"$member\" does not have the correct type.",
388 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
394 # Remember that this name is allowed.
397 # Generate a program to test for the availability of this constant.
398 open (TESTFILE, ">$fnamebase.c");
399 print TESTFILE "$prepend";
400 print TESTFILE "#include <$h>\n";
401 print TESTFILE "__typeof__ ($const) a = $const;\n";
404 $res = compiletest ($fnamebase, "Testing for constant $const",
405 "NOT PRESENT", $res, 1);
407 if ($value ne "" && $res == 0) {
408 # Generate a program to test for the value of this constant.
409 open (TESTFILE, ">$fnamebase.c");
410 print TESTFILE "$prepend";
411 print TESTFILE "#include <$h>\n";
412 # Negate the value since 0 means ok
413 print TESTFILE "int main (void) { return !($const $op $value); }\n";
416 $res = runtest ($fnamebase, "Testing for value of constant $const",
417 "Constant \"$const\" has not the right value.", $res);
419 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
425 # Remember that this name is allowed.
428 # Generate a program to test for the availability of this constant.
429 open (TESTFILE, ">$fnamebase.c");
430 print TESTFILE "$prepend";
431 print TESTFILE "#include <$h>\n";
432 print TESTFILE "__typeof__ ($const) a = $const;\n";
435 $res = compiletest ($fnamebase, "Testing for constant $const",
436 "Constant \"$const\" not available.", $res, 0);
439 # Generate a program to test for the value of this constant.
440 open (TESTFILE, ">$fnamebase.c");
441 print TESTFILE "$prepend";
442 print TESTFILE "#include <$h>\n";
443 # Negate the value since 0 means ok
444 print TESTFILE "int main (void) { return !($const $op $value); }\n";
447 $res = runtest ($fnamebase, "Testing for value of constant $const",
448 "Constant \"$const\" has not the right value.", $res);
450 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
456 # Remember that this name is allowed.
459 # Generate a program to test for the availability of this constant.
460 open (TESTFILE, ">$fnamebase.c");
461 print TESTFILE "$prepend";
462 print TESTFILE "#include <$h>\n";
463 print TESTFILE "__typeof__ ($const) a = $const;\n";
466 $res = compiletest ($fnamebase, "Testing for constant $const",
467 "Constant \"$const\" not available.", $res, 0);
469 # Test the types of the members.
470 open (TESTFILE, ">$fnamebase.c");
471 print TESTFILE "$prepend";
472 print TESTFILE "#include <$h>\n";
473 print TESTFILE "__typeof__ (($type) 0) a;\n";
474 print TESTFILE "extern __typeof__ ($const) a;\n";
477 compiletest ($fnamebase, "Testing for type of constant $const",
478 "Constant \"$const\" does not have the correct type.",
482 # Generate a program to test for the value of this constant.
483 open (TESTFILE, ">$fnamebase.c");
484 print TESTFILE "$prepend";
485 print TESTFILE "#include <$h>\n";
486 print TESTFILE "int main (void) { return $const != $value; }\n";
489 $res = runtest ($fnamebase, "Testing for value of constant $const",
490 "Constant \"$const\" has not the right value.", $res);
492 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
497 # Remember that this name is allowed.
500 # Generate a program to test for the availability of this constant.
501 open (TESTFILE, ">$fnamebase.c");
502 print TESTFILE "$prepend";
503 print TESTFILE "#include <$h>\n";
504 print TESTFILE "__typeof__ ($const) a = $const;\n";
507 $res = compiletest ($fnamebase, "Testing for constant $const",
508 "NOT PRESENT", $res, 1);
510 if ($value ne "" && $res == 0) {
511 # Generate a program to test for the value of this constant.
512 open (TESTFILE, ">$fnamebase.c");
513 print TESTFILE "$prepend";
514 print TESTFILE "#include <$h>\n";
515 print TESTFILE "int main (void) { return $const != $value; }\n";
518 $res = runtest ($fnamebase, "Testing for value of constant $const",
519 "Constant \"$const\" has not the right value.", $res);
521 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
526 # Remember that this name is allowed.
529 # Generate a program to test for the availability of this constant.
530 open (TESTFILE, ">$fnamebase.c");
531 print TESTFILE "$prepend";
532 print TESTFILE "#include <$h>\n";
533 print TESTFILE "__typeof__ ($const) a = $const;\n";
536 $res = compiletest ($fnamebase, "Testing for constant $const",
537 "Constant \"$const\" not available.", $res, 0);
540 # Generate a program to test for the value of this constant.
541 open (TESTFILE, ">$fnamebase.c");
542 print TESTFILE "$prepend";
543 print TESTFILE "#include <$h>\n";
544 print TESTFILE "int main (void) { return $const != $value; }\n";
547 $res = runtest ($fnamebase, "Testing for value of constant $const",
548 "Constant \"$const\" has not the right value.", $res);
550 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
555 # Remember that this name is allowed.
556 push @allow, $symbol;
558 # Generate a program to test for the availability of this constant.
559 open (TESTFILE, ">$fnamebase.c");
560 print TESTFILE "$prepend";
561 print TESTFILE "#include <$h>\n";
562 print TESTFILE "void foobarbaz (void) {\n";
563 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
564 print TESTFILE "}\n";
567 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
568 "Symbol \"$symbol\" not available.", $res, 0);
571 # Generate a program to test for the value of this constant.
572 open (TESTFILE, ">$fnamebase.c");
573 print TESTFILE "$prepend";
574 print TESTFILE "#include <$h>\n";
575 print TESTFILE "int main (void) { return $symbol != $value; }\n";
578 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
579 "Symbol \"$symbol\" has not the right value.", $res);
581 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
587 # Remember that this name is allowed.
590 # Generate a program to test for the availability of this constant.
591 open (TESTFILE, ">$fnamebase.c");
592 print TESTFILE "$prepend";
593 print TESTFILE "#include <$h>\n";
594 print TESTFILE "__typeof__ ($const) a = $const;\n";
597 $res = compiletest ($fnamebase, "Testing for constant $const",
598 "Constant \"$const\" not available.", $res, 0);
600 # Test the types of the members.
601 open (TESTFILE, ">$fnamebase.c");
602 print TESTFILE "$prepend";
603 print TESTFILE "#include <$h>\n";
604 print TESTFILE "__typeof__ (($type) 0) a;\n";
605 print TESTFILE "extern __typeof__ ($const) a;\n";
608 compiletest ($fnamebase, "Testing for type of constant $const",
609 "Constant \"$const\" does not have the correct type.",
613 # Generate a program to test for the value of this constant.
614 open (TESTFILE, ">$fnamebase.c");
615 print TESTFILE "$prepend";
616 print TESTFILE "#include <$h>\n";
617 print TESTFILE "int main (void) { return $const != $value; }\n";
620 $res = runtest ($fnamebase, "Testing for value of constant $const",
621 "Constant \"$const\" has not the right value.", $res);
623 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
625 my($maybe_opaque) = 0;
627 # Remember that this name is allowed.
628 if ($type =~ /^struct *(.*)/) {
630 } elsif ($type =~ /^union *(.*)/) {
637 # Remember that this name is allowed.
640 # Generate a program to test for the availability of this constant.
641 open (TESTFILE, ">$fnamebase.c");
642 print TESTFILE "$prepend";
643 print TESTFILE "#include <$h>\n";
644 if ($maybe_opaque == 1) {
645 print TESTFILE "$type *a;\n";
647 print TESTFILE "$type a;\n";
651 compiletest ($fnamebase, "Testing for type $type",
652 "NOT AVAILABLE", $missing, 1);
653 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
655 my($maybe_opaque) = 0;
657 # Remember that this name is allowed.
658 if ($type =~ /^struct *(.*)/) {
660 } elsif ($type =~ /^union *(.*)/) {
667 # Remember that this name is allowed.
670 # Generate a program to test for the availability of this constant.
671 open (TESTFILE, ">$fnamebase.c");
672 print TESTFILE "$prepend";
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);