Blame tests/run-debuginfod-find.sh

Packit 032894
#!/bin/bash
Packit 032894
#
Packit Service 35cfd5
# Copyright (C) 2019-2020 Red Hat, Inc.
Packit 032894
# This file is part of elfutils.
Packit 032894
#
Packit 032894
# This file is free software; you can redistribute it and/or modify
Packit 032894
# it under the terms of the GNU General Public License as published by
Packit 032894
# the Free Software Foundation; either version 3 of the License, or
Packit 032894
# (at your option) any later version.
Packit 032894
#
Packit 032894
# elfutils is distributed in the hope that it will be useful, but
Packit 032894
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
# GNU General Public License for more details.
Packit 032894
#
Packit 032894
# You should have received a copy of the GNU General Public License
Packit 032894
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 032894
Packit 032894
. $srcdir/test-subr.sh  # includes set -e
Packit 032894
Packit Service 35cfd5
type curl 2>/dev/null || (echo "need curl"; exit 77)
Packit Service 35cfd5
type rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77)
Packit Service 35cfd5
type bzcat 2>/dev/null || (echo "need bzcat"; exit 77)
Packit Service 35cfd5
bsdtar --version | grep -q zstd && zstd=true || zstd=false
Packit Service 35cfd5
echo "zstd=$zstd bsdtar=`bsdtar --version`"
Packit Service 35cfd5
Packit Service 35cfd5
# for test case debugging, uncomment:
Packit Service 35cfd5
#set -x
Packit Service 35cfd5
#VERBOSE=-vvvv
Packit Service 35cfd5
Packit 032894
DB=${PWD}/.debuginfod_tmp.sqlite
Packit 032894
tempfiles $DB
Packit 032894
export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
Packit 032894
Packit 032894
PID1=0
Packit 032894
PID2=0
Packit Service 35cfd5
PID3=0
Packit 032894
Packit 032894
cleanup()
Packit 032894
{
Packit 032894
  if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi
Packit 032894
  if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
Packit Service 35cfd5
  if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
Packit 032894
Packit Service 35cfd5
  rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp*
Packit 032894
  exit_cleanup
Packit 032894
}
Packit 032894
Packit 032894
# clean up trash if we were aborted early
Packit 032894
trap cleanup 0 1 2 3 5 9 15
Packit 032894
Packit 032894
# find an unused port number
Packit 032894
while true; do
Packit 032894
    PORT1=`expr '(' $RANDOM % 1000 ')' + 9000`
Packit 032894
    ss -atn | fgrep ":$PORT1" || break
Packit 032894
done    
Packit 032894
Packit 032894
# We want to run debuginfod in the background.  We also want to start
Packit 032894
# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff
Packit 032894
# that the testrun alias sets.  But: we if we just use
Packit 032894
#    testrun .../debuginfod
Packit 032894
# it runs in a subshell, with different pid, so not helpful.
Packit 032894
#
Packit 032894
# So we gather the LD_LIBRARY_PATH with this cunning trick:
Packit 032894
ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'`
Packit 032894
Packit Service 35cfd5
mkdir F R L D Z
Packit Service 35cfd5
# not tempfiles F R L D Z - they are directories which we clean up manually
Packit 032894
ln -s ${abs_builddir}/dwfllines L/foo   # any program not used elsewhere in this test
Packit 032894
Packit 032894
wait_ready()
Packit 032894
{
Packit 032894
  port=$1;
Packit 032894
  what=$2;
Packit 032894
  value=$3;
Packit 032894
  timeout=20;
Packit 032894
Packit 032894
  echo "Wait $timeout seconds on $port for metric $what to change to $value"
Packit 032894
  while [ $timeout -gt 0 ]; do
Packit 032894
    mvalue="$(curl -s http://127.0.0.1:$port/metrics \
Packit 032894
              | grep "$what" | awk '{print $NF}')"
Packit 032894
    if [ -z "$mvalue" ]; then mvalue=0; fi
Packit 032894
      echo "metric $what: $mvalue"
Packit 032894
      if [ "$mvalue" -eq "$value" ]; then
Packit 032894
        break;
Packit 032894
    fi
Packit 032894
    sleep 0.5;
Packit 032894
    ((timeout--));
Packit 032894
  done;
Packit 032894
Packit 032894
  if [ $timeout -eq 0 ]; then
Packit Service 35cfd5
      echo "metric $what never changed to $value on port $port"
Packit Service 35cfd5
      curl -s http://127.0.0.1:$port/metrics
Packit 032894
    exit 1;
Packit 032894
  fi
