4 $CFLAGS = "-I. '-D__attribute__(x)=' -D_XOPEN_SOURCE=500";
6 # List of the headers we are testing.
7 @headers = ("poll.h", "nl_types.h", "ndbm.h", "mqueue.h", "monetary.h",
8 "math.h", "locale.h", "libgen.h", "langinfo.h", "iso646.h",
9 "inttypes.h", "iconv.h", "grp.h", "glob.h", "ftw.h", "fnmatch.h",
10 "fmtmsg.h", "float.h", "fcntl.h", "errno.h", "dlfcn.h", "dirent.h",
11 "ctype.h", "cpio.h", "assert.h", "aio.h");
13 # These are the ISO C9x keywords.
14 @keywords = ('auto', 'break', 'case', 'char', 'const', 'continue', 'default',
15 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
16 'if', 'inline', 'int', 'long', 'register', 'restrict', 'return',
17 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
18 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while');
20 # Make an hash table from this information.
22 $iskeyword{pop (@keywords)} = 1;
41 my($pattern, $string) = @_;
42 my($strlen) = length ($string);
45 if (substr ($pattern, 0, 1) eq '*') {
46 my($patlen) = length ($pattern) - 1;
47 $res = ($strlen >= $patlen
48 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
49 } elsif (substr ($pattern, -1, 1) eq '*') {
50 my($patlen) = length ($pattern) - 1;
51 $res = ($strlen >= $patlen
52 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
54 $res = $pattern eq $string;
62 my($fnamebase, $msg, $errmsg, $skip) = @_;
73 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
77 printf (" $errmsg Compiler message:\n");
84 if ($verbose > 1 && -s "$fnamebase.out") {
85 # We print all warnings issued.
90 printf (" " . "-" x 71 . "\n");
91 open (MESSAGE, "< $fnamebase.out");
96 printf (" " . "-" x 71 . "\n");
99 unlink "$fnamebase.c";
100 unlink "$fnamebase.o";
101 unlink "$fnamebase.out";
109 my($fnamebase, $msg, $errmsg, $skip) = @_;
120 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
124 printf (" $errmsg Compiler message:\n");
130 # Now run the program. If the exit code is not zero something is wrong.
131 $result = system "$fnamebase > $fnamebase.out2 2>&1";
134 if ($verbose > 1 && -s "$fnamebase.out") {
135 # We print all warnings issued.
137 system "cat $fnamebase.out2 >> $fnamebase.out";
142 unlink "$fnamebase.out";
143 rename "$fnamebase.out2", "$fnamebase.out";
146 if ($printlog != 0) {
147 printf (" " . "-" x 71 . "\n");
148 open (MESSAGE, "< $fnamebase.out");
153 printf (" " . "-" x 71 . "\n");
157 unlink "$fnamebase.c";
158 unlink "$fnamebase.o";
159 unlink "$fnamebase.out";
160 unlink "$fnamebase.out2";
167 my($token, $nerrors, @allow) = @_;
170 for ($idx = 0; $idx <= $#allow; ++$idx) {
171 if ($token =~ /^[0-9_]/ || $iskeyword{$token} || poorfnmatch ($allow[$idx], $token)) {
178 printf ("FAIL\n " . "-" x 72 . "\n");
180 printf (" Namespace violation: \"%s\"\n", $token);
186 my($h, $fnamebase, @allow) = @_;
191 # Generate a program to get the contents of this header.
192 open (TESTFILE, ">$fnamebase.c");
193 print TESTFILE "#include <$h>\n";
196 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
199 if (/^#define (.*)/) {
200 $nerrors = newtoken ($1, $nerrors, @allow);
202 # We have to tokenize the line.
205 my($len) = length ($str);
207 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
209 $nerrors = newtoken ($token, $nerrors, @allow);
215 unlink "$fnamebase.c";
217 printf (" " . "-" x 72 . "\n");
225 while ($#headers >= 0) {
226 my($h) = pop (@headers);
227 my($fnamebase) = "$tmpdir/$h-test";
231 printf ("Testing <$h>\n");
232 printf ("----------" . "-" x length ($h) . "\n");
234 # Generate a program to test for the availability of this header.
235 open (TESTFILE, ">$fnamebase.c");
236 print TESTFILE "#include <$h>\n";
239 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
240 "Header <$h> not available", 0);
244 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
245 control: while (<CONTROL>) {
247 next control if (/^#/);
248 next control if (/^[ ]*$/);
250 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
251 my($struct) = "$2$3";
257 # Remember that this name is allowed.
258 push @allow, $member;
260 # Generate a program to test for the availability of this member.
261 open (TESTFILE, ">$fnamebase.c");
262 print TESTFILE "#include <$h>\n";
263 print TESTFILE "$struct a;\n";
264 print TESTFILE "$struct b;\n";
265 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
266 print TESTFILE "void foobarbaz (void) {\n";
267 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
268 print TESTFILE "}\n";
271 $res = compiletest ($fnamebase, "Testing for member $member",
272 "Member \"$member\" not available.", $res);
275 # Test the types of the members.
276 open (TESTFILE, ">$fnamebase.c");
277 print TESTFILE "#include <$h>\n";
278 print TESTFILE "$struct a;\n";
279 print TESTFILE "extern $type b$rest;\n";
280 print TESTFILE "extern __typeof__ (a.$member) b;\n";
283 compiletest ($fnamebase, "Testing for type of member $member",
284 "Member \"$member\" does not have the correct type.", $res);
285 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
290 # Remember that this name is allowed.
293 # Generate a program to test for the availability of this constant.
294 open (TESTFILE, ">$fnamebase.c");
295 print TESTFILE "#include <$h>\n";
296 print TESTFILE "__typeof__ ($const) a = $const;\n";
299 $res = compiletest ($fnamebase, "Testing for constant $const",
300 "Constant \"$const\" not available.", $res);
303 # Generate a program to test for the value of this constant.
304 open (TESTFILE, ">$fnamebase.c");
305 print TESTFILE "#include <$h>\n";
306 print TESTFILE "int main (void) { return $const != $value; }\n";
309 $res = runtest ($fnamebase, "Testing for value of constant $const",
310 "Constant \"$const\" has not the right value.", $res);
312 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
315 # Remember that this name is allowed.
316 if ($type =~ /^struct *(.*)/) {
318 } elsif ($type =~ /^union *(.*)/) {
324 # Remember that this name is allowed.
327 # Generate a program to test for the availability of this constant.
328 open (TESTFILE, ">$fnamebase.c");
329 print TESTFILE "#include <$h>\n";
330 print TESTFILE "$type *a;\n";
333 compiletest ($fnamebase, "Testing for type $type",
334 "Type \"$type\" not available.", $missing);
335 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(][^)]*[)])/) {
336 my($rettype) = "$2$3";
341 # Remember that this name is allowed.
344 # Generate a program to test for availability of this function.
345 open (TESTFILE, ">$fnamebase.c");
346 print TESTFILE "#include <$h>\n";
347 # print TESTFILE "#undef $fname\n";
348 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
351 $res = compiletest ($fnamebase, "Test availability of function $fname",
352 "Function \"$fname\" is not available.", $res);
354 # Generate a program to test for the type of this function.
355 open (TESTFILE, ">$fnamebase.c");
356 print TESTFILE "#include <$h>\n";
357 # print TESTFILE "#undef $fname\n";
358 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
359 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
362 compiletest ($fnamebase, "Test for type of function $fname",
363 "Function \"$fname\" has incorrect type.", $res);
364 } elsif (/^macro *([^ ]*)/) {
367 # Remember that this name is allowed.
370 # Generate a program to test for availability of this macro.
371 open (TESTFILE, ">$fnamebase.c");
372 print TESTFILE "#include <$h>\n";
373 print TESTFILE "#ifndef $macro\n";
374 print TESTFILE "# error \"Macro $macro not defined\"\n";
375 print TESTFILE "#endif\n";
378 compiletest ($fnamebase, "Test availability of macro $macro",
379 "Macro \"$macro\" is not available.", $missing);
380 } elsif (/^allow *(.*)/) {
382 push @allow, $pattern;
385 # printf ("line is `%s'\n", $_);
393 # Now check the namespace.
394 printf (" Checking the namespace of \"%s\"... ", $h);
399 checknamespace ($h, $fnamebase, @allow);
405 printf "-" x 76 . "\n";
406 printf (" Total number of tests : %4d\n", $total);
407 printf (" Number of failed tests : %4d (%3d%%)\n", $errors, ($errors * 100) / $total);
408 printf (" Number of skipped tests: %4d (%3d%%)\n", $skipped, ($skipped * 100) / $total);