4 $CFLAGS = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
6 # List of the headers we are testing.
7 @headers = ("search.h", "sched.h", "regex.h", "pwd.h", "pthread.h",
8 "poll.h", "nl_types.h", "ndbm.h", "mqueue.h", "monetary.h",
9 "math.h", "locale.h", "libgen.h", "langinfo.h", "iso646.h",
10 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
11 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h", "dirent.h",
12 "ctype.h", "cpio.h", "assert.h", "aio.h");
14 # These are the ISO C9x keywords.
15 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
16 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
17 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
18 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
19 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
21 # Some headers need a bit more attention.
22 $mustprepend{'regex.h'} = "#include <sys/types.h>\n";
24 # Make an hash table from this information.
26 $iskeyword{pop (@keywords)} = 1;
45 my($pattern, $string) = @_;
46 my($strlen) = length ($string);
49 if (substr ($pattern, 0, 1) eq '*') {
50 my($patlen) = length ($pattern) - 1;
51 $res = ($strlen >= $patlen
52 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
53 } elsif (substr ($pattern, -1, 1) eq '*') {
54 my($patlen) = length ($pattern) - 1;
55 $res = ($strlen >= $patlen
56 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
58 $res = $pattern eq $string;
66 my($fnamebase, $msg, $errmsg, $skip) = @_;
77 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
81 printf (" $errmsg Compiler message:\n");
88 if ($verbose > 1 && -s
"$fnamebase.out") {
89 # We print all warnings issued.
94 printf (" " . "-" x
71 . "\n");
95 open (MESSAGE
, "< $fnamebase.out");
100 printf (" " . "-" x
71 . "\n");
103 unlink "$fnamebase.c";
104 unlink "$fnamebase.o";
105 unlink "$fnamebase.out";
113 my($fnamebase, $msg, $errmsg, $skip) = @_;
124 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
128 printf (" $errmsg Compiler message:\n");
134 # Now run the program. If the exit code is not zero something is wrong.
135 $result = system "$fnamebase > $fnamebase.out2 2>&1";
138 if ($verbose > 1 && -s
"$fnamebase.out") {
139 # We print all warnings issued.
141 system "cat $fnamebase.out2 >> $fnamebase.out";
146 unlink "$fnamebase.out";
147 rename "$fnamebase.out2", "$fnamebase.out";
150 if ($printlog != 0) {
151 printf (" " . "-" x
71 . "\n");
152 open (MESSAGE
, "< $fnamebase.out");
157 printf (" " . "-" x
71 . "\n");
161 unlink "$fnamebase.c";
162 unlink "$fnamebase.o";
163 unlink "$fnamebase.out";
164 unlink "$fnamebase.out2";
171 my($token, $nerrors, @allow) = @_;
174 for ($idx = 0; $idx <= $#allow; ++$idx) {
175 if ($token =~ /^[0-9_]/ || $iskeyword{$token} || poorfnmatch
($allow[$idx], $token)) {
182 printf ("FAIL\n " . "-" x
72 . "\n");
184 printf (" Namespace violation: \"%s\"\n", $token);
190 my($h, $fnamebase, @allow) = @_;
195 # Generate a program to get the contents of this header.
196 open (TESTFILE
, ">$fnamebase.c");
197 print TESTFILE
"#include <$h>\n";
200 open (CONTENT
, "$CC $CFLAGS -E $fnamebase.c -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
203 if (/^#define (.*)/) {
204 $nerrors = newtoken
($1, $nerrors, @allow);
206 # We have to tokenize the line.
209 my($len) = length ($str);
211 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
213 $nerrors = newtoken
($token, $nerrors, @allow);
219 unlink "$fnamebase.c";
221 printf (" " . "-" x
72 . "\n");
229 while ($#headers >= 0) {
230 my($h) = pop (@headers);
231 my($fnamebase) = "$tmpdir/$h-test";
234 my($prepend) = $mustprepend{$h};
236 printf ("Testing <$h>\n");
237 printf ("----------" . "-" x
length ($h) . "\n");
239 # Generate a program to test for the availability of this header.
240 open (TESTFILE
, ">$fnamebase.c");
241 print TESTFILE
"$prepend";
242 print TESTFILE
"#include <$h>\n";
245 $missing = compiletest
($fnamebase, "Checking whether <$h> is available",
246 "Header <$h> not available", 0);
250 open (CONTROL
, "$CC -E -D$dialect - < data/$h-data |");
251 control
: while (<CONTROL
>) {
253 next control
if (/^#/);
254 next control
if (/^[ ]*$/);
256 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
257 my($struct) = "$2$3";
263 # Remember that this name is allowed.
264 push @allow, $member;
266 # Generate a program to test for the availability of this member.
267 open (TESTFILE
, ">$fnamebase.c");
268 print TESTFILE
"$prepend";
269 print TESTFILE
"#include <$h>\n";
270 print TESTFILE
"$struct a;\n";
271 print TESTFILE
"$struct b;\n";
272 print TESTFILE
"extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
273 print TESTFILE
"void foobarbaz (void) {\n";
274 print TESTFILE
" xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
275 print TESTFILE
"}\n";
278 $res = compiletest
($fnamebase, "Testing for member $member",
279 "Member \"$member\" not available.", $res);
282 # Test the types of the members.
283 open (TESTFILE
, ">$fnamebase.c");
284 print TESTFILE
"$prepend";
285 print TESTFILE
"#include <$h>\n";
286 print TESTFILE
"$struct a;\n";
287 print TESTFILE
"extern $type b$rest;\n";
288 print TESTFILE
"extern __typeof__ (a.$member) b;\n";
291 compiletest
($fnamebase, "Testing for type of member $member",
292 "Member \"$member\" does not have the correct type.", $res);
293 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
298 # Remember that this name is allowed.
301 # Generate a program to test for the availability of this constant.
302 open (TESTFILE
, ">$fnamebase.c");
303 print TESTFILE
"$prepend";
304 print TESTFILE
"#include <$h>\n";
305 print TESTFILE
"__typeof__ ($const) a = $const;\n";
308 $res = compiletest
($fnamebase, "Testing for constant $const",
309 "Constant \"$const\" not available.", $res);
312 # Generate a program to test for the value of this constant.
313 open (TESTFILE
, ">$fnamebase.c");
314 print TESTFILE
"$prepend";
315 print TESTFILE
"#include <$h>\n";
316 print TESTFILE
"int main (void) { return $const != $value; }\n";
319 $res = runtest
($fnamebase, "Testing for value of constant $const",
320 "Constant \"$const\" has not the right value.", $res);
322 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
325 # Remember that this name is allowed.
326 if ($type =~ /^struct *(.*)/) {
328 } elsif ($type =~ /^union *(.*)/) {
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
"$type *a;\n";
344 compiletest
($fnamebase, "Testing for type $type",
345 "Type \"$type\" not available.", $missing);
346 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(][^)]*[)])/) {
347 my($rettype) = "$2$3";
352 # Remember that this name is allowed.
355 # Generate a program to test for availability of this function.
356 open (TESTFILE
, ">$fnamebase.c");
357 print TESTFILE
"$prepend";
358 print TESTFILE
"#include <$h>\n";
359 # print TESTFILE "#undef $fname\n";
360 print TESTFILE
"$rettype (*foobarbaz) $args = $fname;\n";
363 $res = compiletest
($fnamebase, "Test availability of function $fname",
364 "Function \"$fname\" is not available.", $res);
366 # Generate a program to test for the type of this function.
367 open (TESTFILE
, ">$fnamebase.c");
368 print TESTFILE
"$prepend";
369 print TESTFILE
"#include <$h>\n";
370 # print TESTFILE "#undef $fname\n";
371 print TESTFILE
"extern $rettype (*foobarbaz) $args;\n";
372 print TESTFILE
"extern __typeof__ (&$fname) foobarbaz;\n";
375 compiletest
($fnamebase, "Test for type of function $fname",
376 "Function \"$fname\" has incorrect type.", $res);
377 } elsif (/^macro *([^ ]*)/) {
380 # Remember that this name is allowed.
383 # Generate a program to test for availability of this macro.
384 open (TESTFILE
, ">$fnamebase.c");
385 print TESTFILE
"$prepend";
386 print TESTFILE
"#include <$h>\n";
387 print TESTFILE
"#ifndef $macro\n";
388 print TESTFILE
"# error \"Macro $macro not defined\"\n";
389 print TESTFILE
"#endif\n";
392 compiletest
($fnamebase, "Test availability of macro $macro",
393 "Macro \"$macro\" is not available.", $missing);
394 } elsif (/^allow *(.*)/) {
396 push @allow, $pattern;
399 # printf ("line is `%s'\n", $_);
407 # Now check the namespace.
408 printf (" Checking the namespace of \"%s\"... ", $h);
413 checknamespace
($h, $fnamebase, @allow);
419 printf "-" x
76 . "\n";
420 printf (" Total number of tests : %4d\n", $total);
421 printf (" Number of failed tests : %4d (%3d%%)\n", $errors, ($errors * 100) / $total);
422 printf (" Number of skipped tests: %4d (%3d%%)\n", $skipped, ($skipped * 100) / $total);