summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-12-01 14:55:07 +0100
committerMark Wielaard <mjw@redhat.com>2016-01-06 14:27:10 +0100
commit92acb57eb0468de93c4976eb1de6bf08ede9abd0 (patch)
tree27ba3b9926a47e97bafdcd126f4f6e64ea82453b /tests
parente5f976bcb1b3a27bd89d8d32c0cebb0c14c0e6d2 (diff)
downloadelfutils-92acb57eb0468de93c4976eb1de6bf08ede9abd0.tar.gz
elfcompress: New utility.
Usage: elfcompress [OPTION...] FILE... Compress or decompress sections in an ELF file. -f, --force Force compression of section even if it would become larger -n, --name=SECTION SECTION name to (de)compress, SECTION is an extended wildcard pattern (defaults to '.?(z)debug*') -o, --output=FILE Place (de)compressed output into FILE -p, --permissive Relax a few rules to handle slightly broken ELF files -q, --quiet Be silent when a section cannot be compressed -t, --type=TYPE What type of compression to apply. TYPE can be 'none' (decompress), 'zlib' (ELF ZLIB compression, the default, 'zlib-gabi' is an alias) or 'zlib-gnu' (.zdebug GNU style compression, 'gnu' is an alias) -v, --verbose Print a message for each section being (de)compressed -?, --help Give this help list --usage Give a short usage message -V, --version Print program version Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog6
-rw-r--r--tests/Makefile.am5
-rwxr-xr-xtests/run-compress-test.sh102
3 files changed, 111 insertions, 2 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 419610c4..3d912600 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-16 Mark Wielaard <mjw@redhat.com>
+
+ * run-compress-test.sh: New test.
+ * Makefile.am (TESTS): Add run-compress-test.sh.
+ (EXTRA_DISTS): Likewise.
+
2015-11-26 Mark Wielaard <mjw@redhat.com>
* zstrptr.c: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6d666e9d..819f2d1e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -123,7 +123,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-getsrc-die.sh run-strptr.sh newdata elfstrtab dwfl-proc-attach \
elfshphehdr run-lfs-symbols.sh run-dwelfgnucompressed.sh \
run-elfgetchdr.sh \
- run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh
+ run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh \
+ run-compress-test.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -320,7 +321,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
testfile-zgabi32.bz2 testfile-zgabi64.bz2 \
testfile-zgabi32be.bz2 testfile-zgabi64be.bz2 \
run-elfgetchdr.sh run-elfgetzdata.sh run-elfputzdata.sh \
- run-zstrptr.sh
+ run-zstrptr.sh run-compress-test.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
diff --git a/tests/run-compress-test.sh b/tests/run-compress-test.sh
new file mode 100755
index 00000000..a6a298f5
--- /dev/null
+++ b/tests/run-compress-test.sh
@@ -0,0 +1,102 @@
+#! /bin/sh
+# Copyright (C) 2015 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
+
+# uncompress -> gnucompress -> uncompress -> elfcompress -> uncompress
+testrun_elfcompress_file()
+{
+ infile="$1"
+ uncompressedfile="${infile}.uncompressed"
+ tempfiles "$uncompressedfile"
+
+ echo "uncompress $infile -> $uncompressedfile"
+ testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${uncompressedfile} ${infile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${uncompressedfile}
+
+ SIZE_uncompressed=$(stat -c%s $uncompressedfile)
+
+ gnucompressedfile="${infile}.gnu"
+ tempfiles "$gnucompressedfile"
+ echo "compress gnu $uncompressedfile -> $gnucompressedfile"
+ testrun ${abs_top_builddir}/src/elfcompress -v -t gnu -o ${gnucompressedfile} ${uncompressedfile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${gnucompressedfile}
+
+ SIZE_gnucompressed=$(stat -c%s $gnucompressedfile)
+ test $SIZE_gnucompressed -lt $SIZE_uncompressed ||
+ { echo "*** failure $gnucompressedfile not smaller"; exit -1; }
+
+ gnuuncompressedfile="${infile}.gnu.uncompressed"
+ tempfiles "$gnuuncompressedfile"
+ echo "uncompress $gnucompressedfile -> $gnuuncompressedfile"
+ testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${gnuuncompressedfile} ${gnucompressedfile}
+ testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${gnuuncompressedfile}
+
+ elfcompressedfile="${infile}.gabi"
+ tempfiles "$elfcompressedfile"
+ echo "compress gabi $uncompressedfile -> $elfcompressedfile"
+ testrun ${abs_top_builddir}/src/elfcompress -v -t zlib -o ${elfcompressedfile} ${uncompressedfile}
+ testrun ${abs_top_builddir}/src/elflint --gnu-ld ${elfcompressedfile}
+
+ SIZE_elfcompressed=$(stat -c%s $elfcompressedfile)
+ test $SIZE_elfcompressed -lt $SIZE_uncompressed ||
+ { echo "*** failure $elfcompressedfile not smaller"; exit -1; }
+
+ elfuncompressedfile="${infile}.gabi.uncompressed"
+ tempfiles "$elfuncompressedfile"
+ echo "uncompress $elfcompressedfile -> $elfuncompressedfile"
+ testrun ${abs_top_builddir}/src/elfcompress -v -t none -o ${elfuncompressedfile} ${elfcompressedfile}
+ testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${elfuncompressedfile}
+}
+
+testrun_elfcompress()
+{
+ testfile="$1"
+ testfiles ${testfile}
+ testrun_elfcompress_file ${testfile}
+
+ # Merge the string tables to make things a little more interesting.
+ mergedfile="${testfile}.merged"
+ tempfiles ${mergedfile}
+ echo "merging string tables ${testfile} -> ${mergedfile}"
+ testrun ${abs_top_builddir}/tests/elfstrmerge -o ${mergedfile} ${testfile}
+ testrun_elfcompress_file ${mergedfile}
+}
+
+# Random ELF32 testfile
+testrun_elfcompress testfile4
+
+# Random ELF64 testfile
+testrun_elfcompress testfile12
+
+# Random ELF64BE testfile
+testrun_elfcompress testfileppc64
+
+# Random ELF32BE testfile
+testrun_elfcompress testfileppc32
+
+# Already compressed files
+testrun_elfcompress testfile-zgnu64
+testrun_elfcompress testfile-zgnu64be
+testrun_elfcompress testfile-zgabi64
+testrun_elfcompress testfile-zgabi64be
+testrun_elfcompress testfile-zgnu32
+testrun_elfcompress testfile-zgnu32be
+testrun_elfcompress testfile-zgabi32
+testrun_elfcompress testfile-zgabi32be
+
+exit 0