Set arch_minimum_kernel to 3.4.0 for x32
[glibc.git] / conform / conformtest.pl
blob8b97d0dfc7693d28541d94abcd4c63b558b56690
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 "stdnoreturn.h", "stdlib.h", "stdio.h", "stdint.h", "stddef.h",
24 "stdbool.h", "stdarg.h", "stdalign.h", "spawn.h", "signal.h",
25 "setjmp.h", "semaphore.h", "search.h", "sched.h", "regex.h",
26 "pwd.h", "pthread.h", "poll.h", "nl_types.h", "netinet/tcp.h",
27 "netinet/in.h", "net/if.h", "netdb.h", "ndbm.h", "mqueue.h",
28 "monetary.h", "math.h", "locale.h", "libgen.h", "limits.h",
29 "langinfo.h", "iso646.h", "inttypes.h", "iconv.h", "grp.h",
30 "glob.h", "ftw.h", "fnmatch.h", "fmtmsg.h", "float.h", "fenv.h",
31 "fcntl.h", "errno.h", "dlfcn.h", "dirent.h", "ctype.h", "cpio.h",
32 "complex.h", "assert.h", "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));
240 $errors{$token} = 1;
244 sub removetoken {
245 my($token) = @_;
246 my($idx);
248 return if ($token =~ /^[0-9_]/ || $iskeyword{$token});
250 if (exists $errors{$token}) {
251 undef $errors{$token};
256 sub checknamespace {
257 my($h, $fnamebase, @allow) = @_;
259 ++$total;
261 # Generate a program to get the contents of this header.
262 open (TESTFILE, ">$fnamebase.c");
263 print TESTFILE "#include <$h>\n";
264 close (TESTFILE);
266 undef %errors;
267 $nknown = 0;
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 -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);
343 printf ("\n");
344 last control if ($missing);
347 my($optional) = 0;
348 if (/^optional-/) {
349 s/^optional-//;
350 $optional = 1;
352 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
353 my($struct) = "$2$3";
354 my($type) = "$5$6";
355 my($member) = "$7";
356 my($rest) = "$8";
357 my($res) = $missing;
359 # Remember that this name is allowed.
360 push @allow, $member;
362 # Generate a program to test for the availability of this member.
363 open (TESTFILE, ">$fnamebase.c");
364 print TESTFILE "$prepend";
365 print TESTFILE "#include <$h>\n";
366 print TESTFILE "$struct a;\n";
367 print TESTFILE "$struct b;\n";
368 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
369 print TESTFILE "void foobarbaz (void) {\n";
370 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
371 print TESTFILE "}\n";
372 close (TESTFILE);
374 $res = compiletest ($fnamebase, "Testing for member $member",
375 ($optional
376 ? "NOT AVAILABLE."
377 : "Member \"$member\" not available."), $res,
378 $optional);
380 if ($res == 0 || $missing != 0 || !$optional) {
381 # Test the types of the members.
382 open (TESTFILE, ">$fnamebase.c");
383 print TESTFILE "$prepend";
384 print TESTFILE "#include <$h>\n";
385 print TESTFILE "$struct a;\n";
386 print TESTFILE "extern $type b$rest;\n";
387 print TESTFILE "extern __typeof__ (a.$member) b;\n";
388 close (TESTFILE);
390 compiletest ($fnamebase, "Testing for type of member $member",
391 "Member \"$member\" does not have the correct type.",
392 $res, 0);
394 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
395 my($symbol_type) = $1;
396 my($symbol) = $2;
397 my($type) = $3;
398 my($op) = $4;
399 my($value) = $5;
400 my($res) = $missing;
401 my($mres) = $missing;
402 my($cres) = $missing;
404 # Remember that this name is allowed.
405 push @allow, $symbol;
407 if ($symbol_type =~ /macro/) {
408 # Generate a program to test for availability of this macro.
409 open (TESTFILE, ">$fnamebase.c");
410 print TESTFILE "$prepend";
411 print TESTFILE "#include <$h>\n";
412 print TESTFILE "#ifndef $symbol\n";
413 print TESTFILE "# error \"Macro $symbol not defined\"\n";
414 print TESTFILE "#endif\n";
415 close (TESTFILE);
417 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
418 ($optional
419 ? "NOT PRESENT"
420 : "Macro \"$symbol\" is not available."), $res,
421 $optional);
424 if ($symbol_type =~ /constant/) {
425 # Generate a program to test for the availability of this constant.
426 open (TESTFILE, ">$fnamebase.c");
427 print TESTFILE "$prepend";
428 print TESTFILE "#include <$h>\n";
429 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
430 close (TESTFILE);
432 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
433 ($optional
434 ? "NOT PRESENT"
435 : "Constant \"$symbol\" not available."), $res,
436 $optional);
439 $res = $res || $mres || $cres;
441 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
442 # Test that the symbol is usable in #if.
443 open (TESTFILE, ">$fnamebase.c");
444 print TESTFILE "$prepend";
445 print TESTFILE "#include <$h>\n";
446 print TESTFILE "#if $symbol < 0\n";
447 print TESTFILE "# define conformtest_negative 1\n";
448 my($s) = "0";
449 for (my $i = 0; $i < 63; $i++) {
450 print TESTFILE "# if $symbol & (1LL << $i)\n";
451 print TESTFILE "# define conformtest_bit_$i 0LL\n";
452 print TESTFILE "# else\n";
453 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
454 print TESTFILE "# endif\n";
455 $s .= "|conformtest_bit_$i";
457 print TESTFILE "# define conformtest_value ~($s)\n";
458 print TESTFILE "#else\n";
459 print TESTFILE "# define conformtest_negative 0\n";
460 $s = "0";
461 for (my $i = 0; $i < 64; $i++) {
462 print TESTFILE "# if $symbol & (1ULL << $i)\n";
463 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
464 print TESTFILE "# else\n";
465 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
466 print TESTFILE "# endif\n";
467 $s .= "|conformtest_bit_$i";
469 print TESTFILE "# define conformtest_value ($s)\n";
470 print TESTFILE "#endif\n";
471 print TESTFILE "int main (void) { return !((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value)); }\n";
472 close (TESTFILE);
474 runtest ($fnamebase, "Testing for #if usability of symbol $symbol",
475 "Symbol \"$symbol\" not usable in #if.", $res);
478 if (defined ($type) && ($res == 0 || !$optional)) {
479 # Test the type of the symbol.
480 open (TESTFILE, ">$fnamebase.c");
481 print TESTFILE "$prepend";
482 print TESTFILE "#include <$h>\n";
483 if ($type =~ /^promoted:/) {
484 $type =~ s/^promoted://;
485 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
486 } else {
487 print TESTFILE "__typeof__ (($type) 0) a;\n";
489 print TESTFILE "extern __typeof__ ($symbol) a;\n";
490 close (TESTFILE);
492 compiletest ($fnamebase, "Testing for type of symbol $symbol",
493 "Symbol \"$symbol\" does not have the correct type.",
494 $res, 0);
497 if (defined ($op) && ($res == 0 || !$optional)) {
498 # Generate a program to test for the value of this symbol.
499 open (TESTFILE, ">$fnamebase.c");
500 print TESTFILE "$prepend";
501 print TESTFILE "#include <$h>\n";
502 # Negate the value since 0 means ok
503 print TESTFILE "int main (void) { return !($symbol $op $value); }\n";
504 close (TESTFILE);
506 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
507 "Symbol \"$symbol\" has not the right value.", $res);
509 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
510 my($symbol) = $1;
511 my($value) = $2;
512 my($res) = $missing;
514 # Remember that this name is allowed.
515 push @allow, $symbol;
517 # Generate a program to test for the availability of this constant.
518 open (TESTFILE, ">$fnamebase.c");
519 print TESTFILE "$prepend";
520 print TESTFILE "#include <$h>\n";
521 print TESTFILE "void foobarbaz (void) {\n";
522 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
523 print TESTFILE "}\n";
524 close (TESTFILE);
526 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
527 "Symbol \"$symbol\" not available.", $res, 0);
529 if ($value ne "") {
530 # Generate a program to test for the value of this constant.
531 open (TESTFILE, ">$fnamebase.c");
532 print TESTFILE "$prepend";
533 print TESTFILE "#include <$h>\n";
534 print TESTFILE "int main (void) { return $symbol != $value; }\n";
535 close (TESTFILE);
537 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
538 "Symbol \"$symbol\" has not the right value.", $res);
540 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
541 my($type) = "$2$3";
542 my($maybe_opaque) = 0;
544 # Remember that this name is allowed.
545 if ($type =~ /^struct *(.*)/) {
546 push @allow, $1;
547 } elsif ($type =~ /^union *(.*)/) {
548 push @allow, $1;
549 } else {
550 push @allow, $type;
551 $maybe_opaque = 1;
554 # Generate a program to test for the availability of this type.
555 open (TESTFILE, ">$fnamebase.c");
556 print TESTFILE "$prepend";
557 print TESTFILE "#include <$h>\n";
558 if ($maybe_opaque == 1) {
559 print TESTFILE "$type *a;\n";
560 } else {
561 print TESTFILE "$type a;\n";
563 close (TESTFILE);
565 compiletest ($fnamebase, "Testing for type $type",
566 ($optional
567 ? "NOT AVAILABLE"
568 : "Type \"$type\" not available."), $missing, $optional);
569 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
570 my($type) = "$2$3";
572 # Remember that this name is allowed.
573 if ($type =~ /^struct *(.*)/) {
574 push @allow, $1;
575 } elsif ($type =~ /^union *(.*)/) {
576 push @allow, $1;
577 } else {
578 push @allow, $type;
581 # Generate a program to test for the availability of this type.
582 open (TESTFILE, ">$fnamebase.c");
583 print TESTFILE "$prepend";
584 print TESTFILE "#include <$h>\n";
585 print TESTFILE "$type;\n";
586 close (TESTFILE);
588 compiletest ($fnamebase, "Testing for type $type",
589 "Type \"$type\" not available.", $missing, 0);
590 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
591 my($rettype) = "$2$3";
592 my($fname) = "$4";
593 my($args) = "$5";
594 my($res) = $missing;
596 # Remember that this name is allowed.
597 push @allow, $fname;
599 # Generate a program to test for availability of this function.
600 open (TESTFILE, ">$fnamebase.c");
601 print TESTFILE "$prepend";
602 print TESTFILE "#include <$h>\n";
603 # print TESTFILE "#undef $fname\n";
604 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
605 close (TESTFILE);
607 $res = compiletest ($fnamebase, "Test availability of function $fname",
608 ($optional
609 ? "NOT AVAILABLE"
610 : "Function \"$fname\" is not available."), $res,
611 $optional);
613 if ($res == 0 || $missing == 1 || !$optional) {
614 # Generate a program to test for the type of this function.
615 open (TESTFILE, ">$fnamebase.c");
616 print TESTFILE "$prepend";
617 print TESTFILE "#include <$h>\n";
618 # print TESTFILE "#undef $fname\n";
619 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
620 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
621 close (TESTFILE);
623 compiletest ($fnamebase, "Test for type of function $fname",
624 "Function \"$fname\" has incorrect type.", $res, 0);
626 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
627 my($rettype) = "$2$3";
628 my($fname) = "$4";
629 my($args) = "$5";
630 my($res) = $missing;
632 # Remember that this name is allowed.
633 push @allow, $fname;
635 # Generate a program to test for availability of this function.
636 open (TESTFILE, ">$fnamebase.c");
637 print TESTFILE "$prepend";
638 print TESTFILE "#include <$h>\n";
639 # print TESTFILE "#undef $fname\n";
640 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
641 close (TESTFILE);
643 $res = compiletest ($fnamebase, "Test availability of function $fname",
644 ($optional
645 ? "NOT AVAILABLE"
646 : "Function \"$fname\" is not available."), $res,
647 $optional);
649 if ($res == 0 || $missing != 0 || !$optional) {
650 # Generate a program to test for the type of this function.
651 open (TESTFILE, ">$fnamebase.c");
652 print TESTFILE "$prepend";
653 print TESTFILE "#include <$h>\n";
654 # print TESTFILE "#undef $fname\n";
655 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
656 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
657 close (TESTFILE);
659 compiletest ($fnamebase, "Test for type of function $fname",
660 "Function \"$fname\" has incorrect type.", $res, 0);
662 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
663 my($type) = "$2$3";
664 my($vname) = "$4";
665 my($rest) = "$5";
666 my($res) = $missing;
668 # Remember that this name is allowed.
669 push @allow, $vname;
671 # Generate a program to test for availability 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 "typedef $type xyzzy$rest;\n";
677 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
678 close (TESTFILE);
680 $res = compiletest ($fnamebase, "Test availability of variable $vname",
681 "Variable \"$vname\" is not available.", $res, 0);
683 # Generate a program to test for the type of this function.
684 open (TESTFILE, ">$fnamebase.c");
685 print TESTFILE "$prepend";
686 print TESTFILE "#include <$h>\n";
687 # print TESTFILE "#undef $fname\n";
688 print TESTFILE "extern $type $vname$rest;\n";
689 close (TESTFILE);
691 compiletest ($fnamebase, "Test for type of variable $fname",
692 "Variable \"$vname\" has incorrect type.", $res, 0);
693 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
694 my($rettype) = "$2$3";
695 my($fname) = "$4";
696 my($args) = "$5";
697 my($res) = $missing;
699 # Remember that this name is allowed.
700 push @allow, $fname;
702 # Generate a program to test for availability of this function.
703 open (TESTFILE, ">$fnamebase.c");
704 print TESTFILE "$prepend";
705 print TESTFILE "#include <$h>\n";
706 print TESTFILE "#ifndef $fname\n";
707 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
708 print TESTFILE "#endif\n";
709 close (TESTFILE);
711 $res = compiletest ($fnamebase, "Test availability of macro $fname",
712 "Function \"$fname\" is not available.", $res, 0);
714 # Generate a program to test for the type of this function.
715 open (TESTFILE, ">$fnamebase.c");
716 print TESTFILE "$prepend";
717 print TESTFILE "#include <$h>\n";
718 print TESTFILE "#ifndef $fname\n";
719 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
720 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
721 print TESTFILE "#endif\n";
722 close (TESTFILE);
724 compiletest ($fnamebase, "Test for type of macro $fname",
725 "Function \"$fname\" has incorrect type.", $res, 0);
726 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
727 # The above regex doesn't handle a \" in a string.
728 my($macro) = "$1";
729 my($string) = "$2";
730 my($res) = $missing;
732 # Remember that this name is allowed.
733 push @allow, $macro;
735 # Generate a program to test for availability of this macro.
736 open (TESTFILE, ">$fnamebase.c");
737 print TESTFILE "$prepend";
738 print TESTFILE "#include <$h>\n";
739 print TESTFILE "#ifndef $macro\n";
740 print TESTFILE "# error \"Macro $macro not defined\"\n";
741 print TESTFILE "#endif\n";
742 close (TESTFILE);
744 compiletest ($fnamebase, "Test availability of macro $macro",
745 "Macro \"$macro\" is not available.", $missing, 0);
747 # Generate a program to test for the value of this macro.
748 open (TESTFILE, ">$fnamebase.c");
749 print TESTFILE "$prepend";
750 print TESTFILE "#include <$h>\n";
751 # We can't include <string.h> here.
752 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
753 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
754 close (TESTFILE);
756 $res = runtest ($fnamebase, "Testing for value of macro $macro",
757 "Macro \"$macro\" has not the right value.", $res);
758 } elsif (/^allow-header *(.*)/) {
759 my($pattern) = $1;
760 if ($seenheader{$pattern} != 1) {
761 push @allowheader, $pattern;
762 $seenheader{$pattern} = 1;
764 next control;
765 } elsif (/^allow *(.*)/) {
766 my($pattern) = $1;
767 push @allow, $pattern;
768 next control;
769 } else {
770 # printf ("line is `%s'\n", $_);
771 next control;
774 printf ("\n");
776 close (CONTROL);
778 # Read the data files for the header files which are allowed to be included.
779 while ($#allowheader >= 0) {
780 my($ah) = pop @allowheader;
782 open (ALLOW, "$CC -E -D$standard -x c data/$ah-data |");
783 acontrol: while (<ALLOW>) {
784 chop;
785 next acontrol if (/^#/);
786 next acontrol if (/^[ ]*$/);
788 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
789 push @allow, $7;
790 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
791 push @allow, $2;
792 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
793 my($type) = "$3$4";
795 # Remember that this name is allowed.
796 if ($type =~ /^struct *(.*)/) {
797 push @allow, $1;
798 } elsif ($type =~ /^union *(.*)/) {
799 push @allow, $1;
800 } else {
801 push @allow, $type;
803 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
804 push @allow, $4;
805 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
806 push @allow, $4;
807 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
808 push @allow, $4;
809 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
810 push @allow, $4;
811 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
812 push @allow, $1;
813 } elsif (/^allow-header *(.*)/) {
814 if ($seenheader{$1} != 1) {
815 push @allowheader, $1;
816 $seenheader{$1} = 1;
818 } elsif (/^allow *(.*)/) {
819 push @allow, $1;
822 close (ALLOW);
825 if ($test_exist) {
826 printf (" Not defined\n");
827 } else {
828 # Now check the namespace.
829 printf (" Checking the namespace of \"%s\"... ", $h);
830 if ($missing) {
831 ++$skipped;
832 printf ("SKIP\n");
833 } else {
834 checknamespace ($h, $fnamebase, @allow);
838 printf ("\n\n");
841 printf "-" x 76 . "\n";
842 printf (" Total number of tests : %4d\n", $total);
844 printf (" Number of failed tests : %4d (", $errors);
845 $percent = ($errors * 100) / $total;
846 if ($errors > 0 && $percent < 1.0) {
847 printf (" <1%%)\n");
848 } else {
849 printf ("%3d%%)\n", $percent);
852 printf (" Number of skipped tests : %4d (", $skipped);
853 $percent = ($skipped * 100) / $total;
854 if ($skipped > 0 && $percent < 1.0) {
855 printf (" <1%%)\n");
856 } else {
857 printf ("%3d%%)\n", $percent);
860 exit $errors != 0;
861 # Local Variables:
862 # perl-indent-level: 2
863 # End: