From e1e56b3a2eec04e8360bbc9b644abfde672c78ee Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Sun, 27 Oct 2019 15:26:38 -0400 Subject: debuginfod testsuite: simplify, include SIGUSR2/grooming --- tests/run-debuginfod-find.sh | 265 +++++++++++++++--------------------- tests/testfile-debuginfod-0.rpm.bz2 | Bin 286808 -> 310454 bytes tests/testfile-debuginfod-1.rpm.bz2 | Bin 751886 -> 684919 bytes tests/testfile-debuginfod-2.rpm.bz2 | Bin 642802 -> 641788 bytes 4 files changed, 110 insertions(+), 155 deletions(-) diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh index 37385a0b..2facef2c 100755 --- a/tests/run-debuginfod-find.sh +++ b/tests/run-debuginfod-find.sh @@ -14,14 +14,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. $srcdir/test-subr.sh +set -x +. $srcdir/test-subr.sh # includes set -e + +# These are released Fedora 30 i686 main,-debuginfo,-debugsource rpms from koji +# https://koji.fedoraproject.org/koji/buildinfo?buildID=1355903 testfiles testfile-debuginfod-0.rpm testfile-debuginfod-1.rpm testfile-debuginfod-2.rpm -EXPECT_FAIL=0 -EXPECT_PASS=1 DB=${PWD}/.debuginfod_tmp.sqlite export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache +# clean up trash if we were aborted early +trap 'set +e; kill $PID1 $PID2; rm -rf F R ${PWD}/.client_cache*; exit_cleanup; exit 0' 0 1 2 3 5 9 15 + # find an unused port number while true; do PORT1=`expr '(' $RANDOM % 1000 ')' + 9000` @@ -35,91 +40,124 @@ done # 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'` +mkdir F R +tempfiles F R +env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod -vvvv -d $DB \ +-p $PORT1 -t0 -g0 R F & +PID1=$! +sleep 3 +export DEBUGINFOD_URLS=http://localhost:$PORT1/ # or without trailing / + +# We use -t0 and -g0 here to turn off time-based scanning & grooming. +# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process. + +######################################################################## + # Compile a simple program, strip its debuginfo and save the build-id. # Also move the debuginfo into another directory so that elfutils # cannot find it without debuginfod. echo "int main() { return 0; }" > ${PWD}/prog.c +tempfiles prog.c gcc -g -o prog ${PWD}/prog.c ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ -a prog | grep 'Build ID' | cut -d ' ' -f 7` -mkdir debug exec src -mv prog exec/ -mv prog.debug debug/ -mv testfile-debuginfod-0.rpm debug/ +mv prog F +mv prog.debug F +kill -USR1 $PID1 +sleep 3 # give enough time for scanning pass -# hardcode the buildid of an executable from testfile-debuginfod-0.rpm -BUILDID_RPM0=43a3c5fa7e4a7469b2cf3c25d316ea898d9857fd +######################################################################## -env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod -vvv -d $DB \ --p $PORT1 -t 2 ./debug ./exec ./src & -PID1=$! -sleep 3 - -export DEBUGINFOD_URLS=http://localhost:$PORT1/ # or without trailing / +# Test whether elfutils, via the debuginfod client library dlopen hooks, +# is able to fetch debuginfo from the local debuginfod. +testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 -# Test whether the elfutils client is able to fetch the file from the local debuginfod. -testrun ${abs_builddir}/debuginfod_build_id_find -e exec/prog $EXPECT_PASS +######################################################################## -# Test whether debuginfod-find is able to fetch files from the local debuginfod's rpm and -# directory search paths. -rm -rf $DEBUGINFOD_CACHE_PATH -testrun_compare ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID < ${PWD}/prog2.c +tempfiles prog2.c gcc -g -o prog2 ${PWD}/prog2.c - ${abs_top_builddir}/src/strip -g -f prog2.debug prog2 BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ -a prog2 | grep 'Build ID' | cut -d ' ' -f 7` -mv prog2 exec/ -mv prog2.debug debug/ +mv prog2 F +kill -USR1 $PID1 +sleep 3 -tempfiles prog* +# Rerun same tests for the prog2 binary +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2` +cmp $filename F/prog2 +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2` +cmp $filename F/prog2 +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c` +cmp $filename ${PWD}/prog2.c + +mv testfile-debuginfod-0.rpm R +mv testfile-debuginfod-1.rpm R +mv testfile-debuginfod-2.rpm R +kill -USR1 $PID1 +sleep 10 +kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs +sleep 10 + +RPM_BUILDID=5cae7f84186d4ff6c462c32324a764f7a38c3b80 # ./usr/bin/eu-readelf +RPM_SOURCE_PATH=/usr/src/debug/elfutils-0.177-1.fc30.i386/src/readelf.c +RPM_EXECUTABLE_SHA1SUM=9e4c79dd91a4646d95dfbf091b133e1a21ab2d4c +RPM_DEBUGINFO_SHA1SUM=6b638fa2abc5ff0d4d6c438d904092d20cc71827 +RPM_SOURCE_SHA1SUM=a5bde2a096f6d8f8221456c9380d3532235d7980 + +# Run similar tests against contents of the test RPMs ... except we can't (don't want to) +# compare the returned binary to the one in the RPM(s), so we cheat a bit, just use a +# sha1sum comparison +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID` +hash=`cat $filename | sha1sum | awk '{print $1}'` +test $hash = $RPM_EXECUTABLE_SHA1SUM + +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $RPM_BUILDID` +hash=`cat $filename | sha1sum | awk '{print $1}'` +test $hash = $RPM_DEBUGINFO_SHA1SUM + +filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $RPM_BUILDID $RPM_SOURCE_PATH` +hash=`cat $filename | sha1sum | awk '{print $1}'` +test $hash = $RPM_SOURCE_SHA1SUM + +######################################################################## + +# Drop some of the artifacts, run a groom cycle; confirm that +# debuginfod has forgotten them, but remembers others + +rm R/testfile-* +kill -USR2 $PID1 # groom cycle sleep 3 +rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests -testrun ${abs_builddir}/debuginfod_build_id_find -e exec/prog2 $EXPECT_PASS +testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true -testrun_compare ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 < $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s echo 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s -testrun ${abs_builddir}/debuginfod_build_id_find -e exec/prog $EXPECT_FAIL - -testrun_compare ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 <