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 "termios.h", "tar.h", "sys/wait.h", "sys/utsname.h", "sys/un.h",
16 "sys/uio.h", "sys/types.h", "sys/times.h", "sys/timeb.h",
17 "sys/time.h", "sys/statvfs.h", "sys/stat.h", "sys/socket.h",
18 "sys/shm.h", "sys/sem.h", "sys/select.h", "sys/resource.h",
19 "sys/msg.h", "sys/mman.h", "sys/ipc.h", "syslog.h", "stropts.h",
20 "strings.h", "string.h", "stdlib.h", "stdio.h", "stdint.h",
21 "stddef.h", "stdarg.h", "spawn.h", "signal.h", "setjmp.h",
22 "semaphore.h", "search.h", "sched.h", "regex.h", "pwd.h",
23 "pthread.h", "poll.h", "nl_types.h", "netinet/tcp.h",
24 "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h", "mqueue.h",
25 "monetary.h", "math.h", "locale.h", "libgen.h", "limits.h",
26 "langinfo.h", "iso646.h", "inttypes.h", "iconv.h", "grp.h",
27 "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h", "fcntl.h",
28 "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
29 "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{'wordexp.h'} = "#include <stddef.h>\n";
61 # Make a hash table from this information.
62 while ($#keywords >= 0) {
63 $iskeyword{pop (@keywords)} = 1;
66 # Make a hash table from the known problems.
67 while ($#knownproblems >= 0) {
68 $isknown{pop (@knownproblems)} = 1;
81 my($pattern, $string) = @_;
82 my($strlen) = length ($string);
85 if (substr ($pattern, 0, 1) eq '*') {
86 my($patlen) = length ($pattern) - 1;
87 $res = ($strlen >= $patlen
88 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
89 } elsif (substr ($pattern, -1, 1) eq '*') {
90 my($patlen) = length ($pattern) - 1;
91 $res = ($strlen >= $patlen
92 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
94 $res = $pattern eq $string;
102 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
113 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
115 if ($optional != 0) {
116 printf (" $errmsg\n");
121 printf (" $errmsg Compiler message:\n");
129 if ($verbose > 1 && -s "$fnamebase.out") {
130 # We print all warnings issued.
134 if ($printlog != 0) {
135 printf (" " . "-" x 71 . "\n");
136 open (MESSAGE, "< $fnamebase.out");
141 printf (" " . "-" x 71 . "\n");
144 unlink "$fnamebase.c";
145 unlink "$fnamebase.o";
146 unlink "$fnamebase.out";
154 my($fnamebase, $msg, $errmsg, $skip) = @_;
165 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
169 printf (" $errmsg Compiler message:\n");
175 # Now run the program. If the exit code is not zero something is wrong.
176 $result = system "$fnamebase > $fnamebase.out2 2>&1";
179 if ($verbose > 1 && -s "$fnamebase.out") {
180 # We print all warnings issued.
182 system "cat $fnamebase.out2 >> $fnamebase.out";
188 unlink "$fnamebase.out";
189 rename "$fnamebase.out2", "$fnamebase.out";
192 if ($printlog != 0) {
193 printf (" " . "-" x 71 . "\n");
194 open (MESSAGE, "< $fnamebase.out");
199 printf (" " . "-" x 71 . "\n");
203 unlink "$fnamebase.c";
204 unlink "$fnamebase.o";
205 unlink "$fnamebase.out";
206 unlink "$fnamebase.out2";
213 my($token, @allow) = @_;
216 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
218 for ($idx = 0; $idx <= $#allow; ++$idx) {
219 return if (poorfnmatch ($allow[$idx], $token));
222 if ($isknown{$token}) {
227 printf ("FAIL\n " . "-" x 72 . "\n");
229 printf (" Namespace violation: \"%s\"\n", $token);
235 my($h, $fnamebase, @allow) = @_;
239 # Generate a program to get the contents of this header.
240 open (TESTFILE, ">$fnamebase.c");
241 print TESTFILE "#include <$h>\n";
246 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
247 loop: while (<CONTENT>) {
248 next loop if (/^#undef /);
250 if (/^#define (.*)/) {
251 newtoken ($1, @allow);
253 # We have to tokenize the line.
256 my($len) = length ($str);
258 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
260 newtoken ($token, @allow);
266 unlink "$fnamebase.c";
268 printf (" " . "-" x 72 . "\n");
270 } elsif ($nknown > 0) {
271 printf ("EXPECTED FAILURES\n");
279 while ($#headers >= 0) {
280 my($h) = pop (@headers);
283 my($fnamebase) = "$tmpdir/$hf-test";
286 my(@allowheader) = ();
287 my(%seenheader) = ();
288 my($prepend) = $mustprepend{$h};
290 printf ("Testing <$h>\n");
291 printf ("----------" . "-" x length ($h) . "\n");
293 # Generate a program to test for the availability of this header.
294 open (TESTFILE, ">$fnamebase.c");
295 print TESTFILE "$prepend";
296 print TESTFILE "#include <$h>\n";
299 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
300 "Header <$h> not available", 0, 0);
304 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
305 control: while (<CONTROL>) {
307 next control if (/^#/);
308 next control if (/^[ ]*$/);
310 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
311 my($struct) = "$2$3";
317 # Remember that this name is allowed.
318 push @allow, $member;
320 # Generate a program to test for the availability of this member.
321 open (TESTFILE, ">$fnamebase.c");
322 print TESTFILE "$prepend";
323 print TESTFILE "#include <$h>\n";
324 print TESTFILE "$struct a;\n";
325 print TESTFILE "$struct b;\n";
326 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
327 print TESTFILE "void foobarbaz (void) {\n";
328 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
329 print TESTFILE "}\n";
332 $res = compiletest ($fnamebase, "Testing for member $member",
333 "Member \"$member\" not available.", $res, 0);
336 # Test the types of the members.
337 open (TESTFILE, ">$fnamebase.c");
338 print TESTFILE "$prepend";
339 print TESTFILE "#include <$h>\n";
340 print TESTFILE "$struct a;\n";
341 print TESTFILE "extern $type b$rest;\n";
342 print TESTFILE "extern __typeof__ (a.$member) b;\n";
345 compiletest ($fnamebase, "Testing for type of member $member",
346 "Member \"$member\" does not have the correct type.",
348 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
349 my($struct) = "$2$3";
355 # Remember that this name is allowed.
356 push @allow, $member;
358 # Generate a program to test for the availability of this member.
359 open (TESTFILE, ">$fnamebase.c");
360 print TESTFILE "$prepend";
361 print TESTFILE "#include <$h>\n";
362 print TESTFILE "$struct a;\n";
363 print TESTFILE "$struct b;\n";
364 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
365 print TESTFILE "void foobarbaz (void) {\n";
366 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
367 print TESTFILE "}\n";
370 $res = compiletest ($fnamebase, "Testing for member $member",
371 "NOT AVAILABLE.", $res, 1);
373 if ($res == 0 || $missing != 0) {
374 # Test the types of the members.
375 open (TESTFILE, ">$fnamebase.c");
376 print TESTFILE "$prepend";
377 print TESTFILE "#include <$h>\n";
378 print TESTFILE "$struct a;\n";
379 print TESTFILE "extern $type b$rest;\n";
380 print TESTFILE "extern __typeof__ (a.$member) b;\n";
383 compiletest ($fnamebase, "Testing for type of member $member",
384 "Member \"$member\" does not have the correct type.",
387 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
393 # Remember that this name is allowed.
396 # Generate a program to test for the availability of this constant.
397 open (TESTFILE, ">$fnamebase.c");
398 print TESTFILE "$prepend";
399 print TESTFILE "#include <$h>\n";
400 print TESTFILE "__typeof__ ($const) a = $const;\n";
403 $res = compiletest ($fnamebase, "Testing for constant $const",
404 "NOT PRESENT", $res, 1);
406 if ($value ne "" && $res == 0) {
407 # Generate a program to test for the value of this constant.
408 open (TESTFILE, ">$fnamebase.c");
409 print TESTFILE "$prepend";
410 print TESTFILE "#include <$h>\n";
411 # Negate the value since 0 means ok
412 print TESTFILE "int main (void) { return !($const $op $value); }\n";
415 $res = runtest ($fnamebase, "Testing for value of constant $const",
416 "Constant \"$const\" has not the right value.", $res);
418 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
424 # Remember that this name is allowed.
427 # Generate a program to test for the availability of this constant.
428 open (TESTFILE, ">$fnamebase.c");
429 print TESTFILE "$prepend";
430 print TESTFILE "#include <$h>\n";
431 print TESTFILE "__typeof__ ($const) a = $const;\n";
434 $res = compiletest ($fnamebase, "Testing for constant $const",
435 "Constant \"$const\" not available.", $res, 0);
438 # Generate a program to test for the value of this constant.
439 open (TESTFILE, ">$fnamebase.c");
440 print TESTFILE "$prepend";
441 print TESTFILE "#include <$h>\n";
442 # Negate the value since 0 means ok
443 print TESTFILE "int main (void) { return !($const $op $value); }\n";
446 $res = runtest ($fnamebase, "Testing for value of constant $const",
447 "Constant \"$const\" has not the right value.", $res);
449 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
455 # Remember that this name is allowed.
458 # Generate a program to test for the availability of this constant.
459 open (TESTFILE, ">$fnamebase.c");
460 print TESTFILE "$prepend";
461 print TESTFILE "#include <$h>\n";
462 print TESTFILE "__typeof__ ($const) a = $const;\n";
465 $res = compiletest ($fnamebase, "Testing for constant $const",
466 "Constant \"$const\" not available.", $res, 0);
468 # Test the types of the members.
469 open (TESTFILE, ">$fnamebase.c");
470 print TESTFILE "$prepend";
471 print TESTFILE "#include <$h>\n";
472 print TESTFILE "__typeof__ (($type) 0) a;\n";
473 print TESTFILE "extern __typeof__ ($const) a;\n";
476 compiletest ($fnamebase, "Testing for type of constant $const",
477 "Constant \"$const\" does not have the correct type.",
481 # Generate a program to test for the value of this constant.
482 open (TESTFILE, ">$fnamebase.c");
483 print TESTFILE "$prepend";
484 print TESTFILE "#include <$h>\n";
485 print TESTFILE "int main (void) { return $const != $value; }\n";
488 $res = runtest ($fnamebase, "Testing for value of constant $const",
489 "Constant \"$const\" has not the right value.", $res);
491 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
496 # Remember that this name is allowed.
499 # Generate a program to test for the availability of this constant.
500 open (TESTFILE, ">$fnamebase.c");
501 print TESTFILE "$prepend";
502 print TESTFILE "#include <$h>\n";
503 print TESTFILE "__typeof__ ($const) a = $const;\n";
506 $res = compiletest ($fnamebase, "Testing for constant $const",
507 "NOT PRESENT", $res, 1);
509 if ($value ne "" && $res == 0) {
510 # Generate a program to test for the value of this constant.
511 open (TESTFILE, ">$fnamebase.c");
512 print TESTFILE "$prepend";
513 print TESTFILE "#include <$h>\n";
514 print TESTFILE "int main (void) { return $const != $value; }\n";
517 $res = runtest ($fnamebase, "Testing for value of constant $const",
518 "Constant \"$const\" has not the right value.", $res);
520 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
525 # Remember that this name is allowed.
528 # Generate a program to test for the availability of this constant.
529 open (TESTFILE, ">$fnamebase.c");
530 print TESTFILE "$prepend";
531 print TESTFILE "#include <$h>\n";
532 print TESTFILE "__typeof__ ($const) a = $const;\n";
535 $res = compiletest ($fnamebase, "Testing for constant $const",
536 "Constant \"$const\" not available.", $res, 0);
539 # Generate a program to test for the value of this constant.
540 open (TESTFILE, ">$fnamebase.c");
541 print TESTFILE "$prepend";
542 print TESTFILE "#include <$h>\n";
543 print TESTFILE "int main (void) { return $const != $value; }\n";
546 $res = runtest ($fnamebase, "Testing for value of constant $const",
547 "Constant \"$const\" has not the right value.", $res);
549 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
554 # Remember that this name is allowed.
555 push @allow, $symbol;
557 # Generate a program to test for the availability of this constant.
558 open (TESTFILE, ">$fnamebase.c");
559 print TESTFILE "$prepend";
560 print TESTFILE "#include <$h>\n";
561 print TESTFILE "void foobarbaz (void) {\n";
562 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
563 print TESTFILE "}\n";
566 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
567 "Symbol \"$symbol\" not available.", $res, 0);
570 # Generate a program to test for the value of this constant.
571 open (TESTFILE, ">$fnamebase.c");
572 print TESTFILE "$prepend";
573 print TESTFILE "#include <$h>\n";
574 print TESTFILE "int main (void) { return $symbol != $value; }\n";
577 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
578 "Symbol \"$symbol\" has not the right value.", $res);
580 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
586 # Remember that this name is allowed.
589 # Generate a program to test for the availability of this constant.
590 open (TESTFILE, ">$fnamebase.c");
591 print TESTFILE "$prepend";
592 print TESTFILE "#include <$h>\n";
593 print TESTFILE "__typeof__ ($const) a = $const;\n";
596 $res = compiletest ($fnamebase, "Testing for constant $const",
597 "Constant \"$const\" not available.", $res, 0);
599 # Test the types of the members.
600 open (TESTFILE, ">$fnamebase.c");
601 print TESTFILE "$prepend";
602 print TESTFILE "#include <$h>\n";
603 print TESTFILE "__typeof__ (($type) 0) a;\n";
604 print TESTFILE "extern __typeof__ ($const) a;\n";
607 compiletest ($fnamebase, "Testing for type of constant $const",
608 "Constant \"$const\" does not have the correct type.",
612 # Generate a program to test for the value of this constant.
613 open (TESTFILE, ">$fnamebase.c");
614 print TESTFILE "$prepend";
615 print TESTFILE "#include <$h>\n";
616 print TESTFILE "int main (void) { return $const != $value; }\n";
619 $res = runtest ($fnamebase, "Testing for value of constant $const",
620 "Constant \"$const\" has not the right value.", $res);
622 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
624 my($maybe_opaque) = 0;
626 # Remember that this name is allowed.
627 if ($type =~ /^struct *(.*)/) {
629 } elsif ($type =~ /^union *(.*)/) {
636 # Remember that this name is allowed.
639 # Generate a program to test for the availability of this constant.
640 open (TESTFILE, ">$fnamebase.c");
641 print TESTFILE "$prepend";
642 print TESTFILE "#include <$h>\n";
643 if ($maybe_opaque == 1) {
644 print TESTFILE "$type *a;\n";
646 print TESTFILE "$type a;\n";
650 compiletest ($fnamebase, "Testing for type $type",
651 "NOT AVAILABLE", $missing, 1);
652 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
654 my($maybe_opaque) = 0;
656 # Remember that this name is allowed.
657 if ($type =~ /^struct *(.*)/) {
659 } elsif ($type =~ /^union *(.*)/) {
666 # Remember that this name is allowed.
669 # Generate a program to test for the availability of this constant.
670 open (TESTFILE, ">$fnamebase.c");
671 print TESTFILE "$prepend";
672 print TESTFILE "#include <$h>\n";
673 if ($maybe_opaque == 1) {
674 print TESTFILE "$type *a;\n";
676 print TESTFILE "$type a;\n";
680 compiletest ($fnamebase, "Testing for type $type",
681 "Type \"$type\" not available.", $missing, 0);
682 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
683 my($rettype) = "$2$3";
688 # Remember that this name is allowed.
691 # Generate a program to test for availability of this function.
692 open (TESTFILE, ">$fnamebase.c");
693 print TESTFILE "$prepend";
694 print TESTFILE "#include <$h>\n";
695 # print TESTFILE "#undef $fname\n";
696 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
699 $res = compiletest ($fnamebase, "Test availability of function $fname",
700 "NOT AVAILABLE", $res, 1);
702 if ($res == 0 || $missing == 1) {
703 # Generate a program to test for the type of this function.
704 open (TESTFILE, ">$fnamebase.c");
705 print TESTFILE "$prepend";
706 print TESTFILE "#include <$h>\n";
707 # print TESTFILE "#undef $fname\n";
708 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
709 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
712 compiletest ($fnamebase, "Test for type of function $fname",
713 "Function \"$fname\" has incorrect type.", $res, 0);
715 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
716 my($rettype) = "$2$3";
721 # Remember that this name is allowed.
724 # Generate a program to test for availability of this function.
725 open (TESTFILE, ">$fnamebase.c");
726 print TESTFILE "$prepend";
727 print TESTFILE "#include <$h>\n";
728 # print TESTFILE "#undef $fname\n";
729 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
732 $res = compiletest ($fnamebase, "Test availability of function $fname",
733 "Function \"$fname\" is not available.", $res, 0);
735 # Generate a program to test for the type of this function.
736 open (TESTFILE, ">$fnamebase.c");
737 print TESTFILE "$prepend";
738 print TESTFILE "#include <$h>\n";
739 # print TESTFILE "#undef $fname\n";
740 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
741 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
744 compiletest ($fnamebase, "Test for type of function $fname",
745 "Function \"$fname\" has incorrect type.", $res, 0);
746 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
747 my($rettype) = "$2$3";
752 # Remember that this name is allowed.
755 # Generate a program to test for availability of this function.
756 open (TESTFILE, ">$fnamebase.c");
757 print TESTFILE "$prepend";
758 print TESTFILE "#include <$h>\n";
759 # print TESTFILE "#undef $fname\n";
760 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
763 $res = compiletest ($fnamebase, "Test availability of function $fname",
764 "NOT AVAILABLE", $res, 1);
766 if ($res == 0 || $missing != 0) {
767 # Generate a program to test for the type of this function.
768 open (TESTFILE, ">$fnamebase.c");
769 print TESTFILE "$prepend";
770 print TESTFILE "#include <$h>\n";
771 # print TESTFILE "#undef $fname\n";
772 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
773 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
776 compiletest ($fnamebase, "Test for type of function $fname",
777 "Function \"$fname\" has incorrect type.", $res, 0);
779 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
780 my($rettype) = "$2$3";
785 # Remember that this name is allowed.
788 # Generate a program to test for availability of this function.
789 open (TESTFILE, ">$fnamebase.c");
790 print TESTFILE "$prepend";
791 print TESTFILE "#include <$h>\n";
792 # print TESTFILE "#undef $fname\n";
793 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
796 $res = compiletest ($fnamebase, "Test availability of function $fname",
797 "Function \"$fname\" is not available.", $res, 0);
799 # Generate a program to test for the type of this function.
800 open (TESTFILE, ">$fnamebase.c");
801 print TESTFILE "$prepend";
802 print TESTFILE "#include <$h>\n";
803 # print TESTFILE "#undef $fname\n";
804 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
805 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
808 compiletest ($fnamebase, "Test for type of function $fname",
809 "Function \"$fname\" has incorrect type.", $res, 0);
810 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
815 # Remember that this name is allowed.
818 # Generate a program to test for availability of this function.
819 open (TESTFILE, ">$fnamebase.c");
820 print TESTFILE "$prepend";
821 print TESTFILE "#include <$h>\n";
822 # print TESTFILE "#undef $fname\n";
823 print TESTFILE "$type *foobarbaz = &$vname;\n";
826 $res = compiletest ($fnamebase, "Test availability of variable $vname",
827 "Variable \"$vname\" is not available.", $res, 0);
829 # Generate a program to test for the type of this function.
830 open (TESTFILE, ">$fnamebase.c");
831 print TESTFILE "$prepend";
832 print TESTFILE "#include <$h>\n";
833 # print TESTFILE "#undef $fname\n";
834 print TESTFILE "extern $type $vname;\n";
837 compiletest ($fnamebase, "Test for type of variable $fname",
838 "Variable \"$vname\" has incorrect type.", $res, 0);
839 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
840 my($rettype) = "$2$3";
845 # Remember that this name is allowed.
848 # Generate a program to test for availability of this function.
849 open (TESTFILE, ">$fnamebase.c");
850 print TESTFILE "$prepend";
851 print TESTFILE "#include <$h>\n";
852 print TESTFILE "#ifndef $fname\n";
853 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
854 print TESTFILE "#endif\n";
857 $res = compiletest ($fnamebase, "Test availability of function $fname",
858 "Function \"$fname\" is not available.", $res, 0);
860 # Generate a program to test for the type of this function.
861 open (TESTFILE, ">$fnamebase.c");
862 print TESTFILE "$prepend";
863 print TESTFILE "#include <$h>\n";
864 print TESTFILE "#ifndef $fname\n";
865 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
866 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
867 print TESTFILE "#endif\n";
870 compiletest ($fnamebase, "Test for type of function $fname",
871 "Function \"$fname\" has incorrect type.", $res, 0);
872 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
873 # The above regex doesn't handle a \" in a string.
878 # Remember that this name is allowed.
881 # Generate a program to test for availability of this macro.
882 open (TESTFILE, ">$fnamebase.c");
883 print TESTFILE "$prepend";
884 print TESTFILE "#include <$h>\n";
885 print TESTFILE "#ifndef $macro\n";
886 print TESTFILE "# error \"Macro $macro not defined\"\n";
887 print TESTFILE "#endif\n";
890 compiletest ($fnamebase, "Test availability of macro $macro",
891 "Macro \"$macro\" is not available.", $missing, 0);
893 # Generate a program to test for the value of this macro.
894 open (TESTFILE, ">$fnamebase.c");
895 print TESTFILE "$prepend";
896 print TESTFILE "#include <$h>\n";
897 # We can't include <string.h> here.
898 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
899 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
902 $res = runtest ($fnamebase, "Testing for value of macro $macro",
903 "Macro \"$macro\" has not the right value.", $res);
904 } elsif (/^optional-macro *([^ ]*)/) {
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 "NOT PRESENT", $missing, 1);
921 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
927 # Remember that this name is allowed.
930 # Generate a program to test for availability of this macro.
931 open (TESTFILE, ">$fnamebase.c");
932 print TESTFILE "$prepend";
933 print TESTFILE "#include <$h>\n";
934 print TESTFILE "#ifndef $macro\n";
935 print TESTFILE "# error \"Macro $macro not defined\"\n";
936 print TESTFILE "#endif\n";
939 $res = compiletest ($fnamebase, "Test availability of macro $macro",
940 "Macro \"$macro\" is not available.", $res, 0);
943 # Generate a program to test for the value of this constant.
944 open (TESTFILE, ">$fnamebase.c");
945 print TESTFILE "$prepend";
946 print TESTFILE "#include <$h>\n";
947 # Negate the value since 0 means ok
948 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
951 $res = runtest ($fnamebase, "Testing for value of constant $macro",
952 "Macro \"$macro\" has not the right value.", $res);
954 } elsif (/^macro *([^ ]*)/) {
957 # Remember that this name is allowed.
960 # Generate a program to test for availability of this macro.
961 open (TESTFILE, ">$fnamebase.c");
962 print TESTFILE "$prepend";
963 print TESTFILE "#include <$h>\n";
964 print TESTFILE "#ifndef $macro\n";
965 print TESTFILE "# error \"Macro $macro not defined\"\n";
966 print TESTFILE "#endif\n";
969 compiletest ($fnamebase, "Test availability of macro $macro",
970 "Macro \"$macro\" is not available.", $missing, 0);
971 } elsif (/^allow-header *(.*)/) {
973 if ($seenheader{$pattern} != 1) {
974 push @allowheader, $pattern;
975 $seenheader{$pattern} = 1;
978 } elsif (/^allow *(.*)/) {
980 push @allow, $pattern;
983 # printf ("line is `%s'\n", $_);
991 # Read the data files for the header files which are allowed to be included.
992 while ($#allowheader >= 0) {
993 my($ah) = pop @allowheader;
995 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
996 acontrol: while (<ALLOW>) {
997 next acontrol if (/^#/);
998 next acontrol if (/^[ ]*$/);
1000 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
1002 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
1004 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
1006 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
1009 # Remember that this name is allowed.
1010 if ($type =~ /^struct *(.*)/) {
1012 } elsif ($type =~ /^union *(.*)/) {
1017 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
1019 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1021 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
1023 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
1025 } elsif (/^macro *([^ ]*)/) {
1027 } elsif (/^allow-header *(.*)/) {
1028 if ($seenheader{$1} != 1) {
1029 push @allowheader, $1;
1030 $seenheader{$1} = 1;
1032 } elsif (/^allow *(.*)/) {
1039 # Now check the namespace.
1040 printf (" Checking the namespace of \"%s\"... ", $h);
1045 checknamespace ($h, $fnamebase, @allow);
1051 printf "-" x 76 . "\n";
1052 printf (" Total number of tests : %4d\n", $total);
1054 printf (" Number of known failures: %4d (", $known);
1055 $percent = ($known * 100) / $total;
1056 if ($known > 0 && $percent < 1.0) {
1057 printf (" <1%%)\n");
1059 printf ("%3d%%)\n", $percent);
1062 printf (" Number of failed tests : %4d (", $errors);
1063 $percent = ($errors * 100) / $total;
1064 if ($errors > 0 && $percent < 1.0) {
1065 printf (" <1%%)\n");
1067 printf ("%3d%%)\n", $percent);
1070 printf (" Number of skipped tests : %4d (", $skipped);
1071 $percent = ($skipped * 100) / $total;
1072 if ($skipped > 0 && $percent < 1.0) {
1073 printf (" <1%%)\n");
1075 printf ("%3d%%)\n", $percent);