summaryrefslogtreecommitdiffstats
path: root/tests/run-elfclassify.sh
blob: fb14139d81bfb00ae48117c0be2fb17584b41ffb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/sh
# Copyright (C) 2019 Red Hat, Inc.
# This file is part of elfutils.
#
# This file is free software; you can redistribute it and/or modify
# 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.
#
# elfutils 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, see <http://www.gnu.org/licenses/>.

. $srcdir/test-subr.sh

core_files=\
"testfile_aarch64_core \
 testfile-backtrace-demangle.core \
 testfiledwarfinlines.core \
 testfile_i686_core \
 testfile-m68k-core \
 testfile-riscv64-core \
 backtrace.aarch64.core \
 backtrace.i386.core \
 backtrace.ppc.core \
 backtrace.s390.core"

testfiles $core_files

echo "elfclassify --core"
testrun ${abs_top_builddir}/src/elfclassify --core $core_files
testrun_compare ${abs_top_builddir}/src/elfclassify --core --print $core_files <<EOF
$(echo $core_files | sed -e "s/ /\n/g")
EOF

echo "core files are not programs"
testrun ${abs_top_builddir}/src/elfclassify --not-program $core_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $core_files <<EOF
$(echo $core_files | sed -e "s/ /\n/g")
EOF

echo "core files are not shared"
testrun ${abs_top_builddir}/src/elfclassify --not-shared $core_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $core_files <<EOF
$(echo $core_files | sed -e "s/ /\n/g")
EOF

echo "core files are not kernel-modules"
testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $core_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $core_files <<EOF
$(echo $core_files | sed -e "s/ /\n/g")
EOF

echo "core files are not debug-only"
testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $core_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $core_files <<EOF
$(echo $core_files | sed -e "s/ /\n/g")
EOF

object_files=\
"debug-ranges-no-lowpc.o \
 testfile-annobingroup-i386.o \
 testfile-bpf-dis1.o \
 testfile-debug-rel-g.o \
 testfile-gnu-property-note.o"

testfiles $object_files

echo "elfclassify --elf-file"
testrun ${abs_top_builddir}/src/elfclassify --elf-file $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --elf-file --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not archives"
testrun ${abs_top_builddir}/src/elfclassify --not-elf-archive $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-elf-archive --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not core files"
testrun ${abs_top_builddir}/src/elfclassify --not-core $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-core --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not program files"
testrun ${abs_top_builddir}/src/elfclassify --not-program $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not shared files"
testrun ${abs_top_builddir}/src/elfclassify --not-shared $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not kernel modules"
testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

echo "object files are not debug-only files"
testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $object_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $object_files <<EOF
$(echo $object_files | sed -e "s/ /\n/g")
EOF

ar_files="testarchive64.a"

testfiles $ar_files

echo "elfclassify --elf-archive"
testrun ${abs_top_builddir}/src/elfclassify --elf-archive $ar_files
testrun_compare ${abs_top_builddir}/src/elfclassify --elf-archive --print $ar_files <<EOF
$(echo $ar_files | sed -e "s/ /\n/g")
EOF

echo "archives are not elf-files"
testrun ${abs_top_builddir}/src/elfclassify --not-elf-file $ar_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-elf-file --print $ar_files <<EOF
$(echo $ar_files | sed -e "s/ /\n/g")
EOF

echo "archives are not core files"
testrun ${abs_top_builddir}/src/elfclassify --not-core $ar_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-core --print $ar_files <<EOF
$(echo $ar_files | sed -e "s/ /\n/g")
EOF

echo "archives are not program files"
testrun ${abs_top_builddir}/src/elfclassify --not-program $ar_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $ar_files <<EOF
$(echo $ar_files | sed -e "s/ /\n/g")
EOF

echo "archives are not shared files"
testrun ${abs_top_builddir}/src/elfclassify --not-shared $ar_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $ar_files <<EOF
$(echo $ar_files | sed -e "s/ /\n/g")
EOF

lib_files=\
"testfile52-32.noshdrs.so \
 libtestfile_multi_shared.so \
 testfile52-32.prelink.so \
 testfile52-32.so
 testfile54-64.noshdrs.so \
 testfile54-64.prelink.so \
 testfile54-64.so \
 testlib_dynseg.so"

testfiles $lib_files

echo "elfclassify --shared"
testrun ${abs_top_builddir}/src/elfclassify --shared $lib_files
testrun_compare ${abs_top_builddir}/src/elfclassify --shared --print $lib_files <<EOF
$(echo $lib_files | sed -e "s/ /\n/g")
EOF

echo "shared files are loadable"
testrun ${abs_top_builddir}/src/elfclassify --loadable $lib_files
testrun_compare ${abs_top_builddir}/src/elfclassify --loadable --print $lib_files <<EOF
$(echo $lib_files | sed -e "s/ /\n/g")
EOF