Packit 032894
}
Packit 032894
Packit Service 35cfd5
env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -R -d $DB -p $PORT1 -t0 -g0 --fdcache-fds 1 --fdcache-mbs 2 -Z .tar.xz -Z .tar.bz2=bzcat -v R F Z L > vlog4 2>&1 &
Packit 032894
PID1=$!
Packit Service 35cfd5
tempfiles vlog4
Packit 032894
# Server must become ready
Packit 032894
wait_ready $PORT1 'ready' 1
Packit 032894
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
Packit 032894
Packit 032894
# Be patient when run on a busy machine things might take a bit.
Packit 032894
export DEBUGINFOD_TIMEOUT=10
Packit 032894
Packit 032894
# We use -t0 and -g0 here to turn off time-based scanning & grooming.
Packit 032894
# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Compile a simple program, strip its debuginfo and save the build-id.
Packit 032894
# Also move the debuginfo into another directory so that elfutils
Packit 032894
# cannot find it without debuginfod.
Packit 032894
echo "int main() { return 0; }" > ${PWD}/prog.c
Packit 032894
tempfiles prog.c
Packit Service 35cfd5
# Create a subdirectory to confound source path names
Packit Service 35cfd5
mkdir foobar
Packit Service 35cfd5
gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
Packit Service 35cfd5
testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
Packit 032894
BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit 032894
          -a prog | grep 'Build ID' | cut -d ' ' -f 7`
Packit 032894
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
Packit 032894
mv prog F
Packit 032894
mv prog.debug F
Packit 032894
kill -USR1 $PID1
Packit 032894
# Wait till both files are in the index.
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
Packit Service 35cfd5
wait_ready $PORT1 'thread_busy{role="scan"}' 0
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Test whether elfutils, via the debuginfod client library dlopen hooks,
Packit 032894
# is able to fetch debuginfo from the local debuginfod.
Packit 032894
testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Test whether debuginfod-find is able to fetch those files.
Packit 032894
rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
Packit 032894
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
Packit 032894
cmp $filename F/prog.debug
Packit 032894
Packit Service 35cfd5
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
Packit 032894
cmp $filename F/prog
Packit 032894
Packit Service 35cfd5
# raw source filename
Packit Service 35cfd5
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
Packit Service 35cfd5
cmp $filename  ${PWD}/prog.c
Packit Service 35cfd5
Packit Service 35cfd5
# and also the canonicalized one
Packit 032894
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
Packit 032894
cmp $filename  ${PWD}/prog.c
Packit 032894
Packit Service 35cfd5
Packit Service 35cfd5
########################################################################
Packit Service 35cfd5
Packit Service 35cfd5
# Test whether the cache default locations are correct
Packit Service 35cfd5
Packit Service 35cfd5
mkdir tmphome
Packit Service 35cfd5
Packit Service 35cfd5
# $HOME/.cache should be created.
Packit Service 35cfd5
testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
Packit Service 35cfd5
if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
Packit Service 35cfd5
  echo "could not find cache in $PWD/tmphome/.cache"
Packit Service 35cfd5
  exit 1
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit Service 35cfd5
# $HOME/.cache should be found.
Packit Service 35cfd5
testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
Packit Service 35cfd5
if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
Packit Service 35cfd5
  echo "could not find cache in $PWD/tmphome/.cache"
Packit Service 35cfd5
  exit 1
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit Service 35cfd5
# $XDG_CACHE_HOME should take priority over $HOME.cache.
Packit Service 35cfd5
testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
Packit Service 35cfd5
if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
Packit Service 35cfd5
  echo "could not find cache in $PWD/tmpxdg/"
Packit Service 35cfd5
  exit 1
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit Service 35cfd5
# A cache at the old default location ($HOME/.debuginfod_client_cache) should take
Packit Service 35cfd5
# priority over $HOME/.cache, $XDG_CACHE_HOME.
Packit Service 35cfd5
cp -r $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache
Packit Service 35cfd5
Packit Service 35cfd5
# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
Packit Service 35cfd5
mkdir tmphome/.debuginfod_client_cache/deadbeef
Packit Service 35cfd5
echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo
Packit Service 35cfd5
filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef`
Packit Service 35cfd5
cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo
Packit Service 35cfd5
Packit Service 35cfd5
# $DEBUGINFO_CACHE_PATH should take priority over all else.
Packit Service 35cfd5
testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
Packit Service 35cfd5
if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then
Packit Service 35cfd5
  echo "could not find cache in $PWD/tmpcache/"
