Add i686 __libc_ifunc_impl_list
[glibc.git] / conform / conformtest.pl
blobd3e41be4cb3837b5741595b8eb1405bc6302d37a
1 #! /usr/bin/perl
3 use Getopt::Long;
4 use POSIX;
6 $standard = "XOPEN2K8";
7 $CC = "gcc";
8 $tmpdir = "/tmp";
9 GetOptions ('headers=s' => \@headers, 'standard=s' => \$standard,
10 'flags=s' => \$flags, 'cc=s' => \$CC, 'tmpdir=s' => \$tmpdir);
11 @headers = split(/,/,join(',',@headers));
13 # List of the headers we are testing.
14 if (@headers == ()) {
15 @headers = ("wordexp.h", "wctype.h", "wchar.h", "varargs.h", "utmpx.h",
16 "utime.h", "unistd.h", "ulimit.h", "ucontext.h", "uchar.h",
17 "time.h", "tgmath.h", "termios.h", "tar.h", "sys/wait.h",
18 "sys/utsname.h", "sys/un.h", "sys/uio.h", "sys/types.h",
19 "sys/times.h", "sys/timeb.h", "sys/time.h", "sys/statvfs.h",
20 "sys/stat.h", "sys/socket.h", "sys/shm.h", "sys/sem.h",
21 "sys/select.h", "sys/resource.h", "sys/msg.h", "sys/mman.h",
22 "sys/ipc.h", "syslog.h", "stropts.h", "strings.h", "string.h",
23 "stdlib.h", "stdio.h", "stdint.h", "stddef.h", "stdarg.h",
24 "spawn.h", "signal.h", "setjmp.h", "semaphore.h", "search.h",
25 "sched.h", "regex.h", "pwd.h", "pthread.h", "poll.h",
26 "nl_types.h", "netinet/tcp.h", "netinet/in.h", "net/if.h",
27 "netdb.h", "ndbm.h", "mqueue.h", "monetary.h", "math.h",
28 "locale.h", "libgen.h", "limits.h", "langinfo.h", "iso646.h",
29 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
30 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h",
31 "dirent.h", "ctype.h", "cpio.h", "complex.h", "assert.h",
32 "arpa/inet.h", "aio.h");
35 $CFLAGS{"ISO"} = "-ansi";
36 $CFLAGS{"ISO99"} = "-std=c99";
37 $CFLAGS{"ISO11"} = "-std=c1x -D_ISOC11_SOURCE";
38 $CFLAGS{"POSIX"} = "-D_POSIX_C_SOURCE=199912 -ansi";
39 $CFLAGS{"XPG3"} = "-ansi -D_XOPEN_SOURCE";
40 $CFLAGS{"XPG4"} = "-ansi -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED";
41 $CFLAGS{"UNIX98"} = "-ansi -D_XOPEN_SOURCE=500";
42 $CFLAGS{"XOPEN2K"} = "-std=c99 -D_XOPEN_SOURCE=600";
43 $CFLAGS{"XOPEN2K8"} = "-std=c99 -D_XOPEN_SOURCE=700";
44 $CFLAGS{"POSIX2008"} = "-std=c99 -D_POSIX_C_SOURCE=200809L";
46 $CFLAGS_namespace = "$flags -fno-builtin $CFLAGS{$standard} -D_ISOMAC";
47 $CFLAGS = "$CFLAGS_namespace '-D__attribute__(x)='";
49 # Check standard name for validity.
50 die "unknown standard \"$standard\"" if ($CFLAGS{$standard} eq "");
52 # if ($standard ne "XOPEN2K8" && $standard ne "POSIX2008") {
53 # # Some headers need a bit more attention. At least with XPG7
54 # # all headers should be self-contained.
55 # $mustprepend{'inttypes.h'} = "#include <stddef.h>\n";
56 # $mustprepend{'glob.h'} = "#include <sys/types.h>\n";
57 # $mustprepend{'grp.h'} = "#include <sys/types.h>\n";
58 # $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
59 # $mustprepend{'pwd.h'} = "#include <sys/types.h>\n";
60 # $mustprepend{'sched.h'} = "#include <sys/types.h>\n";
61 # $mustprepend{'signal.h'} = "#include <pthread.h>\n#include <sys/types.h>\n";
62 # $mustprepend{'stdio.h'} = "#include <sys/types.h>\n";
63 # $mustprepend{'sys/stat.h'} = "#include <sys/types.h>\n";
64 # $mustprepend{'wchar.h'} = "#include <stdarg.h>\n";
65 # $mustprepend{'wordexp.h'} = "#include <stddef.h>\n";
66 # }
68 # These are the ISO C90 keywords.
69 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
70 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
71 'if', 'int', 'long', 'register', 'return',
72 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
73 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
74 if ($CFLAGS{$standard} =~ /-std=(c99|c1x)/) {
75 push (@keywords, 'inline', 'restrict');
78 # Make a hash table from this information.
79 while ($#keywords >= 0) {
80 $iskeyword{pop (@keywords)} = 1;
83 $verbose = 1;
85 $total = 0;
86 $skipped = 0;
87 $errors = 0;
90 sub poorfnmatch {
91 my($pattern, $string) = @_;
92 my($strlen) = length ($string);
93 my($res);
95 if (substr ($pattern, 0, 1) eq '*') {
96 my($patlen) = length ($pattern) - 1;
97 $res = ($strlen >= $patlen
98 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
99 } elsif (substr ($pattern, -1, 1) eq '*') {
100 if (substr ($pattern, -2, 1) eq ']') {
101 my($patlen) = index ($pattern, '[');
102 my($range) = substr ($pattern, $patlen + 1, -2);
103 $res = ($strlen > $patlen
104 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen)
105 && index ($range, substr ($string, $patlen, 1)) != -1);
106 } else {
107 my($patlen) = length ($pattern) - 1;
108 $res = ($strlen >= $patlen
109 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
111 } else {
112 $res = $pattern eq $string;
114 return $res;
118 sub compiletest
120 my($fnamebase, $msg, $errmsg, $skip, $optional) = @_;
121 my($result) = $skip;
122 my($printlog) = 0;
124 ++$total;
125 printf (" $msg...");
127 if ($skip != 0) {
128 ++$skipped;
129 printf (" SKIP\n");
130 } else {
131 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
132 if ($ret != 0) {
133 if ($optional != 0) {
134 printf (" $errmsg\n");
135 $result = 1;
136 } else {
137 printf (" FAIL\n");
138 if ($verbose != 0) {
139 printf (" $errmsg Compiler message:\n");
140 $printlog = 1;
142 ++$errors;
143 $result = 1;
145 } else {
146 printf (" OK\n");
147 if ($verbose > 1 && -s "$fnamebase.out") {
148 # We print all warnings issued.
149 $printlog = 1;
152 if ($printlog != 0) {
153 printf (" " . "-" x 71 . "\n");
154 open (MESSAGE, "< $fnamebase.out");
155 while (<MESSAGE>) {
156 printf (" %s", $_);
158 close (MESSAGE);
159 printf (" " . "-" x 71 . "\n");
162 unlink "$fnamebase.c";
163 unlink "$fnamebase.o";
164 unlink "$fnamebase.out";
166 $result;
170 sub runtest
172 my($fnamebase, $msg, $errmsg, $skip) = @_;
173 my($result) = $skip;
174 my($printlog) = 0;
176 ++$total;
177 printf (" $msg...");
179 if ($skip != 0) {
180 ++$skipped;
181 printf (" SKIP\n");
182 } else {
183 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
184 if ($ret != 0) {
185 printf (" FAIL\n");
186 if ($verbose != 0) {
187 printf (" $errmsg Compiler message:\n");
188 $printlog = 1;
190 ++$errors;
191 $result = 1;
192 } else {
193 # Now run the program. If the exit code is not zero something is wrong.
194 $result = system "$fnamebase > $fnamebase.out2 2>&1";
195 if ($result == 0) {
196 printf (" OK\n");
197 if ($verbose > 1 && -s "$fnamebase.out") {
198 # We print all warnings issued.
199 $printlog = 1;
200 system "cat $fnamebase.out2 >> $fnamebase.out";
202 } else {
203 printf (" FAIL\n");
204 ++$errors;
205 $printlog = 1;
206 unlink "$fnamebase.out";
207 rename "$fnamebase.out2", "$fnamebase.out";
210 if ($printlog != 0) {
211 printf (" " . "-" x 71 . "\n");
212 open (MESSAGE, "< $fnamebase.out");
213 while (<MESSAGE>) {
214 printf (" %s", $_);
216 close (MESSAGE);
217 printf (" " . "-" x 71 . "\n");
220 unlink "$fnamebase";
221 unlink "$fnamebase.c";
222 unlink "$fnamebase.o";
223 unlink "$fnamebase.out";
224 unlink "$fnamebase.out2";
226 $result;
230 sub newtoken {
231 my($token, @allow) = @_;
232 my($idx);
234 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
236 for ($idx = 0; $idx <= $#allow; ++$idx) {
237 return if (poorfnmatch ($allow[$idx], $token));
242 sub removetoken {
243 my($token) = @_;
244 my($idx);
246 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
248 if (exists $errors{$token}) {
249 undef $errors{$token};
254 sub checknamespace {
255 my($h, $fnamebase, @allow) = @_;
257 ++$total;
259 # Generate a program to get the contents of this header.
260 open (TESTFILE, ">$fnamebase.c");
261 print TESTFILE "#include <$h>\n";
262 close (TESTFILE);
264 undef %errors;
265 $nknown = 0;
266 open (CONTENT, "$CC $CFLAGS_namespace -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
267 loop: while (<CONTENT>) {
268 chop;
269 if (/^#define (.*)/) {
270 newtoken ($1, @allow);
271 } elsif (/^#undef (.*)/) {
272 removetoken ($1);
273 } else {
274 # We have to tokenize the line.
275 my($str) = $_;
276 my($index) = 0;
277 my($len) = length ($str);
279 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
280 if ($token ne "") {
281 newtoken ($token, @allow);
286 close (CONTENT);
287 unlink "$fnamebase.c";
288 $realerror = 0;
289 if ($#errors != 0) {
290 # Sort the output list so it's easier to compare results with diff.
291 foreach $f (sort keys(%errors)) {
292 if ($errors{$f} == 1) {
293 if ($realerror == 0) {
294 printf ("FAIL\n " . "-" x 72 . "\n");
295 $realerror = 1;
296 ++$errors;
298 printf (" Namespace violation: \"%s\"\n", $f);
301 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
304 if ($realerror == 0) {
305 printf ("OK\n");
310 while ($#headers >= 0) {
311 my($h) = pop (@headers);
312 my($hf) = $h;
313 $hf =~ s|/|-|;
314 my($fnamebase) = "$tmpdir/$hf-test";
315 my($missing) = 1;
316 my(@allow) = ();
317 my(@allowheader) = ();
318 my(%seenheader) = ();
319 my($prepend) = $mustprepend{$h};
320 my($test_exist) = 1;
322 printf ("Testing <$h>\n");
323 printf ("----------" . "-" x length ($h) . "\n");
325 open (CONTROL, "$CC -E -D$standard -x c data/$h-data |");
326 control: while (<CONTROL>) {
327 chop;
328 next control if (/^#/);
329 next control if (/^[ ]*$/);
331 if ($test_exist) {
332 $test_exist = 0;
333 # Generate a program to test for the availability of this header.
334 open (TESTFILE, ">$fnamebase.c");
335 print TESTFILE "$prepend";
336 print TESTFILE "#include <$h>\n";
337 close (TESTFILE);
339 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
340 "Header <$h> not available", 0, 0);
341 printf ("\n");
342 last control if ($missing);
345 my($optional) = 0;
346 if (/^optional-/) {
347 s/^optional-//;
348 $optional = 1;
350 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
351 my($struct) = "$2$3";
352 my($type) = "$5$6";
353 my($member) = "$7";
354 my($rest) = "$8";
355 my($res) = $missing;
357 # Remember that this name is allowed.
358 push @allow, $member;
360 # Generate a program to test for the availability of this member.
361 open (TESTFILE, ">$fnamebase.c");
362 print TESTFILE "$prepend";
363 print TESTFILE "#include <$h>\n";
364 print TESTFILE "$struct a;\n";
365 print TESTFILE "$struct b;\n";
366 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
367 print TESTFILE "void foobarbaz (void) {\n";
368 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
369 print TESTFILE "}\n";
370 close (TESTFILE);
372 $res = compiletest ($fnamebase, "Testing for member $member",
373 ($optional
374 ? "NOT AVAILABLE."
375 : "Member \"$member\" not available."), $res,
376 $optional);
378 if ($res == 0 || $missing != 0 || !$optional) {
379 # Test the types of the members.
380 open (TESTFILE, ">$fnamebase.c");
381 print TESTFILE "$prepend";
382 print TESTFILE "#include <$h>\n";
383 print TESTFILE "$struct a;\n";
384 print TESTFILE "extern $type b$rest;\n";
385 print TESTFILE "extern __typeof__ (a.$member) b;\n";
386 close (TESTFILE);
388 compiletest ($fnamebase, "Testing for type of member $member",
389 "Member \"$member\" does not have the correct type.",
390 $res, 0);
392 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
393 my($symbol_type) = $1;
394 my($symbol) = $2;
395 my($type) = $3;
396 my($op) = $4;
397 my($value) = $5;
398 my($res) = $missing;
399 my($mres) = $missing;
400 my($cres) = $missing;
402 # Remember that this name is allowed.
403 push @allow, $symbol;
405 if ($symbol_type =~ /macro/) {
406 # Generate a program to test for availability of this macro.
407 open (TESTFILE, ">$fnamebase.c");
408 print TESTFILE "$prepend";
409 print TESTFILE "#include <$h>\n";
410 print TESTFILE "#ifndef $symbol\n";
411 print TESTFILE "# error \"Macro $symbol not defined\"\n";
412 print TESTFILE "#endif\n";
413 close (TESTFILE);
415 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
416 ($optional
417 ? "NOT PRESENT"
418 : "Macro \"$symbol\" is not available."), $res,
419 $optional);
422 if ($symbol_type =~ /constant/) {
423 # Generate a program to test for the availability of this constant.
424 open (TESTFILE, ">$fnamebase.c");
425 print TESTFILE "$prepend";
426 print TESTFILE "#include <$h>\n";
427 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
428 close (TESTFILE);
430 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
431 ($optional
432 ? "NOT PRESENT"
433 : "Constant \"$symbol\" not available."), $res,
434 $optional);
437 $res = $res || $mres || $cres;
439 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
440 # Test that the symbol is usable in #if.
441 open (TESTFILE, ">$fnamebase.c");
442 print TESTFILE "$prepend";
443 print TESTFILE "#include <$h>\n";
444 print TESTFILE "#if $symbol < 0\n";
445 print TESTFILE "# define conformtest_negative 1\n";
446 my($s) = "0";
447 for (my $i = 0; $i < 63; $i++) {
448 print TESTFILE "# if $symbol & (1LL << $i)\n";
449 print TESTFILE "# define conformtest_bit_$i 0LL\n";
450 print TESTFILE "# else\n";
451 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
452 print TESTFILE "# endif\n";
453 $s .= "|conformtest_bit_$i";
455 print TESTFILE "# define conformtest_value ~($s)\n";
456 print TESTFILE "#else\n";
457 print TESTFILE "# define conformtest_negative 0\n";
458 $s = "0";
459 for (my $i = 0; $i < 64; $i++) {
460 print TESTFILE "# if $symbol & (1ULL << $i)\n";
461 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
462 print TESTFILE "# else\n";
463 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
464 print TESTFILE "# endif\n";
465 $s .= "|conformtest_bit_$i";
467 print TESTFILE "# define conformtest_value ($s)\n";
468 print TESTFILE "#endif\n";
469 print TESTFILE "int main (void) { return !((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value)); }\n";
470 close (TESTFILE);
472 runtest ($fnamebase, "Testing for #if usability of symbol $symbol",
473 "Symbol \"$symbol\" not usable in #if.", $res);
476 if (defined ($type) && ($res == 0 || !$optional)) {
477 # Test the type of the symbol.
478 open (TESTFILE, ">$fnamebase.c");
479 print TESTFILE "$prepend";
480 print TESTFILE "#include <$h>\n";
481 if ($type =~ /^promoted:/) {
482 $type =~ s/^promoted://;
483 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
484 } else {
485 print TESTFILE "__typeof__ (($type) 0) a;\n";
487 print TESTFILE "extern __typeof__ ($symbol) a;\n";
488 close (TESTFILE);
490 compiletest ($fnamebase, "Testing for type of symbol $symbol",
491 "Symbol \"$symbol\" does not have the correct type.",
492 $res, 0);
495 if (defined ($op) && ($res == 0 || !$optional)) {
496 # Generate a program to test for the value of this symbol.
497 open (TESTFILE, ">$fnamebase.c");
498 print TESTFILE "$prepend";
499 print TESTFILE "#include <$h>\n";
500 # Negate the value since 0 means ok
501 print TESTFILE "int main (void) { return !($symbol $op $value); }\n";
502 close (TESTFILE);
504 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
505 "Symbol \"$symbol\" has not the right value.", $res);
507 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
508 my($symbol) = $1;
509 my($value) = $2;
510 my($res) = $missing;
512 # Remember that this name is allowed.
513 push @allow, $symbol;
515 # Generate a program to test for the availability of this constant.
516 open (TESTFILE, ">$fnamebase.c");
517 print TESTFILE "$prepend";
518 print TESTFILE "#include <$h>\n";
519 print TESTFILE "void foobarbaz (void) {\n";
520 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
521 print TESTFILE "}\n";
522 close (TESTFILE);
524 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
525 "Symbol \"$symbol\" not available.", $res, 0);
527 if ($value ne "") {
528 # Generate a program to test for the value of this constant.
529 open (TESTFILE, ">$fnamebase.c");
530 print TESTFILE "$prepend";
531 print TESTFILE "#include <$h>\n";
532 print TESTFILE "int main (void) { return $symbol != $value; }\n";
533 close (TESTFILE);
535 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
536 "Symbol \"$symbol\" has not the right value.", $res);
538 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
539 my($type) = "$2$3";
540 my($maybe_opaque) = 0;
542 # Remember that this name is allowed.
543 if ($type =~ /^struct *(.*)/) {
544 push @allow, $1;
545 } elsif ($type =~ /^union *(.*)/) {
546 push @allow, $1;
547 } else {
548 push @allow, $type;
549 $maybe_opaque = 1;
552 # Generate a program to test for the availability of this type.
553 open (TESTFILE, ">$fnamebase.c");
554 print TESTFILE "$prepend";
555 print TESTFILE "#include <$h>\n";
556 if ($maybe_opaque == 1) {
557 print TESTFILE "$type *a;\n";
558 } else {
559 print TESTFILE "$type a;\n";
561 close (TESTFILE);
563 compiletest ($fnamebase, "Testing for type $type",
564 ($optional
565 ? "NOT AVAILABLE"
566 : "Type \"$type\" not available."), $missing, $optional);
567 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
568 my($type) = "$2$3";
570 # Remember that this name is allowed.
571 if ($type =~ /^struct *(.*)/) {
572 push @allow, $1;
573 } elsif ($type =~ /^union *(.*)/) {
574 push @allow, $1;
575 } else {
576 push @allow, $type;
579 # Generate a program to test for the availability of this type.
580 open (TESTFILE, ">$fnamebase.c");
581 print TESTFILE "$prepend";
582 print TESTFILE "#include <$h>\n";
583 print TESTFILE "$type;\n";
584 close (TESTFILE);
586 compiletest ($fnamebase, "Testing for type $type",
587 "Type \"$type\" not available.", $missing, 0);
588 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
589 my($rettype) = "$2$3";
590 my($fname) = "$4";
591 my($args) = "$5";
592 my($res) = $missing;
594 # Remember that this name is allowed.
595 push @allow, $fname;
597 # Generate a program to test for availability of this function.
598 open (TESTFILE, ">$fnamebase.c");
599 print TESTFILE "$prepend";
600 print TESTFILE "#include <$h>\n";
601 # print TESTFILE "#undef $fname\n";
602 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
603 close (TESTFILE);
605 $res = compiletest ($fnamebase, "Test availability of function $fname",
606 ($optional
607 ? "NOT AVAILABLE"
608 : "Function \"$fname\" is not available."), $res,
609 $optional);
611 if ($res == 0 || $missing == 1 || !$optional) {
612 # Generate a program to test for the type of this function.
613 open (TESTFILE, ">$fnamebase.c");
614 print TESTFILE "$prepend";
615 print TESTFILE "#include <$h>\n";
616 # print TESTFILE "#undef $fname\n";
617 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
618 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
619 close (TESTFILE);
621 compiletest ($fnamebase, "Test for type of function $fname",
622 "Function \"$fname\" has incorrect type.", $res, 0);
624 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
625 my($rettype) = "$2$3";
626 my($fname) = "$4";
627 my($args) = "$5";
628 my($res) = $missing;
630 # Remember that this name is allowed.
631 push @allow, $fname;
633 # Generate a program to test for availability of this function.
634 open (TESTFILE, ">$fnamebase.c");
635 print TESTFILE "$prepend";
636 print TESTFILE "#include <$h>\n";
637 # print TESTFILE "#undef $fname\n";
638 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
639 close (TESTFILE);
641 $res = compiletest ($fnamebase, "Test availability of function $fname",
642 ($optional
643 ? "NOT AVAILABLE"
644 : "Function \"$fname\" is not available."), $res,
645 $optional);
647 if ($res == 0 || $missing != 0 || !$optional) {
648 # Generate a program to test for the type of this function.
649 open (TESTFILE, ">$fnamebase.c");
650 print TESTFILE "$prepend";
651 print TESTFILE "#include <$h>\n";
652 # print TESTFILE "#undef $fname\n";
653 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
654 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
655 close (TESTFILE);
657 compiletest ($fnamebase, "Test for type of function $fname",
658 "Function \"$fname\" has incorrect type.", $res, 0);
660 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
661 my($type) = "$2$3";
662 my($vname) = "$4";
663 my($rest) = "$5";
664 my($res) = $missing;
666 # Remember that this name is allowed.
667 push @allow, $vname;
669 # Generate a program to test for availability of this function.
670 open (TESTFILE, ">$fnamebase.c");
671 print TESTFILE "$prepend";
672 print TESTFILE "#include <$h>\n";
673 # print TESTFILE "#undef $fname\n";
674 print TESTFILE "typedef $type xyzzy$rest;\n";
675 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
676 close (TESTFILE);
678 $res = compiletest ($fnamebase, "Test availability of variable $vname",
679 "Variable \"$vname\" is not available.", $res, 0);
681 # Generate a program to test for the type 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 "extern $type $vname$rest;\n";
687 close (TESTFILE);
689 compiletest ($fnamebase, "Test for type of variable $fname",
690 "Variable \"$vname\" has incorrect type.", $res, 0);
691 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
692 my($rettype) = "$2$3";
693 my($fname) = "$4";
694 my($args) = "$5";
695 my($res) = $missing;
697 # Remember that this name is allowed.
698 push @allow, $fname;
700 # Generate a program to test for availability of this function.
701 open (TESTFILE, ">$fnamebase.c");
702 print TESTFILE "$prepend";
703 print TESTFILE "#include <$h>\n";
704 print TESTFILE "#ifndef $fname\n";
705 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
706 print TESTFILE "#endif\n";
707 close (TESTFILE);
709 $res = compiletest ($fnamebase, "Test availability of macro $fname",
710 "Function \"$fname\" is not available.", $res, 0);
712 # Generate a program to test for the type of this function.
713 open (TESTFILE, ">$fnamebase.c");
714 print TESTFILE "$prepend";
715 print TESTFILE "#include <$h>\n";
716 print TESTFILE "#ifndef $fname\n";
717 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
718 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
719 print TESTFILE "#endif\n";
720 close (TESTFILE);
722 compiletest ($fnamebase, "Test for type of macro $fname",
723 "Function \"$fname\" has incorrect type.", $res, 0);
724 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
725 # The above regex doesn't handle a \" in a string.
726 my($macro) = "$1";
727 my($string) = "$2";
728 my($res) = $missing;
730 # Remember that this name is allowed.
731 push @allow, $macro;
733 # Generate a program to test for availability of this macro.
734 open (TESTFILE, ">$fnamebase.c");
735 print TESTFILE "$prepend";
736 print TESTFILE "#include <$h>\n";
737 print TESTFILE "#ifndef $macro\n";
738 print TESTFILE "# error \"Macro $macro not defined\"\n";
739 print TESTFILE "#endif\n";
740 close (TESTFILE);
742 compiletest ($fnamebase, "Test availability of macro $macro",
743 "Macro \"$macro\" is not available.", $missing, 0);
745 # Generate a program to test for the value of this macro.
746 open (TESTFILE, ">$fnamebase.c");
747 print TESTFILE "$prepend";
748 print TESTFILE "#include <$h>\n";
749 # We can't include <string.h> here.
750 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
751 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
752 close (TESTFILE);
754 $res = runtest ($fnamebase, "Testing for value of macro $macro",
755 "Macro \"$macro\" has not the right value.", $res);
756 } elsif (/^allow-header *(.*)/) {
757 my($pattern) = $1;
758 if ($seenheader{$pattern} != 1) {
759 push @allowheader, $pattern;
760 $seenheader{$pattern} = 1;
762 next control;
763 } elsif (/^allow *(.*)/) {
764 my($pattern) = $1;
765 push @allow, $pattern;
766 next control;
767 } else {
768 # printf ("line is `%s'\n", $_);
769 next control;
772 printf ("\n");
774 close (CONTROL);
776 # Read the data files for the header files which are allowed to be included.
777 while ($#allowheader >= 0) {
778 my($ah) = pop @allowheader;
780 open (ALLOW, "$CC -E -D$standard - < data/$ah-data |");
781 acontrol: while (<ALLOW>) {
782 chop;
783 next acontrol if (/^#/);
784 next acontrol if (/^[ ]*$/);
786 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
787 push @allow, $7;
788 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
789 push @allow, $1;
790 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
791 my($type) = "$3$4";
793 # Remember that this name is allowed.
794 if ($type =~ /^struct *(.*)/) {
795 push @allow, $1;
796 } elsif ($type =~ /^union *(.*)/) {
797 push @allow, $1;
798 } else {
799 push @allow, $type;
801 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
802 push @allow, $4;
803 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
804 push @allow, $4;
805 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
806 push @allow, $4;
807 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
808 push @allow, $4;
809 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
810 push @allow, $1;
811 } elsif (/^allow-header *(.*)/) {
812 if ($seenheader{$1} != 1) {
813 push @allowheader, $1;
814 $seenheader{$1} = 1;
816 } elsif (/^allow *(.*)/) {
817 push @allow, $1;
820 close (ALLOW);
823 if ($test_exist) {
824 printf (" Not defined\n");
825 } else {
826 # Now check the namespace.
827 printf (" Checking the namespace of \"%s\"... ", $h);
828 if ($missing) {
829 ++$skipped;
830 printf ("SKIP\n");
831 } else {
832 checknamespace ($h, $fnamebase, @allow);
836 printf ("\n\n");
839 printf "-" x 76 . "\n";
840 printf (" Total number of tests : %4d\n", $total);
842 printf (" Number of failed tests : %4d (", $errors);
843 $percent = ($errors * 100) / $total;
844 if ($errors > 0 && $percent < 1.0) {
845 printf (" <1%%)\n");
846 } else {
847 printf ("%3d%%)\n", $percent);
850 printf (" Number of skipped tests : %4d (", $skipped);
851 $percent = ($skipped * 100) / $total;
852 if ($skipped > 0 && $percent < 1.0) {
853 printf (" <1%%)\n");
854 } else {
855 printf ("%3d%%)\n", $percent);
858 exit $errors != 0;
859 # Local Variables:
860 # perl-indent-level: 2
861 # End: