1#!/usr/local/bin/bash
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
20test_reverse ()
21{
22  in_file="$1"
23  out_file="${in_file}.rev"
24  out_file_mmap="${out_file}.mmap"
25
26  testfiles ${in_file}
27  tempfiles ${out_file} ${out_file_mmap}
28
29  # Reverse the offsets (the files should still be the same otherwise)
30  testrun ${abs_builddir}/elfcopy --reverse-offs ${in_file} ${out_file}
31  testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file}
32  testrun ${abs_top_builddir}/src/elflint --gnu ${out_file}
33  # An in-place nop will likely revert them back
34  testrun ${abs_builddir}/elfrdwrnop ${out_file}
35  testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file}
36  testrun ${abs_top_builddir}/src/elflint --gnu ${out_file}
37}
38
39# A collection of random testfiles to test 32/64bit, little/big endian
40# and non-ET_REL (with phdrs)/ET_REL (without phdrs).
41
42# 32bit, big endian, rel
43test_reverse testfile29
44
45# 64bit, big endian, rel
46test_reverse testfile23
47
48# 32bit, little endian, rel
49test_reverse testfile9
50
51# 64bit, little endian, rel
52test_reverse testfile38
53
54# 32bit, big endian, non-rel
55test_reverse testfile26
56
57# 64bit, big endian, non-rel
58test_reverse testfile27
59
60# 32bit, little endian, non-rel
61test_reverse testfile
62
63# 64bit, little endian, non-rel
64# Don't use testfile10. It has section headers in the middle of the file.
65# Same for testfile12. It is legal, but not the point of this testcase.
66# test_reverse testfile10
67test_reverse testfile13
68
69exit 0
70