Packit Service 35cfd5
  exit 1
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Add artifacts to the search paths and test whether debuginfod finds them while already running.
Packit 032894
Packit 032894
# Build another, non-stripped binary
Packit 032894
echo "int main() { return 0; }" > ${PWD}/prog2.c
Packit 032894
tempfiles prog2.c
Packit Service 35cfd5
gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
Packit 032894
BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit 032894
          -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
Packit 032894
Packit 032894
mv prog2 F
Packit 032894
kill -USR1 $PID1
Packit 032894
# Now there should be 3 files in the index
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
Packit Service 35cfd5
wait_ready $PORT1 'thread_busy{role="scan"}' 0
Packit 032894
Packit 032894
# Rerun same tests for the prog2 binary
Packit 032894
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
Packit 032894
cmp $filename F/prog2
Packit 032894
cat vlog
Packit 032894
grep -q Progress vlog
Packit Service 35cfd5
grep -q Downloaded.from vlog
Packit 032894
tempfiles vlog
Packit Service 35cfd5
filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
Packit 032894
cmp $filename F/prog2
Packit Service 35cfd5
cat vlog2
Packit Service 35cfd5
grep -q 'Downloading.*http' vlog2
Packit Service 35cfd5
tempfiles vlog2
Packit 032894
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
Packit 032894
cmp $filename ${PWD}/prog2.c
Packit 032894
Packit Service 35cfd5
cp -rvp ${abs_srcdir}/debuginfod-rpms R
Packit Service 35cfd5
if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
Packit Service 35cfd5
    rm -vrf R/debuginfod-rpms/fedora31
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit Service 35cfd5
cp -rvp ${abs_srcdir}/debuginfod-tars Z
Packit 032894
kill -USR1 $PID1
Packit 032894
# All rpms need to be in the index
Packit 032894
rpms=$(find R -name \*rpm | wc -l)
Packit Service 35cfd5
wait_ready $PORT1 'scanned_total{source=".rpm archive"}' $rpms
Packit Service 35cfd5
txz=$(find Z -name \*tar.xz | wc -l)
Packit Service 35cfd5
wait_ready $PORT1 'scanned_total{source=".tar.xz archive"}' $txz
Packit Service 35cfd5
tb2=$(find Z -name \*tar.bz2 | wc -l)
Packit Service 35cfd5
wait_ready $PORT1 'scanned_total{source=".tar.bz2 archive"}' $tb2
Packit 032894
Packit 032894
kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
Packit 032894
# Expect all source files found in the rpms (they are all called hello.c :)
Packit 032894
# We will need to extract all rpms (in their own directory) and could all
Packit 032894
# sources referenced in the .debug files.
Packit 032894
mkdir extracted
Packit 032894
cd extracted
Packit 032894
subdir=0;
Packit 032894
newrpms=$(find ../R -name \*\.rpm)
Packit 032894
for i in $newrpms; do
Packit 032894
    subdir=$[$subdir+1];
Packit 032894
    mkdir $subdir;
Packit 032894
    cd $subdir;
Packit 032894
    ls -lah ../$i
Packit Service 35cfd5
    rpm2cpio ../$i | cpio -ivd;
Packit 032894
    cd ..;
Packit 032894
done
Packit 032894
sourcefiles=$(find -name \*\\.debug \
Packit 032894
	      | env LD_LIBRARY_PATH=$ldpath xargs \
Packit 032894
		${abs_top_builddir}/src/readelf --debug-dump=decodedline \
Packit 032894
	      | grep mtime: | wc --lines)
