Home | History | Annotate | Download | only in tests
      1 #! /bin/sh
      2 # Copyright (C) 2005, 2007, 2008 Red Hat, Inc.
      3 # This file is part of Red Hat elfutils.
      4 #
      5 # Red Hat elfutils is free software; you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as published by the
      7 # Free Software Foundation; version 2 of the License.
      8 #
      9 # Red Hat elfutils is distributed in the hope that it will be useful, but
     10 # WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12 # General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License along
     15 # with Red Hat elfutils; if not, write to the Free Software Foundation,
     16 # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     17 #
     18 # Red Hat elfutils is an included package of the Open Invention Network.
     19 # An included package of the Open Invention Network is a package for which
     20 # Open Invention Network licensees cross-license their patents.  No patent
     21 # license is granted, either expressly or impliedly, by designation as an
     22 # included package.  Should you wish to participate in the Open Invention
     23 # Network licensing program, please visit www.openinventionnetwork.com
     24 # <http://www.openinventionnetwork.com>.
     25 
     26 
     27 # This file is sourced by ". $srcdir/test-subr.sh" at the start of
     28 # each test script.  It defines some functions they use and sets up
     29 # canonical sh state for test runs.
     30 
     31 set -e
     32 
     33 #LC_ALL=C
     34 #export LC_ALL
     35 
     36 remove_files=
     37 trap 'rm -f $remove_files' 0
     38 
     39 tempfiles()
     40 {
     41   remove_files="$remove_files $*"
     42 }
     43 
     44 testfiles()
     45 {
     46   for file; do
     47     bunzip2 -c $srcdir/${file}.bz2 > ${file} 2>/dev/null || exit 77
     48     remove_files="$remove_files $file"
     49   done
     50 }
     51 
     52 testrun_out()
     53 {
     54   outfile="$1"
     55   shift
     56   remove_files="$remove_files $outfile"
     57   testrun "$@" > $outfile 2>&1 || :
     58 }
     59 
     60 testrun_compare()
     61 {
     62   outfile="${1##*/}.out"
     63   testrun_out $outfile "$@"
     64   diff -u $outfile -
     65   # diff's exit status will kill the script.
     66 }
     67 
     68 test_cleanup()
     69 {
     70   rm -f $remove_files
     71   remove_files=
     72 }
     73 
     74 # See test-wrapper.sh, which sets the environment for this.
     75 testrun()
     76 {
     77   ${elfutils_testrun}_testrun "$@"
     78 }
     79 
     80 built_testrun()
     81 {
     82   LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"\
     83   "$@"
     84 }
     85 
     86 installed_testrun()
     87 {
     88   program="$1"
     89   shift
     90   case "$program" in
     91   ./*)
     92     if [ "x$elfutils_tests_rpath" != xno ]; then
     93       echo >&2 installcheck not possible with --enable-tests-rpath
     94       exit 77
     95     fi
     96     ;;
     97   ../*)
     98     program=${bindir}/`program_transform ${program##*/}`
     99     ;;
    100   esac
    101   if [ "${libdir}" != /usr/lib ] && [ "${libdir}" != /usr/lib64 ]; then
    102     LD_LIBRARY_PATH="${libdir}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" \
    103     $program ${1+"$@"}
    104   else
    105     $program ${1+"$@"}
    106   fi
    107 }
    108 
    109 program_transform()
    110 {
    111   echo "$*" | sed "${program_transform_name}"
    112 }
    113