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{'wordexp.h'} = "#include <stddef.h>\n";
60 # Make a hash table from this information.
61 while ($#keywords >= 0) {
62 $iskeyword{pop (@keywords)} = 1;
65 # Make a hash table from the known problems.
66 while ($#knownproblems >= 0) {
67 $isknown{pop (@knownproblems)} = 1;
80 my($pattern, $string) = @_;
81 my($strlen) = length ($string);
84 if (substr ($pattern, 0, 1) eq '*') {
85 my($patlen) = length ($pattern) - 1;
86 $res = ($strlen >= $patlen
87 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
88 } elsif (substr ($pattern, -1, 1) eq '*') {
89 my($patlen) = length ($pattern) - 1;
90 $res = ($strlen >= $patlen
91 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
93 $res = $pattern eq $string;
101 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
112 $ret = system "$CC $CFLAGS{$dialect} -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
114 if ($optional != 0) {
115 printf (" $errmsg\n");
120 printf (" $errmsg Compiler message:\n");
128 if ($verbose > 1 && -s "$fnamebase.out") {
129 # We print all warnings issued.
133 if ($printlog != 0) {
134 printf (" " . "-" x 71 . "\n");
135 open (MESSAGE, "< $fnamebase.out");
140 printf (" " . "-" x 71 . "\n");
143 unlink "$fnamebase.c";
144 unlink "$fnamebase.o";
145 unlink "$fnamebase.out";
153 my($fnamebase, $msg, $errmsg, $skip) = @_;
164 $ret = system "$CC $CFLAGS{$dialect} -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
168 printf (" $errmsg Compiler message:\n");
174 # Now run the program. If the exit code is not zero something is wrong.
175 $result = system "$fnamebase > $fnamebase.out2 2>&1";
178 if ($verbose > 1 && -s "$fnamebase.out") {
179 # We print all warnings issued.
181 system "cat $fnamebase.out2 >> $fnamebase.out";
187 unlink "$fnamebase.out";
188 rename "$fnamebase.out2", "$fnamebase.out";
191 if ($printlog != 0) {
192 printf (" " . "-" x 71 . "\n");
193 open (MESSAGE, "< $fnamebase.out");
198 printf (" " . "-" x 71 . "\n");
202 unlink "$fnamebase.c";
203 unlink "$fnamebase.o";
204 unlink "$fnamebase.out";
205 unlink "$fnamebase.out2";
212 my($token, @allow) = @_;
215 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
217 for ($idx = 0; $idx <= $#allow; ++$idx) {
218 return if (poorfnmatch ($allow[$idx], $token));
221 if ($isknown{$token}) {
226 printf ("FAIL\n " . "-" x 72 . "\n");
228 printf (" Namespace violation: \"%s\"\n", $token);
234 my($h, $fnamebase, @allow) = @_;
238 # Generate a program to get the contents of this header.
239 open (TESTFILE, ">$fnamebase.c");
240 print TESTFILE "#include <$h>\n";
245 open (CONTENT, "$CC $CFLAGS{$dialect} -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
246 loop: while (<CONTENT>) {
247 next loop if (/^#undef /);
249 if (/^#define (.*)/) {
250 newtoken ($1, @allow);
252 # We have to tokenize the line.
255 my($len) = length ($str);
257 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
259 newtoken ($token, @allow);
265 unlink "$fnamebase.c";
267 printf (" " . "-" x 72 . "\n");
269 } elsif ($nknown > 0) {
270 printf ("EXPECTED FAILURES\n");
278 while ($#headers >= 0) {
279 my($h) = pop (@headers);
282 my($fnamebase) = "$tmpdir/$hf-test";
285 my(@allowheader) = ();
286 my(%seenheader) = ();
287 my($prepend) = $mustprepend{$h};
289 printf ("Testing <$h>\n");
290 printf ("----------" . "-" x length ($h) . "\n");
292 # Generate a program to test for the availability of this header.
293 open (TESTFILE, ">$fnamebase.c");
294 print TESTFILE "$prepend";
295 print TESTFILE "#include <$h>\n";
298 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
299 "Header <$h> not available", 0, 0);
303 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
304 control: while (<CONTROL>) {
306 next control if (/^#/);
307 next control if (/^[ ]*$/);
309 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
310 my($struct) = "$2$3";
316 # Remember that this name is allowed.
317 push @allow, $member;
319 # Generate a program to test for the availability of this member.
320 open (TESTFILE, ">$fnamebase.c");
321 print TESTFILE "$prepend";
322 print TESTFILE "#include <$h>\n";
323 print TESTFILE "$struct a;\n";
324 print TESTFILE "$struct b;\n";
325 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
326 print TESTFILE "void foobarbaz (void) {\n";
327 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
328 print TESTFILE "}\n";
331 $res = compiletest ($fnamebase, "Testing for member $member",
332 "Member \"$member\" not available.", $res, 0);
335 # Test the types of the members.
336 open (TESTFILE, ">$fnamebase.c");
337 print TESTFILE "$prepend";
338 print TESTFILE "#include <$h>\n";
339 print TESTFILE "$struct a;\n";
340 print TESTFILE "extern $type b$rest;\n";
341 print TESTFILE "extern __typeof__ (a.$member) b;\n";
344 compiletest ($fnamebase, "Testing for type of member $member",
345 "Member \"$member\" does not have the correct type.",
347 } elsif (/^optional-element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
348 my($struct) = "$2$3";
354 # Remember that this name is allowed.
355 push @allow, $member;
357 # Generate a program to test for the availability of this member.
358 open (TESTFILE, ">$fnamebase.c");
359 print TESTFILE "$prepend";
360 print TESTFILE "#include <$h>\n";
361 print TESTFILE "$struct a;\n";
362 print TESTFILE "$struct b;\n";
363 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
364 print TESTFILE "void foobarbaz (void) {\n";
365 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
366 print TESTFILE "}\n";
369 $res = compiletest ($fnamebase, "Testing for member $member",
370 "NOT AVAILABLE.", $res, 1);
372 if ($res == 0 || $missing != 0) {
373 # Test the types of the members.
374 open (TESTFILE, ">$fnamebase.c");
375 print TESTFILE "$prepend";
376 print TESTFILE "#include <$h>\n";
377 print TESTFILE "$struct a;\n";
378 print TESTFILE "extern $type b$rest;\n";
379 print TESTFILE "extern __typeof__ (a.$member) b;\n";
382 compiletest ($fnamebase, "Testing for type of member $member",
383 "Member \"$member\" does not have the correct type.",
386 } elsif (/^optional-constant *([a-zA-Z0-9_]*) ([>=<]+) ([A-Za-z0-9_]*)/) {
392 # Remember that this name is allowed.
395 # Generate a program to test for the availability of this constant.
396 open (TESTFILE, ">$fnamebase.c");
397 print TESTFILE "$prepend";
398 print TESTFILE "#include <$h>\n";
399 print TESTFILE "__typeof__ ($const) a = $const;\n";
402 $res = compiletest ($fnamebase, "Testing for constant $const",
403 "NOT PRESENT", $res, 1);
405 if ($value ne "" && $res == 0) {
406 # Generate a program to test for the value of this constant.
407 open (TESTFILE, ">$fnamebase.c");
408 print TESTFILE "$prepend";
409 print TESTFILE "#include <$h>\n";
410 # Negate the value since 0 means ok
411 print TESTFILE "int main (void) { return !($const $op $value); }\n";
414 $res = runtest ($fnamebase, "Testing for value of constant $const",
415 "Constant \"$const\" has not the right value.", $res);
417 } elsif (/^constant *([a-zA-Z0-9_]*) *([>=<]+) ([A-Za-z0-9_]*)/) {
423 # Remember that this name is allowed.
426 # Generate a program to test for the availability of this constant.
427 open (TESTFILE, ">$fnamebase.c");
428 print TESTFILE "$prepend";
429 print TESTFILE "#include <$h>\n";
430 print TESTFILE "__typeof__ ($const) a = $const;\n";
433 $res = compiletest ($fnamebase, "Testing for constant $const",
434 "Constant \"$const\" not available.", $res, 0);
437 # Generate a program to test for the value of this constant.
438 open (TESTFILE, ">$fnamebase.c");
439 print TESTFILE "$prepend";
440 print TESTFILE "#include <$h>\n";
441 # Negate the value since 0 means ok
442 print TESTFILE "int main (void) { return !($const $op $value); }\n";
445 $res = runtest ($fnamebase, "Testing for value of constant $const",
446 "Constant \"$const\" has not the right value.", $res);
448 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
454 # Remember that this name is allowed.
457 # Generate a program to test for the availability of this constant.
458 open (TESTFILE, ">$fnamebase.c");
459 print TESTFILE "$prepend";
460 print TESTFILE "#include <$h>\n";
461 print TESTFILE "__typeof__ ($const) a = $const;\n";
464 $res = compiletest ($fnamebase, "Testing for constant $const",
465 "Constant \"$const\" not available.", $res, 0);
467 # Test the types of the members.
468 open (TESTFILE, ">$fnamebase.c");
469 print TESTFILE "$prepend";
470 print TESTFILE "#include <$h>\n";
471 print TESTFILE "__typeof__ (($type) 0) a;\n";
472 print TESTFILE "extern __typeof__ ($const) a;\n";
475 compiletest ($fnamebase, "Testing for type of constant $const",
476 "Constant \"$const\" does not have the correct type.",
480 # Generate a program to test for the value of this constant.
481 open (TESTFILE, ">$fnamebase.c");
482 print TESTFILE "$prepend";
483 print TESTFILE "#include <$h>\n";
484 print TESTFILE "int main (void) { return $const != $value; }\n";
487 $res = runtest ($fnamebase, "Testing for value of constant $const",
488 "Constant \"$const\" has not the right value.", $res);
490 } elsif (/^optional-constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
495 # Remember that this name is allowed.
498 # Generate a program to test for the availability of this constant.
499 open (TESTFILE, ">$fnamebase.c");
500 print TESTFILE "$prepend";
501 print TESTFILE "#include <$h>\n";
502 print TESTFILE "__typeof__ ($const) a = $const;\n";
505 $res = compiletest ($fnamebase, "Testing for constant $const",
506 "NOT PRESENT", $res, 1);
508 if ($value ne "" && $res == 0) {
509 # Generate a program to test for the value of this constant.
510 open (TESTFILE, ">$fnamebase.c");
511 print TESTFILE "$prepend";
512 print TESTFILE "#include <$h>\n";
513 print TESTFILE "int main (void) { return $const != $value; }\n";
516 $res = runtest ($fnamebase, "Testing for value of constant $const",
517 "Constant \"$const\" has not the right value.", $res);
519 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
524 # Remember that this name is allowed.
527 # Generate a program to test for the availability of this constant.
528 open (TESTFILE, ">$fnamebase.c");
529 print TESTFILE "$prepend";
530 print TESTFILE "#include <$h>\n";
531 print TESTFILE "__typeof__ ($const) a = $const;\n";
534 $res = compiletest ($fnamebase, "Testing for constant $const",
535 "Constant \"$const\" not available.", $res, 0);
538 # Generate a program to test for the value of this constant.
539 open (TESTFILE, ">$fnamebase.c");
540 print TESTFILE "$prepend";
541 print TESTFILE "#include <$h>\n";
542 print TESTFILE "int main (void) { return $const != $value; }\n";
545 $res = runtest ($fnamebase, "Testing for value of constant $const",
546 "Constant \"$const\" has not the right value.", $res);
548 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
554 # Remember that this name is allowed.
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 "__typeof__ ($const) a = $const;\n";
564 $res = compiletest ($fnamebase, "Testing for constant $const",
565 "Constant \"$const\" not available.", $res, 0);
567 # Test the types of the members.
568 open (TESTFILE, ">$fnamebase.c");
569 print TESTFILE "$prepend";
570 print TESTFILE "#include <$h>\n";
571 print TESTFILE "__typeof__ (($type) 0) a;\n";
572 print TESTFILE "extern __typeof__ ($const) a;\n";
575 compiletest ($fnamebase, "Testing for type of constant $const",
576 "Constant \"$const\" does not have the correct type.",
580 # Generate a program to test for the value of this constant.
581 open (TESTFILE, ">$fnamebase.c");
582 print TESTFILE "$prepend";
583 print TESTFILE "#include <$h>\n";
584 print TESTFILE "int main (void) { return $const != $value; }\n";
587 $res = runtest ($fnamebase, "Testing for value of constant $const",
588 "Constant \"$const\" has not the right value.", $res);
590 } elsif (/^optional-type *({([^}]*)|([a-zA-Z0-9_]*))/) {
593 # Remember that this name is allowed.
594 if ($type =~ /^struct *(.*)/) {
596 } elsif ($type =~ /^union *(.*)/) {
602 # Remember that this name is allowed.
605 # Generate a program to test for the availability of this constant.
606 open (TESTFILE, ">$fnamebase.c");
607 print TESTFILE "$prepend";
608 print TESTFILE "#include <$h>\n";
609 print TESTFILE "$type *a;\n";
612 compiletest ($fnamebase, "Testing for type $type",
613 "Type \"$type\" not available.", $missing, 1);
614 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
617 # Remember that this name is allowed.
618 if ($type =~ /^struct *(.*)/) {
620 } elsif ($type =~ /^union *(.*)/) {
626 # Remember that this name is allowed.
629 # Generate a program to test for the availability of this constant.
630 open (TESTFILE, ">$fnamebase.c");
631 print TESTFILE "$prepend";
632 print TESTFILE "#include <$h>\n";
633 print TESTFILE "$type *a;\n";
636 compiletest ($fnamebase, "Testing for type $type",
637 "Type \"$type\" not available.", $missing, 0);
638 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
639 my($rettype) = "$2$3";
644 # Remember that this name is allowed.
647 # Generate a program to test for availability of this function.
648 open (TESTFILE, ">$fnamebase.c");
649 print TESTFILE "$prepend";
650 print TESTFILE "#include <$h>\n";
651 # print TESTFILE "#undef $fname\n";
652 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
655 $res = compiletest ($fnamebase, "Test availability of function $fname",
656 "Function \"$fname\" is not available.", $res, 0);
658 # Generate a program to test for the type of this function.
659 open (TESTFILE, ">$fnamebase.c");
660 print TESTFILE "$prepend";
661 print TESTFILE "#include <$h>\n";
662 # print TESTFILE "#undef $fname\n";
663 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
664 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
667 compiletest ($fnamebase, "Test for type of function $fname",
668 "Function \"$fname\" has incorrect type.", $res, 0);
669 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
670 my($rettype) = "$2$3";
675 # Remember that this name is allowed.
678 # Generate a program to test for availability of this function.
679 open (TESTFILE, ">$fnamebase.c");
680 print TESTFILE "$prepend";
681 print TESTFILE "#include <$h>\n";
682 # print TESTFILE "#undef $fname\n";
683 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
686 $res = compiletest ($fnamebase, "Test availability of function $fname",
687 "Function \"$fname\" is not available.", $res, 0);
689 # Generate a program to test for the type of this function.
690 open (TESTFILE, ">$fnamebase.c");
691 print TESTFILE "$prepend";
692 print TESTFILE "#include <$h>\n";
693 # print TESTFILE "#undef $fname\n";
694 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
695 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
698 compiletest ($fnamebase, "Test for type of function $fname",
699 "Function \"$fname\" has incorrect type.", $res, 0);
700 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
705 # Remember that this name is allowed.
708 # Generate a program to test for availability of this function.
709 open (TESTFILE, ">$fnamebase.c");
710 print TESTFILE "$prepend";
711 print TESTFILE "#include <$h>\n";
712 # print TESTFILE "#undef $fname\n";
713 print TESTFILE "$type *foobarbaz = &$vname;\n";
716 $res = compiletest ($fnamebase, "Test availability of variable $vname",
717 "Variable \"$vname\" is not available.", $res, 0);
719 # Generate a program to test for the type of this function.
720 open (TESTFILE, ">$fnamebase.c");
721 print TESTFILE "$prepend";
722 print TESTFILE "#include <$h>\n";
723 # print TESTFILE "#undef $fname\n";
724 print TESTFILE "extern $type $vname;\n";
727 compiletest ($fnamebase, "Test for type of variable $fname",
728 "Variable \"$vname\" has incorrect type.", $res, 0);
729 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
730 my($rettype) = "$2$3";
735 # Remember that this name is allowed.
738 # Generate a program to test for availability of this function.
739 open (TESTFILE, ">$fnamebase.c");
740 print TESTFILE "$prepend";
741 print TESTFILE "#include <$h>\n";
742 print TESTFILE "#ifndef $fname\n";
743 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
744 print TESTFILE "#endif\n";
747 $res = compiletest ($fnamebase, "Test availability of function $fname",
748 "Function \"$fname\" is not available.", $res, 0);
750 # Generate a program to test for the type of this function.
751 open (TESTFILE, ">$fnamebase.c");
752 print TESTFILE "$prepend";
753 print TESTFILE "#include <$h>\n";
754 print TESTFILE "#ifndef $fname\n";
755 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
756 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
757 print TESTFILE "#endif\n";
760 compiletest ($fnamebase, "Test for type of function $fname",
761 "Function \"$fname\" has incorrect type.", $res, 0);
762 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
763 # The above regex doesn't handle a \" in a string.
768 # Remember that this name is allowed.
771 # Generate a program to test for availability of this macro.
772 open (TESTFILE, ">$fnamebase.c");
773 print TESTFILE "$prepend";
774 print TESTFILE "#include <$h>\n";
775 print TESTFILE "#ifndef $macro\n";
776 print TESTFILE "# error \"Macro $macro not defined\"\n";
777 print TESTFILE "#endif\n";
780 compiletest ($fnamebase, "Test availability of macro $macro",
781 "Macro \"$macro\" is not available.", $missing, 0);
783 # Generate a program to test for the value of this macro.
784 open (TESTFILE, ">$fnamebase.c");
785 print TESTFILE "$prepend";
786 print TESTFILE "#include <$h>\n";
787 # We can't include <string.h> here.
788 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
789 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
792 $res = runtest ($fnamebase, "Testing for value of macro $macro",
793 "Macro \"$macro\" has not the right value.", $res);
794 } elsif (/^optional-macro *([^ ]*)/) {
797 # Remember that this name is allowed.
800 # Generate a program to test for availability of this macro.
801 open (TESTFILE, ">$fnamebase.c");
802 print TESTFILE "$prepend";
803 print TESTFILE "#include <$h>\n";
804 print TESTFILE "#ifndef $macro\n";
805 print TESTFILE "# error \"Macro $macro not defined\"\n";
806 print TESTFILE "#endif\n";
809 compiletest ($fnamebase, "Test availability of macro $macro",
810 "NOT PRESENT", $missing, 1);
811 } elsif (/^macro *([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 macro.
821 open (TESTFILE, ">$fnamebase.c");
822 print TESTFILE "$prepend";
823 print TESTFILE "#include <$h>\n";
824 print TESTFILE "#ifndef $macro\n";
825 print TESTFILE "# error \"Macro $macro not defined\"\n";
826 print TESTFILE "#endif\n";
829 $res = compiletest ($fnamebase, "Test availability of macro $macro",
830 "Macro \"$macro\" is not available.", $res, 0);
833 # Generate a program to test for the value of this constant.
834 open (TESTFILE, ">$fnamebase.c");
835 print TESTFILE "$prepend";
836 print TESTFILE "#include <$h>\n";
837 # Negate the value since 0 means ok
838 print TESTFILE "int main (void) { return !($macro $op $value); }\n";
841 $res = runtest ($fnamebase, "Testing for value of constant $macro",
842 "Macro \"$macro\" has not the right value.", $res);
844 } elsif (/^macro *([^ ]*)/) {
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);
861 } elsif (/^allow-header *(.*)/) {
863 if ($seenheader{$pattern} != 1) {
864 push @allowheader, $pattern;
865 $seenheader{$pattern} = 1;
868 } elsif (/^allow *(.*)/) {
870 push @allow, $pattern;
873 # printf ("line is `%s'\n", $_);
881 # Read the data files for the header files which are allowed to be included.
882 while ($#allowheader >= 0) {
883 my($ah) = pop @allowheader;
885 open (ALLOW, "$CC -E -D$dialect - < data/$ah-data |");
886 acontrol: while (<ALLOW>) {
887 next acontrol if (/^#/);
888 next acontrol if (/^[ ]*$/);
890 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
892 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
894 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
896 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
899 # Remember that this name is allowed.
900 if ($type =~ /^struct *(.*)/) {
902 } elsif ($type =~ /^union *(.*)/) {
907 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
909 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
911 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
913 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
915 } elsif (/^macro *([^ ]*)/) {
917 } elsif (/^allow-header *(.*)/) {
918 if ($seenheader{$1} != 1) {
919 push @allowheader, $1;
922 } elsif (/^allow *(.*)/) {
929 # Now check the namespace.
930 printf (" Checking the namespace of \"%s\"... ", $h);
935 checknamespace ($h, $fnamebase, @allow);
941 printf "-" x 76 . "\n";
942 printf (" Total number of tests : %4d\n", $total);
944 printf (" Number of known failures: %4d (", $known);
945 $percent = ($known * 100) / $total;
946 if ($known > 0 && $percent < 1.0) {
949 printf ("%3d%%)\n", $percent);
952 printf (" Number of failed tests : %4d (", $errors);
953 $percent = ($errors * 100) / $total;
954 if ($errors > 0 && $percent < 1.0) {
957 printf ("%3d%%)\n", $percent);
960 printf (" Number of skipped tests : %4d (", $skipped);
961 $percent = ($skipped * 100) / $total;
962 if ($skipped > 0 && $percent < 1.0) {
965 printf ("%3d%%)\n", $percent);