Replace cpuid asm statement with __cpuid_count
[glibc.git] / conform / conformtest.pl
blobc8c1d2a839b971808ed5cd91652ad3b864279871
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 open (CONTENT, "$CC $CFLAGS_namespace -E $fnamebase.c -P -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
268 loop: while (<CONTENT>) {
269 chop;
270 if (/^#define (.*)/) {
271 newtoken ($1, @allow);
272 } elsif (/^#undef (.*)/) {
273 removetoken ($1);
274 } else {
275 # We have to tokenize the line.
276 my($str) = $_;
277 my($index) = 0;
278 my($len) = length ($str);
280 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
281 if ($token ne "") {
282 newtoken ($token, @allow);
287 close (CONTENT);
288 unlink "$fnamebase.c";
289 $realerror = 0;
290 if ($#errors != 0) {
291 # Sort the output list so it's easier to compare results with diff.
292 foreach $f (sort keys(%errors)) {
293 if ($errors{$f} == 1) {
294 if ($realerror == 0) {
295 printf ("FAIL\n " . "-" x 72 . "\n");
296 $realerror = 1;
297 ++$errors;
299 printf (" Namespace violation: \"%s\"\n", $f);
302 printf (" " . "-" x 72 . "\n") if ($realerror != 0);
305 if ($realerror == 0) {
306 printf ("OK\n");
311 while ($#headers >= 0) {
312 my($h) = pop (@headers);
313 my($hf) = $h;
314 $hf =~ s|/|-|;
315 my($fnamebase) = "$tmpdir/$hf-test";
316 my($missing) = 1;
317 my(@allow) = ();
318 my(@allowheader) = ();
319 my(%seenheader) = ();
320 my($prepend) = $mustprepend{$h};
321 my($test_exist) = 1;
323 printf ("Testing <$h>\n");
324 printf ("----------" . "-" x length ($h) . "\n");
326 open (CONTROL, "$CC -E -D$standard -std=c99 -x c data/$h-data |");
327 control: while (<CONTROL>) {
328 chop;
329 next control if (/^#/);
330 next control if (/^[ ]*$/);
332 if ($test_exist) {
333 $test_exist = 0;
334 # Generate a program to test for the availability of this header.
335 open (TESTFILE, ">$fnamebase.c");
336 print TESTFILE "$prepend";
337 print TESTFILE "#include <$h>\n";
338 close (TESTFILE);
340 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
341 "Header <$h> not available", 0, 0);
342 printf ("\n");
343 last control if ($missing);
346 my($optional) = 0;
347 if (/^optional-/) {
348 s/^optional-//;
349 $optional = 1;
351 if (/^element *({([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
352 my($struct) = "$2$3";
353 my($type) = "$5$6";
354 my($member) = "$7";
355 my($rest) = "$8";
356 my($res) = $missing;
358 # Remember that this name is allowed.
359 push @allow, $member;
361 # Generate a program to test for the availability of this member.
362 open (TESTFILE, ">$fnamebase.c");
363 print TESTFILE "$prepend";
364 print TESTFILE "#include <$h>\n";
365 print TESTFILE "$struct a;\n";
366 print TESTFILE "$struct b;\n";
367 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
368 print TESTFILE "void foobarbaz (void) {\n";
369 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
370 print TESTFILE "}\n";
371 close (TESTFILE);
373 $res = compiletest ($fnamebase, "Testing for member $member",
374 ($optional
375 ? "NOT AVAILABLE."
376 : "Member \"$member\" not available."), $res,
377 $optional);
379 if ($res == 0 || $missing != 0 || !$optional) {
380 # Test the types of the members.
381 open (TESTFILE, ">$fnamebase.c");
382 print TESTFILE "$prepend";
383 print TESTFILE "#include <$h>\n";
384 print TESTFILE "$struct a;\n";
385 print TESTFILE "extern $type b$rest;\n";
386 print TESTFILE "extern __typeof__ (a.$member) b;\n";
387 close (TESTFILE);
389 compiletest ($fnamebase, "Testing for type of member $member",
390 "Member \"$member\" does not have the correct type.",
391 $res, 0);
393 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_\\'-]*))?/) {
394 my($symbol_type) = $1;
395 my($symbol) = $2;
396 my($type) = $3;
397 my($op) = $4;
398 my($value) = $5;
399 my($res) = $missing;
400 my($mres) = $missing;
401 my($cres) = $missing;
403 # Remember that this name is allowed.
404 push @allow, $symbol;
406 if ($symbol_type =~ /macro/) {
407 # Generate a program to test for availability of this macro.
408 open (TESTFILE, ">$fnamebase.c");
409 print TESTFILE "$prepend";
410 print TESTFILE "#include <$h>\n";
411 print TESTFILE "#ifndef $symbol\n";
412 print TESTFILE "# error \"Macro $symbol not defined\"\n";
413 print TESTFILE "#endif\n";
414 close (TESTFILE);
416 $mres = compiletest ($fnamebase, "Test availability of macro $symbol",
417 ($optional
418 ? "NOT PRESENT"
419 : "Macro \"$symbol\" is not available."), $res,
420 $optional);
423 if ($symbol_type =~ /constant/) {
424 # Generate a program to test for the availability of this constant.
425 open (TESTFILE, ">$fnamebase.c");
426 print TESTFILE "$prepend";
427 print TESTFILE "#include <$h>\n";
428 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
429 close (TESTFILE);
431 $cres = compiletest ($fnamebase, "Testing for constant $symbol",
432 ($optional
433 ? "NOT PRESENT"
434 : "Constant \"$symbol\" not available."), $res,
435 $optional);
438 $res = $res || $mres || $cres;
440 if ($symbol_type eq "macro-int-constant" && ($res == 0 || !$optional)) {
441 # Test that the symbol is usable in #if.
442 open (TESTFILE, ">$fnamebase.c");
443 print TESTFILE "$prepend";
444 print TESTFILE "#include <$h>\n";
445 print TESTFILE "#if $symbol < 0\n";
446 print TESTFILE "# define conformtest_negative 1\n";
447 my($s) = "0";
448 for (my $i = 0; $i < 63; $i++) {
449 print TESTFILE "# if $symbol & (1LL << $i)\n";
450 print TESTFILE "# define conformtest_bit_$i 0LL\n";
451 print TESTFILE "# else\n";
452 print TESTFILE "# define conformtest_bit_$i (1LL << $i)\n";
453 print TESTFILE "# endif\n";
454 $s .= "|conformtest_bit_$i";
456 print TESTFILE "# define conformtest_value ~($s)\n";
457 print TESTFILE "#else\n";
458 print TESTFILE "# define conformtest_negative 0\n";
459 $s = "0";
460 for (my $i = 0; $i < 64; $i++) {
461 print TESTFILE "# if $symbol & (1ULL << $i)\n";
462 print TESTFILE "# define conformtest_bit_$i (1ULL << $i)\n";
463 print TESTFILE "# else\n";
464 print TESTFILE "# define conformtest_bit_$i 0ULL\n";
465 print TESTFILE "# endif\n";
466 $s .= "|conformtest_bit_$i";
468 print TESTFILE "# define conformtest_value ($s)\n";
469 print TESTFILE "#endif\n";
470 print TESTFILE "int main (void) { return !((($symbol < 0) == conformtest_negative) && ($symbol == conformtest_value)); }\n";
471 close (TESTFILE);
473 runtest ($fnamebase, "Testing for #if usability of symbol $symbol",
474 "Symbol \"$symbol\" not usable in #if.", $res);
477 if (defined ($type) && ($res == 0 || !$optional)) {
478 # Test the type of the symbol.
479 open (TESTFILE, ">$fnamebase.c");
480 print TESTFILE "$prepend";
481 print TESTFILE "#include <$h>\n";
482 if ($type =~ /^promoted:/) {
483 $type =~ s/^promoted://;
484 print TESTFILE "__typeof__ (($type) 0 + ($type) 0) a;\n";
485 } else {
486 print TESTFILE "__typeof__ (($type) 0) a;\n";
488 print TESTFILE "extern __typeof__ ($symbol) a;\n";
489 close (TESTFILE);
491 compiletest ($fnamebase, "Testing for type of symbol $symbol",
492 "Symbol \"$symbol\" does not have the correct type.",
493 $res, 0);
496 if (defined ($op) && ($res == 0 || !$optional)) {
497 # Generate a program to test for the value of this symbol.
498 open (TESTFILE, ">$fnamebase.c");
499 print TESTFILE "$prepend";
500 print TESTFILE "#include <$h>\n";
501 # Negate the value since 0 means ok
502 print TESTFILE "int main (void) { return !($symbol $op $value); }\n";
503 close (TESTFILE);
505 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
506 "Symbol \"$symbol\" has not the right value.", $res);
508 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
509 my($symbol) = $1;
510 my($value) = $2;
511 my($res) = $missing;
513 # Remember that this name is allowed.
514 push @allow, $symbol;
516 # Generate a program to test for the availability of this constant.
517 open (TESTFILE, ">$fnamebase.c");
518 print TESTFILE "$prepend";
519 print TESTFILE "#include <$h>\n";
520 print TESTFILE "void foobarbaz (void) {\n";
521 print TESTFILE "__typeof__ ($symbol) a = $symbol;\n";
522 print TESTFILE "}\n";
523 close (TESTFILE);
525 $res = compiletest ($fnamebase, "Testing for symbol $symbol",
526 "Symbol \"$symbol\" not available.", $res, 0);
528 if ($value ne "") {
529 # Generate a program to test for the value of this constant.
530 open (TESTFILE, ">$fnamebase.c");
531 print TESTFILE "$prepend";
532 print TESTFILE "#include <$h>\n";
533 print TESTFILE "int main (void) { return $symbol != $value; }\n";
534 close (TESTFILE);
536 $res = runtest ($fnamebase, "Testing for value of symbol $symbol",
537 "Symbol \"$symbol\" has not the right value.", $res);
539 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
540 my($type) = "$2$3";
541 my($maybe_opaque) = 0;
543 # Remember that this name is allowed.
544 if ($type =~ /^struct *(.*)/) {
545 push @allow, $1;
546 } elsif ($type =~ /^union *(.*)/) {
547 push @allow, $1;
548 } else {
549 push @allow, $type;
550 $maybe_opaque = 1;
553 # Generate a program to test for the availability of this type.
554 open (TESTFILE, ">$fnamebase.c");
555 print TESTFILE "$prepend";
556 print TESTFILE "#include <$h>\n";
557 if ($maybe_opaque == 1) {
558 print TESTFILE "$type *a;\n";
559 } else {
560 print TESTFILE "$type a;\n";
562 close (TESTFILE);
564 compiletest ($fnamebase, "Testing for type $type",
565 ($optional
566 ? "NOT AVAILABLE"
567 : "Type \"$type\" not available."), $missing, $optional);
568 } elsif (/^tag *({([^}]*)|([a-zA-Z0-9_]*))/) {
569 my($type) = "$2$3";
571 # Remember that this name is allowed.
572 if ($type =~ /^struct *(.*)/) {
573 push @allow, $1;
574 } elsif ($type =~ /^union *(.*)/) {
575 push @allow, $1;
576 } else {
577 push @allow, $type;
580 # Generate a program to test for the availability of this type.
581 open (TESTFILE, ">$fnamebase.c");
582 print TESTFILE "$prepend";
583 print TESTFILE "#include <$h>\n";
584 print TESTFILE "$type;\n";
585 close (TESTFILE);
587 compiletest ($fnamebase, "Testing for type $type",
588 "Type \"$type\" not available.", $missing, 0);
589 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
590 my($rettype) = "$2$3";
591 my($fname) = "$4";
592 my($args) = "$5";
593 my($res) = $missing;
595 # Remember that this name is allowed.
596 push @allow, $fname;
598 # Generate a program to test for availability of this function.
599 open (TESTFILE, ">$fnamebase.c");
600 print TESTFILE "$prepend";
601 print TESTFILE "#include <$h>\n";
602 # print TESTFILE "#undef $fname\n";
603 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
604 close (TESTFILE);
606 $res = compiletest ($fnamebase, "Test availability of function $fname",
607 ($optional
608 ? "NOT AVAILABLE"
609 : "Function \"$fname\" is not available."), $res,
610 $optional);
612 if ($res == 0 || $missing == 1 || !$optional) {
613 # Generate a program to test for the type of this function.
614 open (TESTFILE, ">$fnamebase.c");
615 print TESTFILE "$prepend";
616 print TESTFILE "#include <$h>\n";
617 # print TESTFILE "#undef $fname\n";
618 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
619 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
620 close (TESTFILE);
622 compiletest ($fnamebase, "Test for type of function $fname",
623 "Function \"$fname\" has incorrect type.", $res, 0);
625 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
626 my($rettype) = "$2$3";
627 my($fname) = "$4";
628 my($args) = "$5";
629 my($res) = $missing;
631 # Remember that this name is allowed.
632 push @allow, $fname;
634 # Generate a program to test for availability 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 "$rettype (*foobarbaz) $args = $fname;\n";
640 close (TESTFILE);
642 $res = compiletest ($fnamebase, "Test availability of function $fname",
643 ($optional
644 ? "NOT AVAILABLE"
645 : "Function \"$fname\" is not available."), $res,
646 $optional);
648 if ($res == 0 || $missing != 0 || !$optional) {
649 # Generate a program to test for the type of this function.
650 open (TESTFILE, ">$fnamebase.c");
651 print TESTFILE "$prepend";
652 print TESTFILE "#include <$h>\n";
653 # print TESTFILE "#undef $fname\n";
654 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
655 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
656 close (TESTFILE);
658 compiletest ($fnamebase, "Test for type of function $fname",
659 "Function \"$fname\" has incorrect type.", $res, 0);
661 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) *(.*)/) {
662 my($type) = "$2$3";
663 my($vname) = "$4";
664 my($rest) = "$5";
665 my($res) = $missing;
667 # Remember that this name is allowed.
668 push @allow, $vname;
670 # Generate a program to test for availability of this function.
671 open (TESTFILE, ">$fnamebase.c");
672 print TESTFILE "$prepend";
673 print TESTFILE "#include <$h>\n";
674 # print TESTFILE "#undef $fname\n";
675 print TESTFILE "typedef $type xyzzy$rest;\n";
676 print TESTFILE "$xyzzy *foobarbaz = &$vname;\n";
677 close (TESTFILE);
679 $res = compiletest ($fnamebase, "Test availability of variable $vname",
680 "Variable \"$vname\" is not available.", $res, 0);
682 # Generate a program to test for the type of this function.
683 open (TESTFILE, ">$fnamebase.c");
684 print TESTFILE "$prepend";
685 print TESTFILE "#include <$h>\n";
686 # print TESTFILE "#undef $fname\n";
687 print TESTFILE "extern $type $vname$rest;\n";
688 close (TESTFILE);
690 compiletest ($fnamebase, "Test for type of variable $fname",
691 "Variable \"$vname\" has incorrect type.", $res, 0);
692 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
693 my($rettype) = "$2$3";
694 my($fname) = "$4";
695 my($args) = "$5";
696 my($res) = $missing;
698 # Remember that this name is allowed.
699 push @allow, $fname;
701 # Generate a program to test for availability of this function.
702 open (TESTFILE, ">$fnamebase.c");
703 print TESTFILE "$prepend";
704 print TESTFILE "#include <$h>\n";
705 print TESTFILE "#ifndef $fname\n";
706 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
707 print TESTFILE "#endif\n";
708 close (TESTFILE);
710 $res = compiletest ($fnamebase, "Test availability of macro $fname",
711 "Function \"$fname\" is not available.", $res, 0);
713 # Generate a program to test for the type 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 "extern $rettype (*foobarbaz) $args;\n";
719 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
720 print TESTFILE "#endif\n";
721 close (TESTFILE);
723 compiletest ($fnamebase, "Test for type of macro $fname",
724 "Function \"$fname\" has incorrect type.", $res, 0);
725 } elsif (/^macro-str *([^ ]*) *(\".*\")/) {
726 # The above regex doesn't handle a \" in a string.
727 my($macro) = "$1";
728 my($string) = "$2";
729 my($res) = $missing;
731 # Remember that this name is allowed.
732 push @allow, $macro;
734 # Generate a program to test for availability of this macro.
735 open (TESTFILE, ">$fnamebase.c");
736 print TESTFILE "$prepend";
737 print TESTFILE "#include <$h>\n";
738 print TESTFILE "#ifndef $macro\n";
739 print TESTFILE "# error \"Macro $macro not defined\"\n";
740 print TESTFILE "#endif\n";
741 close (TESTFILE);
743 compiletest ($fnamebase, "Test availability of macro $macro",
744 "Macro \"$macro\" is not available.", $missing, 0);
746 # Generate a program to test for the value of this macro.
747 open (TESTFILE, ">$fnamebase.c");
748 print TESTFILE "$prepend";
749 print TESTFILE "#include <$h>\n";
750 # We can't include <string.h> here.
751 print TESTFILE "extern int (strcmp)(const char *, const char *);\n";
752 print TESTFILE "int main (void) { return (strcmp) ($macro, $string) != 0;}\n";
753 close (TESTFILE);
755 $res = runtest ($fnamebase, "Testing for value of macro $macro",
756 "Macro \"$macro\" has not the right value.", $res);
757 } elsif (/^allow-header *(.*)/) {
758 my($pattern) = $1;
759 if ($seenheader{$pattern} != 1) {
760 push @allowheader, $pattern;
761 $seenheader{$pattern} = 1;
763 next control;
764 } elsif (/^allow *(.*)/) {
765 my($pattern) = $1;
766 push @allow, $pattern;
767 next control;
768 } else {
769 # printf ("line is `%s'\n", $_);
770 next control;
773 printf ("\n");
775 close (CONTROL);
777 # Read the data files for the header files which are allowed to be included.
778 while ($#allowheader >= 0) {
779 my($ah) = pop @allowheader;
781 open (ALLOW, "$CC -E -D$standard -x c data/$ah-data |");
782 acontrol: while (<ALLOW>) {
783 chop;
784 next acontrol if (/^#/);
785 next acontrol if (/^[ ]*$/);
787 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
788 push @allow, $7;
789 } elsif (/^(macro|constant|macro-constant|macro-int-constant) +([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=<!]+) ([A-Za-z0-9_-]*))?/) {
790 push @allow, $2;
791 } elsif (/^(type|tag) *({([^}]*)|([a-zA-Z0-9_]*))/) {
792 my($type) = "$3$4";
794 # Remember that this name is allowed.
795 if ($type =~ /^struct *(.*)/) {
796 push @allow, $1;
797 } elsif ($type =~ /^union *(.*)/) {
798 push @allow, $1;
799 } else {
800 push @allow, $type;
802 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
803 push @allow, $4;
804 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
805 push @allow, $4;
806 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
807 push @allow, $4;
808 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
809 push @allow, $4;
810 } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) {
811 push @allow, $1;
812 } elsif (/^allow-header *(.*)/) {
813 if ($seenheader{$1} != 1) {
814 push @allowheader, $1;
815 $seenheader{$1} = 1;
817 } elsif (/^allow *(.*)/) {
818 push @allow, $1;
821 close (ALLOW);
824 if ($test_exist) {
825 printf (" Not defined\n");
826 } else {
827 # Now check the namespace.
828 printf (" Checking the namespace of \"%s\"... ", $h);
829 if ($missing) {
830 ++$skipped;
831 printf ("SKIP\n");
832 } else {
833 checknamespace ($h, $fnamebase, @allow);
837 printf ("\n\n");
840 printf "-" x 76 . "\n";
841 printf (" Total number of tests : %4d\n", $total);
843 printf (" Number of failed tests : %4d (", $errors);
844 $percent = ($errors * 100) / $total;
845 if ($errors > 0 && $percent < 1.0) {
846 printf (" <1%%)\n");
847 } else {
848 printf ("%3d%%)\n", $percent);
851 printf (" Number of skipped tests : %4d (", $skipped);
852 $percent = ($skipped * 100) / $total;
853 if ($skipped > 0 && $percent < 1.0) {
854 printf (" <1%%)\n");
855 } else {
856 printf ("%3d%%)\n", $percent);
859 exit $errors != 0;
860 # Local Variables:
861 # perl-indent-level: 2
862 # End: