b4a94688e9478f12d58c6a47ff7d1152f010f75e
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / compress.exp
1 # Copyright (C) 2010-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 # Test compressed .debug section.
18
19 if { [is_remote host] || ![is_elf_format] || ![is_zlib_supported] } then {
20 return
21 }
22
23 set testfile tmpdir/dw2-1
24 set compressedfile tmpdir/dw2-1-compressed
25 set copyfile tmpdir/dw2-copy
26 set compressedfile2 tmpdir/dw2-2-compressed
27 set libfile tmpdir/libdw2
28 set compressedcopyfile tmpdir/dw2-copy-compressed
29 set testfile3 tmpdir/dw2-3
30 set compressedfile3 tmpdir/dw2-3-compressed
31
32 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${testfile}.o --nocompress-debug-sections] } then {
33 unsupported "compressed debug sections"
34 return
35 }
36
37 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-1.S ${compressedfile}.o --compress-debug-sections] } then {
38 unsupported "compressed debug sections"
39 return
40 }
41
42 set got [remote_exec host "cmp ${testfile}.o ${compressedfile}.o"]
43 # Use it to set up xfail.
44 set exec_output [lindex $got 1]
45 if [string match "" $exec_output] then {
46 set compression_used ""
47 } else {
48 set compression_used "yes"
49 }
50
51 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-2.S ${compressedfile2}.o --compress-debug-sections] } then {
52 unsupported "compressed debug sections"
53 return
54 }
55
56 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${testfile3}.o --nocompress-debug-sections] } then {
57 unsupported "compressed debug sections"
58 return
59 }
60
61 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${compressedfile3}.o --compress-debug-sections] } then {
62 unsupported "compressed debug sections"
63 return
64 }
65
66 remote_file host delete ${libfile}.a
67 set got [binutils_run $AR "rc ${libfile}.a ${compressedfile}.o ${compressedfile2}.o ${compressedfile3}.o"]
68 if ![string match "" $got] then {
69 fail "compressed debug sections"
70 return
71 }
72
73 set testname "objcopy compress debug sections"
74 set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}.o ${copyfile}.o"]
75 if ![string match "" $got] then {
76 fail "objcopy ($testname)"
77 } else {
78 send_log "cmp ${compressedfile}.o ${copyfile}.o\n"
79 verbose "cmp ${compressedfile}.o ${copyfile}.o"
80 set src1 ${compressedfile}.o
81 set src2 ${copyfile}.o
82 set status [remote_exec build cmp "${src1} ${src2}"]
83 set exec_output [lindex $status 1]
84 set exec_output [prune_warnings $exec_output]
85
86 if [string match "" $exec_output] then {
87 pass "objcopy ($testname)"
88 } else {
89 send_log "$exec_output\n"
90 verbose "$exec_output" 1
91 fail "objcopy ($testname)"
92 }
93 }
94
95 set testname "objcopy decompress compressed debug sections"
96 set got [binutils_run $OBJCOPY "--decompress-debug-sections ${compressedfile}.o ${copyfile}.o"]
97 if ![string match "" $got] then {
98 fail "objcopy ($testname)"
99 } else {
100 send_log "cmp ${testfile}.o ${copyfile}.o\n"
101 verbose "cmp ${testfile}.o ${copyfile}.o"
102 set src1 ${testfile}.o
103 set src2 ${copyfile}.o
104 set status [remote_exec build cmp "${src1} ${src2}"]
105 set exec_output [lindex $status 1]
106 set exec_output [prune_warnings $exec_output]
107
108 if [string match "" $exec_output] then {
109 pass "objcopy ($testname)"
110 } else {
111 send_log "$exec_output\n"
112 verbose "$exec_output" 1
113 fail "objcopy ($testname)"
114 }
115 }
116
117 set testname "objcopy decompress debug sections in archive"
118 set got [binutils_run $OBJCOPY "--decompress-debug-sections ${libfile}.a ${copyfile}.a"]
119 if ![string match "" $got] then {
120 fail "objcopy ($testname)"
121 } else {
122 set got [remote_exec host "$READELF -S --wide ${copyfile}.a" "" "/dev/null" "tmpdir/libdw2.out"]
123
124 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
125 fail "$testname (reason: unexpected output)"
126 send_log $got
127 send_log "\n"
128 }
129
130 if { [regexp_diff tmpdir/libdw2.out $srcdir/$subdir/libdw2.out] } then {
131 fail "$testname"
132 } else {
133 pass "$testname"
134 }
135 }
136
137 # Xfail this test if there are no compressed sections.
138 setup_xfail "$compression_used$target_triplet"
139 set testname "objcopy compress debug sections in archive"
140 set got [binutils_run $OBJCOPY "--compress-debug-sections ${copyfile}.a ${compressedcopyfile}.a"]
141 if ![string match "" $got] then {
142 fail "objcopy ($testname)"
143 } else {
144 set got [remote_exec host "$OBJDUMP -s -j .zdebug_line ${compressedcopyfile}.a" "" "/dev/null" "tmpdir/libdw2-compressed.out"]
145
146 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
147 fail "$testname (reason: unexpected output)"
148 send_log $got
149 send_log "\n"
150 }
151
152 setup_xfail "$compression_used$target_triplet"
153 if { [regexp_diff tmpdir/libdw2-compressed.out $srcdir/$subdir/libdw2-compressed.out] } then {
154 fail "$testname"
155 } else {
156 pass "$testname"
157 }
158 }
159
160 set testname "objdump compress debug sections"
161 set got [remote_exec host "$OBJDUMP -W ${compressedfile}.o" "" "/dev/null" "objdump.out"]
162 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
163 fail "$testname"
164 send_log "$got\n"
165 }
166 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-1.W] } then {
167 fail "$testname"
168 } else {
169 pass "$testname"
170 }
171
172 set testname "objdump compress debug sections 3"
173 set got [remote_exec host "$OBJDUMP -W ${compressedfile3}.o" "" "/dev/null" "objdump.out"]
174 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
175 fail "$testname"
176 send_log "$got\n"
177 }
178 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3.W] } then {
179 fail "$testname"
180 } else {
181 pass "$testname"
182 }
183
184 if { ![binutils_assemble_flags $srcdir/$subdir/dw2-empty.S ${testfile}empty.o --nocompress-debug-sections] } then {
185 unsupported "compressed debug sections"
186 return
187 }
188
189 set testname "objcopy compress empty debug sections"
190 set got [binutils_run $OBJCOPY "--compress-debug-sections ${testfile}empty.o ${copyfile}empty.o"]
191 if ![string match "" $got] then {
192 fail "objcopy ($testname)"
193 } else {
194 send_log "cmp ${testfile}empty.o ${copyfile}empty.o\n"
195 verbose "cmp ${testfile}empty.o ${copyfile}empty.o"
196 set src1 ${testfile}empty.o
197 set src2 ${copyfile}empty.o
198 set status [remote_exec build cmp "${src1} ${src2}"]
199 set exec_output [lindex $status 1]
200 set exec_output [prune_warnings $exec_output]
201
202 if [string match "" $exec_output] then {
203 pass "objcopy ($testname)"
204 } else {
205 send_log "$exec_output\n"
206 verbose "$exec_output" 1
207 fail "objcopy ($testname)"
208 }
209 }
210
211 if ![is_remote host] {
212 set tempfile tmpdir/debug_str.o
213 set copyfile tmpdir/debug_str.copy
214 } else {
215 set tempfile [remote_download host tmpdir/debug_str.o]
216 set copyfile debug_str.copy
217 }
218
219 run_dump_test "debug_str"
This page took 0.033389 seconds and 4 git commands to generate.