1#! /bin/sh 2# Copyright (C) 2005-2015, 2017 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 19# This file is sourced by ". $srcdir/test-subr.sh" at the start of 20# each test script. It defines some functions they use and sets up 21# canonical sh state for test runs. 22 23set -e 24 25# Each test runs in its own directory to make sure they can run in parallel. 26test_dir="test-$$" 27mkdir -p "$test_dir" 28cd "$test_dir" 29 30#LC_ALL=C 31#export LC_ALL 32 33remove_files= 34 35# Tests that trap EXIT (0) themselves should call this explicitly. 36exit_cleanup() 37{ 38 rm -f $remove_files; cd ..; rmdir $test_dir 39} 40trap exit_cleanup 0 41 42tempfiles() 43{ 44 remove_files="$remove_files $*" 45} 46 47testfiles() 48{ 49 for file; do 50 bunzip2 -c ${abs_srcdir}/${file}.bz2 > ${file} || exit 77 51 remove_files="$remove_files $file" 52 done 53} 54 55testrun_out() 56{ 57 outfile="$1" 58 shift 59 remove_files="$remove_files $outfile" 60 testrun "$@" > $outfile 2>&1 || : 61} 62 63testrun_compare() 64{ 65 outfile="${1##*/}.out" 66 testrun_out $outfile "$@" 67 diff -u $outfile - 68 # diff's exit status will kill the script. 69} 70 71test_cleanup() 72{ 73 rm -f $remove_files 74 remove_files= 75} 76 77# See test-wrapper.sh, which sets the environment for this. 78testrun() 79{ 80 ${elfutils_testrun}_testrun "$@" 81} 82 83built_testrun() 84{ 85 LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"\ 86 $VALGRIND_CMD "$@" 87} 88 89installed_testrun() 90{ 91 program="$1" 92 shift 93 case "$program" in 94 ${abs_builddir}/*) 95 if [ "x$elfutils_tests_rpath" != xno ]; then 96 echo >&2 installcheck not possible with --enable-tests-rpath 97 exit 77 98 fi 99 ;; 100 ${abs_top_builddir}/src/*) 101 program=${bindir}/`program_transform ${program##*/}` 102 ;; 103 esac 104 if [ "${libdir}" != /usr/lib ] && [ "${libdir}" != /usr/lib64 ]; then 105 LD_LIBRARY_PATH="${libdir}:${libdir}/elfutils\ 106${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" \ 107 $VALGRIND_CMD $program ${1+"$@"} 108 else 109 $VALGRIND_CMD $program ${1+"$@"} 110 fi 111} 112 113program_transform() 114{ 115 echo "$*" | sed "${program_transform_name}" 116} 117 118self_test_files_exe=`echo ${abs_top_builddir}/src/addr2line \ 119${abs_top_builddir}/src/elfcmp \ 120${abs_top_builddir}/src/objdump \ 121${abs_top_builddir}/src/readelf` 122 123self_test_files_lib=`echo ${abs_top_builddir}/libelf/libelf.so \ 124${abs_top_builddir}/libdw/libdw.so \ 125${abs_top_builddir}/backends/libebl_i386.so \ 126${abs_top_builddir}/backends/libebl_x86_64.so` 127 128self_test_files_obj=`echo ${abs_top_builddir}/src/size.o \ 129${abs_top_builddir}/src/strip.o` 130 131self_test_files="$self_test_files_exe $self_test_files_lib $self_test_files_obj" 132 133# Provide a command to run on all self-test files with testrun. 134testrun_on_self() 135{ 136 exit_status=0 137 138 for file in $self_test_files; do 139 testrun $* $file \ 140 || { echo "*** failure in $* $file"; exit_status=1; } 141 done 142 143 # Only exit if something failed 144 if test $exit_status != 0; then exit $exit_status; fi 145} 146 147testrun_on_self_exe() 148{ 149 exit_status=0 150 151 for file in $self_test_files_exe; do 152 testrun $* $file \ 153 || { echo "*** failure in $* $file"; exit_status=1; } 154 done 155 156 # Only exit if something failed 157 if test $exit_status != 0; then exit $exit_status; fi 158} 159 160testrun_on_self_lib() 161{ 162 exit_status=0 163 164 for file in $self_test_files_lib; do 165 testrun $* $file \ 166 || { echo "*** failure in $* $file"; exit_status=1; } 167 done 168 169 # Only exit if something failed 170 if test $exit_status != 0; then exit $exit_status; fi 171} 172 173# Compress the files first. Compress both debug sections and symtab. 174testrun_on_self_compressed() 175{ 176 exit_status=0 177 178 for file in $self_test_files; do 179 tempfiles ${file}z 180 testrun ${abs_top_builddir}/src/elfcompress -f -q -o ${file}z ${file} 181 testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' ${file}z 182 183 testrun $* ${file}z \ 184 || { echo "*** failure in $* ${file}z"; exit_status=1; } 185 done 186 187 # Only exit if something failed 188 if test $exit_status != 0; then exit $exit_status; fi 189} 190 191# Same as above, but redirects stdout to /dev/null 192testrun_on_self_quiet() 193{ 194 exit_status=0 195 196 for file in $self_test_files; do 197 testrun $* $file > /dev/null \ 198 || { echo "*** failure in $* $file"; exit_status=1; } 199 done 200 201 # Only exit if something failed 202 if test $exit_status != 0; then exit $exit_status; fi 203} 204