tst-tzset: raise timeout to 5 seconds
[glibc.git] / conform / conformtest.pl
bloba8a27f5d2a3af3a35b8eb80f462a34ced0b9524f
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) = $_;
278 my($index) = 0;
279 my($len) = length ($str);
281 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
282 if ($token ne "") {
283 newtoken ($token, @allow);
288 close (CONTENT);
289 unlink "$fnamebase.c";
290 $realerror = 0;
291 if ($#errors != 0) {
292 # Sort the output list so it's easier to compare results with diff.
293 foreach $f (sort keys(%errors)) {
294 if ($errors{$f} == 1) {
295 if ($realerror == 0) {
296 printf ("FAIL\n " . "-" x 72 . "\n");
297 $realerror = 1;
298 ++$errors;
300 printf (" Namespace violation: \"%s\"\n", $f);
303 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
306 if ($realerror == 0) {
307 printf ("OK\n");
312 while ($#headers >= 0) {
313 my($h) = pop (@headers);
314 my($hf) = $h;
315 $hf =~ s|/|-|;
316 my($fnamebase) = "$tmpdir/$hf-test";
317 my($missing) = 1;
318 my(@allow) = ();
319 my(@allowheader) = ();
320 my(%seenheader) = ();
321 my($prepend) = $mustprepend{$h};
322 my($test_exist) = 1;
324 printf ("Testing <$h>\n");
325 printf ("----------" . "-" x length ($h) . "\n");
327 open (CONTROL, "$CC -E -D$standard -std=c99 -x c data/$h-data |");
328 control: while (<CONTROL>) {
329 chop;
330 next control if (/^#/);
331 next control if (/^[ ]*$/);
333 if ($test_exist) {
334 $test_exist = 0;
335 # Generate a program to test for the availability of this header.
336 open (TESTFILE, ">$fnamebase.c");
337 print TESTFILE "$prepend";
338 print TESTFILE "#include <$h>\n";
339 close (TESTFILE);
341 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
342 "Header <$h> not available", 0, 0, 0);
343 printf ("\n");
344 last control if ($missing);
347 my($xfail) = 0;
348 if (/^xfail-/) {
349 s/^xfail-//;
350 $xfail = 1;
352 my($optional) = 0;
353 if (/^optional-/) {
354 s/^optional-//;
355 $optional = 1;
357 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
358 my($struct) = "$2$3";
359 my($type) = "$5$6";
360 my($member) = "$7";
361 my($rest) = "$8";
362 my($res) = $missing;
364 # Remember that this name is allowed.
365 push @allow, $member;
367 # Generate a program to test for the availability of this member.
368 open (TESTFILE, ">$fnamebase.c");
369 print TESTFILE "$prepend";
370 print TESTFILE "#include <$h>\n";
371 print TESTFILE "$struct a;\n";
372 print TESTFILE "$struct b;\n";
373 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
374 print TESTFILE "void foobarbaz (void) {\n";
375 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
376 print TESTFILE "}\n";
377 close (TESTFILE);
379 $res = compiletest ($fnamebase, "Testing for member $member",
380 ($optional
381 ? "NOT AVAILABLE."
382 : "Member \"$member\" not available."), $res,
383 $optional, $xfail);
385 if ($res == 0 || $missing != 0 || !$optional) {
386 # Test the types of the members.
387 open (TESTFILE, ">$fnamebase.c");
388 print TESTFILE "$prepend";
389 print TESTFILE "#include <$h>\n";
390 print TESTFILE "$struct a;\n";
391 print TESTFILE "extern $type b$rest;\n";
392 print TESTFILE "extern __typeof__ (a.$member) b;\n";
393 close (TESTFILE);
395 compiletest ($fnamebase, "Testing for type of member $member",
396 "Member \"$member\" does not have the correct type.",
397 $res, 0, $xfail);
399 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_\\'-]*))?/) {
400 my($symbol_type) = $1;
401 my($symbol) = $2;
402 my($type) = $3;
403 my($op) = $4;
404 my($value) = $5;
405 my($res) = $missing;
406 my($mres) = $missing;
407 my($cres) = $missing;
409 # Remember that this name is allowed.
410 push @allow, $symbol;
412 if ($symbol_type =~ /macro/) {
413 # Generate a program to test for availability of this macro.
414 open (TESTFILE, ">$fnamebase.c");
415 print TESTFILE "$prepend";
416 print TESTFILE "#include <$h>\n";
417 print TESTFILE "#ifndef $symbol\n";
418 print TESTFILE "# error \"Macro $symbol not defined\"\n";
419 print TESTFILE "#endif\n";
420 close (TESTFILE);
422 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
423 ($optional
424 ? "NOT PRESENT"
425 : "Macro \"$symbol\" is not available."), $res,
426 $optional, $xfail);
429 if ($symbol_type =~ /constant/) {
430 # Generate a program to test for the availability of this constant.
431 open (TESTFILE, ">$fnamebase.c");
432 print TESTFILE "$prepend";
433 print TESTFILE "#include <$h>\n";
434 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
435 close (TESTFILE);
437 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
438 ($optional
439 ? "NOT PRESENT"
440 : "Constant \"$symbol\" not available."), $res,
441 $optional, $xfail);
444 $res = $res || $mres || $cres;
446 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
447 # Test that the symbol is usable in #if.
448 open (TESTFILE, ">$fnamebase.c");
449 print TESTFILE "$prepend";
450 print TESTFILE "#include <$h>\n";
451 print TESTFILE "#if $symbol < 0\n";
452 print TESTFILE "# define conformtest_negative 1\n";
453 my($s) = "0";
454 for (my $i = 0; $i < 63; $i++) {
455 print TESTFILE "# if $symbol & (1LL << $i)\n";
456 print TESTFILE "# define conformtest_bit_$i 0LL\n";
457 print TESTFILE "# else\n";
458 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
459 print TESTFILE "# endif\n";
460 $s .= "|conformtest_bit_$i";
462 print TESTFILE "# define conformtest_value ~($s)\n";
463 print TESTFILE "#else\n";
464 print TESTFILE "# define conformtest_negative 0\n";
465 $s = "0";
466 for (my $i = 0; $i < 64; $i++) {
467 print TESTFILE "# if $symbol & (1ULL << $i)\n";
468 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
469 print TESTFILE "# else\n";
470 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
471 print TESTFILE "# endif\n";
472 $s .= "|conformtest_bit_$i";
474 print TESTFILE "# define conformtest_value ($s)\n";
475 print TESTFILE "#endif\n";
476 print TESTFILE "int main (void) { return !((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value)); }\n";
477 close (TESTFILE);
479 runtest ($fnamebase, "Testing for #if usability of symbol $symbol",
480 "Symbol \"$symbol\" not usable in #if.", $res, $xfail);
483 if (defined ($type) && ($res == 0 || !$optional)) {
484 # Test the type of the symbol.
485 open (TESTFILE, ">$fnamebase.c");
486 print TESTFILE "$prepend";
487 print TESTFILE "#include <$h>\n";
488 if ($type =~ /^promoted:/) {
489 $type =~ s/^promoted://;
490 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
491 } else {
492 print TESTFILE "__typeof__ (($type) 0) a;\n";
494 print TESTFILE "extern __typeof__ ($symbol) a;\n";
495 close (TESTFILE);
497 compiletest ($fnamebase, "Testing for type of symbol $symbol",
498 "Symbol \"$symbol\" does not have the correct type.",
499 $res, 0, $xfail);
502 if (defined ($op) && ($res == 0 || !$optional)) {
503 # Generate a program to test for the value of this symbol.
504 open (TESTFILE, ">$fnamebase.c");
505 print TESTFILE "$prepend";
506 print TESTFILE "#include <$h>\n";
507 # Negate the value since 0 means ok
508 print TESTFILE "int main (void) { return !($symbol $op $value); }\n";
509 close (TESTFILE);
511 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
512 "Symbol \"$symbol\" has not the right value.", $res,
513 $xfail);
515 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
516 my($symbol) = $1;
517 my($value) = $2;
518 my($res) = $missing;
520 # Remember that this name is allowed.
521 push @allow, $symbol;
523 # Generate a program to test for the availability of this constant.
524 open (TESTFILE, ">$fnamebase.c");
525 print TESTFILE "$prepend";
526 print TESTFILE "#include <$h>\n";
527 print TESTFILE "void foobarbaz (void) {\n";
528 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
529 print TESTFILE "}\n";
530 close (TESTFILE);
532 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
533 "Symbol \"$symbol\" not available.", $res, 0, $xfail);
535 if ($value ne "") {
536 # Generate a program to test for the value of this constant.
537 open (TESTFILE, ">$fnamebase.c");
538 print TESTFILE "$prepend";
539 print TESTFILE "#include <$h>\n";
540 print TESTFILE "int main (void) { return $symbol != $value; }\n";
541 close (TESTFILE);
543 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
544 "Symbol \"$symbol\" has not the right value.", $res,
545 $xfail);
547 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
548 my($type) = "$2$3";
549 my($maybe_opaque) = 0;
551 # Remember that this name is allowed.
552 if ($type =~ /^struct *(.*)/) {
553 push @allow, $1;
554 } elsif ($type =~ /^union *(.*)/) {
555 push @allow, $1;
556 } else {
557 push @allow, $type;
558 $maybe_opaque = 1;
561 # Generate a program to test for the availability of this type.
562 open (TESTFILE, ">$fnamebase.c");
563 print TESTFILE "$prepend";
564 print TESTFILE "#include <$h>\n";
565 if ($maybe_opaque == 1) {
566 print TESTFILE "$type *a;\n";
567 } else {
568 print TESTFILE "$type a;\n";
570 close (TESTFILE);
572 compiletest ($fnamebase, "Testing for type $type",
573 ($optional
574 ? "NOT AVAILABLE"
575 : "Type \"$type\" not available."), $missing, $optional,
576 $xfail);
577 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
578 my($type) = "$2$3";
580 # Remember that this name is allowed.
581 if ($type =~ /^struct *(.*)/) {
582 push @allow, $1;
583 } elsif ($type =~ /^union *(.*)/) {
584 push @allow, $1;
585 } else {
586 push @allow, $type;
589 # Generate a program to test for the availability of this type.
590 open (TESTFILE, ">$fnamebase.c");
591 print TESTFILE "$prepend";
592 print TESTFILE "#include <$h>\n";
593 print TESTFILE "$type;\n";
594 close (TESTFILE);
596 compiletest ($fnamebase, "Testing for type $type",
597 "Type \"$type\" not available.", $missing, 0, $xfail);
598 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
599 my($rettype) = "$2$3";
600 my($fname) = "$4";
601 my($args) = "$5";
602 my($res) = $missing;
604 # Remember that this name is allowed.
605 push @allow, $fname;
607 # Generate a program to test for availability of this function.
608 open (TESTFILE, ">$fnamebase.c");
609 print TESTFILE "$prepend";
610 print TESTFILE "#include <$h>\n";
611 # print TESTFILE "#undef $fname\n";
612 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
613 close (TESTFILE);
615 $res = compiletest ($fnamebase, "Test availability of function $fname",
616 ($optional
617 ? "NOT AVAILABLE"
618 : "Function \"$fname\" is not available."), $res,
619 $optional, $xfail);
621 if ($res == 0 || $missing == 1 || !$optional) {
622 # Generate a program to test for the type of this function.
623 open (TESTFILE, ">$fnamebase.c");
624 print TESTFILE "$prepend";
625 print TESTFILE "#include <$h>\n";
626 # print TESTFILE "#undef $fname\n";
627 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
628 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
629 close (TESTFILE);
631 compiletest ($fnamebase, "Test for type of function $fname",
632 "Function \"$fname\" has incorrect type.", $res, 0,
633 $xfail);
635 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
636 my($rettype) = "$2$3";
637 my($fname) = "$4";
638 my($args) = "$5";
639 my($res) = $missing;
641 # Remember that this name is allowed.
642 push @allow, $fname;
644 # Generate a program to test for availability of this function.
645 open (TESTFILE, ">$fnamebase.c");
646 print TESTFILE "$prepend";
647 print TESTFILE "#include <$h>\n";
648 # print TESTFILE "#undef $fname\n";
649 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
650 close (TESTFILE);
652 $res = compiletest ($fnamebase, "Test availability of function $fname",
653 ($optional
654 ? "NOT AVAILABLE"
655 : "Function \"$fname\" is not available."), $res,
656 $optional, $xfail);
658 if ($res == 0 || $missing != 0 || !$optional) {
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";
666 close (TESTFILE);
668 compiletest ($fnamebase, "Test for type of function $fname",
669 "Function \"$fname\" has incorrect type.", $res, 0,
670 $xfail);
672 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
673 my($type) = "$2$3";
674 my($vname) = "$4";
675 my($rest) = "$5";
676 my($res) = $missing;
678 # Remember that this name is allowed.
679 push @allow, $vname;
681 # Generate a program to test for availability of this function.
682 open (TESTFILE, ">$fnamebase.c");
683 print TESTFILE "$prepend";
684 print TESTFILE "#include <$h>\n";
685 # print TESTFILE "#undef $fname\n";
686 print TESTFILE "typedef $type xyzzy$rest;\n";
687 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
688 close (TESTFILE);
690 $res = compiletest ($fnamebase, "Test availability of variable $vname",
691 "Variable \"$vname\" is not available.", $res, 0,
692 $xfail);
694 # Generate a program to test for the type of this function.
695 open (TESTFILE, ">$fnamebase.c");
696 print TESTFILE "$prepend";
697 print TESTFILE "#include <$h>\n";
698 # print TESTFILE "#undef $fname\n";
699 print TESTFILE "extern $type $vname$rest;\n";
700 close (TESTFILE);
702 compiletest ($fnamebase, "Test for type of variable $fname",
703 "Variable \"$vname\" has incorrect type.", $res, 0, $xfail);
704 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
705 my($rettype) = "$2$3";
706 my($fname) = "$4";
707 my($args) = "$5";
708 my($res) = $missing;
710 # Remember that this name is allowed.
711 push @allow, $fname;
713 # Generate a program to test for availability of this function.
714 open (TESTFILE, ">$fnamebase.c");
715 print TESTFILE "$prepend";
716 print TESTFILE "#include <$h>\n";
717 print TESTFILE "#ifndef $fname\n";
718 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
719 print TESTFILE "#endif\n";
720 close (TESTFILE);
722 $res = compiletest ($fnamebase, "Test availability of macro $fname",
723 "Function \"$fname\" is not available.", $res, 0,
724 $xfail);
726 # Generate a program to test for the type of this function.
727 open (TESTFILE, ">$fnamebase.c");
728 print TESTFILE "$prepend";
729 print TESTFILE "#include <$h>\n";
730 print TESTFILE "#ifndef $fname\n";
731 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
732 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
733 print TESTFILE "#endif\n";
734 close (TESTFILE);
736 compiletest ($fnamebase, "Test for type of macro $fname",
737 "Function \"$fname\" has incorrect type.", $res, 0, $xfail);
738 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
739 # The above regex doesn't handle a \" in a string.
740 my($macro) = "$1";
741 my($string) = "$2";
742 my($res) = $missing;
744 # Remember that this name is allowed.
745 push @allow, $macro;
747 # Generate a program to test for availability of this macro.
748 open (TESTFILE, ">$fnamebase.c");
749 print TESTFILE "$prepend";
750 print TESTFILE "#include <$h>\n";
751 print TESTFILE "#ifndef $macro\n";
752 print TESTFILE "# error \"Macro $macro not defined\"\n";
753 print TESTFILE "#endif\n";
754 close (TESTFILE);
756 compiletest ($fnamebase, "Test availability of macro $macro",
757 "Macro \"$macro\" is not available.", $missing, 0, $xfail);
759 # Generate a program to test for the value of this macro.
760 open (TESTFILE, ">$fnamebase.c");
761 print TESTFILE "$prepend";
762 print TESTFILE "#include <$h>\n";
763 # We can't include <string.h> here.
764 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
765 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
766 close (TESTFILE);
768 $res = runtest ($fnamebase, "Testing for value of macro $macro",
769 "Macro \"$macro\" has not the right value.", $res,
770 $xfail);
771 } elsif (/^allow-header *(.*)/) {
772 my($pattern) = $1;
773 if ($seenheader{$pattern} != 1) {
774 push @allowheader, $pattern;
775 $seenheader{$pattern} = 1;
777 next control;
778 } elsif (/^allow *(.*)/) {
779 my($pattern) = $1;
780 push @allow, $pattern;
781 next control;
782 } else {
783 # printf ("line is `%s'\n", $_);
784 next control;
787 printf ("\n");
789 close (CONTROL);
791 # Read the data files for the header files which are allowed to be included.
792 while ($#allowheader >= 0) {
793 my($ah) = pop @allowheader;
795 open (ALLOW, "$CC -E -D$standard -x c data/$ah-data |");
796 acontrol: while (<ALLOW>) {
797 chop;
798 next acontrol if (/^#/);
799 next acontrol if (/^[ ]*$/);
801 s/^xfail-//;
802 s/^optional-//;
803 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
804 push @allow, $7;
805 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
806 push @allow, $2;
807 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
808 my($type) = "$3$4";
810 # Remember that this name is allowed.
811 if ($type =~ /^struct *(.*)/) {
812 push @allow, $1;
813 } elsif ($type =~ /^union *(.*)/) {
814 push @allow, $1;
815 } else {
816 push @allow, $type;
818 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
819 push @allow, $4;
820 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
821 push @allow, $4;
822 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
823 push @allow, $4;
824 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
825 push @allow, $4;
826 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
827 push @allow, $1;
828 } elsif (/^allow-header *(.*)/) {
829 if ($seenheader{$1} != 1) {
830 push @allowheader, $1;
831 $seenheader{$1} = 1;
833 } elsif (/^allow *(.*)/) {
834 push @allow, $1;
837 close (ALLOW);
840 if ($test_exist) {
841 printf (" Not defined\n");
842 } else {
843 # Now check the namespace.
844 printf (" Checking the namespace of \"%s\"... ", $h);
845 if ($missing) {
846 ++$skipped;
847 printf ("SKIP\n");
848 } else {
849 checknamespace ($h, $fnamebase, @allow);
853 printf ("\n\n");
856 printf "-" x 76 . "\n";
857 printf (" Total number of tests : %4d\n", $total);
859 printf (" Number of failed tests : %4d (", $errors);
860 $percent = ($errors * 100) / $total;
861 if ($errors > 0 && $percent < 1.0) {
862 printf (" <1%%)\n");
863 } else {
864 printf ("%3d%%)\n", $percent);
867 printf (" Number of xfailed tests : %4d (", $xerrors);
868 $percent = ($xerrors * 100) / $total;
869 if ($xerrors > 0 && $percent < 1.0) {
870 printf (" <1%%)\n");
871 } else {
872 printf ("%3d%%)\n", $percent);
875 printf (" Number of skipped tests : %4d (", $skipped);
876 $percent = ($skipped * 100) / $total;
877 if ($skipped > 0 && $percent < 1.0) {
878 printf (" <1%%)\n");
879 } else {
880 printf ("%3d%%)\n", $percent);
883 exit $errors != 0;
884 # Local Variables:
885 # perl-indent-level: 2
886 # End: