From 2bd7f877afeadd6da4c6b1dfc4d0489e9c0efb55 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 7 Feb 2017 22:31:46 +0000 Subject: [PATCH] ld: Add additional checking for warnings/errors in testsuite 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 | 9 ++++ ld/testsuite/ld-elf/shared.exp | 6 ++- ld/testsuite/ld-plugin/lto.exp | 6 ++- ld/testsuite/lib/ld-lib.exp | 79 ++++++++++++++++++++++++++++------ 4 files changed, 84 insertions(+), 16 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index ee89792dfa7..8d493737e3d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2017-02-16 Andrew Burgess + + * 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 * testsuite/ld-elf/check-ptr-eq.c (check_ptr_eq): Change params diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 29462629fa0..9d5a9d9fe90 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -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"} diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index c7388958214..80c084bda11 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -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] } { diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index fece871307d..42cfe1c824f 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -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" -- 2.30.2