echo "shared files are not executables"
testrun ${abs_top_builddir}/src/elfclassify --not-executable $lib_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-executable --print $lib_files <<EOF
$(echo $lib_files | sed -e "s/ /\n/g")
EOF

echo "shared files are not debug-only"
testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $lib_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $lib_files <<EOF
$(echo $lib_files | sed -e "s/ /\n/g")
EOF

echo "shared files are not kernel modules"
testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $lib_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $lib_files <<EOF
$(echo $lib_files | sed -e "s/ /\n/g")
EOF

exe_files=\
"backtrace.aarch64.exec \
 backtrace.i386.exec \
 backtrace.ppc.exec \
 backtrace.s390x.exec \
 testfile70.exec \
 test-offset-loop \
 testfilebaztab \
 testfilebaztabppc64"

testfiles $exe_files

echo "elfclassify --program"
testrun ${abs_top_builddir}/src/elfclassify --program $exe_files
testrun_compare ${abs_top_builddir}/src/elfclassify --program --print $exe_files <<EOF
$(echo $exe_files | sed -e "s/ /\n/g")
EOF

echo "programs are executables (in this case)"
testrun ${abs_top_builddir}/src/elfclassify --executable $exe_files
testrun_compare ${abs_top_builddir}/src/elfclassify --executable --print $exe_files <<EOF
$(echo $exe_files | sed -e "s/ /\n/g")
EOF

echo "programs are not shared libraries (in this case)"
testrun ${abs_top_builddir}/src/elfclassify --not-shared $exe_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $exe_files <<EOF
$(echo $exe_files | sed -e "s/ /\n/g")
EOF

echo "programs are not kernel-modules"
testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $exe_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $exe_files <<EOF
$(echo $exe_files | sed -e "s/ /\n/g")
EOF

echo "programs are not debug-only"
testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $exe_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $exe_files <<EOF
$(echo $exe_files | sed -e "s/ /\n/g")
EOF

kmod_files=\
"hello_aarch64.ko \
 hello_csky.ko \
 hello_i386.ko \
 hello_m68k.ko \
 hello_ppc64.ko \
 hello_riscv64.ko \
 hello_s390.ko \
 hello_x86_64.ko"

testfiles $kmod_files

echo "elfclassify --linux-kernel-module"
testrun ${abs_top_builddir}/src/elfclassify --linux-kernel-module $kmod_files
testrun_compare ${abs_top_builddir}/src/elfclassify --linux-kernel-module --print $kmod_files <<EOF
$(echo $kmod_files | sed -e "s/ /\n/g")
EOF

echo "kmods are unstripped"
testrun ${abs_top_builddir}/src/elfclassify --unstripped $kmod_files
testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $kmod_files <<EOF
$(echo $kmod_files | sed -e "s/ /\n/g")
EOF

echo "kmods are not debug-only"
testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $kmod_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $kmod_files <<EOF
$(echo $kmod_files | sed -e "s/ /\n/g")
EOF

echo "kmods are not loabable (in the normal sense)"
testrun ${abs_top_builddir}/src/elfclassify --not-loadable $kmod_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-loadable --print $kmod_files <<EOF
$(echo $kmod_files | sed -e "s/ /\n/g")
EOF

echo "gnu compressed kmods are unstripped"
testrun ${abs_top_builddir}/src/elfcompress -t gnu --force $kmod_files
testrun ${abs_top_builddir}/src/elfclassify --unstripped $kmod_files
testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $kmod_files <<EOF
$(echo $kmod_files | sed -e "s/ /\n/g")
EOF

debug_files=\
"testfile15.debug \
 testfile35.debug \
 testfile40.debug \
 testfile48.debug \
 testfile53-32.debug \
 testfile53-64.debug \
 testfilebazdbg.debug \
 testfilebazdbgppc64.debug \
 addrx_constx-4.dwo \
 addrx_constx-5.dwo"

testfiles $debug_files

echo "elfclassify --debug-only"
testrun ${abs_top_builddir}/src/elfclassify --debug-only $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --debug-only --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF

echo "debug-only files are unstripped"
testrun ${abs_top_builddir}/src/elfclassify --unstripped $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF

echo "debug-only files are not programs"
testrun ${abs_top_builddir}/src/elfclassify --not-program $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF

echo "debug-only files are not shared"
testrun ${abs_top_builddir}/src/elfclassify --not-shared $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF

echo "compress the debug sections and try again"
testrun ${abs_top_builddir}/src/elfcompress -t gnu --force $debug_files

echo "again unstripped"
testrun ${abs_top_builddir}/src/elfclassify --unstripped $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF

echo "again debug-only"
testrun ${abs_top_builddir}/src/elfclassify --debug-only $debug_files
testrun_compare ${abs_top_builddir}/src/elfclassify --debug-only --print $debug_files <<EOF
$(echo $debug_files | sed -e "s/ /\n/g")
EOF