Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 1 | #! /bin/sh |
Mark Wielaard | c80375d | 2014-01-16 13:48:24 +0100 | [diff] [blame] | 2 | # Copyright (C) 2005-2014 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | # This file is part of elfutils. |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 4 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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. |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 9 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 10 | # elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 14 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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/>. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 17 | |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 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 | |
| 23 | set -e |
| 24 | |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 25 | # Each test runs in its own directory to make sure they can run in parallel. |
| 26 | test_dir="test-$$" |
| 27 | mkdir -p "$test_dir" |
Mark Wielaard | 807ea31 | 2013-04-29 20:48:36 +0200 | [diff] [blame] | 28 | cd "$test_dir" |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 29 | |
Roland McGrath | a845f68 | 2008-12-03 03:41:58 +0000 | [diff] [blame] | 30 | #LC_ALL=C |
| 31 | #export LC_ALL |
| 32 | |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 33 | remove_files= |
Mark Wielaard | 527e21e | 2013-04-27 23:15:44 +0200 | [diff] [blame] | 34 | |
| 35 | # Tests that trap EXIT (0) themselves should call this explicitly. |
| 36 | exit_cleanup() |
| 37 | { |
Mark Wielaard | 807ea31 | 2013-04-29 20:48:36 +0200 | [diff] [blame] | 38 | rm -f $remove_files; cd ..; rmdir $test_dir |
Mark Wielaard | 527e21e | 2013-04-27 23:15:44 +0200 | [diff] [blame] | 39 | } |
| 40 | trap exit_cleanup 0 |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 41 | |
| 42 | tempfiles() |
| 43 | { |
| 44 | remove_files="$remove_files $*" |
| 45 | } |
| 46 | |
| 47 | testfiles() |
| 48 | { |
| 49 | for file; do |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 50 | bunzip2 -c ${abs_srcdir}/${file}.bz2 > ${file} 2>/dev/null || exit 77 |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 51 | remove_files="$remove_files $file" |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | testrun_out() |
| 56 | { |
| 57 | outfile="$1" |
| 58 | shift |
| 59 | remove_files="$remove_files $outfile" |
| 60 | testrun "$@" > $outfile 2>&1 || : |
| 61 | } |
| 62 | |
| 63 | testrun_compare() |
| 64 | { |
| 65 | outfile="${1##*/}.out" |
| 66 | testrun_out $outfile "$@" |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 67 | diff -u $outfile - |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 68 | # diff's exit status will kill the script. |
| 69 | } |
| 70 | |
| 71 | test_cleanup() |
| 72 | { |
| 73 | rm -f $remove_files |
| 74 | remove_files= |
| 75 | } |
| 76 | |
| 77 | # See test-wrapper.sh, which sets the environment for this. |
| 78 | testrun() |
| 79 | { |
| 80 | ${elfutils_testrun}_testrun "$@" |
| 81 | } |
| 82 | |
| 83 | built_testrun() |
| 84 | { |
| 85 | LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"\ |
Mark Wielaard | e3e3ee2 | 2012-10-01 16:14:12 +0200 | [diff] [blame] | 86 | $VALGRIND_CMD "$@" |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | installed_testrun() |
| 90 | { |
| 91 | program="$1" |
| 92 | shift |
| 93 | case "$program" in |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 94 | ${abs_builddir}/*) |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 95 | if [ "x$elfutils_tests_rpath" != xno ]; then |
| 96 | echo >&2 installcheck not possible with --enable-tests-rpath |
| 97 | exit 77 |
| 98 | fi |
| 99 | ;; |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 100 | ${abs_top_builddir}/src/*) |
Roland McGrath | af74f5c | 2005-11-18 02:25:14 +0000 | [diff] [blame] | 101 | program=${bindir}/`program_transform ${program##*/}` |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 102 | ;; |
| 103 | esac |
Roland McGrath | 9365d2c | 2005-11-18 23:55:47 +0000 | [diff] [blame] | 104 | if [ "${libdir}" != /usr/lib ] && [ "${libdir}" != /usr/lib64 ]; then |
Roland McGrath | c1c6a9d | 2012-02-21 12:51:36 -0800 | [diff] [blame] | 105 | LD_LIBRARY_PATH="${libdir}:${libdir}/elfutils\ |
| 106 | ${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" \ |
Mark Wielaard | e3e3ee2 | 2012-10-01 16:14:12 +0200 | [diff] [blame] | 107 | $VALGRIND_CMD $program ${1+"$@"} |
Roland McGrath | af74f5c | 2005-11-18 02:25:14 +0000 | [diff] [blame] | 108 | else |
Mark Wielaard | e3e3ee2 | 2012-10-01 16:14:12 +0200 | [diff] [blame] | 109 | $VALGRIND_CMD $program ${1+"$@"} |
Roland McGrath | af74f5c | 2005-11-18 02:25:14 +0000 | [diff] [blame] | 110 | fi |
Roland McGrath | 1b8b446 | 2005-11-16 01:33:38 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | program_transform() |
| 114 | { |
| 115 | echo "$*" | sed "${program_transform_name}" |
| 116 | } |
Mark Wielaard | 94e387f | 2012-08-01 15:31:12 +0200 | [diff] [blame] | 117 | |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 118 | self_test_files=`echo ${abs_top_builddir}/src/addr2line \ |
| 119 | ${abs_top_builddir}/src/elfcmp ${abs_top_builddir}/src/elflint \ |
| 120 | ${abs_top_builddir}/src/nm ${abs_top_builddir}/src/objdump \ |
Mark Wielaard | c80375d | 2014-01-16 13:48:24 +0100 | [diff] [blame] | 121 | ${abs_top_builddir}/src/readelf \ |
| 122 | ${abs_top_builddir}/src/size.o ${abs_top_builddir}/src/strip.o \ |
| 123 | ${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` |
Mark Wielaard | 94e387f | 2012-08-01 15:31:12 +0200 | [diff] [blame] | 127 | |
| 128 | # Provide a command to run on all self-test files with testrun. |
| 129 | testrun_on_self() |
| 130 | { |
| 131 | exit_status=0 |
| 132 | |
| 133 | for file in $self_test_files; do |
Mark Wielaard | bf707b5 | 2012-08-01 15:39:11 +0200 | [diff] [blame] | 134 | testrun $* $file \ |
| 135 | || { echo "*** failure in $* $file"; exit_status=1; } |
| 136 | done |
| 137 | |
| 138 | # Only exit if something failed |
| 139 | if test $exit_status != 0; then exit $exit_status; fi |
| 140 | } |
| 141 | |
| 142 | # Same as above, but redirects stdout to /dev/null |
| 143 | testrun_on_self_quiet() |
| 144 | { |
| 145 | exit_status=0 |
| 146 | |
| 147 | for file in $self_test_files; do |
| 148 | testrun $* $file > /dev/null \ |
| 149 | || { echo "*** failure in $* $file"; exit_status=1; } |
Mark Wielaard | 94e387f | 2012-08-01 15:31:12 +0200 | [diff] [blame] | 150 | done |
| 151 | |
| 152 | # Only exit if something failed |
| 153 | if test $exit_status != 0; then exit $exit_status; fi |
| 154 | } |