diff options
author | Alan Modra <amodra@gmail.com> | 2015-10-15 21:37:13 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2015-10-15 23:38:29 +1030 |
commit | 21c40443ce8b12faa085149ba8a30b33193f6cc7 (patch) | |
tree | 34baa55bde1908d49ef27f1d763aef2f88586f38 /binutils | |
parent | 7b19bec22f266f2e1fab6528f166912328b999b6 (diff) | |
download | gdb-21c40443ce8b12faa085149ba8a30b33193f6cc7.zip gdb-21c40443ce8b12faa085149ba8a30b33193f6cc7.tar.gz gdb-21c40443ce8b12faa085149ba8a30b33193f6cc7.tar.bz2 |
binutils objcopy test tidy
The main aim of this patch is to perform more objcopy tests when we
can build executables but not run them. ie. non-native with cross
compiler available.
* binutils-all/objcopy.exp: Delete trailing whitespace. Use
"string equal" rather than "string match" when making simple
string comparisons. Revert 2008-07-08 host_triplet checks.
Perform non-run tests when we can build executable.
(strip_executable, strip_executable_with_saving_a_symbol): Move
run test later. Take extra param on whether to perform run test.
Update callers.
(keep_debug_symbols_and_test_copy): Delete unused vars.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/testsuite/ChangeLog | 11 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/objcopy.exp | 224 |
2 files changed, 126 insertions, 109 deletions
diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog index 3f9b3e5..79b5b25 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2015-10-15 Alan Modra <amodra@gmail.com> + + * binutils-all/objcopy.exp: Delete trailing whitespace. Use + "string equal" rather than "string match" when making simple + string comparisons. Revert 2008-07-08 host_triplet checks. + Perform non-run tests when we can build executable. + (strip_executable, strip_executable_with_saving_a_symbol): Move + run test later. Take extra param on whether to perform run test. + Update callers. + (keep_debug_symbols_and_test_copy): Delete unused vars. + 2015-09-30 H.J. Lu <hongjiu.lu@intel.com> * lib/utils-lib.exp (run_dump_test): Handle symbolic link when diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index bb33e4f..252cb49 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -4,12 +4,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. @@ -54,7 +54,7 @@ proc objcopy_test {testname srcfile} { set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $tempfile ${copyfile}.o"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy ($testname)" } else { send_log "cmp $tempfile ${copyfile}.o\n" @@ -91,7 +91,7 @@ proc objcopy_test {testname srcfile} { clear_xfail "hppa*-*-*n*bsd*" "hppa*-*-rtems*" "*-*-*elf*" clear_xfail "m68*-*-sysv4*" - if [string match "" $exec_output] then { + if [string equal "" $exec_output] then { pass "objcopy ($testname)" } else { send_log "$exec_output\n" @@ -112,7 +112,7 @@ objcopy_test "simple copy" bintest.s set reversed ${tempfile}-reversed set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -j .data --reverse-bytes=4 $tempfile $reversed"] -if ![string match "" $got] then { +if ![string equal "" $got] then { fail "objcopy --reverse-bytes" } else { if [is_remote host] { @@ -159,7 +159,7 @@ if [is_remote host] { set got [binutils_run $OBJCOPY "-I binary -i 4 -b 0 --interleave-width 2 ${sequence_file} ${copyfile}"] -if ![string match "" $got] then { +if ![string equal "" $got] then { fail "objcopy -i --interleave-width" } else { if [is_remote host] { @@ -174,7 +174,7 @@ if ![string match "" $got] then { send_log "$line\n" verbose $line - if ![string match "1256" $line] then { + if ![string equal "1256" $line] then { fail "objcopy -i --interleave-width" } pass "objcopy -i --interleave-width" @@ -197,7 +197,7 @@ if [is_remote host] { set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $tempfile ${srecfile}"] -if ![string match "" $got] then { +if ![string equal "" $got] then { fail "objcopy -O srec" } else { if [is_remote host] { @@ -257,7 +257,7 @@ if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { set origstart "" } else { set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --set-start 0x7654 $tempfile ${copyfile}.srec"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy --set-start" } else { set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] @@ -274,7 +274,7 @@ if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { } set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-start 0x123 $tempfile ${copyfile}.srec"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy --adjust-start" } else { set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f ${copyfile}.srec"] @@ -319,7 +319,7 @@ if {$low == "" || $origstart == ""} then { perror "objdump can not recognize bintest.o" } else { set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec --adjust-vma 0x123 $tempfile ${copyfile}.srec"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy --adjust-vma" } else { set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh ${copyfile}.srec"] @@ -353,7 +353,7 @@ if {$low == "" || $origstart == ""} then { } set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $arg $tempfile ${copyfile}.srec"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy --adjust-section-vma +" } else { set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] @@ -373,7 +373,7 @@ if {$low == "" || $origstart == ""} then { regsub -all "\\+4" $arg "=[expr $low + 4]" argeq set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec $argeq $tempfile ${copyfile}.srec"] - if ![string match "" $got] then { + if ![string equal "" $got] then { fail "objcopy --adjust-section-vma =" } else { set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h ${copyfile}.srec"] @@ -417,7 +417,7 @@ proc strip_test { } { verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.in" set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.in"] if { [lindex $exec_output 0] != 0 } then { - unresolved "$test preserving OS/ABI" + unresolved "$test preserving OS/ABI" set osabi_fail "true" } else { verbose -log "grep OS/ABI tmpdir/osabi.in" @@ -437,23 +437,23 @@ proc strip_test { } { remote_file build delete tmpdir/libstrip.a set exec_output [binutils_run $AR "rc $archive ${objfile}"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test - unresolved "$test preserving OS/ABI" + unresolved "$test preserving OS/ABI" return } set exec_output [binutils_run $STRIP "-g $archive"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test - unresolved "$test preserving OS/ABI" + unresolved "$test preserving OS/ABI" return } set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test - unresolved "$test preserving OS/ABI" + unresolved "$test preserving OS/ABI" return } @@ -461,7 +461,7 @@ proc strip_test { } { verbose -log "$READELF -a tmpdir/testprog.o > tmpdir/osabi.out" set exec_output [remote_exec host "$READELF -h tmpdir/testprog.o" "" "/dev/null" "tmpdir/osabi.out"] if { [lindex $exec_output 0] != 0 } then { - unresolved "$test preserving OS/ABI" + unresolved "$test preserving OS/ABI" } else { verbose -log "grep OS/ABI tmpdir/osabi.out" catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out @@ -485,7 +485,7 @@ proc strip_test { } { } set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test return } @@ -526,7 +526,7 @@ proc strip_test_with_saving_a_symbol { } { } set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test return } @@ -557,14 +557,14 @@ proc copy_setup { } { global gcc_gas_flag global test_prog global host_triplet - + set res [build_wrapper testglue.o] set flags { debug } - + if { [istarget *-*-uclinux*] && ![istarget tic6x-*-*] } { return 1 } - + if { $res != "" } { lappend flags "additional_flags=[lindex $res 1]" set add_libs "testglue.o" @@ -587,10 +587,7 @@ proc copy_setup { } { if { $status != "pass" } { send_log "cannot run executable, status = ${status} on ${host_triplet}\n" - if { [istarget $host_triplet] } { - return 3 - } - set status "pass" + return 3 } return 0 @@ -600,7 +597,6 @@ proc copy_setup { } { proc copy_executable { prog flags test1 test2 } { global test_prog - global host_triplet if [is_remote host] { set testfile [remote_download host tmpdir/$test_prog] @@ -613,9 +609,9 @@ proc copy_executable { prog flags test1 test2 } { set exec_output [binutils_run $prog "$flags $testfile $testcopy"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test1 - if [string match "" $test2] { + if [string equal "" $test2] { return } fail $test2 @@ -629,7 +625,7 @@ proc copy_executable { prog flags test1 test2 } { set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"] set exec_output [lindex $status 1] - if [string match "" $exec_output] then { + if [string equal "" $exec_output] then { pass $test1 } else { send_log "$exec_output\n" @@ -654,19 +650,16 @@ proc copy_executable { prog flags test1 test2 } { setup_xfail "arm*-*-pe" setup_xfail "*-*-mingw*" setup_xfail "*-*-cygwin*" - + fail $test1 } - if [string match "" $test2] { + if [string equal "" $test2] { return } set output [remote_load target tmpdir/copyprog] set status [lindex $output 0] - if { ![istarget $host_triplet] } { - set status "pass" - } if { $status != "pass" } { fail $test2 } else { @@ -676,11 +669,10 @@ proc copy_executable { prog flags test1 test2 } { # Test stripping an executable -proc strip_executable { prog flags test } { +proc strip_executable { prog flags test1 test2 } { global NM global NMFLAGS global READELF - global host_triplet remote_file build delete tmpdir/striprog remote_download build tmpdir/copyprog tmpdir/striprog @@ -695,7 +687,7 @@ proc strip_executable { prog flags test } { verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.in" set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.in"] if { [lindex $exec_output 0] != 0 } then { - unresolved "$test preserving OS/ABI" + unresolved "$test1 preserving OS/ABI" set osabi_fail "true" } else { verbose -log "grep OS/ABI tmpdir/osabi.in" @@ -704,8 +696,12 @@ proc strip_executable { prog flags test } { } set exec_output [binutils_run $prog "$flags ${copyfile}"] - if ![string match "" $exec_output] { - fail $test + if ![string equal "" $exec_output] { + fail $test1 + if [string equal "" $test2] { + return + } + fail $test2 return } @@ -713,46 +709,47 @@ proc strip_executable { prog flags test } { remote_upload host ${copyfile} tmpdir/striprog } - set result [remote_load target tmpdir/striprog] - set status [lindex $result 0] - if { ![istarget $host_triplet] } { - set status "pass" - } - if { $status != "pass" } { - fail $test - return - } - if { $osabi_fail != "true" && [is_elf_format] } { verbose -log "$READELF -a ${copyfile} > tmpdir/osabi.out" set exec_output [remote_exec host "$READELF -h ${copyfile}" "" "/dev/null" "tmpdir/osabi.out"] if { [lindex $exec_output 0] != 0 } then { - unresolved "$test preserving OS/ABI" + unresolved "$test1 preserving OS/ABI" } else { verbose -log "grep OS/ABI tmpdir/osabi.out" catch "exec grep OS/ABI tmpdir/osabi.out" osabi_out if { "$osabi_in" == "$osabi_out" } { - pass "$test preserving OS/ABI" + pass "$test1 preserving OS/ABI" } else { - fail "$test preserving OS/ABI" + fail "$test1 preserving OS/ABI" } } } set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] if ![string match "*: no symbols*" $exec_output] { - fail $test + fail $test1 return } - pass $test + + if [string equal "" $test2] { + return + } + + set result [remote_load target tmpdir/striprog] + set status [lindex $result 0] + if { $status != "pass" } { + fail $test2 + return + } + + pass $test2 } # Test stripping an executable with saving a symbol -proc strip_executable_with_saving_a_symbol { prog flags test } { +proc strip_executable_with_saving_a_symbol { prog flags test1 test2 } { global NM global NMFLAGS - global host_triplet remote_file build delete tmpdir/striprog remote_download build tmpdir/copyprog tmpdir/striprog @@ -763,25 +760,15 @@ proc strip_executable_with_saving_a_symbol { prog flags test } { } set exec_output [binutils_run $prog "$flags ${copyfile}"] - if ![string match "" $exec_output] { - fail $test + if ![string equal "" $exec_output] { + fail $test1 + if [string equal "" $test2] { + return + } + fail $test2 return } - if [is_remote host] { - remote_upload host ${copyfile} tmpdir/striprog - } - - set result [remote_load target tmpdir/striprog] - set status [lindex $result 0] - if { ![istarget $host_triplet] } { - set status "pass" - } - if { $status != "pass" } { - fail $test - return - } - set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] if { [istarget mmix-knuth-mmixware] } { # Whenever there's a symbol in the mmo format, there's the symbol @@ -794,18 +781,31 @@ proc strip_executable_with_saving_a_symbol { prog flags test } { if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} { - fail $test + fail $test1 return } - pass $test + + if [string equal "" $test2] { + return + } + + if [is_remote host] { + remote_upload host ${copyfile} tmpdir/striprog + } + + set result [remote_load target tmpdir/striprog] + set status [lindex $result 0] + if { $status != "pass" } { + fail $test2 + return + } + + pass $test2 } # Test keeping only debug symbols of an executable proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } { - global NM - global NMFLAGS - remote_file build delete tmpdir/striprog remote_download build tmpdir/copyprog tmpdir/striprog if [is_remote host] { @@ -815,14 +815,14 @@ proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } } set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test1 return } pass $test1 set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test2 return } @@ -845,7 +845,7 @@ proc keep_debug_symbols_and_check_links { prog flags test } { } set exec_output [binutils_run $prog "$flags ${copyfile}"] - if ![string match "" $exec_output] { + if ![string equal "" $exec_output] { fail $test return } @@ -885,13 +885,15 @@ proc keep_debug_symbols_and_check_links { prog flags test } { set test1 "simple objcopy of executable" -set test2 "run objcopy of executable" -set test3 "run stripped executable" -set test4 "run stripped executable with saving a symbol" -set test5 "keep only debug data" -set test6 "simple objcopy of debug data" +set test1r "run objcopy of executable" +set test2 "strip executable" +set test2r "run stripped executable" +set test3 "strip executable with saving a symbol" +set test3r "run stripped executable with saving a symbol" +set test4 "keep only debug data" +set test5 "simple objcopy of debug data" if [is_elf_format] { - set test7 "NOBITS sections retain sh_link field" + set test6 "NOBITS sections retain sh_link field" } switch [copy_setup] { @@ -900,34 +902,38 @@ switch [copy_setup] { } "2" { untested $test1 + untested $test1r untested $test2 + untested $test2r untested $test3 + untested $test3r untested $test4 untested $test5 - untested $test6 if [is_elf_format] { - untested $test7 + untested $test6 } } "3" { copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "" - unsupported $test2 - unsupported $test3 - unsupported $test4 - unsupported $test5 - unsupported $test6 + unsupported $test1r + strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "" + unsupported $test2r + strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "" + unsupported $test3r + keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ + "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" if [is_elf_format] { - unsupported $test7 + keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" } } "0" { - copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2" - strip_executable "$STRIP" "$STRIPFLAGS" "$test3" - strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4" - keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \ - "$OBJCOPY" "$OBJCOPYFLAGS" "$test6" + copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test1r" + strip_executable "$STRIP" "$STRIPFLAGS" "$test2" "$test2r" + strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test3" "$test3r" + keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test4" \ + "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" if [is_elf_format] { - keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7" + keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" } } } @@ -947,7 +953,7 @@ proc objcopy_test_readelf {testname srcfile} { verbose -log "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o" set exec_output [remote_exec host "$OBJCOPY $OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"] if { [lindex $exec_output 0] != 0 - || ![string match "" [lindex $exec_output 1]] } then { + || ![string equal "" [lindex $exec_output 1]] } then { fail "objcopy ($testname)" return } @@ -959,7 +965,7 @@ proc objcopy_test_readelf {testname srcfile} { return } set exec_output [prune_warnings [lindex $exec_output 1]] - if ![string match "" $exec_output] then { + if ![string equal "" $exec_output] then { unresolved "objcopy ($testname)" return } @@ -971,7 +977,7 @@ proc objcopy_test_readelf {testname srcfile} { return } set exec_output [prune_warnings [lindex $exec_output 1]] - if ![string match "" $exec_output] then { + if ![string equal "" $exec_output] then { unresolved "objcopy ($testname)" return } @@ -980,7 +986,7 @@ proc objcopy_test_readelf {testname srcfile} { catch "exec diff tmpdir/bintest.o.out tmpdir/copy.o.out" exec_output set exec_output [prune_warnings $exec_output] - if [string match "" $exec_output] then { + if [string equal "" $exec_output] then { pass "objcopy ($testname)" } else { fail "objcopy ($testname)" |