objcopy: Add --update-section option.
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / update-section.exp
1 # Copyright (C) 2015 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16
17 if { [is_remote host] } then {
18 return
19 }
20
21 send_user "Version [binutil_version $OBJCOPY]"
22
23 proc do_assemble {srcfile} {
24 global srcdir
25 global subdir
26 set objfile [regsub -- "\.s$" $srcfile ".o"]
27 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
28 return 0;
29 }
30 return 1;
31 }
32
33 proc do_objcopy {objfile extraflags {pattern ""}} {
34 global OBJCOPY
35 global OBJCOPYFLAGS
36
37 set testname "objcopy $extraflags ${objfile}"
38 set got [binutils_run $OBJCOPY \
39 "$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
40 if ![regexp $pattern $got] then {
41 fail "objcopy ($testname)"
42 return 0
43 }
44 if { $pattern != "" } then {
45 pass "objcopy ($testname)"
46 }
47 return 1
48 }
49
50 proc do_compare {file1 file2} {
51 set src1 "tmpdir/${file1}"
52 set src2 "tmpdir/${file2}"
53 set status [remote_exec build cmp "${src1} ${src2}"]
54 set exec_output [lindex $status 1]
55 set exec_output [prune_warnings $exec_output]
56
57 set testname "compare ${file1} ${file2}"
58 if [string match "" $exec_output] then {
59 pass "objcopy ($testname)"
60 } else {
61 send_log "$exec_output\n"
62 verbose "$exec_output" 1
63 fail "objcopy ($testname)"
64 return 0
65 }
66 return 1
67 }
68
69 #
70 # Start Of Tests
71 #
72
73 foreach f [list update-1.s update-2.s update-3.s update-4.s] {
74 if { ![do_assemble $f] } then {
75 unsupported "update-section.exp"
76 return
77 }
78 }
79
80 if { ![do_objcopy update-1.o \
81 "--dump-section .foo=tmpdir/dumped-contents"]
82 || ![do_objcopy update-2.o \
83 "--update-section .foo=tmpdir/dumped-contents"]
84 || ![do_objcopy update-3.o \
85 "--update-section .foo=tmpdir/dumped-contents"]
86 || ![do_objcopy update-4.o \
87 "--update-section .bar=tmpdir/dumped-contents \
88 --rename-section .bar=.foo"] } then {
89 # If any of the above tests failed then a FAIL will already have
90 # been reported.
91 return
92 }
93
94 # Check that the updated object files are as expected.
95 do_compare update-1.o update-2.o
96 do_compare update-1.o update-3.o
97 do_compare update-1.o update-4.o
98
99 # Check that --update-section on an unknown section will fail.
100 if { ![do_objcopy update-2.o \
101 "--update-section .bar=tmpdir/dumped-contents" \
102 "error: .bar not found, can't be updated"] } then {
103 return
104 }
105
106 # Check that --update-section and --remove-section on the same section
107 # will fail.
108 if { ![do_objcopy update-2.o \
109 "--update-section .foo=tmpdir/dumped-contents \
110 --remove-section .foo" \
111 "error: section .foo matches both update and remove options"] \
112 } then {
113 return
114 }
This page took 0.035305 seconds and 4 git commands to generate.