sparc: refactor sparc64 __mpn_sub_n selector to C
[glibc.git] / conform / conformtest.pl
blobcb500f0e761821723af6e4b93f33acecea5d59fe
1 #!/usr/bin/perl
3 use GlibcConform;
4 use Getopt::Long;
5 use POSIX;
7 $standard = "XOPEN2K8";
8 $CC = "gcc";
9 $tmpdir = "/tmp";
10 $cross = "";
11 $xfail_str = "";
12 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
13 'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir,
14 'cross' => \$cross, 'xfail=s' => \$xfail_str);
15 @headers = split(/,/,join(',',@headers));
17 # List of the headers we are testing.
18 if (@headers == ()) {
19 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
20 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "uchar.h",
21 "time.h", "tgmath.h", "termios.h", "tar.h", "sys/wait.h",
22 "sys/utsname.h", "sys/un.h", "sys/uio.h", "sys/types.h",
23 "sys/times.h", "sys/timeb.h", "sys/time.h", "sys/statvfs.h",
24 "sys/stat.h", "sys/socket.h", "sys/shm.h", "sys/sem.h",
25 "sys/select.h", "sys/resource.h", "sys/msg.h", "sys/mman.h",
26 "sys/ipc.h", "syslog.h", "stropts.h", "strings.h", "string.h",
27 "stdnoreturn.h", "stdlib.h", "stdio.h", "stdint.h", "stddef.h",
28 "stdbool.h", "stdarg.h", "stdalign.h", "spawn.h", "signal.h",
29 "setjmp.h", "semaphore.h", "search.h", "sched.h", "regex.h",
30 "pwd.h", "pthread.h", "poll.h", "nl_types.h", "netinet/tcp.h",
31 "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h", "mqueue.h",
32 "monetary.h", "math.h", "locale.h", "libgen.h", "limits.h",
33 "langinfo.h", "iso646.h", "inttypes.h", "iconv.h", "grp.h",
34 "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h", "fenv.h",
35 "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
36 "complex.h", "assert.h", "arpa/inet.h", "aio.h");
39 $CFLAGS_namespace = "$flags -fno-builtin $CFLAGS{$standard} -D_ISOMAC";
40 $CFLAGS = "$CFLAGS_namespace '-D__attribute__(x)='";
42 # Check standard name for validity.
43 die "unknown standard \"$standard\"" if ($CFLAGS{$standard} eq "");
45 # if ($standard ne "XOPEN2K8" && $standard ne "POSIX2008") {
46 # # Some headers need a bit more attention. At least with XPG7
47 # # all headers should be self-contained.
48 # $mustprepend{'inttypes.h'} = "#include <stddef.h>\n";
49 # $mustprepend{'glob.h'} = "#include <sys/types.h>\n";
50 # $mustprepend{'grp.h'} = "#include <sys/types.h>\n";
51 # $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
52 # $mustprepend{'pwd.h'} = "#include <sys/types.h>\n";
53 # $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
54 # $mustprepend{'signal.h'} = "#include <pthread.h>\n#include <sys/types.h>\n";
55 # $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
56 # $mustprepend{'sys/stat.h'} = "#include <sys/types.h>\n";
57 # $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
58 # $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
59 # }
61 # These are the ISO C90 keywords.
62 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
63 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
64 'if', 'int', 'long', 'register', 'return',
65 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
66 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
67 if ($CFLAGS{$standard} =~ /-std=(c99|c1x)/) {
68 push (@keywords, 'inline', 'restrict');
71 # Make a hash table from this information.
72 while ($#keywords >= 0) {
73 $iskeyword{pop (@keywords)} = 1;
76 $verbose = 1;
78 $total = 0;
79 $skipped = 0;
80 $errors = 0;
81 $xerrors = 0;
83 sub note_error {
84 my($xfail) = @_;
85 if ($xfail) {
86 $xerrors++;
87 printf ("Ignoring this failure.\n");
88 } else {
89 $errors++;
94 sub poorfnmatch {
95 my($pattern, $string) = @_;
96 my($strlen) = length ($string);
97 my($res);
99 if (substr ($pattern, 0, 1) eq '*') {
100 my($patlen) = length ($pattern) - 1;
101 $res = ($strlen >= $patlen
102 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
103 } elsif (substr ($pattern, -1, 1) eq '*') {
104 if (substr ($pattern, -2, 1) eq ']') {
105 my($patlen) = index ($pattern, '[');
106 my($range) = substr ($pattern, $patlen + 1, -2);
107 $res = ($strlen > $patlen
108 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)
109 && index ($range, substr ($string, $patlen, 1)) != -1);
110 } else {
111 my($patlen) = length ($pattern) - 1;
112 $res = ($strlen >= $patlen
113 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
115 } else {
116 $res = $pattern eq $string;
118 return $res;
122 sub compiletest
124 my($fnamebase, $msg, $errmsg, $skip, $optional, $xfail) = @_;
125 my($result) = $skip;
126 my($printlog) = 0;
128 ++$total;
129 printf (" $msg...");
131 if ($skip != 0) {
132 ++$skipped;
133 printf (" SKIP\n");
134 } else {
135 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
136 if ($ret != 0) {
137 if ($optional != 0) {
138 printf (" $errmsg\n");
139 $result = 1;
140 } else {
141 printf (" FAIL\n");
142 if ($verbose != 0) {
143 printf (" $errmsg Compiler message:\n");
144 $printlog = 1;
146 note_error($xfail);
147 $result = 1;
149 } else {
150 printf (" OK\n");
151 if ($verbose > 1 && -s "$fnamebase.out") {
152 # We print all warnings issued.
153 $printlog = 1;
156 if ($printlog != 0) {
157 printf (" " . "-" x 71 . "\n");
158 open (MESSAGE, "< $fnamebase.out");
159 while (<MESSAGE>) {
160 printf (" %s", $_);
162 close (MESSAGE);
163 printf (" " . "-" x 71 . "\n");
166 unlink "$fnamebase.c";
167 unlink "$fnamebase.o";
168 unlink "$fnamebase.out";
170 $result;
174 sub runtest
176 my($fnamebase, $msg, $errmsg, $skip, $xfail) = @_;
177 my($result) = $skip;
178 my($printlog) = 0;
180 ++$total;
181 printf (" $msg...");
183 if ($skip != 0) {
184 ++$skipped;
185 printf (" SKIP\n");
186 } else {
187 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
188 if ($ret != 0) {
189 printf (" FAIL\n");
190 if ($verbose != 0) {
191 printf (" $errmsg Compiler message:\n");
192 $printlog = 1;
194 note_error($xfail);
195 $result = 1;
196 } elsif ($cross) {
197 printf (" SKIP\n");
198 } else {
199 # Now run the program. If the exit code is not zero something is wrong.
200 $result = system "$fnamebase > $fnamebase.out2 2>&1";
201 if ($result == 0) {
202 printf (" OK\n");
203 if ($verbose > 1 && -s "$fnamebase.out") {
204 # We print all warnings issued.
205 $printlog = 1;
206 system "cat $fnamebase.out2 >> $fnamebase.out";
208 } else {
209 printf (" FAIL\n");
210 note_error($xfail);
211 $printlog = 1;
212 unlink "$fnamebase.out";
213 rename "$fnamebase.out2", "$fnamebase.out";
216 if ($printlog != 0) {
217 printf (" " . "-" x 71 . "\n");
218 open (MESSAGE, "< $fnamebase.out");
219 while (<MESSAGE>) {
220 printf (" %s", $_);
222 close (MESSAGE);
223 printf (" " . "-" x 71 . "\n");
226 unlink "$fnamebase";
227 unlink "$fnamebase.c";
228 unlink "$fnamebase.o";
229 unlink "$fnamebase.out";
230 unlink "$fnamebase.out2";
232 $result;
236 sub newtoken {
237 my($token, @allow) = @_;
238 my($idx);
240 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
242 for ($idx = 0; $idx <= $#allow; ++$idx) {
243 return if (poorfnmatch ($allow[$idx], $token));
246 $errors{$token} = 1;
250 sub removetoken {
251 my($token) = @_;
252 my($idx);
254 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
256 if (exists $errors{$token}) {
257 undef $errors{$token};
262 sub checknamespace {
263 my($h, $fnamebase, @allow) = @_;
265 ++$total;
267 # Generate a program to get the contents of this header.
268 open (TESTFILE, ">$fnamebase.c");
269 print TESTFILE "#include <$h>\n";
270 close (TESTFILE);
272 undef %errors;
273 open (CONTENT, "$CC $CFLAGS_namespace -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
274 loop: while (<CONTENT>) {
275 chop;
276 if (/^#define (.*)/) {
277 newtoken ($1, @allow);
278 } elsif (/^#undef (.*)/) {
279 removetoken ($1);
280 } else {
281 # We have to tokenize the line.
282 my($str) = $_;
284 $str =~ s/"[^"]*"//g;
285 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
286 if ($token ne "") {
287 newtoken ($token, @allow);
292 close (CONTENT);
293 unlink "$fnamebase.c";
294 $realerror = 0;
295 if ($#errors != 0) {
296 # Sort the output list so it's easier to compare results with diff.
297 foreach $f (sort keys(%errors)) {
298 if ($errors{$f} == 1) {
299 if ($realerror == 0) {
300 printf ("FAIL\n " . "-" x 72 . "\n");
301 $realerror = 1;
302 ++$errors;
304 printf (" Namespace violation: \"%s\"\n", $f);
307 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
310 if ($realerror == 0) {
311 printf ("OK\n");
316 while ($#headers >= 0) {
317 my($h) = pop (@headers);
318 my($hf) = $h;
319 $hf =~ s|/|-|;
320 my($fnamebase) = "$tmpdir/$hf-test";
321 my($missing) = 1;
322 my(@allow) = ();
323 my(@allowheader) = ();
324 my(%seenheader) = ();
325 my($prepend) = $mustprepend{$h};
326 my($test_exist) = 1;
328 printf ("Testing <$h>\n");
329 printf ("----------" . "-" x length ($h) . "\n");
331 open (CONTROL, "$CC -E -D$standard -std=c99 -x c data/$h-data |");
332 control: while (<CONTROL>) {
333 chop;
334 next control if (/^#/);
335 next control if (/^[ ]*$/);
337 if ($test_exist) {
338 $test_exist = 0;
339 # Generate a program to test for the availability of this header.
340 open (TESTFILE, ">$fnamebase.c");
341 print TESTFILE "$prepend";
342 print TESTFILE "#include <$h>\n";
343 close (TESTFILE);
345 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
346 "Header <$h> not available", 0, 0, 0);
347 printf ("\n");
348 last control if ($missing);
351 my($xfail) = 0;
352 if (/^xfail-/) {
353 s/^xfail-//;
354 $xfail = 1;
355 } elsif (/^xfail\[([^\]]*)\]-/) {
356 my($xfail_cond) = $1;
357 s/^xfail\[([^\]]*)\]-//;
358 # "xfail[cond]-" or "xfail[cond1|cond2|...]-" means a failure of
359 # the test is allowed if any of the listed conditions are in the
360 # --xfail command-line option argument.
361 if ($xfail_str =~ /\b($xfail_cond)\b/) {
362 $xfail = 1;
365 my($optional) = 0;
366 if (/^optional-/) {
367 s/^optional-//;
368 $optional = 1;
370 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
371 my($struct) = "$2$3";
372 my($type) = "$5$6";
373 my($member) = "$7";
374 my($rest) = "$8";
375 my($res) = $missing;
377 # Remember that this name is allowed.
378 push @allow, $member;
380 # Generate a program to test for the availability of this member.
381 open (TESTFILE, ">$fnamebase.c");
382 print TESTFILE "$prepend";
383 print TESTFILE "#include <$h>\n";
384 print TESTFILE "$struct a;\n";
385 print TESTFILE "$struct b;\n";
386 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
387 print TESTFILE "void foobarbaz (void) {\n";
388 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
389 print TESTFILE "}\n";
390 close (TESTFILE);
392 $res = compiletest ($fnamebase, "Testing for member $member",
393 ($optional
394 ? "NOT AVAILABLE."
395 : "Member \"$member\" not available."), $res,
396 $optional, $xfail);
398 if ($res == 0 || $missing != 0 || !$optional) {
399 # Test the types of the members.
400 open (TESTFILE, ">$fnamebase.c");
401 print TESTFILE "$prepend";
402 print TESTFILE "#include <$h>\n";
403 print TESTFILE "$struct a;\n";
404 print TESTFILE "extern $type b$rest;\n";
405 print TESTFILE "extern __typeof__ (a.$member) b;\n";
406 close (TESTFILE);
408 compiletest ($fnamebase, "Testing for type of member $member",
409 "Member \"$member\" does not have the correct type.",
410 $res, 0, $xfail);
412 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_\\'-]*))?/) {
413 my($symbol_type) = $1;
414 my($symbol) = $2;
415 my($type) = $3;
416 my($op) = $4;
417 my($value) = $5;
418 my($res) = $missing;
419 my($mres) = $missing;
420 my($cres) = $missing;
422 # Remember that this name is allowed.
423 push @allow, $symbol;
425 if ($symbol_type =~ /macro/) {
426 # Generate a program to test for availability of this macro.
427 open (TESTFILE, ">$fnamebase.c");
428 print TESTFILE "$prepend";
429 print TESTFILE "#include <$h>\n";
430 print TESTFILE "#ifndef $symbol\n";
431 print TESTFILE "# error \"Macro $symbol not defined\"\n";
432 print TESTFILE "#endif\n";
433 close (TESTFILE);
435 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
436 ($optional
437 ? "NOT PRESENT"
438 : "Macro \"$symbol\" is not available."), $res,
439 $optional, $xfail);
442 if ($symbol_type =~ /constant/) {
443 # Generate a program to test for the availability of this constant.
444 open (TESTFILE, ">$fnamebase.c");
445 print TESTFILE "$prepend";
446 print TESTFILE "#include <$h>\n";
447 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
448 close (TESTFILE);
450 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
451 ($optional
452 ? "NOT PRESENT"
453 : "Constant \"$symbol\" not available."), $res,
454 $optional, $xfail);
457 $res = $res || $mres || $cres;
459 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
460 # Test that the symbol is usable in #if.
461 open (TESTFILE, ">$fnamebase.c");
462 print TESTFILE "$prepend";
463 print TESTFILE "#include <$h>\n";
464 print TESTFILE "#if $symbol < 0\n";
465 print TESTFILE "# define conformtest_negative 1\n";
466 my($s) = "0";
467 for (my $i = 0; $i < 63; $i++) {
468 print TESTFILE "# if $symbol & (1LL << $i)\n";
469 print TESTFILE "# define conformtest_bit_$i 0LL\n";
470 print TESTFILE "# else\n";
471 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
472 print TESTFILE "# endif\n";
473 $s .= "|conformtest_bit_$i";
475 print TESTFILE "# define conformtest_value ~($s)\n";
476 print TESTFILE "#else\n";
477 print TESTFILE "# define conformtest_negative 0\n";
478 $s = "0";
479 for (my $i = 0; $i < 64; $i++) {
480 print TESTFILE "# if $symbol & (1ULL << $i)\n";
481 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
482 print TESTFILE "# else\n";
483 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
484 print TESTFILE "# endif\n";
485 $s .= "|conformtest_bit_$i";
487 print TESTFILE "# define conformtest_value ($s)\n";
488 print TESTFILE "#endif\n";
489 print TESTFILE "_Static_assert ((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value), \"value match inside and outside #if\");\n";
490 close (TESTFILE);
492 compiletest ($fnamebase, "Testing for #if usability of symbol $symbol",
493 "Symbol \"$symbol\" not usable in #if.", $res, 0, $xfail);
496 if (defined ($type) && ($res == 0 || !$optional)) {
497 # Test the type of the symbol.
498 open (TESTFILE, ">$fnamebase.c");
499 print TESTFILE "$prepend";
500 print TESTFILE "#include <$h>\n";
501 if ($type =~ /^promoted:/) {
502 $type =~ s/^promoted://;
503 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
504 } else {
505 print TESTFILE "__typeof__ (($type) 0) a;\n";
507 print TESTFILE "extern __typeof__ ($symbol) a;\n";
508 close (TESTFILE);
510 compiletest ($fnamebase, "Testing for type of symbol $symbol",
511 "Symbol \"$symbol\" does not have the correct type.",
512 $res, 0, $xfail);
515 if (defined ($op) && ($res == 0 || !$optional)) {
516 # Generate a program to test for the value of this symbol.
517 open (TESTFILE, ">$fnamebase.c");
518 print TESTFILE "$prepend";
519 print TESTFILE "#include <$h>\n";
520 print TESTFILE "_Static_assert ($symbol $op $value, \"value constraint\");\n";
521 close (TESTFILE);
523 $res = compiletest ($fnamebase, "Testing for value of symbol $symbol",
524 "Symbol \"$symbol\" has not the right value.",
525 $res, 0, $xfail);
527 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
528 my($symbol) = $1;
529 my($value) = $2;
530 my($res) = $missing;
532 # Remember that this name is allowed.
533 push @allow, $symbol;
535 # Generate a program to test for the availability of this constant.
536 open (TESTFILE, ">$fnamebase.c");
537 print TESTFILE "$prepend";
538 print TESTFILE "#include <$h>\n";
539 print TESTFILE "void foobarbaz (void) {\n";
540 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
541 print TESTFILE "}\n";
542 close (TESTFILE);
544 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
545 "Symbol \"$symbol\" not available.", $res, 0, $xfail);
547 if ($value ne "") {
548 # Generate a program to test for the value of this constant.
549 open (TESTFILE, ">$fnamebase.c");
550 print TESTFILE "$prepend";
551 print TESTFILE "#include <$h>\n";
552 print TESTFILE "int main (void) { return $symbol != $value; }\n";
553 close (TESTFILE);
555 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
556 "Symbol \"$symbol\" has not the right value.", $res,
557 $xfail);
559 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
560 my($type) = "$2$3";
561 my($maybe_opaque) = 0;
563 # Remember that this name is allowed.
564 if ($type =~ /^struct *(.*)/) {
565 push @allow, $1;
566 } elsif ($type =~ /^union *(.*)/) {
567 push @allow, $1;
568 } else {
569 push @allow, $type;
570 $maybe_opaque = 1;
573 # Generate a program to test for the availability of this type.
574 open (TESTFILE, ">$fnamebase.c");
575 print TESTFILE "$prepend";
576 print TESTFILE "#include <$h>\n";
577 if ($maybe_opaque == 1) {
578 print TESTFILE "$type *a;\n";
579 } else {
580 print TESTFILE "$type a;\n";
582 close (TESTFILE);
584 compiletest ($fnamebase, "Testing for type $type",
585 ($optional
586 ? "NOT AVAILABLE"
587 : "Type \"$type\" not available."), $missing, $optional,
588 $xfail);
589 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
590 my($type) = "$2$3";
592 # Remember that this name is allowed.
593 if ($type =~ /^struct *(.*)/) {
594 push @allow, $1;
595 } elsif ($type =~ /^union *(.*)/) {
596 push @allow, $1;
597 } else {
598 push @allow, $type;
601 # Generate a program to test for the availability of this type.
602 open (TESTFILE, ">$fnamebase.c");
603 print TESTFILE "$prepend";
604 print TESTFILE "#include <$h>\n";
605 print TESTFILE "$type;\n";
606 close (TESTFILE);
608 compiletest ($fnamebase, "Testing for type $type",
609 "Type \"$type\" not available.", $missing, 0, $xfail);
610 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
611 my($rettype) = "$2$3";
612 my($fname) = "$4";
613 my($args) = "$5";
614 my($res) = $missing;
616 # Remember that this name is allowed.
617 push @allow, $fname;
619 # Generate a program to test for availability of this function.
620 open (TESTFILE, ">$fnamebase.c");
621 print TESTFILE "$prepend";
622 print TESTFILE "#include <$h>\n";
623 # print TESTFILE "#undef $fname\n";
624 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
625 close (TESTFILE);
627 $res = compiletest ($fnamebase, "Test availability of function $fname",
628 ($optional
629 ? "NOT AVAILABLE"
630 : "Function \"$fname\" is not available."), $res,
631 $optional, $xfail);
633 if ($res == 0 || $missing == 1 || !$optional) {
634 # Generate a program to test for the type of this function.
635 open (TESTFILE, ">$fnamebase.c");
636 print TESTFILE "$prepend";
637 print TESTFILE "#include <$h>\n";
638 # print TESTFILE "#undef $fname\n";
639 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
640 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
641 close (TESTFILE);
643 compiletest ($fnamebase, "Test for type of function $fname",
644 "Function \"$fname\" has incorrect type.", $res, 0,
645 $xfail);
647 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
648 my($rettype) = "$2$3";
649 my($fname) = "$4";
650 my($args) = "$5";
651 my($res) = $missing;
653 # Remember that this name is allowed.
654 push @allow, $fname;
656 # Generate a program to test for availability of this function.
657 open (TESTFILE, ">$fnamebase.c");
658 print TESTFILE "$prepend";
659 print TESTFILE "#include <$h>\n";
660 # print TESTFILE "#undef $fname\n";
661 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
662 close (TESTFILE);
664 $res = compiletest ($fnamebase, "Test availability of function $fname",
665 ($optional
666 ? "NOT AVAILABLE"
667 : "Function \"$fname\" is not available."), $res,
668 $optional, $xfail);
670 if ($res == 0 || $missing != 0 || !$optional) {
671 # Generate a program to test for the type of this function.
672 open (TESTFILE, ">$fnamebase.c");
673 print TESTFILE "$prepend";
674 print TESTFILE "#include <$h>\n";
675 # print TESTFILE "#undef $fname\n";
676 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
677 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
678 close (TESTFILE);
680 compiletest ($fnamebase, "Test for type of function $fname",
681 "Function \"$fname\" has incorrect type.", $res, 0,
682 $xfail);
684 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
685 my($type) = "$2$3";
686 my($vname) = "$4";
687 my($rest) = "$5";
688 my($res) = $missing;
690 # Remember that this name is allowed.
691 push @allow, $vname;
693 # Generate a program to test for availability of this function.
694 open (TESTFILE, ">$fnamebase.c");
695 print TESTFILE "$prepend";
696 print TESTFILE "#include <$h>\n";
697 # print TESTFILE "#undef $fname\n";
698 print TESTFILE "typedef $type xyzzy$rest;\n";
699 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
700 close (TESTFILE);
702 $res = compiletest ($fnamebase, "Test availability of variable $vname",
703 "Variable \"$vname\" is not available.", $res, 0,
704 $xfail);
706 # Generate a program to test for the type of this function.
707 open (TESTFILE, ">$fnamebase.c");
708 print TESTFILE "$prepend";
709 print TESTFILE "#include <$h>\n";
710 # print TESTFILE "#undef $fname\n";
711 print TESTFILE "extern $type $vname$rest;\n";
712 close (TESTFILE);
714 compiletest ($fnamebase, "Test for type of variable $fname",
715 "Variable \"$vname\" has incorrect type.", $res, 0, $xfail);
716 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
717 my($rettype) = "$2$3";
718 my($fname) = "$4";
719 my($args) = "$5";
720 my($res) = $missing;
722 # Remember that this name is allowed.
723 push @allow, $fname;
725 # Generate a program to test for availability of this function.
726 open (TESTFILE, ">$fnamebase.c");
727 print TESTFILE "$prepend";
728 print TESTFILE "#include <$h>\n";
729 print TESTFILE "#ifndef $fname\n";
730 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
731 print TESTFILE "#endif\n";
732 close (TESTFILE);
734 $res = compiletest ($fnamebase, "Test availability of macro $fname",
735 "Function \"$fname\" is not available.", $res, 0,
736 $xfail);
738 # Generate a program to test for the type 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 "extern $rettype (*foobarbaz) $args;\n";
744 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
745 print TESTFILE "#endif\n";
746 close (TESTFILE);
748 compiletest ($fnamebase, "Test for type of macro $fname",
749 "Function \"$fname\" has incorrect type.", $res, 0, $xfail);
750 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
751 # The above regex doesn't handle a \" in a string.
752 my($macro) = "$1";
753 my($string) = "$2";
754 my($res) = $missing;
756 # Remember that this name is allowed.
757 push @allow, $macro;
759 # Generate a program to test for availability of this macro.
760 open (TESTFILE, ">$fnamebase.c");
761 print TESTFILE "$prepend";
762 print TESTFILE "#include <$h>\n";
763 print TESTFILE "#ifndef $macro\n";
764 print TESTFILE "# error \"Macro $macro not defined\"\n";
765 print TESTFILE "#endif\n";
766 close (TESTFILE);
768 compiletest ($fnamebase, "Test availability of macro $macro",
769 "Macro \"$macro\" is not available.", $missing, 0, $xfail);
771 # Generate a program to test for the value of this macro.
772 open (TESTFILE, ">$fnamebase.c");
773 print TESTFILE "$prepend";
774 print TESTFILE "#include <$h>\n";
775 # We can't include <string.h> here.
776 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
777 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
778 close (TESTFILE);
780 $res = runtest ($fnamebase, "Testing for value of macro $macro",
781 "Macro \"$macro\" has not the right value.", $res,
782 $xfail);
783 } elsif (/^allow-header *(.*)/) {
784 my($pattern) = $1;
785 if ($seenheader{$pattern} != 1) {
786 push @allowheader, $pattern;
787 $seenheader{$pattern} = 1;
789 next control;
790 } elsif (/^allow *(.*)/) {
791 my($pattern) = $1;
792 push @allow, $pattern;
793 next control;
794 } else {
795 # printf ("line is `%s'\n", $_);
796 next control;
799 printf ("\n");
801 close (CONTROL);
803 # Read the data files for the header files which are allowed to be included.
804 while ($#allowheader >= 0) {
805 my($ah) = pop @allowheader;
807 open (ALLOW, "$CC -E -D$standard -x c data/$ah-data |");
808 acontrol: while (<ALLOW>) {
809 chop;
810 next acontrol if (/^#/);
811 next acontrol if (/^[ ]*$/);
813 s/^xfail(\[([^\]]*)\])?-//;
814 s/^optional-//;
815 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
816 push @allow, $7;
817 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
818 push @allow, $2;
819 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
820 my($type) = "$3$4";
822 # Remember that this name is allowed.
823 if ($type =~ /^struct *(.*)/) {
824 push @allow, $1;
825 } elsif ($type =~ /^union *(.*)/) {
826 push @allow, $1;
827 } else {
828 push @allow, $type;
830 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
831 push @allow, $4;
832 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
833 push @allow, $4;
834 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
835 push @allow, $4;
836 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
837 push @allow, $4;
838 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
839 push @allow, $1;
840 } elsif (/^allow-header *(.*)/) {
841 if ($seenheader{$1} != 1) {
842 push @allowheader, $1;
843 $seenheader{$1} = 1;
845 } elsif (/^allow *(.*)/) {
846 push @allow, $1;
849 close (ALLOW);
852 if ($test_exist) {
853 printf (" Not defined\n");
854 } else {
855 # Now check the namespace.
856 printf (" Checking the namespace of \"%s\"... ", $h);
857 if ($missing) {
858 ++$skipped;
859 printf ("SKIP\n");
860 } else {
861 checknamespace ($h, $fnamebase, @allow);
865 printf ("\n\n");
868 printf "-" x 76 . "\n";
869 printf (" Total number of tests : %4d\n", $total);
871 printf (" Number of failed tests : %4d (", $errors);
872 $percent = ($errors * 100) / $total;
873 if ($errors > 0 && $percent < 1.0) {
874 printf (" <1%%)\n");
875 } else {
876 printf ("%3d%%)\n", $percent);
879 printf (" Number of xfailed tests : %4d (", $xerrors);
880 $percent = ($xerrors * 100) / $total;
881 if ($xerrors > 0 && $percent < 1.0) {
882 printf (" <1%%)\n");
883 } else {
884 printf ("%3d%%)\n", $percent);
887 printf (" Number of skipped tests : %4d (", $skipped);
888 $percent = ($skipped * 100) / $total;
889 if ($skipped > 0 && $percent < 1.0) {
890 printf (" <1%%)\n");
891 } else {
892 printf ("%3d%%)\n", $percent);
895 exit $errors != 0;
896 # Local Variables:
897 # perl-indent-level: 2
898 # End: