ld: Add additional checking for warnings/errors in testsuite
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 7 Feb 2017 22:31:46 +0000 (22:31 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 16 Feb 2017 13:06:12 +0000 (13:06 +0000)
This commit adds new actions to the run_cc_link_tests mechanism in the
linker testsuite.

Previously this procedure could take a parameter containing a regular
expression that would be matched against warnings from the linker.

After this commit the warnings parameter is removed, instead, the
actions list can contain the actions 'warning', 'error',
'warning_output', or 'error_output'.  The action names are chosen to
match the actions already present in the run_dump_test procedure.

These new actions allow for the current warning checking, but also allow
for checking of errors using a regular expression.  More interestingly,
the *_output actions allow for the warning/error patterns to be placed
in a separate file.

The small number of tests that make use of the warning parameter have
been updated to the new mechanism.  Later commits will make use of the
new features added in this commit.

ld/ChangeLog:

* testsuite/lib/ld-lib.exp (run_cc_link_tests): Add warning,
error, warning_output, and error_output actions.  Remove separate
warnings parameter.
* testsuite/ld-elf/shared.exp (build_tests): Updated to use
'warning' action.
* testsuite/ld-plugin/lto.exp (lto_link_tests): Likewise.

ld/ChangeLog
ld/testsuite/ld-elf/shared.exp
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/lib/ld-lib.exp

index ee89792dfa7c60d833582cdebb72be91d7ccb8f2..8d493737e3d79dadbc0c1726f1b159bf756e9d55 100644 (file)
@@ -1,3 +1,12 @@
+2017-02-16  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * testsuite/lib/ld-lib.exp (run_cc_link_tests): Add warning,
+       error, warning_output, and error_output actions.  Remove separate
+       warnings parameter.
+       * testsuite/ld-elf/shared.exp (build_tests): Updated to use
+       'warning' action.
+       * testsuite/ld-plugin/lto.exp (lto_link_tests): Likewise.
+
 2017-02-16  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-elf/check-ptr-eq.c (check_ptr_eq): Change params
index 29462629fa0200fe26340f445c0eb709920c686c..9d5a9d9fe904f28b9468d66217615ea7908d9767 100644 (file)
@@ -103,8 +103,10 @@ set build_tests {
    {begin.c end.c} {} "libbar.so"}
   {"Build warn libbar.so"
    "-shared" "-fPIC"
-   {beginwarn.c end.c} {{readelf {-S --wide} libbarw.rd}} "libbarw.so"
-   "c" {^.*\): warning: function foo is deprecated$} }
+  {beginwarn.c end.c}
+  {{readelf {-S --wide} libbarw.rd}
+   {warning "^.*\\): warning: function foo is deprecated$"}}
+  "libbarw.so" "c"}
   {"Build hidden libbar.so"
    "-shared" "-fPIC"
    {begin.c endhidden.c} {} "libbarh.so"}
index c7388958214f00c73e67f4bf05ca1088e4b87ee8..80c084bda119c8fed8452d1e612dea06341cc383 100644 (file)
@@ -154,7 +154,8 @@ set lto_link_tests [list \
    {pr12760b.c} {} "libpr12760.a"] \
   [list "PR ld/12760" \
    "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
-   {dummy.c} {} "pr12760.exe" "c" "pr12760a.c:6: warning: Bad \\.?bar"] \
+   {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
+   "pr12760.exe" "c"] \
   [list "Build libpr13183.a" \
    "-T" "-flto -O2 $lto_fat" \
    {pr13183a.c} {} "libpr13183.a"] \
@@ -205,7 +206,8 @@ set lto_link_tests [list \
    {pr20267b.c} {} "libpr20267b.a"] \
   [list "Build pr20321" \
    "-flto -Wl,-plugin,$plug_so" "-flto" \
-   {pr20321.c} {} "pr20321" "c" ".*: duplicated plugin"] \
+   {pr20321.c} {{warning ".*: duplicated plugin"}} \
+   "pr20321" "c"] \
 ]
 
 if { [at_least_gcc_version 4 7] } {
index fece871307dfe5f2a6d40d31b019bc1eca0ba38c..42cfe1c824f7f40249baf694295f9f8e501e543a 100644 (file)
@@ -1508,12 +1508,15 @@ proc run_ld_link_exec_tests { ldtests args } {
 #  4:action and options.
 #  5:name of output file
 #  6:language (optional)
-#  7:linker warnings (optional)
 #
 # Actions:
 # objdump: Apply objdump options on result.  Compare with regex (last arg).
 # nm: Apply nm options on result.  Compare with regex (last arg).
 # readelf: Apply readelf options on result.  Compare with regex (last arg).
+# warning: Check linker output against regex (last arg).
+# error: Like 'warning' but checking output in error case.
+# warning_output: Check linker output against regex in a file (last arg).
+# error_output: Like 'warning_output' but checking output in error case.
 #
 proc run_cc_link_tests { ldtests } {
     global nm
@@ -1544,10 +1547,11 @@ proc run_cc_link_tests { ldtests } {
        set actions [lindex $testitem 4]
        set binfile tmpdir/[lindex $testitem 5]
        set lang [lindex $testitem 6]
-       set warnings [lindex $testitem 7]
        set objfiles {}
        set is_unresolved 0
        set failed 0
+       set check_ld(terminal) 0
+       set check_ld(source) ""
 
        #verbose -log "testname  is $testname"
        #verbose -log "ldflags   is $ldflags"
@@ -1556,7 +1560,37 @@ proc run_cc_link_tests { ldtests } {
        #verbose -log "actions   is $actions"
        #verbose -log "binfile   is $binfile"
        #verbose -log "lang      is $lang"
-       #verbose -log "warnings  is $warnings"
+
+       foreach actionlist $actions {
+           set action [lindex $actionlist 0]
+           set progopts [lindex $actionlist 1]
+
+           # Find actions related to error/warning processing.
+           switch -- $action {
+               error
+               {
+                   set check_ld(source) "regexp"
+                   set check_ld(regexp) $progopts
+                   set check_ld(terminal) 1
+               }
+               warning
+               {
+                   set check_ld(source) "regexp"
+                   set check_ld(regexp) $progopts
+               }
+               error_output
+               {
+                   set check_ld(source) "file"
+                   set check_ld(file) $progopts
+                   set check_ld(terminal) 1
+               }
+               warning_output
+               {
+                   set check_ld(source) "file"
+                   set check_ld(file) $progopts
+               }
+           }
+       }
 
        # Compile each file in the test.
        foreach src_file $src_files {
@@ -1598,18 +1632,35 @@ proc run_cc_link_tests { ldtests } {
                set failed 1
            }
        } else {
-           if { ![ld_link $cc_cmd $binfile "$board_cflags -L$srcdir/$subdir $ldflags $objfiles"] } {
-               set failed 1
-           }
+           ld_link $cc_cmd $binfile "$board_cflags -L$srcdir/$subdir $ldflags $objfiles"
+           set ld_output "$exec_output"
 
-           # Check if exec_output is expected.
-           if { $warnings != "" } then {
-               verbose -log "returned with: <$exec_output>, expected: <$warnings>"
-               if { [regexp $warnings $exec_output] } then {
-                   set failed 0
-               } else {
+           if { $check_ld(source) == "regexp" } then {
+               # Match output against regexp argument.
+               verbose -log "returned with: <$ld_output>, expected: <$check_ld(regexp)>"
+               if { ![regexp $check_ld(regexp) $ld_output] } then {
                    set failed 1
                }
+           } elseif { $check_ld(source) == "file" } then {
+               # Match output against patterns in a file.
+               set_file_contents "tmpdir/ld.messages" "$ld_output"
+               verbose "ld.messages has '[file_contents tmpdir/ld.messages]'"
+               if { [regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$check_ld(file)"] } then {
+                   verbose "output is $ld_output" 2
+                   set failed 1
+               }
+           }
+
+           if { $check_ld(source) != "" } then {
+                if { $ld_output == "" } then {
+                    verbose -log "Linker was expected to give error or warning"
+                    set failed 1
+                }
+           } else {
+                if { $ld_output != "" } then {
+                    verbose -log "Unexpected linker warning or error"
+                    set failed 1
+                }
            }
        }
 
@@ -1629,6 +1680,10 @@ proc run_cc_link_tests { ldtests } {
                        { set dump_prog $nm }
                    readelf
                        { set dump_prog $READELF }
+                   error {}
+                   warning {}
+                   error_output {}
+                   warning_output {}
                    default
                        {
                            perror "Unrecognized action $action"
This page took 0.031641 seconds and 4 git commands to generate.