diff options
| author | Noah Sanci <[email protected]> | 2021-08-10 11:21:35 -0400 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2021-09-03 10:40:52 +0200 |
| commit | ef856762088bcd85ac9121b129dba0c6910369a2 (patch) | |
| tree | b33ae613f227794530adf125dc3e4ff0101f55e5 /tests/debuginfod-subr.sh | |
| parent | 6eb991a9ebc45cc468a049ef30a98a0f7cad4a0d (diff) | |
debuginfod: Fracture tests/run-debuginfod-find.sh into specific tests
tests/run-debuginfod-find.sh was a massive test script with many broadly
varying tests. This caused the test script to fail when any number of
things went wrong and because of its intertwined nature, detecting the
source of a failure could be difficult. The size of the test script
also meant many unrelated tests were run making the testing process
unnecessarily lengthy.
This patch fractures tests/run-debuginfod-find.sh into smaller, more
manageable individual test script files. This ensures that when failure
occurs, a programmer can easily determine where their patch went
wrong. It also allows programmers to specify exactly which tests to
run, making testing more efficient. Redundancies are also reduced by
placing code in tests/debuginfod-subr.sh.
Signed-off-by: Noah Sanci <[email protected]>
Diffstat (limited to 'tests/debuginfod-subr.sh')
| -rwxr-xr-x | tests/debuginfod-subr.sh | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/tests/debuginfod-subr.sh b/tests/debuginfod-subr.sh new file mode 100755 index 00000000..3222a2b0 --- /dev/null +++ b/tests/debuginfod-subr.sh @@ -0,0 +1,149 @@ +# Copyright (C) 2021 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/>. + +# sourced from run-debuginfod-*.sh tests (must be bash scripts) + +. $srcdir/test-subr.sh # includes set -e + +type curl 2>/dev/null || (echo "need curl"; exit 77) +type rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77) +type cpio 2>/dev/null || (echo "need cpio"; exit 77) +type bzcat 2>/dev/null || (echo "need bzcat"; exit 77) +bsdtar --version | grep -q zstd && zstd=true || zstd=false +echo "zstd=$zstd bsdtar=`bsdtar --version`" + +cleanup() +{ + if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi + if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi + rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp* + exit_cleanup +} + +# clean up trash if we were aborted early +trap cleanup 0 1 2 3 5 9 15 + +errfiles_list= +err() { + echo ERROR REPORTS + for ports in $PORT1 $PORT2 + do + echo ERROR REPORT $port metrics + curl -s http://127.0.0.1:$port/metrics + echo + done + for x in $errfiles_list + do + echo ERROR REPORT "$x" + cat $x + echo + done + false # trigger set -e +} +trap err ERR + +errfiles() { + errfiles_list="$errfiles_list $*" +} + +# We want to run debuginfod in the background. We also want to start +# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff +# that the testrun alias sets. But: we if we just use +# testrun .../debuginfod +# it runs in a subshell, with different pid, so not helpful. +# +# So we gather the LD_LIBRARY_PATH with this cunning trick: +ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'` + +wait_ready() +{ + port=$1; + what=$2; + value=$3; + timeout=20; + + echo "Wait $timeout seconds on $port for metric $what to change to $value" + while [ $timeout -gt 0 ]; do + mvalue="$(curl -s http://127.0.0.1:$port/metrics \ + | grep "$what" | awk '{print $NF}')" + if [ -z "$mvalue" ]; then mvalue=0; fi + echo "metric $what: $mvalue" + if [ "$mvalue" -eq "$value" ]; then + break; + fi + sleep 0.5; + ((timeout--)); + done; + + if [ $timeout -eq 0 ]; then + echo "metric $what never changed to $value on port $port" + err + fi +} + +archive_test() { + __BUILDID=$1 + __SOURCEPATH=$2 + __SOURCESHA1=$3 + + filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID` + buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ + -a $filename | grep 'Build ID' | cut -d ' ' -f 7` + test $__BUILDID = $buildid + # check that timestamps are plausible - older than the near-present (tmpdir mtime) + test $filename -ot `pwd` + + # run again to assure that fdcache is being enjoyed + filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID` + buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ + -a $filename | grep 'Build ID' | cut -d ' ' -f 7` + test $__BUILDID = $buildid + test $filename -ot `pwd` + + filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID` + buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ + -a $filename | grep 'Build ID' | cut -d ' ' -f 7` + test $__BUILDID = $buildid + test $filename -ot `pwd` + + if test "x$__SOURCEPATH" != "x"; then + filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH` + hash=`cat $filename | sha1sum | awk '{print $1}'` + test $__SOURCESHA1 = $hash + test $filename -ot `pwd` + fi +} + +get_ports() { + while true; do + PORT1=`expr '(' $RANDOM % 100 ')' + $base` + ss -atn | fgrep ":$PORT1" || break + done +# Some tests will use two servers, so assign the second var + while true; do + PORT2=`expr '(' $RANDOM % 100 ')' + $base` + ss -atn | fgrep ":$PORT2" && $PORT1 -ne $PORT2 || break + done + +} + +VERBOSE=-vvv +# We gather the LD_LIBRARY_PATH with this cunning trick: +ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'` +PORT1=0 +PORT2=0 +PID1=0 +PID2=0 |
