4 $CFLAGS = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
6 # List of the headers we are testing.
7 @headers = ("sys/msg.h", "sys/mman.h", "sys/ipc.h", "syslog.h",
8 "stropts.h", "strings.h", "string.h", "stdlib.h", "stdio.h",
9 "stddef.h", "stdarg.h", "signal.h", "setjmp.h", "semaphore.h",
10 "search.h", "sched.h", "regex.h", "pwd.h", "pthread.h",
11 "poll.h", "nl_types.h", "ndbm.h", "mqueue.h", "monetary.h",
12 "math.h", "locale.h", "libgen.h", "langinfo.h", "iso646.h",
13 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
14 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h", "dirent.h",
15 "ctype.h", "cpio.h", "assert.h", "aio.h");
17 # These are the ISO C99 keywords.
18 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
19 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
20 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
21 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
22 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
24 # Some headers need a bit more attention.
25 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
27 # Make an hash table from this information.
29 $iskeyword{pop (@keywords)} = 1;
48 my($pattern, $string) = @_;
49 my($strlen) = length ($string);
52 if (substr ($pattern, 0, 1) eq '*') {
53 my($patlen) = length ($pattern) - 1;
54 $res = ($strlen >= $patlen
55 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
56 } elsif (substr ($pattern, -1, 1) eq '*') {
57 my($patlen) = length ($pattern) - 1;
58 $res = ($strlen >= $patlen
59 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
61 $res = $pattern eq $string;
69 my($fnamebase, $msg, $errmsg, $skip) = @_;
80 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
84 printf (" $errmsg Compiler message:\n");
91 if ($verbose > 1 && -s "$fnamebase.out") {
92 # We print all warnings issued.
97 printf (" " . "-" x 71 . "\n");
98 open (MESSAGE, "< $fnamebase.out");
103 printf (" " . "-" x 71 . "\n");
106 unlink "$fnamebase.c";
107 unlink "$fnamebase.o";
108 unlink "$fnamebase.out";
116 my($fnamebase, $msg, $errmsg, $skip) = @_;
127 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
131 printf (" $errmsg Compiler message:\n");
137 # Now run the program. If the exit code is not zero something is wrong.
138 $result = system "$fnamebase > $fnamebase.out2 2>&1";
141 if ($verbose > 1 && -s "$fnamebase.out") {
142 # We print all warnings issued.
144 system "cat $fnamebase.out2 >> $fnamebase.out";
149 unlink "$fnamebase.out";
150 rename "$fnamebase.out2", "$fnamebase.out";
153 if ($printlog != 0) {
154 printf (" " . "-" x 71 . "\n");
155 open (MESSAGE, "< $fnamebase.out");
160 printf (" " . "-" x 71 . "\n");
164 unlink "$fnamebase.c";
165 unlink "$fnamebase.o";
166 unlink "$fnamebase.out";
167 unlink "$fnamebase.out2";
174 my($token, $nerrors, @allow) = @_;
177 if ($token =~ /^[0-9_]/ || $iskeyword{$token}) {
181 for ($idx = 0; $idx <= $#allow; ++$idx) {
182 if (poorfnmatch ($allow[$idx], $token)) {
189 printf ("FAIL\n " . "-" x 72 . "\n");
191 printf (" Namespace violation: \"%s\"\n", $token);
197 my($h, $fnamebase, @allow) = @_;
202 # Generate a program to get the contents of this header.
203 open (TESTFILE, ">$fnamebase.c");
204 print TESTFILE "#include <$h>\n";
207 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
210 if (/^#define (.*)/) {
211 $nerrors = newtoken ($1, $nerrors, @allow);
213 # We have to tokenize the line.
216 my($len) = length ($str);
218 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
220 $nerrors = newtoken ($token, $nerrors, @allow);
226 unlink "$fnamebase.c";
228 printf (" " . "-" x 72 . "\n");
236 while ($#headers >= 0) {
237 my($h) = pop (@headers);
240 my($fnamebase) = "$tmpdir/$hf-test";
243 my($prepend) = $mustprepend{$h};
245 printf ("Testing <$h>\n");
246 printf ("----------" . "-" x length ($h) . "\n");
248 # Generate a program to test for the availability of this header.
249 open (TESTFILE, ">$fnamebase.c");
250 print TESTFILE "$prepend";
251 print TESTFILE "#include <$h>\n";
254 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
255 "Header <$h> not available", 0);
259 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
260 control: while (<CONTROL>) {
262 next control if (/^#/);
263 next control if (/^[ ]*$/);
265 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
266 my($struct) = "$2$3";
272 # Remember that this name is allowed.
273 push @allow, $member;
275 # Generate a program to test for the availability of this member.
276 open (TESTFILE, ">$fnamebase.c");
277 print TESTFILE "$prepend";
278 print TESTFILE "#include <$h>\n";
279 print TESTFILE "$struct a;\n";
280 print TESTFILE "$struct b;\n";
281 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
282 print TESTFILE "void foobarbaz (void) {\n";
283 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
284 print TESTFILE "}\n";
287 $res = compiletest ($fnamebase, "Testing for member $member",
288 "Member \"$member\" not available.", $res);
291 # Test the types of the members.
292 open (TESTFILE, ">$fnamebase.c");
293 print TESTFILE "$prepend";
294 print TESTFILE "#include <$h>\n";
295 print TESTFILE "$struct a;\n";
296 print TESTFILE "extern $type b$rest;\n";
297 print TESTFILE "extern __typeof__ (a.$member) b;\n";
300 compiletest ($fnamebase, "Testing for type of member $member",
301 "Member \"$member\" does not have the correct type.", $res);
302 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
307 # Remember that this name is allowed.
310 # Generate a program to test for the availability of this constant.
311 open (TESTFILE, ">$fnamebase.c");
312 print TESTFILE "$prepend";
313 print TESTFILE "#include <$h>\n";
314 print TESTFILE "__typeof__ ($const) a = $const;\n";
317 $res = compiletest ($fnamebase, "Testing for constant $const",
318 "Constant \"$const\" not available.", $res);
321 # Generate a program to test for the value of this constant.
322 open (TESTFILE, ">$fnamebase.c");
323 print TESTFILE "$prepend";
324 print TESTFILE "#include <$h>\n";
325 print TESTFILE "int main (void) { return $const != $value; }\n";
328 $res = runtest ($fnamebase, "Testing for value of constant $const",
329 "Constant \"$const\" has not the right value.", $res);
331 } elsif (/^typed-constant *([a-zA-Z0-9_]*) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*)?/) {
337 # Remember that this name is allowed.
340 # Generate a program to test for the availability of this constant.
341 open (TESTFILE, ">$fnamebase.c");
342 print TESTFILE "$prepend";
343 print TESTFILE "#include <$h>\n";
344 print TESTFILE "__typeof__ ($const) a = $const;\n";
347 $res = compiletest ($fnamebase, "Testing for constant $const",
348 "Constant \"$const\" not available.", $res);
350 # Test the types of the members.
351 open (TESTFILE, ">$fnamebase.c");
352 print TESTFILE "$prepend";
353 print TESTFILE "#include <$h>\n";
354 print TESTFILE "__typeof__ (($type) 0) a;\n";
355 print TESTFILE "extern __typeof__ ($const) a;\n";
358 compiletest ($fnamebase, "Testing for type of constant $const",
359 "Constant \"$const\" does not have the correct type.",
363 # Generate a program to test for the value of this constant.
364 open (TESTFILE, ">$fnamebase.c");
365 print TESTFILE "$prepend";
366 print TESTFILE "#include <$h>\n";
367 print TESTFILE "int main (void) { return $const != $value; }\n";
370 $res = runtest ($fnamebase, "Testing for value of constant $const",
371 "Constant \"$const\" has not the right value.", $res);
373 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
376 # Remember that this name is allowed.
377 if ($type =~ /^struct *(.*)/) {
379 } elsif ($type =~ /^union *(.*)/) {
385 # Remember that this name is allowed.
388 # Generate a program to test for the availability of this constant.
389 open (TESTFILE, ">$fnamebase.c");
390 print TESTFILE "$prepend";
391 print TESTFILE "#include <$h>\n";
392 print TESTFILE "$type *a;\n";
395 compiletest ($fnamebase, "Testing for type $type",
396 "Type \"$type\" not available.", $missing);
397 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) [(][*]([a-zA-Z0-9_]*) ([(].*[)])/) {
398 my($rettype) = "$2$3";
403 # Remember that this name is allowed.
406 # Generate a program to test for availability of this function.
407 open (TESTFILE, ">$fnamebase.c");
408 print TESTFILE "$prepend";
409 print TESTFILE "#include <$h>\n";
410 # print TESTFILE "#undef $fname\n";
411 print TESTFILE "$rettype (*(*foobarbaz) $args = $fname;\n";
414 $res = compiletest ($fnamebase, "Test availability of function $fname",
415 "Function \"$fname\" is not available.", $res);
417 # Generate a program to test for the type of this function.
418 open (TESTFILE, ">$fnamebase.c");
419 print TESTFILE "$prepend";
420 print TESTFILE "#include <$h>\n";
421 # print TESTFILE "#undef $fname\n";
422 print TESTFILE "extern $rettype (*(*foobarbaz) $args;\n";
423 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
426 compiletest ($fnamebase, "Test for type of function $fname",
427 "Function \"$fname\" has incorrect type.", $res);
428 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
429 my($rettype) = "$2$3";
434 # Remember that this name is allowed.
437 # Generate a program to test for availability of this function.
438 open (TESTFILE, ">$fnamebase.c");
439 print TESTFILE "$prepend";
440 print TESTFILE "#include <$h>\n";
441 # print TESTFILE "#undef $fname\n";
442 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
445 $res = compiletest ($fnamebase, "Test availability of function $fname",
446 "Function \"$fname\" is not available.", $res);
448 # Generate a program to test for the type of this function.
449 open (TESTFILE, ">$fnamebase.c");
450 print TESTFILE "$prepend";
451 print TESTFILE "#include <$h>\n";
452 # print TESTFILE "#undef $fname\n";
453 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
454 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
457 compiletest ($fnamebase, "Test for type of function $fname",
458 "Function \"$fname\" has incorrect type.", $res);
459 } elsif (/^variable *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*)/) {
464 # Remember that this name is allowed.
467 # Generate a program to test for availability of this function.
468 open (TESTFILE, ">$fnamebase.c");
469 print TESTFILE "$prepend";
470 print TESTFILE "#include <$h>\n";
471 # print TESTFILE "#undef $fname\n";
472 print TESTFILE "$type *foobarbaz = &$vname;\n";
475 $res = compiletest ($fnamebase, "Test availability of variable $vname",
476 "Variable \"$vname\" is not available.", $res);
478 # Generate a program to test for the type of this function.
479 open (TESTFILE, ">$fnamebase.c");
480 print TESTFILE "$prepend";
481 print TESTFILE "#include <$h>\n";
482 # print TESTFILE "#undef $fname\n";
483 print TESTFILE "extern $type $vname;\n";
486 compiletest ($fnamebase, "Test for type of variable $fname",
487 "Variable \"$vname\" has incorrect type.", $res);
488 } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) {
489 my($rettype) = "$2$3";
494 # Remember that this name is allowed.
497 # Generate a program to test for availability of this function.
498 open (TESTFILE, ">$fnamebase.c");
499 print TESTFILE "$prepend";
500 print TESTFILE "#include <$h>\n";
501 print TESTFILE "#ifndef $fname\n";
502 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
503 print TESTFILE "#endif\n";
506 $res = compiletest ($fnamebase, "Test availability of function $fname",
507 "Function \"$fname\" is not available.", $res);
509 # Generate a program to test for the type of this function.
510 open (TESTFILE, ">$fnamebase.c");
511 print TESTFILE "$prepend";
512 print TESTFILE "#include <$h>\n";
513 print TESTFILE "#ifndef $fname\n";
514 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
515 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
516 print TESTFILE "#endif\n";
519 compiletest ($fnamebase, "Test for type of function $fname",
520 "Function \"$fname\" has incorrect type.", $res);
521 } elsif (/^macro *([^ ]*)/) {
524 # Remember that this name is allowed.
527 # Generate a program to test for availability of this macro.
528 open (TESTFILE, ">$fnamebase.c");
529 print TESTFILE "$prepend";
530 print TESTFILE "#include <$h>\n";
531 print TESTFILE "#ifndef $macro\n";
532 print TESTFILE "# error \"Macro $macro not defined\"\n";
533 print TESTFILE "#endif\n";
536 compiletest ($fnamebase, "Test availability of macro $macro",
537 "Macro \"$macro\" is not available.", $missing);
538 } elsif (/^allow *(.*)/) {
540 push @allow, $pattern;
543 # printf ("line is `%s'\n", $_);
551 # Now check the namespace.
552 printf (" Checking the namespace of \"%s\"... ", $h);
557 checknamespace ($h, $fnamebase, @allow);
563 printf "-" x 76 . "\n";
564 printf (" Total number of tests : %4d\n", $total);
565 printf (" Number of failed tests : %4d (%3d%%)\n", $errors, ($errors * 100) / $total);
566 printf (" Number of skipped tests: %4d (%3d%%)\n", $skipped, ($skipped * 100) / $total);