1*7304104dSAndroid Build Coastguard Worker#! /bin/sh 2*7304104dSAndroid Build Coastguard Worker# Copyright (C) 2015 Red Hat, Inc. 3*7304104dSAndroid Build Coastguard Worker# This file is part of elfutils. 4*7304104dSAndroid Build Coastguard Worker# 5*7304104dSAndroid Build Coastguard Worker# This file is free software; you can redistribute it and/or modify 6*7304104dSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by 7*7304104dSAndroid Build Coastguard Worker# the Free Software Foundation; either version 3 of the License, or 8*7304104dSAndroid Build Coastguard Worker# (at your option) any later version. 9*7304104dSAndroid Build Coastguard Worker# 10*7304104dSAndroid Build Coastguard Worker# elfutils is distributed in the hope that it will be useful, but 11*7304104dSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of 12*7304104dSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*7304104dSAndroid Build Coastguard Worker# GNU General Public License for more details. 14*7304104dSAndroid Build Coastguard Worker# 15*7304104dSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License 16*7304104dSAndroid Build Coastguard Worker# along with this program. If not, see <http://www.gnu.org/licenses/>. 17*7304104dSAndroid Build Coastguard Worker 18*7304104dSAndroid Build Coastguard Worker. $srcdir/test-subr.sh 19*7304104dSAndroid Build Coastguard Worker 20*7304104dSAndroid Build Coastguard Worker# uncompress -> gnucompress -> uncompress -> elfcompress -> uncompress 21*7304104dSAndroid Build Coastguard Workertestrun_elfcompress_file() 22*7304104dSAndroid Build Coastguard Worker{ 23*7304104dSAndroid Build Coastguard Worker infile="$1" 24*7304104dSAndroid Build Coastguard Worker uncompressedfile="${infile}.uncompressed" 25*7304104dSAndroid Build Coastguard Worker tempfiles "$uncompressedfile" 26*7304104dSAndroid Build Coastguard Worker 27*7304104dSAndroid Build Coastguard Worker echo "uncompress $infile -> $uncompressedfile" 28*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${uncompressedfile} ${infile} 29*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elflint --gnu-ld ${uncompressedfile} 30*7304104dSAndroid Build Coastguard Worker 31*7304104dSAndroid Build Coastguard Worker SIZE_uncompressed=$(stat -c%s $uncompressedfile) 32*7304104dSAndroid Build Coastguard Worker 33*7304104dSAndroid Build Coastguard Worker gnucompressedfile="${infile}.gnu" 34*7304104dSAndroid Build Coastguard Worker tempfiles "$gnucompressedfile" 35*7304104dSAndroid Build Coastguard Worker echo "compress gnu $uncompressedfile -> $gnucompressedfile" 36*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t gnu -o ${gnucompressedfile} ${uncompressedfile} 37*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elflint --gnu-ld ${gnucompressedfile} 38*7304104dSAndroid Build Coastguard Worker 39*7304104dSAndroid Build Coastguard Worker SIZE_gnucompressed=$(stat -c%s $gnucompressedfile) 40*7304104dSAndroid Build Coastguard Worker test $SIZE_gnucompressed -lt $SIZE_uncompressed || 41*7304104dSAndroid Build Coastguard Worker { echo "*** failure $gnucompressedfile not smaller"; exit -1; } 42*7304104dSAndroid Build Coastguard Worker 43*7304104dSAndroid Build Coastguard Worker gnuuncompressedfile="${infile}.gnu.uncompressed" 44*7304104dSAndroid Build Coastguard Worker tempfiles "$gnuuncompressedfile" 45*7304104dSAndroid Build Coastguard Worker echo "uncompress $gnucompressedfile -> $gnuuncompressedfile" 46*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${gnuuncompressedfile} ${gnucompressedfile} 47*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${gnuuncompressedfile} 48*7304104dSAndroid Build Coastguard Worker 49*7304104dSAndroid Build Coastguard Worker elfcompressedfile="${infile}.gabi" 50*7304104dSAndroid Build Coastguard Worker tempfiles "$elfcompressedfile" 51*7304104dSAndroid Build Coastguard Worker echo "compress gabi $uncompressedfile -> $elfcompressedfile" 52*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t zlib -o ${elfcompressedfile} ${uncompressedfile} 53*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elflint --gnu-ld ${elfcompressedfile} 54*7304104dSAndroid Build Coastguard Worker 55*7304104dSAndroid Build Coastguard Worker SIZE_elfcompressed=$(stat -c%s $elfcompressedfile) 56*7304104dSAndroid Build Coastguard Worker test $SIZE_elfcompressed -lt $SIZE_uncompressed || 57*7304104dSAndroid Build Coastguard Worker { echo "*** failure $elfcompressedfile not smaller"; exit -1; } 58*7304104dSAndroid Build Coastguard Worker 59*7304104dSAndroid Build Coastguard Worker elfuncompressedfile="${infile}.gabi.uncompressed" 60*7304104dSAndroid Build Coastguard Worker tempfiles "$elfuncompressedfile" 61*7304104dSAndroid Build Coastguard Worker echo "uncompress $elfcompressedfile -> $elfuncompressedfile" 62*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${elfuncompressedfile} ${elfcompressedfile} 63*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${elfuncompressedfile} 64*7304104dSAndroid Build Coastguard Worker 65*7304104dSAndroid Build Coastguard Worker if test -z "$ELFUTILS_ZSTD"; then 66*7304104dSAndroid Build Coastguard Worker return; 67*7304104dSAndroid Build Coastguard Worker fi 68*7304104dSAndroid Build Coastguard Worker 69*7304104dSAndroid Build Coastguard Worker outputfile="${infile}.gabi.zstd" 70*7304104dSAndroid Build Coastguard Worker tempfiles "$outputfile" 71*7304104dSAndroid Build Coastguard Worker echo "zstd compress $elfcompressedfile -> $outputfile" 72*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t zstd -o ${outputfile} ${elfcompressedfile} 73*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${outputfile} 74*7304104dSAndroid Build Coastguard Worker echo "checking compressed section header" $outputfile 75*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/readelf -Sz ${outputfile} | grep "ELF ZSTD" >/dev/null 76*7304104dSAndroid Build Coastguard Worker 77*7304104dSAndroid Build Coastguard Worker zstdfile="${infile}.zstd" 78*7304104dSAndroid Build Coastguard Worker tempfiles "$zstdfile" 79*7304104dSAndroid Build Coastguard Worker echo "zstd compress $uncompressedfile -> $zstdfile" 80*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t zstd -o ${zstdfile} ${elfuncompressedfile} 81*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${zstdfile} 82*7304104dSAndroid Build Coastguard Worker echo "checking compressed section header" $zstdfile 83*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/readelf -Sz ${zstdfile} | grep "ELF ZSTD" >/dev/null 84*7304104dSAndroid Build Coastguard Worker 85*7304104dSAndroid Build Coastguard Worker zstdgnufile="${infile}.zstd.gnu" 86*7304104dSAndroid Build Coastguard Worker tempfiles "$zstdgnufile" 87*7304104dSAndroid Build Coastguard Worker echo "zstd re-compress to GNU ZLIB $zstdfile -> $zstdgnufile" 88*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcompress -v -t zlib-gnu -o ${zstdgnufile} ${zstdfile} 89*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${zstdgnufile} 90*7304104dSAndroid Build Coastguard Worker echo "checking .zdebug section name" $zstdgnufile 91*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/src/readelf -S ${zstdgnufile} | grep ".zdebug" >/dev/null 92*7304104dSAndroid Build Coastguard Worker} 93*7304104dSAndroid Build Coastguard Worker 94*7304104dSAndroid Build Coastguard Workertestrun_elfcompress() 95*7304104dSAndroid Build Coastguard Worker{ 96*7304104dSAndroid Build Coastguard Worker testfile="$1" 97*7304104dSAndroid Build Coastguard Worker testfiles ${testfile} 98*7304104dSAndroid Build Coastguard Worker testrun_elfcompress_file ${testfile} 99*7304104dSAndroid Build Coastguard Worker 100*7304104dSAndroid Build Coastguard Worker # Merge the string tables to make things a little more interesting. 101*7304104dSAndroid Build Coastguard Worker mergedfile="${testfile}.merged" 102*7304104dSAndroid Build Coastguard Worker tempfiles ${mergedfile} 103*7304104dSAndroid Build Coastguard Worker echo "merging string tables ${testfile} -> ${mergedfile}" 104*7304104dSAndroid Build Coastguard Worker testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile} 105*7304104dSAndroid Build Coastguard Worker testrun_elfcompress_file ${mergedfile} 106*7304104dSAndroid Build Coastguard Worker} 107*7304104dSAndroid Build Coastguard Worker 108*7304104dSAndroid Build Coastguard Worker# Random ELF32 testfile 109*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile4 110*7304104dSAndroid Build Coastguard Worker 111*7304104dSAndroid Build Coastguard Worker# Random ELF64 testfile 112*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile12 113*7304104dSAndroid Build Coastguard Worker 114*7304104dSAndroid Build Coastguard Worker# Random ELF64BE testfile 115*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfileppc64 116*7304104dSAndroid Build Coastguard Worker 117*7304104dSAndroid Build Coastguard Worker# Random ELF32BE testfile 118*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfileppc32 119*7304104dSAndroid Build Coastguard Worker 120*7304104dSAndroid Build Coastguard Worker# Already compressed files 121*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgnu64 122*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgnu64be 123*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgabi64 124*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgabi64be 125*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgnu32 126*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgnu32be 127*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgabi32 128*7304104dSAndroid Build Coastguard Workertestrun_elfcompress testfile-zgabi32be 129*7304104dSAndroid Build Coastguard Worker 130*7304104dSAndroid Build Coastguard Workerexit 0 131