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 (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
555 # Remember that this name is allowed.
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 "__typeof__ ($const) a = $const;\n";
565 $res = compiletest ($fnamebase, "Testing for constant $const",
566 "Constant \"$const\" not available.", $res, 0);
568 # Test the types of the members.
569 open (TESTFILE, ">$fnamebase.c");
570 print TESTFILE "$prepend";
571 print TESTFILE "#include <$h>\n";
572 print TESTFILE "__typeof__ (($type) 0) a;\n";
573 print TESTFILE "extern __typeof__ ($const) a;\n";
576 compiletest ($fnamebase, "Testing for type of constant $const",
577 "Constant \"$const\" does not have the correct type.",
581 # Generate a program to test for the value of this constant.
582 open (TESTFILE, ">$fnamebase.c");
583 print TESTFILE "$prepend";
584 print TESTFILE "#include <$h>\n";
585 print TESTFILE "int main (void) { return $const != $value; }\n";
588 $res = runtest ($fnamebase, "Testing for value of constant $const",
589 "Constant \"$const\" has not the right value.", $res);
591 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
593 my($maybe_opaque) = 0;
595 # Remember that this name is allowed.
596 if ($type =~ /^struct *(.*)/) {
598 } elsif ($type =~ /^union *(.*)/) {
605 # Remember that this name is allowed.
608 # Generate a program to test for the availability of this constant.
609 open (TESTFILE, ">$fnamebase.c");
610 print TESTFILE "$prepend";
611 print TESTFILE "#include <$h>\n";
612 if ($maybe_opaque == 1) {
613 print TESTFILE "$type *a;\n";
615 print TESTFILE "$type a;\n";
619 compiletest ($fnamebase, "Testing for type $type",
620 "NOT AVAILABLE", $missing, 1);
621 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
623 my($maybe_opaque) = 0;
625 # Remember that this name is allowed.
626 if ($type =~ /^struct *(.*)/) {
628 } elsif ($type =~ /^union *(.*)/) {
635 # Remember that this name is allowed.
638 # Generate a program to test for the availability of this constant.
639 open (TESTFILE, ">$fnamebase.c");
640 print TESTFILE "$prepend";
641 print TESTFILE "#include <$h>\n";
642 if ($maybe_opaque == 1) {
643 print TESTFILE "$type *a;\n";
645 print TESTFILE "$type a;\n";
649 compiletest ($fnamebase, "Testing for type $type",
650 "Type \"$type\" not available.", $missing, 0);
651 } elsif (/^optional-function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
652 my($rettype) = "$2$3";
657 # Remember that this name is allowed.
660 # Generate a program to test for availability of this function.
661 open (TESTFILE, ">$fnamebase.c");
662 print TESTFILE "$prepend";
663 print TESTFILE "#include <$h>\n";
664 # print TESTFILE "#undef $fname\n";
665 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
668 $res = compiletest ($fnamebase, "Test availability of function $fname",
669 "NOT AVAILABLE", $res, 1);
671 if ($res == 0 || $missing == 1) {
672 # Generate a program to test for the type of this function.
673 open (TESTFILE, ">$fnamebase.c");
674 print TESTFILE "$prepend";
675 print TESTFILE "#include <$h>\n";
676 # print TESTFILE "#undef $fname\n";
677 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
678 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
681 compiletest ($fnamebase, "Test for type of function $fname",
682 "Function \"$fname\" has incorrect type.", $res, 0);
684 } elsif (/^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 "Function \"$fname\" is not available.", $res, 0);
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);
715 } elsif (/^optional-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 "NOT AVAILABLE", $res, 1);
735 if ($res == 0 || $missing != 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);
748 } elsif (/^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 "Function \"$fname\" is not available.", $res, 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);
779 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
784 # Remember that this name is allowed.
787 # Generate a program to test for availability of this function.
788 open (TESTFILE, ">$fnamebase.c");
789 print TESTFILE "$prepend";
790 print TESTFILE "#include <$h>\n";
791 # print TESTFILE "#undef $fname\n";
792 print TESTFILE "$type *foobarbaz = &$vname;\n";
795 $res = compiletest ($fnamebase, "Test availability of variable $vname",
796 "Variable \"$vname\" is not available.", $res, 0);
798 # Generate a program to test for the type of this function.
799 open (TESTFILE, ">$fnamebase.c");
800 print TESTFILE "$prepend";
801 print TESTFILE "#include <$h>\n";
802 # print TESTFILE "#undef $fname\n";
803 print TESTFILE "extern $type $vname;\n";
806 compiletest ($fnamebase, "Test for type of variable $fname",
807 "Variable \"$vname\" has incorrect type.", $res, 0);
808 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
809 my($rettype) = "$2$3";
814 # Remember that this name is allowed.
817 # Generate a program to test for availability of this function.
818 open (TESTFILE, ">$fnamebase.c");
819 print TESTFILE "$prepend";
820 print TESTFILE "#include <$h>\n";
821 print TESTFILE "#ifndef $fname\n";
822 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
823 print TESTFILE "#endif\n";
826 $res = compiletest ($fnamebase, "Test availability of function $fname",
827 "Function \"$fname\" 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 "#ifndef $fname\n";
834 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
835 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
836 print TESTFILE "#endif\n";
839 compiletest ($fnamebase, "Test for type of function $fname",
840 "Function \"$fname\" has incorrect type.", $res, 0);
841 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
842 # The above regex doesn't handle a \" in a string.
847 # Remember that this name is allowed.
850 # Generate a program to test for availability of this macro.
851 open (TESTFILE, ">$fnamebase.c");
852 print TESTFILE "$prepend";
853 print TESTFILE "#include <$h>\n";
854 print TESTFILE "#ifndef $macro\n";
855 print TESTFILE "# error \"Macro $macro not defined\"\n";
856 print TESTFILE "#endif\n";
859 compiletest ($fnamebase, "Test availability of macro $macro",
860 "Macro \"$macro\" is not available.", $missing, 0);
862 # Generate a program to test for the value of this macro.
863 open (TESTFILE, ">$fnamebase.c");
864 print TESTFILE "$prepend";
865 print TESTFILE "#include <$h>\n";
866 # We can't include <string.h> here.
867 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
868 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
871 $res = runtest ($fnamebase, "Testing for value of macro $macro",
872 "Macro \"$macro\" has not the right value.", $res);
873 } elsif (/^optional-macro *([^ ]*)/) {
876 # Remember that this name is allowed.
879 # Generate a program to test for availability of this macro.
880 open (TESTFILE, ">$fnamebase.c");
881 print TESTFILE "$prepend";
882 print TESTFILE "#include <$h>\n";
883 print TESTFILE "#ifndef $macro\n";
884 print TESTFILE "# error \"Macro $macro not defined\"\n";
885 print TESTFILE "#endif\n";
888 compiletest ($fnamebase, "Test availability of macro $macro",
889 "NOT PRESENT", $missing, 1);
890 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
896 # Remember that this name is allowed.
899 # Generate a program to test for availability of this macro.
900 open (TESTFILE, ">$fnamebase.c");
901 print TESTFILE "$prepend";
902 print TESTFILE "#include <$h>\n";
903 print TESTFILE "#ifndef $macro\n";
904 print TESTFILE "# error \"Macro $macro not defined\"\n";
905 print TESTFILE "#endif\n";
908 $res = compiletest ($fnamebase, "Test availability of macro $macro",
909 "Macro \"$macro\" is not available.", $res, 0);
912 # Generate a program to test for the value of this constant.
913 open (TESTFILE, ">$fnamebase.c");
914 print TESTFILE "$prepend";
915 print TESTFILE "#include <$h>\n";
916 # Negate the value since 0 means ok
917 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
920 $res = runtest ($fnamebase, "Testing for value of constant $macro",
921 "Macro \"$macro\" has not the right value.", $res);
923 } elsif (/^macro *([^ ]*)/) {
926 # Remember that this name is allowed.
929 # Generate a program to test for availability of this macro.
930 open (TESTFILE, ">$fnamebase.c");
931 print TESTFILE "$prepend";
932 print TESTFILE "#include <$h>\n";
933 print TESTFILE "#ifndef $macro\n";
934 print TESTFILE "# error \"Macro $macro not defined\"\n";
935 print TESTFILE "#endif\n";
938 compiletest ($fnamebase, "Test availability of macro $macro",
939 "Macro \"$macro\" is not available.", $missing, 0);
940 } elsif (/^allow-header *(.*)/) {
942 if ($seenheader{$pattern} != 1) {
943 push @allowheader, $pattern;
944 $seenheader{$pattern} = 1;
947 } elsif (/^allow *(.*)/) {
949 push @allow, $pattern;
952 # printf ("line is `%s'\n", $_);
960 # Read the data files for the header files which are allowed to be included.
961 while ($#allowheader >= 0) {
962 my($ah) = pop @allowheader;
964 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
965 acontrol: while (<ALLOW>) {
966 next acontrol if (/^#/);
967 next acontrol if (/^[ ]*$/);
969 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
971 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
973 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
975 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
978 # Remember that this name is allowed.
979 if ($type =~ /^struct *(.*)/) {
981 } elsif ($type =~ /^union *(.*)/) {
986 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
988 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
990 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
992 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
994 } elsif (/^macro *([^ ]*)/) {
996 } elsif (/^allow-header *(.*)/) {
997 if ($seenheader{$1} != 1) {
998 push @allowheader, $1;
1001 } elsif (/^allow *(.*)/) {
1008 # Now check the namespace.
1009 printf (" Checking the namespace of \"%s\"... ", $h);
1014 checknamespace ($h, $fnamebase, @allow);
1020 printf "-" x 76 . "\n";
1021 printf (" Total number of tests : %4d\n", $total);
1023 printf (" Number of known failures: %4d (", $known);
1024 $percent = ($known * 100) / $total;
1025 if ($known > 0 && $percent < 1.0) {
1026 printf (" <1%%)\n");
1028 printf ("%3d%%)\n", $percent);
1031 printf (" Number of failed tests : %4d (", $errors);
1032 $percent = ($errors * 100) / $total;
1033 if ($errors > 0 && $percent < 1.0) {
1034 printf (" <1%%)\n");
1036 printf ("%3d%%)\n", $percent);
1039 printf (" Number of skipped tests : %4d (", $skipped);
1040 $percent = ($skipped * 100) / $total;
1041 if ($skipped > 0 && $percent < 1.0) {
1042 printf (" <1%%)\n");
1044 printf ("%3d%%)\n", $percent);