Packit 032894
cd ..
Packit 032894
rm -rf extracted
Packit 032894
Packit Service 35cfd5
wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
Packit 032894
Packit Service 35cfd5
# Run a bank of queries against the debuginfod-rpms / debuginfod-debs test cases
Packit 032894
Packit Service 35cfd5
archive_test() {
Packit 032894
    __BUILDID=$1
Packit 032894
    __SOURCEPATH=$2
Packit 032894
    __SOURCESHA1=$3
Packit 032894
    
Packit 032894
    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
Packit 032894
    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit 032894
             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
Packit 032894
    test $__BUILDID = $buildid
Packit Service 35cfd5
    # check that timestamps are plausible - older than the near-present (tmpdir mtime)
Packit Service 35cfd5
    test $filename -ot `pwd`
Packit Service 35cfd5
Packit Service 35cfd5
    # run again to assure that fdcache is being enjoyed
Packit Service 35cfd5
    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
Packit Service 35cfd5
    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit Service 35cfd5
             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
Packit Service 35cfd5
    test $__BUILDID = $buildid
Packit Service 35cfd5
    test $filename -ot `pwd`
Packit 032894
Packit 032894
    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID`
Packit 032894
    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit 032894
             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
Packit 032894
    test $__BUILDID = $buildid
Packit Service 35cfd5
    test $filename -ot `pwd`
Packit Service 35cfd5
Packit Service 35cfd5
    if test "x$__SOURCEPATH" != "x"; then
Packit Service 35cfd5
        filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH`
Packit Service 35cfd5
        hash=`cat $filename | sha1sum | awk '{print $1}'`
Packit Service 35cfd5
        test $__SOURCESHA1 = $hash
Packit Service 35cfd5
        test $filename -ot `pwd`
Packit Service 35cfd5
    fi
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
# common source file sha1
Packit 032894
SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
Packit Service 35cfd5
# fedora31
Packit Service 35cfd5
if [ $zstd = true ]; then
Packit Service 35cfd5
    # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
Packit Service 35cfd5
    # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
Packit Service 35cfd5
    archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
Packit Service 35cfd5
    archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
Packit Service 35cfd5
fi
Packit 032894
# fedora30
Packit Service 35cfd5
archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
Packit Service 35cfd5
archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
Packit 032894
# rhel7
Packit Service 35cfd5
archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
Packit Service 35cfd5
archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
Packit 032894
# rhel6
Packit Service 35cfd5
archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
Packit Service 35cfd5
archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
Packit Service 35cfd5
# arch
Packit Service 35cfd5
archive_test cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb /usr/src/debug/hello.c 7a1334e086b97e5f124003a6cfb3ed792d10cdf4
Packit 032894
Packit 032894
RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir, for a later test
Packit 032894
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Drop some of the artifacts, run a groom cycle; confirm that
Packit 032894
# debuginfod has forgotten them, but remembers others
Packit 032894
Packit 032894
rm -r R/debuginfod-rpms/rhel6/*
Packit 032894
kill -USR2 $PID1  # groom cycle
Packit 032894
# Expect 3 rpms to be deleted by the groom
Packit Service 35cfd5
# 1 groom already took place at/soon-after startup, so -USR2 makes 2
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_total{role="groom"}' 2
Packit 032894
wait_ready $PORT1 'groom{statistic="file d/e"}' 3
Packit 032894
Packit 032894
rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
Packit 032894
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
Packit 032894
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Federation mode
Packit 032894
Packit 032894
# find another unused port
Packit 032894
while true; do
Packit 032894
    PORT2=`expr '(' $RANDOM % 1000 ')' + 9000`
Packit 032894
    ss -atn | fgrep ":$PORT2" || break
Packit 032894
done
Packit 032894
Packit 032894
export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
Packit 032894
mkdir -p $DEBUGINFOD_CACHE_PATH
Packit 032894
# NB: inherits the DEBUGINFOD_URLS to the first server
Packit 032894
# NB: run in -L symlink-following mode for the L subdir
Packit Service 35cfd5
env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d ${DB}_2 -p $PORT2 -L L D > vlog3 2>&1 &
Packit 032894
PID2=$!
Packit Service 35cfd5
tempfiles vlog3
Packit 032894
tempfiles ${DB}_2
Packit 032894
wait_ready $PORT2 'ready' 1
Packit Service 35cfd5
wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
Packit Service 35cfd5
wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
Packit Service 35cfd5
wait_ready $PORT2 'thread_busy{role="scan"}' 0
Packit 032894
Packit 032894
# have clients contact the new server
Packit 032894
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
Packit Service 35cfd5
Packit Service 35cfd5
if type bsdtar 2>/dev/null; then
Packit Service 35cfd5
    # copy in the deb files
Packit Service 35cfd5
    cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
Packit Service 35cfd5
    kill -USR1 $PID2
Packit Service 35cfd5
    # All debs need to be in the index
Packit Service 35cfd5
    debs=$(find D -name \*.deb | wc -l)
Packit Service 35cfd5
    wait_ready $PORT2 'scanned_total{source=".deb archive"}' `expr $debs`
Packit Service 35cfd5
    ddebs=$(find D -name \*.ddeb | wc -l)
Packit Service 35cfd5
    wait_ready $PORT2 'scanned_total{source=".ddeb archive"}' `expr $ddebs`
Packit Service 35cfd5
Packit Service 35cfd5
    # ubuntu
Packit Service 35cfd5
    archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit 032894
rm -rf $DEBUGINFOD_CACHE_PATH
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
Packit 032894
Packit Service 35cfd5
# send a request to stress XFF and User-Agent federation relay;
Packit Service 35cfd5
# we'll grep for the two patterns in vlog4
Packit Service 35cfd5
curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
Packit Service 35cfd5
Packit Service 35cfd5
grep UA:TESTCURL vlog4
Packit Service 35cfd5
grep XFF:TESTXFF vlog4
Packit Service 35cfd5
Packit Service 35cfd5
Packit 032894
# confirm that first server can't resolve symlinked info in L/ but second can
Packit 032894
BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
Packit 032894
         -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
Packit 032894
file L/foo
Packit 032894
file -L L/foo
Packit 032894
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
Packit 032894
rm -rf $DEBUGINFOD_CACHE_PATH
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
Packit 032894
export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
Packit 032894
Packit 032894
Packit 032894
# test parallel queries in client
Packit 032894
export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
Packit 032894
mkdir -p $DEBUGINFOD_CACHE_PATH
Packit 032894
export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
Packit 032894
Packit 032894
testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit Service 35cfd5
# Fetch some metrics
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/badapi
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT2/metrics
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*error'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*fdcache'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT2/metrics | grep -q 'http_responses_total.*result.*upstream'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_count'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_sum'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count'
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_sum'
Packit Service 35cfd5
Packit Service 35cfd5
# And generate a few errors into the second debuginfod's logs, for analysis just below
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
Packit Service 35cfd5
curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
Packit Service 35cfd5
Packit 032894
Packit 032894
########################################################################
Packit 032894
Packit 032894
# Run the tests again without the servers running. The target file should
Packit 032894
# be found in the cache.
Packit 032894
Packit 032894
kill -INT $PID1 $PID2
Packit 032894
wait $PID1 $PID2
Packit 032894
PID1=0
Packit 032894
PID2=0
Packit 032894
tempfiles .debuginfod_*
Packit 032894
Packit 032894
testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
Packit 032894
Packit Service 35cfd5
# check out the debuginfod logs for the new style status lines
Packit Service 35cfd5
# cat vlog3
Packit Service 35cfd5
grep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog3
Packit Service 35cfd5
grep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog3
Packit Service 35cfd5
grep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog3
Packit Service 35cfd5
grep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog3
Packit Service 35cfd5
Packit 032894
########################################################################
Packit 032894
Packit Service 35cfd5
# Add some files to the cache that do not fit its naming format.
Packit Service 35cfd5
# They should survive cache cleaning.
Packit Service 35cfd5
mkdir $DEBUGINFOD_CACHE_PATH/malformed
Packit Service 35cfd5
touch $DEBUGINFOD_CACHE_PATH/malformed0
Packit Service 35cfd5
touch $DEBUGINFOD_CACHE_PATH/malformed/malformed1
Packit Service 35cfd5
Packit 032894
# Trigger a cache clean and run the tests again. The clients should be unable to
Packit 032894
# find the target.
Packit 032894
echo 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s
Packit 032894
echo 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s
Packit 032894
Packit 032894
testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
Packit 032894
Packit 032894
testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 && false || true
Packit 032894
Packit Service 35cfd5
if [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \
Packit Service 35cfd5
    || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then
Packit Service 35cfd5
  echo "unrelated files did not survive cache cleaning"
Packit Service 35cfd5
  exit 1
Packit Service 35cfd5
fi
Packit Service 35cfd5
Packit Service 35cfd5
# Test debuginfod without a path list; reuse $PORT1
Packit Service 35cfd5
env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F &
Packit Service 35cfd5
PID3=$!
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
Packit Service 35cfd5
wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
Packit Service 35cfd5
wait_ready $PORT1 'thread_busy{role="scan"}' 0
Packit Service 35cfd5
kill -int $PID3
Packit Service 35cfd5
wait $PID3
Packit Service 35cfd5
PID3=0
Packit Service 35cfd5
Packit Service 35cfd5
########################################################################
Packit Service 35cfd5
# Test fetching a file using file:// . No debuginfod server needs to be run for
Packit Service 35cfd5
# this test.
Packit Service 35cfd5
local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
Packit Service 35cfd5
mkdir -p ${local_dir}
Packit Service 35cfd5
echo "int main() { return 0; }" > ${local_dir}/main.c
Packit Service 35cfd5
Packit Service 35cfd5
# first test that is doesn't work, when no DEBUGINFOD_URLS is set
Packit Service 35cfd5
DEBUGINFOD_URLS=""
Packit Service 35cfd5
testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
Packit Service 35cfd5
Packit Service 35cfd5
# Now test is with proper DEBUGINFOD_URLS
Packit Service 35cfd5
DEBUGINFOD_URLS="file://${PWD}/mocktree/"
Packit Service 35cfd5
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
Packit Service 35cfd5
cmp $filename ${local_dir}/main.c
Packit Service 35cfd5
Packit 032894
exit 0