4 $CFLAGS = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
6 # List of the headers we are testing.
8 "stddef.h", "stdarg.h", "signal.h", "setjmp.h", "semaphore.h",
9 "search.h", "sched.h", "regex.h", "pwd.h", "pthread.h",
10 "poll.h", "nl_types.h", "ndbm.h", "mqueue.h", "monetary.h",
11 "math.h", "locale.h", "libgen.h", "langinfo.h", "iso646.h",
12 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
13 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h", "dirent.h",
14 "ctype.h", "cpio.h", "assert.h", "aio.h");
16 # These are the ISO C9x keywords.
17 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
18 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
19 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
20 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
21 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
23 # Some headers need a bit more attention.
24 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
26 # Make an hash table from this information.
28 $iskeyword{pop (@keywords)} = 1;
47 my($pattern, $string) = @_;
48 my($strlen) = length ($string);
51 if (substr ($pattern, 0, 1) eq '*') {
52 my($patlen) = length ($pattern) - 1;
53 $res = ($strlen >= $patlen
54 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
55 } elsif (substr ($pattern, -1, 1) eq '*') {
56 my($patlen) = length ($pattern) - 1;
57 $res = ($strlen >= $patlen
58 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
60 $res = $pattern eq $string;
68 my($fnamebase, $msg, $errmsg, $skip) = @_;
79 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
83 printf (" $errmsg Compiler message:\n");
90 if ($verbose > 1 && -s "$fnamebase.out") {
91 # We print all warnings issued.
96 printf (" " . "-" x 71 . "\n");
97 open (MESSAGE, "< $fnamebase.out");
102 printf (" " . "-" x 71 . "\n");
105 unlink "$fnamebase.c";
106 unlink "$fnamebase.o";
107 unlink "$fnamebase.out";
115 my($fnamebase, $msg, $errmsg, $skip) = @_;
126 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
130 printf (" $errmsg Compiler message:\n");
136 # Now run the program. If the exit code is not zero something is wrong.
137 $result = system "$fnamebase > $fnamebase.out2 2>&1";
140 if ($verbose > 1 && -s "$fnamebase.out") {
141 # We print all warnings issued.
143 system "cat $fnamebase.out2 >> $fnamebase.out";
148 unlink "$fnamebase.out";
149 rename "$fnamebase.out2", "$fnamebase.out";
152 if ($printlog != 0) {
153 printf (" " . "-" x 71 . "\n");
154 open (MESSAGE, "< $fnamebase.out");
159 printf (" " . "-" x 71 . "\n");
163 unlink "$fnamebase.c";
164 unlink "$fnamebase.o";
165 unlink "$fnamebase.out";
166 unlink "$fnamebase.out2";
173 my($token, $nerrors, @allow) = @_;
176 if ($token =~ /^[0-9_]/ || $iskeyword{$token}) {
180 for ($idx = 0; $idx <= $#allow; ++$idx) {
181 if (poorfnmatch ($allow[$idx], $token)) {
188 printf ("FAIL\n " . "-" x 72 . "\n");
190 printf (" Namespace violation: \"%s\"\n", $token);
196 my($h, $fnamebase, @allow) = @_;
201 # Generate a program to get the contents of this header.
202 open (TESTFILE, ">$fnamebase.c");
203 print TESTFILE "#include <$h>\n";
206 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
209 if (/^#define (.*)/) {
210 $nerrors = newtoken ($1, $nerrors, @allow);
212 # We have to tokenize the line.
215 my($len) = length ($str);
217 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
219 $nerrors = newtoken ($token, $nerrors, @allow);
225 unlink "$fnamebase.c";
227 printf (" " . "-" x 72 . "\n");
235 while ($#headers >= 0) {
236 my($h) = pop (@headers);
237 my($fnamebase) = "$tmpdir/$h-test";
240 my($prepend) = $mustprepend{$h};
242 printf ("Testing <$h>\n");
243 printf ("----------" . "-" x length ($h) . "\n");
245 # Generate a program to test for the availability of this header.
246 open (TESTFILE, ">$fnamebase.c");
247 print TESTFILE "$prepend";
248 print TESTFILE "#include <$h>\n";
251 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
252 "Header <$h> not available", 0);
256 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
257 control: while (<CONTROL>) {
259 next control if (/^#/);
260 next control if (/^[ ]*$/);
262 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
263 my($struct) = "$2$3";
269 # Remember that this name is allowed.
270 push @allow, $member;
272 # Generate a program to test for the availability of this member.
273 open (TESTFILE, ">$fnamebase.c");
274 print TESTFILE "$prepend";
275 print TESTFILE "#include <$h>\n";
276 print TESTFILE "$struct a;\n";
277 print TESTFILE "$struct b;\n";
278 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
279 print TESTFILE "void foobarbaz (void) {\n";
280 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
281 print TESTFILE "}\n";
284 $res = compiletest ($fnamebase, "Testing for member $member",
285 "Member \"$member\" not available.", $res);
288 # Test the types of the members.
289 open (TESTFILE, ">$fnamebase.c");
290 print TESTFILE "$prepend";
291 print TESTFILE "#include <$h>\n";
292 print TESTFILE "$struct a;\n";
293 print TESTFILE "extern $type b$rest;\n";
294 print TESTFILE "extern __typeof__ (a.$member) b;\n";
297 compiletest ($fnamebase, "Testing for type of member $member",
298 "Member \"$member\" does not have the correct type.", $res);
299 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
304 # Remember that this name is allowed.
307 # Generate a program to test for the availability of this constant.
308 open (TESTFILE, ">$fnamebase.c");
309 print TESTFILE "$prepend";
310 print TESTFILE "#include <$h>\n";
311 print TESTFILE "__typeof__ ($const) a = $const;\n";
314 $res = compiletest ($fnamebase, "Testing for constant $const",
315 "Constant \"$const\" not available.", $res);
318 # Generate a program to test for the value of this constant.
319 open (TESTFILE, ">$fnamebase.c");
320 print TESTFILE "$prepend";
321 print TESTFILE "#include <$h>\n";
322 print TESTFILE "int main (void) { return $const != $value; }\n";
325 $res = runtest ($fnamebase, "Testing for value of constant $const",
326 "Constant \"$const\" has not the right value.", $res);
328 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
334 # Remember that this name is allowed.
337 # Generate a program to test for the availability of this constant.
338 open (TESTFILE, ">$fnamebase.c");
339 print TESTFILE "$prepend";
340 print TESTFILE "#include <$h>\n";
341 print TESTFILE "__typeof__ ($const) a = $const;\n";
344 $res = compiletest ($fnamebase, "Testing for constant $const",
345 "Constant \"$const\" not available.", $res);
347 # Test the types of the members.
348 open (TESTFILE, ">$fnamebase.c");
349 print TESTFILE "$prepend";
350 print TESTFILE "#include <$h>\n";
351 print TESTFILE "__typeof__ (($type) 0) a;\n";
352 print TESTFILE "extern __typeof__ ($const) a;\n";
355 compiletest ($fnamebase, "Testing for type of constant $const",
356 "Constant \"$const\" does not have the correct type.",
360 # Generate a program to test for the value of this constant.
361 open (TESTFILE, ">$fnamebase.c");
362 print TESTFILE "$prepend";
363 print TESTFILE "#include <$h>\n";
364 print TESTFILE "int main (void) { return $const != $value; }\n";
367 $res = runtest ($fnamebase, "Testing for value of constant $const",
368 "Constant \"$const\" has not the right value.", $res);
370 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
373 # Remember that this name is allowed.
374 if ($type =~ /^struct *(.*)/) {
376 } elsif ($type =~ /^union *(.*)/) {
382 # Remember that this name is allowed.
385 # Generate a program to test for the availability of this constant.
386 open (TESTFILE, ">$fnamebase.c");
387 print TESTFILE "$prepend";
388 print TESTFILE "#include <$h>\n";
389 print TESTFILE "$type *a;\n";
392 compiletest ($fnamebase, "Testing for type $type",
393 "Type \"$type\" not available.", $missing);
394 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
395 my($rettype) = "$2$3";
400 # Remember that this name is allowed.
403 # Generate a program to test for availability of this function.
404 open (TESTFILE, ">$fnamebase.c");
405 print TESTFILE "$prepend";
406 print TESTFILE "#include <$h>\n";
407 # print TESTFILE "#undef $fname\n";
408 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
411 $res = compiletest ($fnamebase, "Test availability of function $fname",
412 "Function \"$fname\" is not available.", $res);
414 # Generate a program to test for the type of this function.
415 open (TESTFILE, ">$fnamebase.c");
416 print TESTFILE "$prepend";
417 print TESTFILE "#include <$h>\n";
418 # print TESTFILE "#undef $fname\n";
419 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
420 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
423 compiletest ($fnamebase, "Test for type of function $fname",
424 "Function \"$fname\" has incorrect type.", $res);
425 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
426 my($rettype) = "$2$3";
431 # Remember that this name is allowed.
434 # Generate a program to test for availability of this function.
435 open (TESTFILE, ">$fnamebase.c");
436 print TESTFILE "$prepend";
437 print TESTFILE "#include <$h>\n";
438 # print TESTFILE "#undef $fname\n";
439 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
442 $res = compiletest ($fnamebase, "Test availability of function $fname",
443 "Function \"$fname\" is not available.", $res);
445 # Generate a program to test for the type of this function.
446 open (TESTFILE, ">$fnamebase.c");
447 print TESTFILE "$prepend";
448 print TESTFILE "#include <$h>\n";
449 # print TESTFILE "#undef $fname\n";
450 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
451 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
454 compiletest ($fnamebase, "Test for type of function $fname",
455 "Function \"$fname\" has incorrect type.", $res);
456 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
461 # Remember that this name is allowed.
464 # Generate a program to test for availability of this function.
465 open (TESTFILE, ">$fnamebase.c");
466 print TESTFILE "$prepend";
467 print TESTFILE "#include <$h>\n";
468 # print TESTFILE "#undef $fname\n";
469 print TESTFILE "$type *foobarbaz = &$vname;\n";
472 $res = compiletest ($fnamebase, "Test availability of variable $vname",
473 "Variable \"$vname\" is not available.", $res);
475 # Generate a program to test for the type of this function.
476 open (TESTFILE, ">$fnamebase.c");
477 print TESTFILE "$prepend";
478 print TESTFILE "#include <$h>\n";
479 # print TESTFILE "#undef $fname\n";
480 print TESTFILE "extern $type $vname;\n";
483 compiletest ($fnamebase, "Test for type of variable $fname",
484 "Variable \"$vname\" has incorrect type.", $res);
485 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
486 my($rettype) = "$2$3";
491 # Remember that this name is allowed.
494 # Generate a program to test for availability of this function.
495 open (TESTFILE, ">$fnamebase.c");
496 print TESTFILE "$prepend";
497 print TESTFILE "#include <$h>\n";
498 print TESTFILE "#ifndef $fname\n";
499 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
500 print TESTFILE "#endif\n";
503 $res = compiletest ($fnamebase, "Test availability of function $fname",
504 "Function \"$fname\" is not available.", $res);
506 # Generate a program to test for the type of this function.
507 open (TESTFILE, ">$fnamebase.c");
508 print TESTFILE "$prepend";
509 print TESTFILE "#include <$h>\n";
510 print TESTFILE "#ifndef $fname\n";
511 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
512 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
513 print TESTFILE "#endif\n";
516 compiletest ($fnamebase, "Test for type of function $fname",
517 "Function \"$fname\" has incorrect type.", $res);
518 } elsif (/^macro *([^ ]*)/) {
521 # Remember that this name is allowed.
524 # Generate a program to test for availability of this macro.
525 open (TESTFILE, ">$fnamebase.c");
526 print TESTFILE "$prepend";
527 print TESTFILE "#include <$h>\n";
528 print TESTFILE "#ifndef $macro\n";
529 print TESTFILE "# error \"Macro $macro not defined\"\n";
530 print TESTFILE "#endif\n";
533 compiletest ($fnamebase, "Test availability of macro $macro",
534 "Macro \"$macro\" is not available.", $missing);
535 } elsif (/^allow *(.*)/) {
537 push @allow, $pattern;
540 # printf ("line is `%s'\n", $_);
548 # Now check the namespace.
549 printf (" Checking the namespace of \"%s\"... ", $h);
554 checknamespace ($h, $fnamebase, @allow);
560 printf "-" x 76 . "\n";
561 printf (" Total number of tests : %4d\n", $total);
562 printf (" Number of failed tests : %4d (%3d%%)\n", $errors, ($errors * 100) / $total);
563 printf (" Number of skipped tests: %4d (%3d%%)\n", $skipped, ($skipped * 100) / $total);