From aafc49b3fccb44f0da4bac49abe55fa3651ecabe Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 1 May 2012 20:02:48 +0000 Subject: [PATCH] conformtest: Unify "macro" and "constant" handling. --- ChangeLog | 3 ++ conform/conformtest.pl | 114 ++++++++++++++++++++++--------------------------- 2 files changed, 53 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb313e1..8b89cd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-05-01 Joseph Myers + * conform/conformtest.pl: Parse all "constant" and "macro" lines + in one place. Also handle "macro-constant". + * conform/conformtest.pl: Only accept expected macro values with "==". Parse all "macro" lines in one place. * conform/data/stdlib.h-data: Use "==" form on "macro" lines. diff --git a/conform/conformtest.pl b/conform/conformtest.pl index c38be1d..f5860ac 100644 --- a/conform/conformtest.pl +++ b/conform/conformtest.pl @@ -385,54 +385,78 @@ while ($#headers >= 0) { "Member \"$member\" does not have the correct type.", $res, 0); } - } elsif (/^constant *([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>==$fnamebase.c"); - print TESTFILE "$prepend"; - print TESTFILE "#include <$h>\n"; - print TESTFILE "__typeof__ ($const) a = $const;\n"; - close (TESTFILE); + if ($symbol_type =~ /macro/) { + # Generate a program to test for availability of this macro. + open (TESTFILE, ">$fnamebase.c"); + print TESTFILE "$prepend"; + print TESTFILE "#include <$h>\n"; + print TESTFILE "#ifndef $symbol\n"; + print TESTFILE "# error \"Macro $symbol not defined\"\n"; + print TESTFILE "#endif\n"; + close (TESTFILE); - $res = compiletest ($fnamebase, "Testing for constant $const", - ($optional - ? "NOT PRESENT" - : "Constant \"$const\" not available."), $res, - $optional); + $mres = compiletest ($fnamebase, "Test availability of macro $symbol", + ($optional + ? "NOT PRESENT" + : "Macro \"$symbol\" is not available."), $res, + $optional); + } + + if ($symbol_type =~ /constant/) { + # Generate a program to test for the availability of this constant. + open (TESTFILE, ">$fnamebase.c"); + print TESTFILE "$prepend"; + print TESTFILE "#include <$h>\n"; + print TESTFILE "__typeof__ ($symbol) a = $symbol;\n"; + close (TESTFILE); + + $cres = compiletest ($fnamebase, "Testing for constant $symbol", + ($optional + ? "NOT PRESENT" + : "Constant \"$symbol\" not available."), $res, + $optional); + } + + $res = $res || $mres || $cres; if (defined ($type) && ($res == 0 || !$optional)) { - # Test the types of the members. + # Test the type of the symbol. open (TESTFILE, ">$fnamebase.c"); print TESTFILE "$prepend"; print TESTFILE "#include <$h>\n"; print TESTFILE "__typeof__ (($type) 0) a;\n"; - print TESTFILE "extern __typeof__ ($const) a;\n"; + print TESTFILE "extern __typeof__ ($symbol) a;\n"; close (TESTFILE); - compiletest ($fnamebase, "Testing for type of constant $const", - "Constant \"$const\" does not have the correct type.", + compiletest ($fnamebase, "Testing for type of symbol $symbol", + "Symbol \"$symbol\" does not have the correct type.", $res, 0); } if (defined ($op) && ($res == 0 || !$optional)) { - # Generate a program to test for the value of this constant. + # Generate a program to test for the value of this symbol. open (TESTFILE, ">$fnamebase.c"); print TESTFILE "$prepend"; print TESTFILE "#include <$h>\n"; # Negate the value since 0 means ok - print TESTFILE "int main (void) { return !($const $op $value); }\n"; + print TESTFILE "int main (void) { return !($symbol $op $value); }\n"; close (TESTFILE); - $res = runtest ($fnamebase, "Testing for value of constant $const", - "Constant \"$const\" has not the right value.", $res); + $res = runtest ($fnamebase, "Testing for value of symbol $symbol", + "Symbol \"$symbol\" has not the right value.", $res); } } elsif (/^symbol *([a-zA-Z0-9_]*) *([A-Za-z0-9_-]*)?/) { my($symbol) = $1; @@ -683,42 +707,6 @@ while ($#headers >= 0) { $res = runtest ($fnamebase, "Testing for value of macro $macro", "Macro \"$macro\" has not the right value.", $res); - } elsif (/^macro *([a-zA-Z0-9_]*) *(?:([>=$fnamebase.c"); - print TESTFILE "$prepend"; - print TESTFILE "#include <$h>\n"; - print TESTFILE "#ifndef $macro\n"; - print TESTFILE "# error \"Macro $macro not defined\"\n"; - print TESTFILE "#endif\n"; - close (TESTFILE); - - $res = compiletest ($fnamebase, "Test availability of macro $macro", - ($optional - ? "NOT PRESENT" - : "Macro \"$macro\" is not available."), $res, - $optional); - - if (defined ($op) && ($res == 0 || !$optional)) { - # Generate a program to test for the value of this constant. - open (TESTFILE, ">$fnamebase.c"); - print TESTFILE "$prepend"; - print TESTFILE "#include <$h>\n"; - # Negate the value since 0 means ok - print TESTFILE "int main (void) { return !($macro $op $value); }\n"; - close (TESTFILE); - - $res = runtest ($fnamebase, "Testing for value of macro $macro", - "Macro \"$macro\" has not the right value.", $res); - } } elsif (/^allow-header *(.*)/) { my($pattern) = $1; if ($seenheader{$pattern} != 1) { @@ -751,7 +739,7 @@ while ($#headers >= 0) { if (/^element *({([^}]*)}|([^ ]*)) *({([^}]*)}|([^ ]*)) *([A-Za-z0-9_]*) *(.*)/) { push @allow, $7; - } elsif (/^constant *([a-zA-Z0-9_]*) *(?:{([^}]*)} *)?(?:([>=== 0) { push @allow, $4; } elsif (/^macro-function *({([^}]*)}|([a-zA-Z0-9_]*)) ([a-zA-Z0-9_]*) ([(].*[)])/) { push @allow, $4; - } elsif (/^macro *([a-zA-Z0-9_]*) *(?:([>=