1#!/bin/sh
2# Copyright (C) 2019 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/test-subr.sh
19
20core_files=\
21"testfile_aarch64_core \
22 testfile-backtrace-demangle.core \
23 testfiledwarfinlines.core \
24 testfile_i686_core \
25 testfile-m68k-core \
26 testfile-riscv64-core \
27 backtrace.aarch64.core \
28 backtrace.i386.core \
29 backtrace.ppc.core \
30 backtrace.s390.core"
31
32testfiles $core_files
33
34echo "elfclassify --core"
35testrun ${abs_top_builddir}/src/elfclassify --core $core_files
36testrun_compare ${abs_top_builddir}/src/elfclassify --core --print $core_files <<EOF
37$(echo $core_files | sed -e "s/ /\n/g")
38EOF
39
40echo "core files are not programs"
41testrun ${abs_top_builddir}/src/elfclassify --not-program $core_files
42testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $core_files <<EOF
43$(echo $core_files | sed -e "s/ /\n/g")
44EOF
45
46echo "core files are not shared"
47testrun ${abs_top_builddir}/src/elfclassify --not-shared $core_files
48testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $core_files <<EOF
49$(echo $core_files | sed -e "s/ /\n/g")
50EOF
51
52echo "core files are not kernel-modules"
53testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $core_files
54testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $core_files <<EOF
55$(echo $core_files | sed -e "s/ /\n/g")
56EOF
57
58echo "core files are not debug-only"
59testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $core_files
60testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $core_files <<EOF
61$(echo $core_files | sed -e "s/ /\n/g")
62EOF
63
64object_files=\
65"debug-ranges-no-lowpc.o \
66 testfile-annobingroup-i386.o \
67 testfile-bpf-dis1.o \
68 testfile-debug-rel-g.o \
69 testfile-gnu-property-note.o"
70
71testfiles $object_files
72
73echo "elfclassify --elf-file"
74testrun ${abs_top_builddir}/src/elfclassify --elf-file $object_files
75testrun_compare ${abs_top_builddir}/src/elfclassify --elf-file --print $object_files <<EOF
76$(echo $object_files | sed -e "s/ /\n/g")
77EOF
78
79echo "object files are not archives"
80testrun ${abs_top_builddir}/src/elfclassify --not-elf-archive $object_files
81testrun_compare ${abs_top_builddir}/src/elfclassify --not-elf-archive --print $object_files <<EOF
82$(echo $object_files | sed -e "s/ /\n/g")
83EOF
84
85echo "object files are not core files"
86testrun ${abs_top_builddir}/src/elfclassify --not-core $object_files
87testrun_compare ${abs_top_builddir}/src/elfclassify --not-core --print $object_files <<EOF
88$(echo $object_files | sed -e "s/ /\n/g")
89EOF
90
91echo "object files are not program files"
92testrun ${abs_top_builddir}/src/elfclassify --not-program $object_files
93testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $object_files <<EOF
94$(echo $object_files | sed -e "s/ /\n/g")
95EOF
96
97echo "object files are not shared files"
98testrun ${abs_top_builddir}/src/elfclassify --not-shared $object_files
99testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $object_files <<EOF
100$(echo $object_files | sed -e "s/ /\n/g")
101EOF
102
103echo "object files are not kernel modules"
104testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $object_files
105testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $object_files <<EOF
106$(echo $object_files | sed -e "s/ /\n/g")
107EOF
108
109echo "object files are not debug-only files"
110testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $object_files
111testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $object_files <<EOF
112$(echo $object_files | sed -e "s/ /\n/g")
113EOF
114
115ar_files="testarchive64.a"
116
117testfiles $ar_files
118
119echo "elfclassify --elf-archive"
120testrun ${abs_top_builddir}/src/elfclassify --elf-archive $ar_files
121testrun_compare ${abs_top_builddir}/src/elfclassify --elf-archive --print $ar_files <<EOF
122$(echo $ar_files | sed -e "s/ /\n/g")
123EOF
124
125echo "archives are not elf-files"
126testrun ${abs_top_builddir}/src/elfclassify --not-elf-file $ar_files
127testrun_compare ${abs_top_builddir}/src/elfclassify --not-elf-file --print $ar_files <<EOF
128$(echo $ar_files | sed -e "s/ /\n/g")
129EOF
130
131echo "archives are not core files"
132testrun ${abs_top_builddir}/src/elfclassify --not-core $ar_files
133testrun_compare ${abs_top_builddir}/src/elfclassify --not-core --print $ar_files <<EOF
134$(echo $ar_files | sed -e "s/ /\n/g")
135EOF
136
137echo "archives are not program files"
138testrun ${abs_top_builddir}/src/elfclassify --not-program $ar_files
139testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $ar_files <<EOF
140$(echo $ar_files | sed -e "s/ /\n/g")
141EOF
142
143echo "archives are not shared files"
144testrun ${abs_top_builddir}/src/elfclassify --not-shared $ar_files
145testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $ar_files <<EOF
146$(echo $ar_files | sed -e "s/ /\n/g")
147EOF
148
149lib_files=\
150"testfile52-32.noshdrs.so \
151 libtestfile_multi_shared.so \
152 testfile52-32.prelink.so \
153 testfile52-32.so
154 testfile54-64.noshdrs.so \
155 testfile54-64.prelink.so \
156 testfile54-64.so \
157 testlib_dynseg.so"
158
159testfiles $lib_files
160
161echo "elfclassify --shared"
162testrun ${abs_top_builddir}/src/elfclassify --shared $lib_files
163testrun_compare ${abs_top_builddir}/src/elfclassify --shared --print $lib_files <<EOF
164$(echo $lib_files | sed -e "s/ /\n/g")
165EOF
166
167echo "shared files are loadable"
168testrun ${abs_top_builddir}/src/elfclassify --loadable $lib_files
169testrun_compare ${abs_top_builddir}/src/elfclassify --loadable --print $lib_files <<EOF
170$(echo $lib_files | sed -e "s/ /\n/g")
171EOF
172
173echo "shared files are not executables"
174testrun ${abs_top_builddir}/src/elfclassify --not-executable $lib_files
175testrun_compare ${abs_top_builddir}/src/elfclassify --not-executable --print $lib_files <<EOF
176$(echo $lib_files | sed -e "s/ /\n/g")
177EOF
178
179echo "shared files are not debug-only"
180testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $lib_files
181testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $lib_files <<EOF
182$(echo $lib_files | sed -e "s/ /\n/g")
183EOF
184
185echo "shared files are not kernel modules"
186testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $lib_files
187testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $lib_files <<EOF
188$(echo $lib_files | sed -e "s/ /\n/g")
189EOF
190
191exe_files=\
192"backtrace.aarch64.exec \
193 backtrace.i386.exec \
194 backtrace.ppc.exec \
195 backtrace.s390x.exec \
196 testfile70.exec \
197 test-offset-loop \
198 testfilebaztab \
199 testfilebaztabppc64"
200
201testfiles $exe_files
202
203echo "elfclassify --program"
204testrun ${abs_top_builddir}/src/elfclassify --program $exe_files
205testrun_compare ${abs_top_builddir}/src/elfclassify --program --print $exe_files <<EOF
206$(echo $exe_files | sed -e "s/ /\n/g")
207EOF
208
209echo "programs are executables (in this case)"
210testrun ${abs_top_builddir}/src/elfclassify --executable $exe_files
211testrun_compare ${abs_top_builddir}/src/elfclassify --executable --print $exe_files <<EOF
212$(echo $exe_files | sed -e "s/ /\n/g")
213EOF
214
215echo "programs are not shared libraries (in this case)"
216testrun ${abs_top_builddir}/src/elfclassify --not-shared $exe_files
217testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $exe_files <<EOF
218$(echo $exe_files | sed -e "s/ /\n/g")
219EOF
220
221echo "programs are not kernel-modules"
222testrun ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module $exe_files
223testrun_compare ${abs_top_builddir}/src/elfclassify --not-linux-kernel-module --print $exe_files <<EOF
224$(echo $exe_files | sed -e "s/ /\n/g")
225EOF
226
227echo "programs are not debug-only"
228testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $exe_files
229testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $exe_files <<EOF
230$(echo $exe_files | sed -e "s/ /\n/g")
231EOF
232
233kmod_files=\
234"hello_aarch64.ko \
235 hello_csky.ko \
236 hello_i386.ko \
237 hello_m68k.ko \
238 hello_ppc64.ko \
239 hello_riscv64.ko \
240 hello_s390.ko \
241 hello_x86_64.ko"
242
243testfiles $kmod_files
244
245echo "elfclassify --linux-kernel-module"
246testrun ${abs_top_builddir}/src/elfclassify --linux-kernel-module $kmod_files
247testrun_compare ${abs_top_builddir}/src/elfclassify --linux-kernel-module --print $kmod_files <<EOF
248$(echo $kmod_files | sed -e "s/ /\n/g")
249EOF
250
251echo "kmods are unstripped"
252testrun ${abs_top_builddir}/src/elfclassify --unstripped $kmod_files
253testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $kmod_files <<EOF
254$(echo $kmod_files | sed -e "s/ /\n/g")
255EOF
256
257echo "kmods are not debug-only"
258testrun ${abs_top_builddir}/src/elfclassify --not-debug-only $kmod_files
259testrun_compare ${abs_top_builddir}/src/elfclassify --not-debug-only --print $kmod_files <<EOF
260$(echo $kmod_files | sed -e "s/ /\n/g")
261EOF
262
263echo "kmods are not loabable (in the normal sense)"
264testrun ${abs_top_builddir}/src/elfclassify --not-loadable $kmod_files
265testrun_compare ${abs_top_builddir}/src/elfclassify --not-loadable --print $kmod_files <<EOF
266$(echo $kmod_files | sed -e "s/ /\n/g")
267EOF
268
269echo "gnu compressed kmods are unstripped"
270testrun ${abs_top_builddir}/src/elfcompress -t gnu --force $kmod_files
271testrun ${abs_top_builddir}/src/elfclassify --unstripped $kmod_files
272testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $kmod_files <<EOF
273$(echo $kmod_files | sed -e "s/ /\n/g")
274EOF
275
276debug_files=\
277"testfile15.debug \
278 testfile35.debug \
279 testfile40.debug \
280 testfile48.debug \
281 testfile53-32.debug \
282 testfile53-64.debug \
283 testfilebazdbg.debug \
284 testfilebazdbgppc64.debug \
285 addrx_constx-4.dwo \
286 addrx_constx-5.dwo"
287
288testfiles $debug_files
289
290echo "elfclassify --debug-only"
291testrun ${abs_top_builddir}/src/elfclassify --debug-only $debug_files
292testrun_compare ${abs_top_builddir}/src/elfclassify --debug-only --print $debug_files <<EOF
293$(echo $debug_files | sed -e "s/ /\n/g")
294EOF
295
296echo "debug-only files are unstripped"
297testrun ${abs_top_builddir}/src/elfclassify --unstripped $debug_files
298testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $debug_files <<EOF
299$(echo $debug_files | sed -e "s/ /\n/g")
300EOF
301
302echo "debug-only files are not programs"
303testrun ${abs_top_builddir}/src/elfclassify --not-program $debug_files
304testrun_compare ${abs_top_builddir}/src/elfclassify --not-program --print $debug_files <<EOF
305$(echo $debug_files | sed -e "s/ /\n/g")
306EOF
307
308echo "debug-only files are not shared"
309testrun ${abs_top_builddir}/src/elfclassify --not-shared $debug_files
310testrun_compare ${abs_top_builddir}/src/elfclassify --not-shared --print $debug_files <<EOF
311$(echo $debug_files | sed -e "s/ /\n/g")
312EOF
313
314echo "compress the debug sections and try again"
315testrun ${abs_top_builddir}/src/elfcompress -t gnu --force $debug_files
316
317echo "again unstripped"
318testrun ${abs_top_builddir}/src/elfclassify --unstripped $debug_files
319testrun_compare ${abs_top_builddir}/src/elfclassify --unstripped --print $debug_files <<EOF
320$(echo $debug_files | sed -e "s/ /\n/g")
321EOF
322
323echo "again debug-only"
324testrun ${abs_top_builddir}/src/elfclassify --debug-only $debug_files
325testrun_compare ${abs_top_builddir}/src/elfclassify --debug-only --print $debug_files <<EOF
326$(echo $debug_files | sed -e "s/ /\n/g")
327EOF
328