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 # Make an hash table from this information.
23 $iskeyword{pop (@keywords)} = 1;
42 my($pattern, $string) = @_;
43 my($strlen) = length ($string);
46 if (substr ($pattern, 0, 1) eq '*') {
47 my($patlen) = length ($pattern) - 1;
48 $res = ($strlen >= $patlen
49 && substr ($pattern, -$patlen, $patlen) eq substr ($string, -$patlen, $patlen));
50 } elsif (substr ($pattern, -1, 1) eq '*') {
51 my($patlen) = length ($pattern) - 1;
52 $res = ($strlen >= $patlen
53 && substr ($pattern, 0, $patlen) eq substr ($string, 0, $patlen));
55 $res = $pattern eq $string;
63 my($fnamebase, $msg, $errmsg, $skip) = @_;
74 $ret = system "$CC $CFLAGS -c $fnamebase.c -o $fnamebase.o > $fnamebase.out 2>&1";
78 printf (" $errmsg Compiler message:\n");
85 if ($verbose > 1 && -s "$fnamebase.out") {
86 # We print all warnings issued.
91 printf (" " . "-" x 71 . "\n");
92 open (MESSAGE, "< $fnamebase.out");
97 printf (" " . "-" x 71 . "\n");
100 unlink "$fnamebase.c";
101 unlink "$fnamebase.o";
102 unlink "$fnamebase.out";
110 my($fnamebase, $msg, $errmsg, $skip) = @_;
121 $ret = system "$CC $CFLAGS -o $fnamebase $fnamebase.c > $fnamebase.out 2>&1";
125 printf (" $errmsg Compiler message:\n");
131 # Now run the program. If the exit code is not zero something is wrong.
132 $result = system "$fnamebase > $fnamebase.out2 2>&1";
135 if ($verbose > 1 && -s "$fnamebase.out") {
136 # We print all warnings issued.
138 system "cat $fnamebase.out2 >> $fnamebase.out";
143 unlink "$fnamebase.out";
144 rename "$fnamebase.out2", "$fnamebase.out";
147 if ($printlog != 0) {
148 printf (" " . "-" x 71 . "\n");
149 open (MESSAGE, "< $fnamebase.out");
154 printf (" " . "-" x 71 . "\n");
158 unlink "$fnamebase.c";
159 unlink "$fnamebase.o";
160 unlink "$fnamebase.out";
161 unlink "$fnamebase.out2";
168 my($token, $nerrors, @allow) = @_;
171 for ($idx = 0; $idx <= $#allow; ++$idx) {
172 if ($token =~ /^[0-9_]/ || $iskeyword{$token} || poorfnmatch ($allow[$idx], $token)) {
179 printf ("FAIL\n " . "-" x 72 . "\n");
181 printf (" Namespace violation: \"%s\"\n", $token);
187 my($h, $fnamebase, @allow) = @_;
192 # Generate a program to get the contents of this header.
193 open (TESTFILE, ">$fnamebase.c");
194 print TESTFILE "#include <$h>\n";
197 open (CONTENT, "$CC $CFLAGS -E $fnamebase.c -Wp,-dN | sed -e '/^# [1-9]/d' -e '/^[[:space:]]*\$/d' |");
200 if (/^#define (.*)/) {
201 $nerrors = newtoken ($1, $nerrors, @allow);
203 # We have to tokenize the line.
206 my($len) = length ($str);
208 foreach $token (split(/[^a-zA-Z0-9_]/, $str)) {
210 $nerrors = newtoken ($token, $nerrors, @allow);
216 unlink "$fnamebase.c";
218 printf (" " . "-" x 72 . "\n");
226 while ($#headers >= 0) {
227 my($h) = pop (@headers);
228 my($fnamebase) = "$tmpdir/$h-test";
232 printf ("Testing <$h>\n");
233 printf ("----------" . "-" x length ($h) . "\n");
235 # Generate a program to test for the availability of this header.
236 open (TESTFILE, ">$fnamebase.c");
237 print TESTFILE "#include <$h>\n";
240 $missing = compiletest ($fnamebase, "Checking whether <$h> is available",
241 "Header <$h> not available", 0);
245 open (CONTROL, "$CC -E -D$dialect - < data/$h-data |");
246 control: while (<CONTROL>) {
248 next control if (/^#/);
249 next control if (/^[ ]*$/);
251 if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) {
252 my($struct) = "$2$3";
258 # Remember that this name is allowed.
259 push @allow, $member;
261 # Generate a program to test for the availability of this member.
262 open (TESTFILE, ">$fnamebase.c");
263 print TESTFILE "#include <$h>\n";
264 print TESTFILE "$struct a;\n";
265 print TESTFILE "$struct b;\n";
266 print TESTFILE "extern void xyzzy (__typeof__ (&b.$member), __typeof__ (&a.$member), unsigned);\n";
267 print TESTFILE "void foobarbaz (void) {\n";
268 print TESTFILE " xyzzy (&a.$member, &b.$member, sizeof (a.$member));\n";
269 print TESTFILE "}\n";
272 $res = compiletest ($fnamebase, "Testing for member $member",
273 "Member \"$member\" not available.", $res);
276 # Test the types of the members.
277 open (TESTFILE, ">$fnamebase.c");
278 print TESTFILE "#include <$h>\n";
279 print TESTFILE "$struct a;\n";
280 print TESTFILE "extern $type b$rest;\n";
281 print TESTFILE "extern __typeof__ (a.$member) b;\n";
284 compiletest ($fnamebase, "Testing for type of member $member",
285 "Member \"$member\" does not have the correct type.", $res);
286 } elsif (/^constant *([a-zA-Z0-9_]*) *([A-Za-z0-9_]*)?/) {
291 # Remember that this name is allowed.
294 # Generate a program to test for the availability of this constant.
295 open (TESTFILE, ">$fnamebase.c");
296 print TESTFILE "#include <$h>\n";
297 print TESTFILE "__typeof__ ($const) a = $const;\n";
300 $res = compiletest ($fnamebase, "Testing for constant $const",
301 "Constant \"$const\" not available.", $res);
304 # Generate a program to test for the value of this constant.
305 open (TESTFILE, ">$fnamebase.c");
306 print TESTFILE "#include <$h>\n";
307 print TESTFILE "int main (void) { return $const != $value; }\n";
310 $res = runtest ($fnamebase, "Testing for value of constant $const",
311 "Constant \"$const\" has not the right value.", $res);
313 } elsif (/^type *({([^}]*)|([a-zA-Z0-9_]*))/) {
316 # Remember that this name is allowed.
317 if ($type =~ /^struct *(.*)/) {
319 } elsif ($type =~ /^union *(.*)/) {
325 # Remember that this name is allowed.
328 # Generate a program to test for the availability of this constant.
329 open (TESTFILE, ">$fnamebase.c");
330 print TESTFILE "#include <$h>\n";
331 print TESTFILE "$type *a;\n";
334 compiletest ($fnamebase, "Testing for type $type",
335 "Type \"$type\" not available.", $missing);
336 } elsif (/^function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(][^)]*[)])/) {
337 my($rettype) = "$2$3";
342 # Remember that this name is allowed.
345 # Generate a program to test for availability of this function.
346 open (TESTFILE, ">$fnamebase.c");
347 print TESTFILE "#include <$h>\n";
348 # print TESTFILE "#undef $fname\n";
349 print TESTFILE "$rettype (*foobarbaz) $args = $fname;\n";
352 $res = compiletest ($fnamebase, "Test availability of function $fname",
353 "Function \"$fname\" is not available.", $res);
355 # Generate a program to test for the type of this function.
356 open (TESTFILE, ">$fnamebase.c");
357 print TESTFILE "#include <$h>\n";
358 # print TESTFILE "#undef $fname\n";
359 print TESTFILE "extern $rettype (*foobarbaz) $args;\n";
360 print TESTFILE "extern __typeof__ (&$fname) foobarbaz;\n";
363 compiletest ($fnamebase, "Test for type of function $fname",
364 "Function \"$fname\" has incorrect type.", $res);
365 } elsif (/^macro *([^ ]*)/) {
368 # Remember that this name is allowed.
371 # Generate a program to test for availability of this macro.
372 open (TESTFILE, ">$fnamebase.c");
373 print TESTFILE "#include <$h>\n";
374 print TESTFILE "#ifndef $macro\n";
375 print TESTFILE "# error \"Macro $macro not defined\"\n";
376 print TESTFILE "#endif\n";
379 compiletest ($fnamebase, "Test availability of macro $macro",
380 "Macro \"$macro\" is not available.", $missing);
381 } elsif (/^allow *(.*)/) {
383 push @allow, $pattern;
386 # printf ("line is `%s'\n", $_);
394 # Now check the namespace.
395 printf (" Checking the namespace of \"%s\"... ", $h);
400 checknamespace ($h, $fnamebase, @allow);
406 printf "-" x 76 . "\n";
407 printf (" Total number of tests : %4d\n", $total);
408 printf (" Number of failed tests : %4d (%3d%%)\n", $errors, ($errors * 100) / $total);
409 printf (" Number of skipped tests: %4d (%3d%%)\n", $skipped, ($skipped * 100) / $total);