conformtest: Make more tests into compilation tests.
[glibc.git] / conform / conformtest.pl
blob54b38f85e91021af6fb7dbfcd65e4084d30fa093
1 #!/usr/bin/perl
3 use GlibcConform;
4 use Getopt::Long;
5 use POSIX;
7 $standard = "XOPEN2K8";
8 $CC = "gcc";
9 $tmpdir = "/tmp";
10 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
11 'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir);
12 @headers = split(/,/,join(',',@headers));
14 # List of the headers we are testing.
15 if (@headers == ()) {
16 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
17 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "uchar.h",
18 "time.h", "tgmath.h", "termios.h", "tar.h", "sys/wait.h",
19 "sys/utsname.h", "sys/un.h", "sys/uio.h", "sys/types.h",
20 "sys/times.h", "sys/timeb.h", "sys/time.h", "sys/statvfs.h",
21 "sys/stat.h", "sys/socket.h", "sys/shm.h", "sys/sem.h",
22 "sys/select.h", "sys/resource.h", "sys/msg.h", "sys/mman.h",
23 "sys/ipc.h", "syslog.h", "stropts.h", "strings.h", "string.h",
24 "stdnoreturn.h", "stdlib.h", "stdio.h", "stdint.h", "stddef.h",
25 "stdbool.h", "stdarg.h", "stdalign.h", "spawn.h", "signal.h",
26 "setjmp.h", "semaphore.h", "search.h", "sched.h", "regex.h",
27 "pwd.h", "pthread.h", "poll.h", "nl_types.h", "netinet/tcp.h",
28 "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h", "mqueue.h",
29 "monetary.h", "math.h", "locale.h", "libgen.h", "limits.h",
30 "langinfo.h", "iso646.h", "inttypes.h", "iconv.h", "grp.h",
31 "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h", "fenv.h",
32 "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
33 "complex.h", "assert.h", "arpa/inet.h", "aio.h");
36 $CFLAGS_namespace = "$flags -fno-builtin $CFLAGS{$standard} -D_ISOMAC";
37 $CFLAGS = "$CFLAGS_namespace '-D__attribute__(x)='";
39 # Check standard name for validity.
40 die "unknown standard \"$standard\"" if ($CFLAGS{$standard} eq "");
42 # if ($standard ne "XOPEN2K8" && $standard ne "POSIX2008") {
43 # # Some headers need a bit more attention. At least with XPG7
44 # # all headers should be self-contained.
45 # $mustprepend{'inttypes.h'} = "#include <stddef.h>\n";
46 # $mustprepend{'glob.h'} = "#include <sys/types.h>\n";
47 # $mustprepend{'grp.h'} = "#include <sys/types.h>\n";
48 # $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
49 # $mustprepend{'pwd.h'} = "#include <sys/types.h>\n";
50 # $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
51 # $mustprepend{'signal.h'} = "#include <pthread.h>\n#include <sys/types.h>\n";
52 # $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
53 # $mustprepend{'sys/stat.h'} = "#include <sys/types.h>\n";
54 # $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
55 # $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
56 # }
58 # These are the ISO C90 keywords.
59 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
60 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
61 'if', 'int', 'long', 'register', 'return',
62 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
63 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
64 if ($CFLAGS{$standard} =~ /-std=(c99|c1x)/) {
65 push (@keywords, 'inline', 'restrict');
68 # Make a hash table from this information.
69 while ($#keywords >= 0) {
70 $iskeyword{pop (@keywords)} = 1;
73 $verbose = 1;
75 $total = 0;
76 $skipped = 0;
77 $errors = 0;
78 $xerrors = 0;
80 sub note_error {
81 my($xfail) = @_;
82 if ($xfail) {
83 $xerrors++;
84 printf ("Ignoring this failure.\n");
85 } else {
86 $errors++;
91 sub poorfnmatch {
92 my($pattern, $string) = @_;
93 my($strlen) = length ($string);
94 my($res);
96 if (substr ($pattern, 0, 1) eq '*') {
97 my($patlen) = length ($pattern) - 1;
98 $res = ($strlen >= $patlen
99 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
100 } elsif (substr ($pattern, -1, 1) eq '*') {
101 if (substr ($pattern, -2, 1) eq ']') {
102 my($patlen) = index ($pattern, '[');
103 my($range) = substr ($pattern, $patlen + 1, -2);
104 $res = ($strlen > $patlen
105 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)
106 && index ($range, substr ($string, $patlen, 1)) != -1);
107 } else {
108 my($patlen) = length ($pattern) - 1;
109 $res = ($strlen >= $patlen
110 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
112 } else {
113 $res = $pattern eq $string;
115 return $res;
119 sub compiletest
121 my($fnamebase, $msg, $errmsg, $skip, $optional, $xfail) = @_;
122 my($result) = $skip;
123 my($printlog) = 0;
125 ++$total;
126 printf (" $msg...");
128 if ($skip != 0) {
129 ++$skipped;
130 printf (" SKIP\n");
131 } else {
132 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
133 if ($ret != 0) {
134 if ($optional != 0) {
135 printf (" $errmsg\n");
136 $result = 1;
137 } else {
138 printf (" FAIL\n");
139 if ($verbose != 0) {
140 printf (" $errmsg Compiler message:\n");
141 $printlog = 1;
143 note_error($xfail);
144 $result = 1;
146 } else {
147 printf (" OK\n");
148 if ($verbose > 1 && -s "$fnamebase.out") {
149 # We print all warnings issued.
150 $printlog = 1;
153 if ($printlog != 0) {
154 printf (" " . "-" x 71 . "\n");
155 open (MESSAGE, "< $fnamebase.out");
156 while (<MESSAGE>) {
157 printf (" %s", $_);
159 close (MESSAGE);
160 printf (" " . "-" x 71 . "\n");
163 unlink "$fnamebase.c";
164 unlink "$fnamebase.o";
165 unlink "$fnamebase.out";
167 $result;
171 sub runtest
173 my($fnamebase, $msg, $errmsg, $skip, $xfail) = @_;
174 my($result) = $skip;
175 my($printlog) = 0;
177 ++$total;
178 printf (" $msg...");
180 if ($skip != 0) {
181 ++$skipped;
182 printf (" SKIP\n");
183 } else {
184 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
185 if ($ret != 0) {
186 printf (" FAIL\n");
187 if ($verbose != 0) {
188 printf (" $errmsg Compiler message:\n");
189 $printlog = 1;
191 note_error($xfail);
192 $result = 1;
193 } else {
194 # Now run the program. If the exit code is not zero something is wrong.
195 $result = system "$fnamebase > $fnamebase.out2 2>&1";
196 if ($result == 0) {
197 printf (" OK\n");
198 if ($verbose > 1 && -s "$fnamebase.out") {
199 # We print all warnings issued.
200 $printlog = 1;
201 system "cat $fnamebase.out2 >> $fnamebase.out";
203 } else {
204 printf (" FAIL\n");
205 note_error($xfail);
206 $printlog = 1;
207 unlink "$fnamebase.out";
208 rename "$fnamebase.out2", "$fnamebase.out";
211 if ($printlog != 0) {
212 printf (" " . "-" x 71 . "\n");
213 open (MESSAGE, "< $fnamebase.out");
214 while (<MESSAGE>) {
215 printf (" %s", $_);
217 close (MESSAGE);
218 printf (" " . "-" x 71 . "\n");
221 unlink "$fnamebase";
222 unlink "$fnamebase.c";
223 unlink "$fnamebase.o";
224 unlink "$fnamebase.out";
225 unlink "$fnamebase.out2";
227 $result;
231 sub newtoken {
232 my($token, @allow) = @_;
233 my($idx);
235 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
237 for ($idx = 0; $idx <= $#allow; ++$idx) {
238 return if (poorfnmatch ($allow[$idx], $token));
241 $errors{$token} = 1;
245 sub removetoken {
246 my($token) = @_;
247 my($idx);
249 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
251 if (exists $errors{$token}) {
252 undef $errors{$token};
257 sub checknamespace {
258 my($h, $fnamebase, @allow) = @_;
260 ++$total;
262 # Generate a program to get the contents of this header.
263 open (TESTFILE, ">$fnamebase.c");
264 print TESTFILE "#include <$h>\n";
265 close (TESTFILE);
267 undef %errors;
268 open (CONTENT, "$CC $CFLAGS_namespace -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
269 loop: while (<CONTENT>) {
270 chop;
271 if (/^#define (.*)/) {
272 newtoken ($1, @allow);
273 } elsif (/^#undef (.*)/) {
274 removetoken ($1);
275 } else {
276 # We have to tokenize the line.
277 my($str) = $_;
279 $str =~ s/"[^"]*"//g;
280 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
281 if ($token ne "") {
282 newtoken ($token, @allow);
287 close (CONTENT);
288 unlink "$fnamebase.c";
289 $realerror = 0;
290 if ($#errors != 0) {
291 # Sort the output list so it's easier to compare results with diff.
292 foreach $f (sort keys(%errors)) {
293 if ($errors{$f} == 1) {
294 if ($realerror == 0) {
295 printf ("FAIL\n " . "-" x 72 . "\n");
296 $realerror = 1;
297 ++$errors;
299 printf (" Namespace violation: \"%s\"\n", $f);
302 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
305 if ($realerror == 0) {
306 printf ("OK\n");
311 while ($#headers >= 0) {
312 my($h) = pop (@headers);
313 my($hf) = $h;
314 $hf =~ s|/|-|;
315 my($fnamebase) = "$tmpdir/$hf-test";
316 my($missing) = 1;
317 my(@allow) = ();
318 my(@allowheader) = ();
319 my(%seenheader) = ();
320 my($prepend) = $mustprepend{$h};
321 my($test_exist) = 1;
323 printf ("Testing <$h>\n");
324 printf ("----------" . "-" x length ($h) . "\n");
326 open (CONTROL, "$CC -E -D$standard -std=c99 -x c data/$h-data |");
327 control: while (<CONTROL>) {
328 chop;
329 next control if (/^#/);
330 next control if (/^[ ]*$/);
332 if ($test_exist) {
333 $test_exist = 0;
334 # Generate a program to test for the availability of this header.
335 open (TESTFILE, ">$fnamebase.c");
336 print TESTFILE "$prepend";
337 print TESTFILE "#include <$h>\n";
338 close (TESTFILE);
340 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
341 "Header <$h> not available", 0, 0, 0);
342 printf ("\n");
343 last control if ($missing);
346 my($xfail) = 0;
347 if (/^xfail-/) {
348 s/^xfail-//;
349 $xfail = 1;
351 my($optional) = 0;
352 if (/^optional-/) {
353 s/^optional-//;
354 $optional = 1;
356 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
357 my($struct) = "$2$3";
358 my($type) = "$5$6";
359 my($member) = "$7";
360 my($rest) = "$8";
361 my($res) = $missing;
363 # Remember that this name is allowed.
364 push @allow, $member;
366 # Generate a program to test for the availability of this member.
367 open (TESTFILE, ">$fnamebase.c");
368 print TESTFILE "$prepend";
369 print TESTFILE "#include <$h>\n";
370 print TESTFILE "$struct a;\n";
371 print TESTFILE "$struct b;\n";
372 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
373 print TESTFILE "void foobarbaz (void) {\n";
374 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
375 print TESTFILE "}\n";
376 close (TESTFILE);
378 $res = compiletest ($fnamebase, "Testing for member $member",
379 ($optional
380 ? "NOT AVAILABLE."
381 : "Member \"$member\" not available."), $res,
382 $optional, $xfail);
384 if ($res == 0 || $missing != 0 || !$optional) {
385 # Test the types of the members.
386 open (TESTFILE, ">$fnamebase.c");
387 print TESTFILE "$prepend";
388 print TESTFILE "#include <$h>\n";
389 print TESTFILE "$struct a;\n";
390 print TESTFILE "extern $type b$rest;\n";
391 print TESTFILE "extern __typeof__ (a.$member) b;\n";
392 close (TESTFILE);
394 compiletest ($fnamebase, "Testing for type of member $member",
395 "Member \"$member\" does not have the correct type.",
396 $res, 0, $xfail);
398 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_\\'-]*))?/) {
399 my($symbol_type) = $1;
400 my($symbol) = $2;
401 my($type) = $3;
402 my($op) = $4;
403 my($value) = $5;
404 my($res) = $missing;
405 my($mres) = $missing;
406 my($cres) = $missing;
408 # Remember that this name is allowed.
409 push @allow, $symbol;
411 if ($symbol_type =~ /macro/) {
412 # Generate a program to test for availability of this macro.
413 open (TESTFILE, ">$fnamebase.c");
414 print TESTFILE "$prepend";
415 print TESTFILE "#include <$h>\n";
416 print TESTFILE "#ifndef $symbol\n";
417 print TESTFILE "# error \"Macro $symbol not defined\"\n";
418 print TESTFILE "#endif\n";
419 close (TESTFILE);
421 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
422 ($optional
423 ? "NOT PRESENT"
424 : "Macro \"$symbol\" is not available."), $res,
425 $optional, $xfail);
428 if ($symbol_type =~ /constant/) {
429 # Generate a program to test for the availability of this constant.
430 open (TESTFILE, ">$fnamebase.c");
431 print TESTFILE "$prepend";
432 print TESTFILE "#include <$h>\n";
433 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
434 close (TESTFILE);
436 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
437 ($optional
438 ? "NOT PRESENT"
439 : "Constant \"$symbol\" not available."), $res,
440 $optional, $xfail);
443 $res = $res || $mres || $cres;
445 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
446 # Test that the symbol is usable in #if.
447 open (TESTFILE, ">$fnamebase.c");
448 print TESTFILE "$prepend";
449 print TESTFILE "#include <$h>\n";
450 print TESTFILE "#if $symbol < 0\n";
451 print TESTFILE "# define conformtest_negative 1\n";
452 my($s) = "0";
453 for (my $i = 0; $i < 63; $i++) {
454 print TESTFILE "# if $symbol & (1LL << $i)\n";
455 print TESTFILE "# define conformtest_bit_$i 0LL\n";
456 print TESTFILE "# else\n";
457 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
458 print TESTFILE "# endif\n";
459 $s .= "|conformtest_bit_$i";
461 print TESTFILE "# define conformtest_value ~($s)\n";
462 print TESTFILE "#else\n";
463 print TESTFILE "# define conformtest_negative 0\n";
464 $s = "0";
465 for (my $i = 0; $i < 64; $i++) {
466 print TESTFILE "# if $symbol & (1ULL << $i)\n";
467 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
468 print TESTFILE "# else\n";
469 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
470 print TESTFILE "# endif\n";
471 $s .= "|conformtest_bit_$i";
473 print TESTFILE "# define conformtest_value ($s)\n";
474 print TESTFILE "#endif\n";
475 print TESTFILE "_Static_assert ((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value), \"value match inside and outside #if\");\n";
476 close (TESTFILE);
478 compiletest ($fnamebase, "Testing for #if usability of symbol $symbol",
479 "Symbol \"$symbol\" not usable in #if.", $res, 0, $xfail);
482 if (defined ($type) && ($res == 0 || !$optional)) {
483 # Test the type of the symbol.
484 open (TESTFILE, ">$fnamebase.c");
485 print TESTFILE "$prepend";
486 print TESTFILE "#include <$h>\n";
487 if ($type =~ /^promoted:/) {
488 $type =~ s/^promoted://;
489 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
490 } else {
491 print TESTFILE "__typeof__ (($type) 0) a;\n";
493 print TESTFILE "extern __typeof__ ($symbol) a;\n";
494 close (TESTFILE);
496 compiletest ($fnamebase, "Testing for type of symbol $symbol",
497 "Symbol \"$symbol\" does not have the correct type.",
498 $res, 0, $xfail);
501 if (defined ($op) && ($res == 0 || !$optional)) {
502 # Generate a program to test for the value of this symbol.
503 open (TESTFILE, ">$fnamebase.c");
504 print TESTFILE "$prepend";
505 print TESTFILE "#include <$h>\n";
506 print TESTFILE "_Static_assert ($symbol $op $value, \"value constraint\");\n";
507 close (TESTFILE);
509 $res = compiletest ($fnamebase, "Testing for value of symbol $symbol",
510 "Symbol \"$symbol\" has not the right value.",
511 $res, 0, $xfail);
513 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
514 my($symbol) = $1;
515 my($value) = $2;
516 my($res) = $missing;
518 # Remember that this name is allowed.
519 push @allow, $symbol;
521 # Generate a program to test for the availability of this constant.
522 open (TESTFILE, ">$fnamebase.c");
523 print TESTFILE "$prepend";
524 print TESTFILE "#include <$h>\n";
525 print TESTFILE "void foobarbaz (void) {\n";
526 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
527 print TESTFILE "}\n";
528 close (TESTFILE);
530 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
531 "Symbol \"$symbol\" not available.", $res, 0, $xfail);
533 if ($value ne "") {
534 # Generate a program to test for the value of this constant.
535 open (TESTFILE, ">$fnamebase.c");
536 print TESTFILE "$prepend";
537 print TESTFILE "#include <$h>\n";
538 print TESTFILE "int main (void) { return $symbol != $value; }\n";
539 close (TESTFILE);
541 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
542 "Symbol \"$symbol\" has not the right value.", $res,
543 $xfail);
545 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
546 my($type) = "$2$3";
547 my($maybe_opaque) = 0;
549 # Remember that this name is allowed.
550 if ($type =~ /^struct *(.*)/) {
551 push @allow, $1;
552 } elsif ($type =~ /^union *(.*)/) {
553 push @allow, $1;
554 } else {
555 push @allow, $type;
556 $maybe_opaque = 1;
559 # Generate a program to test for the availability of this type.
560 open (TESTFILE, ">$fnamebase.c");
561 print TESTFILE "$prepend";
562 print TESTFILE "#include <$h>\n";
563 if ($maybe_opaque == 1) {
564 print TESTFILE "$type *a;\n";
565 } else {
566 print TESTFILE "$type a;\n";
568 close (TESTFILE);
570 compiletest ($fnamebase, "Testing for type $type",
571 ($optional
572 ? "NOT AVAILABLE"
573 : "Type \"$type\" not available."), $missing, $optional,
574 $xfail);
575 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
576 my($type) = "$2$3";
578 # Remember that this name is allowed.
579 if ($type =~ /^struct *(.*)/) {
580 push @allow, $1;
581 } elsif ($type =~ /^union *(.*)/) {
582 push @allow, $1;
583 } else {
584 push @allow, $type;
587 # Generate a program to test for the availability of this type.
588 open (TESTFILE, ">$fnamebase.c");
589 print TESTFILE "$prepend";
590 print TESTFILE "#include <$h>\n";
591 print TESTFILE "$type;\n";
592 close (TESTFILE);
594 compiletest ($fnamebase, "Testing for type $type",
595 "Type \"$type\" not available.", $missing, 0, $xfail);
596 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
597 my($rettype) = "$2$3";
598 my($fname) = "$4";
599 my($args) = "$5";
600 my($res) = $missing;
602 # Remember that this name is allowed.
603 push @allow, $fname;
605 # Generate a program to test for availability of this function.
606 open (TESTFILE, ">$fnamebase.c");
607 print TESTFILE "$prepend";
608 print TESTFILE "#include <$h>\n";
609 # print TESTFILE "#undef $fname\n";
610 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
611 close (TESTFILE);
613 $res = compiletest ($fnamebase, "Test availability of function $fname",
614 ($optional
615 ? "NOT AVAILABLE"
616 : "Function \"$fname\" is not available."), $res,
617 $optional, $xfail);
619 if ($res == 0 || $missing == 1 || !$optional) {
620 # Generate a program to test for the type of this function.
621 open (TESTFILE, ">$fnamebase.c");
622 print TESTFILE "$prepend";
623 print TESTFILE "#include <$h>\n";
624 # print TESTFILE "#undef $fname\n";
625 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
626 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
627 close (TESTFILE);
629 compiletest ($fnamebase, "Test for type of function $fname",
630 "Function \"$fname\" has incorrect type.", $res, 0,
631 $xfail);
633 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
634 my($rettype) = "$2$3";
635 my($fname) = "$4";
636 my($args) = "$5";
637 my($res) = $missing;
639 # Remember that this name is allowed.
640 push @allow, $fname;
642 # Generate a program to test for availability of this function.
643 open (TESTFILE, ">$fnamebase.c");
644 print TESTFILE "$prepend";
645 print TESTFILE "#include <$h>\n";
646 # print TESTFILE "#undef $fname\n";
647 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
648 close (TESTFILE);
650 $res = compiletest ($fnamebase, "Test availability of function $fname",
651 ($optional
652 ? "NOT AVAILABLE"
653 : "Function \"$fname\" is not available."), $res,
654 $optional, $xfail);
656 if ($res == 0 || $missing != 0 || !$optional) {
657 # Generate a program to test for the type of this function.
658 open (TESTFILE, ">$fnamebase.c");
659 print TESTFILE "$prepend";
660 print TESTFILE "#include <$h>\n";
661 # print TESTFILE "#undef $fname\n";
662 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
663 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
664 close (TESTFILE);
666 compiletest ($fnamebase, "Test for type of function $fname",
667 "Function \"$fname\" has incorrect type.", $res, 0,
668 $xfail);
670 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
671 my($type) = "$2$3";
672 my($vname) = "$4";
673 my($rest) = "$5";
674 my($res) = $missing;
676 # Remember that this name is allowed.
677 push @allow, $vname;
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 "typedef $type xyzzy$rest;\n";
685 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
686 close (TESTFILE);
688 $res = compiletest ($fnamebase, "Test availability of variable $vname",
689 "Variable \"$vname\" is not available.", $res, 0,
690 $xfail);
692 # Generate a program to test for the type of this function.
693 open (TESTFILE, ">$fnamebase.c");
694 print TESTFILE "$prepend";
695 print TESTFILE "#include <$h>\n";
696 # print TESTFILE "#undef $fname\n";
697 print TESTFILE "extern $type $vname$rest;\n";
698 close (TESTFILE);
700 compiletest ($fnamebase, "Test for type of variable $fname",
701 "Variable \"$vname\" has incorrect type.", $res, 0, $xfail);
702 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
703 my($rettype) = "$2$3";
704 my($fname) = "$4";
705 my($args) = "$5";
706 my($res) = $missing;
708 # Remember that this name is allowed.
709 push @allow, $fname;
711 # Generate a program to test for availability of this function.
712 open (TESTFILE, ">$fnamebase.c");
713 print TESTFILE "$prepend";
714 print TESTFILE "#include <$h>\n";
715 print TESTFILE "#ifndef $fname\n";
716 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
717 print TESTFILE "#endif\n";
718 close (TESTFILE);
720 $res = compiletest ($fnamebase, "Test availability of macro $fname",
721 "Function \"$fname\" is not available.", $res, 0,
722 $xfail);
724 # Generate a program to test for the type of this function.
725 open (TESTFILE, ">$fnamebase.c");
726 print TESTFILE "$prepend";
727 print TESTFILE "#include <$h>\n";
728 print TESTFILE "#ifndef $fname\n";
729 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
730 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
731 print TESTFILE "#endif\n";
732 close (TESTFILE);
734 compiletest ($fnamebase, "Test for type of macro $fname",
735 "Function \"$fname\" has incorrect type.", $res, 0, $xfail);
736 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
737 # The above regex doesn't handle a \" in a string.
738 my($macro) = "$1";
739 my($string) = "$2";
740 my($res) = $missing;
742 # Remember that this name is allowed.
743 push @allow, $macro;
745 # Generate a program to test for availability of this macro.
746 open (TESTFILE, ">$fnamebase.c");
747 print TESTFILE "$prepend";
748 print TESTFILE "#include <$h>\n";
749 print TESTFILE "#ifndef $macro\n";
750 print TESTFILE "# error \"Macro $macro not defined\"\n";
751 print TESTFILE "#endif\n";
752 close (TESTFILE);
754 compiletest ($fnamebase, "Test availability of macro $macro",
755 "Macro \"$macro\" is not available.", $missing, 0, $xfail);
757 # Generate a program to test for the value of this macro.
758 open (TESTFILE, ">$fnamebase.c");
759 print TESTFILE "$prepend";
760 print TESTFILE "#include <$h>\n";
761 # We can't include <string.h> here.
762 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
763 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
764 close (TESTFILE);
766 $res = runtest ($fnamebase, "Testing for value of macro $macro",
767 "Macro \"$macro\" has not the right value.", $res,
768 $xfail);
769 } elsif (/^allow-header *(.*)/) {
770 my($pattern) = $1;
771 if ($seenheader{$pattern} != 1) {
772 push @allowheader, $pattern;
773 $seenheader{$pattern} = 1;
775 next control;
776 } elsif (/^allow *(.*)/) {
777 my($pattern) = $1;
778 push @allow, $pattern;
779 next control;
780 } else {
781 # printf ("line is `%s'\n", $_);
782 next control;
785 printf ("\n");
787 close (CONTROL);
789 # Read the data files for the header files which are allowed to be included.
790 while ($#allowheader >= 0) {
791 my($ah) = pop @allowheader;
793 open (ALLOW, "$CC -E -D$standard -x c data/$ah-data |");
794 acontrol: while (<ALLOW>) {
795 chop;
796 next acontrol if (/^#/);
797 next acontrol if (/^[ ]*$/);
799 s/^xfail-//;
800 s/^optional-//;
801 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
802 push @allow, $7;
803 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
804 push @allow, $2;
805 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
806 my($type) = "$3$4";
808 # Remember that this name is allowed.
809 if ($type =~ /^struct *(.*)/) {
810 push @allow, $1;
811 } elsif ($type =~ /^union *(.*)/) {
812 push @allow, $1;
813 } else {
814 push @allow, $type;
816 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
817 push @allow, $4;
818 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
819 push @allow, $4;
820 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
821 push @allow, $4;
822 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
823 push @allow, $4;
824 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
825 push @allow, $1;
826 } elsif (/^allow-header *(.*)/) {
827 if ($seenheader{$1} != 1) {
828 push @allowheader, $1;
829 $seenheader{$1} = 1;
831 } elsif (/^allow *(.*)/) {
832 push @allow, $1;
835 close (ALLOW);
838 if ($test_exist) {
839 printf (" Not defined\n");
840 } else {
841 # Now check the namespace.
842 printf (" Checking the namespace of \"%s\"... ", $h);
843 if ($missing) {
844 ++$skipped;
845 printf ("SKIP\n");
846 } else {
847 checknamespace ($h, $fnamebase, @allow);
851 printf ("\n\n");
854 printf "-" x 76 . "\n";
855 printf (" Total number of tests : %4d\n", $total);
857 printf (" Number of failed tests : %4d (", $errors);
858 $percent = ($errors * 100) / $total;
859 if ($errors > 0 && $percent < 1.0) {
860 printf (" <1%%)\n");
861 } else {
862 printf ("%3d%%)\n", $percent);
865 printf (" Number of xfailed tests : %4d (", $xerrors);
866 $percent = ($xerrors * 100) / $total;
867 if ($xerrors > 0 && $percent < 1.0) {
868 printf (" <1%%)\n");
869 } else {
870 printf ("%3d%%)\n", $percent);
873 printf (" Number of skipped tests : %4d (", $skipped);
874 $percent = ($skipped * 100) / $total;
875 if ($skipped > 0 && $percent < 1.0) {
876 printf (" <1%%)\n");
877 } else {
878 printf ("%3d%%)\n", $percent);
881 exit $errors != 0;
882 # Local Variables:
883 # perl-indent-level: 2
884 # End: