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/resource.h", "sys/msg.h",
19 "sys/mman.h", "sys/ipc.h", "syslog.h", "stropts.h", "strings.h",
20 "string.h", "stdlib.h", "stdio.h", "stdint.h", "stddef.h",
21 "stdarg.h", "spawn.h", "signal.h", "setjmp.h", "semaphore.h",
22 "search.h", "sched.h", "regex.h", "pwd.h", "pthread.h",
23 "poll.h", "nl_types.h", "netinet/tcp.h", "netinet/in.h",
24 "net/if.h", "netdb.h", "ndbm.h", "mqueue.h", "monetary.h",
25 "math.h", "locale.h", "libgen.h", "limits.h", "langinfo.h",
26 "iso646.h", "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h",
27 "fnmatch.h", "fmtmsg.h", "float.h", "fcntl.h", "errno.h",
28 "dlfcn.h", "dirent.h", "ctype.h", "cpio.h", "assert.h",
29 "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_]*))/) {
594 # Remember that this name is allowed.
595 if ($type =~ /^struct *(.*)/) {
597 } elsif ($type =~ /^union *(.*)/) {
603 # Remember that this name is allowed.
606 # Generate a program to test for the availability of this constant.
607 open (TESTFILE, ">$fnamebase.c");
608 print TESTFILE "$prepend";
609 print TESTFILE "#include <$h>\n";
610 print TESTFILE "$type *a;\n";
613 compiletest ($fnamebase, "Testing for type $type",
614 "Type \"$type\" not available.", $missing, 1);
615 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
618 # Remember that this name is allowed.
619 if ($type =~ /^struct *(.*)/) {
621 } elsif ($type =~ /^union *(.*)/) {
627 # Remember that this name is allowed.
630 # Generate a program to test for the availability of this constant.
631 open (TESTFILE, ">$fnamebase.c");
632 print TESTFILE "$prepend";
633 print TESTFILE "#include <$h>\n";
634 print TESTFILE "$type *a;\n";
637 compiletest ($fnamebase, "Testing for type $type",
638 "Type \"$type\" not available.", $missing, 0);
639 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
640 my($rettype) = "$2$3";
645 # Remember that this name is allowed.
648 # Generate a program to test for availability of this function.
649 open (TESTFILE, ">$fnamebase.c");
650 print TESTFILE "$prepend";
651 print TESTFILE "#include <$h>\n";
652 # print TESTFILE "#undef $fname\n";
653 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
656 $res = compiletest ($fnamebase, "Test availability of function $fname",
657 "Function \"$fname\" is not available.", $res, 0);
659 # Generate a program to test for the type of this function.
660 open (TESTFILE, ">$fnamebase.c");
661 print TESTFILE "$prepend";
662 print TESTFILE "#include <$h>\n";
663 # print TESTFILE "#undef $fname\n";
664 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
665 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
668 compiletest ($fnamebase, "Test for type of function $fname",
669 "Function \"$fname\" has incorrect type.", $res, 0);
670 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
671 my($rettype) = "$2$3";
676 # Remember that this name is allowed.
679 # Generate a program to test for availability of this function.
680 open (TESTFILE, ">$fnamebase.c");
681 print TESTFILE "$prepend";
682 print TESTFILE "#include <$h>\n";
683 # print TESTFILE "#undef $fname\n";
684 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
687 $res = compiletest ($fnamebase, "Test availability of function $fname",
688 "Function \"$fname\" is not available.", $res, 0);
690 # Generate a program to test for the type of this function.
691 open (TESTFILE, ">$fnamebase.c");
692 print TESTFILE "$prepend";
693 print TESTFILE "#include <$h>\n";
694 # print TESTFILE "#undef $fname\n";
695 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
696 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
699 compiletest ($fnamebase, "Test for type of function $fname",
700 "Function \"$fname\" has incorrect type.", $res, 0);
701 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
706 # Remember that this name is allowed.
709 # Generate a program to test for availability of this function.
710 open (TESTFILE, ">$fnamebase.c");
711 print TESTFILE "$prepend";
712 print TESTFILE "#include <$h>\n";
713 # print TESTFILE "#undef $fname\n";
714 print TESTFILE "$type *foobarbaz = &$vname;\n";
717 $res = compiletest ($fnamebase, "Test availability of variable $vname",
718 "Variable \"$vname\" is not available.", $res, 0);
720 # Generate a program to test for the type of this function.
721 open (TESTFILE, ">$fnamebase.c");
722 print TESTFILE "$prepend";
723 print TESTFILE "#include <$h>\n";
724 # print TESTFILE "#undef $fname\n";
725 print TESTFILE "extern $type $vname;\n";
728 compiletest ($fnamebase, "Test for type of variable $fname",
729 "Variable \"$vname\" has incorrect type.", $res, 0);
730 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
731 my($rettype) = "$2$3";
736 # Remember that this name is allowed.
739 # Generate a program to test for availability of this function.
740 open (TESTFILE, ">$fnamebase.c");
741 print TESTFILE "$prepend";
742 print TESTFILE "#include <$h>\n";
743 print TESTFILE "#ifndef $fname\n";
744 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
745 print TESTFILE "#endif\n";
748 $res = compiletest ($fnamebase, "Test availability of function $fname",
749 "Function \"$fname\" is not available.", $res, 0);
751 # Generate a program to test for the type of this function.
752 open (TESTFILE, ">$fnamebase.c");
753 print TESTFILE "$prepend";
754 print TESTFILE "#include <$h>\n";
755 print TESTFILE "#ifndef $fname\n";
756 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
757 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
758 print TESTFILE "#endif\n";
761 compiletest ($fnamebase, "Test for type of function $fname",
762 "Function \"$fname\" has incorrect type.", $res, 0);
763 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
764 # The above regex doesn't handle a \" in a string.
769 # Remember that this name is allowed.
772 # Generate a program to test for availability of this macro.
773 open (TESTFILE, ">$fnamebase.c");
774 print TESTFILE "$prepend";
775 print TESTFILE "#include <$h>\n";
776 print TESTFILE "#ifndef $macro\n";
777 print TESTFILE "# error \"Macro $macro not defined\"\n";
778 print TESTFILE "#endif\n";
781 compiletest ($fnamebase, "Test availability of macro $macro",
782 "Macro \"$macro\" is not available.", $missing, 0);
784 # Generate a program to test for the value of this macro.
785 open (TESTFILE, ">$fnamebase.c");
786 print TESTFILE "$prepend";
787 print TESTFILE "#include <$h>\n";
788 # We can't include <string.h> here.
789 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
790 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
793 $res = runtest ($fnamebase, "Testing for value of macro $macro",
794 "Macro \"$macro\" has not the right value.", $res);
795 } elsif (/^optional-macro *([^ ]*)/) {
798 # Remember that this name is allowed.
801 # Generate a program to test for availability of this macro.
802 open (TESTFILE, ">$fnamebase.c");
803 print TESTFILE "$prepend";
804 print TESTFILE "#include <$h>\n";
805 print TESTFILE "#ifndef $macro\n";
806 print TESTFILE "# error \"Macro $macro not defined\"\n";
807 print TESTFILE "#endif\n";
810 compiletest ($fnamebase, "Test availability of macro $macro",
811 "NOT PRESENT", $missing, 1);
812 } elsif (/^macro *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
818 # Remember that this name is allowed.
821 # Generate a program to test for availability of this macro.
822 open (TESTFILE, ">$fnamebase.c");
823 print TESTFILE "$prepend";
824 print TESTFILE "#include <$h>\n";
825 print TESTFILE "#ifndef $macro\n";
826 print TESTFILE "# error \"Macro $macro not defined\"\n";
827 print TESTFILE "#endif\n";
830 $res = compiletest ($fnamebase, "Test availability of macro $macro",
831 "Macro \"$macro\" is not available.", $res, 0);
834 # Generate a program to test for the value of this constant.
835 open (TESTFILE, ">$fnamebase.c");
836 print TESTFILE "$prepend";
837 print TESTFILE "#include <$h>\n";
838 # Negate the value since 0 means ok
839 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
842 $res = runtest ($fnamebase, "Testing for value of constant $macro",
843 "Macro \"$macro\" has not the right value.", $res);
845 } elsif (/^macro *([^ ]*)/) {
848 # Remember that this name is allowed.
851 # Generate a program to test for availability of this macro.
852 open (TESTFILE, ">$fnamebase.c");
853 print TESTFILE "$prepend";
854 print TESTFILE "#include <$h>\n";
855 print TESTFILE "#ifndef $macro\n";
856 print TESTFILE "# error \"Macro $macro not defined\"\n";
857 print TESTFILE "#endif\n";
860 compiletest ($fnamebase, "Test availability of macro $macro",
861 "Macro \"$macro\" is not available.", $missing, 0);
862 } elsif (/^allow-header *(.*)/) {
864 if ($seenheader{$pattern} != 1) {
865 push @allowheader, $pattern;
866 $seenheader{$pattern} = 1;
869 } elsif (/^allow *(.*)/) {
871 push @allow, $pattern;
874 # printf ("line is `%s'\n", $_);
882 # Read the data files for the header files which are allowed to be included.
883 while ($#allowheader >= 0) {
884 my($ah) = pop @allowheader;
886 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
887 acontrol: while (<ALLOW>) {
888 next acontrol if (/^#/);
889 next acontrol if (/^[ ]*$/);
891 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
893 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
895 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
897 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
900 # Remember that this name is allowed.
901 if ($type =~ /^struct *(.*)/) {
903 } elsif ($type =~ /^union *(.*)/) {
908 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
910 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
912 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
914 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
916 } elsif (/^macro *([^ ]*)/) {
918 } elsif (/^allow-header *(.*)/) {
919 if ($seenheader{$1} != 1) {
920 push @allowheader, $1;
923 } elsif (/^allow *(.*)/) {
930 # Now check the namespace.
931 printf (" Checking the namespace of \"%s\"... ", $h);
936 checknamespace ($h, $fnamebase, @allow);
942 printf "-" x 76 . "\n";
943 printf (" Total number of tests : %4d\n", $total);
945 printf (" Number of known failures: %4d (", $known);
946 $percent = ($known * 100) / $total;
947 if ($known > 0 && $percent < 1.0) {
950 printf ("%3d%%)\n", $percent);
953 printf (" Number of failed tests : %4d (", $errors);
954 $percent = ($errors * 100) / $total;
955 if ($errors > 0 && $percent < 1.0) {
958 printf ("%3d%%)\n", $percent);
961 printf (" Number of skipped tests : %4d (", $skipped);
962 $percent = ($skipped * 100) / $total;
963 if ($skipped > 0 && $percent < 1.0) {
966 printf ("%3d%%)\n", $percent);