]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/testsuite/binutils-all/update-section.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / binutils / testsuite / binutils-all / update-section.exp
1 # Copyright (C) 2015-2021 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 # These tests use ELF .section directives
22 if ![is_elf_format] {
23 return
24 }
25
26 send_user "Version [binutil_version $OBJCOPY]"
27
28 proc do_assemble {srcfile} {
29 global srcdir
30 global subdir
31 set objfile [regsub -- "\.s$" $srcfile ".o"]
32 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
33 return 0;
34 }
35 return 1;
36 }
37
38 proc do_objcopy {objfile extraflags {pattern ""}} {
39 global OBJCOPY
40 global OBJCOPYFLAGS
41
42 set testname "objcopy $extraflags ${objfile}"
43 set got [binutils_run $OBJCOPY \
44 "$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
45 if ![regexp $pattern $got] then {
46 fail "objcopy ($testname)"
47 return 0
48 }
49 if { $pattern != "" } then {
50 pass "objcopy ($testname)"
51 }
52 return 1
53 }
54
55 proc do_compare {file1 file2} {
56 set src1 "tmpdir/${file1}"
57 set src2 "tmpdir/${file2}"
58 set status [remote_exec build cmp "${src1} ${src2}"]
59 set exec_output [lindex $status 1]
60 set exec_output [prune_warnings $exec_output]
61
62 set testname "compare ${file1} ${file2}"
63 if [string match "" $exec_output] then {
64 pass "objcopy ($testname)"
65 } else {
66 send_log "$exec_output\n"
67 verbose "$exec_output" 1
68 fail "objcopy ($testname)"
69 return 0
70 }
71 return 1
72 }
73
74 #
75 # Start Of Tests
76 #
77
78 foreach f [list update-1.s update-2.s update-3.s update-4.s] {
79 if { ![do_assemble $f] } then {
80 unsupported "update-section.exp"
81 return
82 }
83 }
84
85 # Check that we can dump empty sections.
86 if { ![do_objcopy update-1.o "--dump-section .text=tmpdir/empty"] } {
87 fail "objcopy (dump empty section)"
88 } else {
89 pass "objcopy (dump empty section)"
90 }
91
92 if { ![do_objcopy update-1.o \
93 "--dump-section .foo=tmpdir/dumped-contents"]
94 || ![do_objcopy update-2.o \
95 "--update-section .foo=tmpdir/dumped-contents"]
96 || ![do_objcopy update-3.o \
97 "--update-section .foo=tmpdir/dumped-contents"]
98 || ![do_objcopy update-4.o \
99 "--update-section .bar=tmpdir/dumped-contents \
100 --rename-section .bar=.foo"] } then {
101 # If any of the above tests failed then a FAIL will already have
102 # been reported.
103 return
104 }
105
106 # Check that the updated object files are as expected.
107 do_compare update-1.o update-2.o
108 do_compare update-1.o update-3.o
109 do_compare update-1.o update-4.o
110
111 # Check that --update-section on an unknown section will fail.
112 if { ![do_objcopy update-2.o \
113 "--update-section .bar=tmpdir/dumped-contents" \
114 "error: .bar not found, can't be updated"] } then {
115 return
116 }
117
118 # Check that --update-section and --remove-section on the same section
119 # will fail.
120 if { ![do_objcopy update-2.o \
121 "--update-section .foo=tmpdir/dumped-contents \
122 --remove-section .foo" \
123 "error: section .foo matches both update and remove options"] \
124 } then {
125 return
126 }