1#!/usr/bin/env bash 2# 3# Copyright (C) 2019-2021 Red Hat, Inc. 4# This file is part of elfutils. 5# 6# This file is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 3 of the License, or 9# (at your option) any later version. 10# 11# elfutils is distributed in the hope that it will be useful, but 12# WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <http://www.gnu.org/licenses/>. 18 19. $srcdir/debuginfod-subr.sh 20 21# for test case debugging, uncomment: 22set -x 23unset VALGRIND_CMD 24 25DB=${PWD}/.debuginfod_tmp.sqlite 26export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 27tempfiles $DB 28 29# Clean old dirictories 30mkdir D L F 31# not tempfiles F R L D Z - they are directories which we clean up manually 32ln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test 33 34######################################################################## 35# Compile a simple program, strip its debuginfo and save the build-id. 36# Also move the debuginfo into another directory so that elfutils 37# cannot find it without debuginfod. 38echo "int main() { return 0; }" > ${PWD}/prog.c 39tempfiles prog.c 40# Create a subdirectory to confound source path names 41mkdir foobar 42gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c 43testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog 44BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 45 -a prog | grep 'Build ID' | cut -d ' ' -f 7` 46 47mv prog F 48mv prog.debug F 49# This variable is essential and ensures no time-race for claiming ports occurs 50# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 51base=9100 52get_ports 53# Launch server which will be unable to follow symlinks 54env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 & 55PID1=$! 56tempfiles vlog$PORT1 57errfiles vlog$PORT1 58 59wait_ready $PORT1 'ready' 1 60 61# Wait till initial scan is done 62wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 63wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 64wait_ready $PORT1 'thread_busy{role="scan"}' 0 65 66export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2 67mkdir -p $DEBUGINFOD_CACHE_PATH 68# NB: run in -L symlink-following mode for the L subdir 69env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D F > vlog$PORT2 2>&1 & 70PID2=$! 71tempfiles vlog$PORT2 72errfiles vlog$PORT2 73tempfiles ${DB}_2 74wait_ready $PORT2 'ready' 1 75# Wait till initial scan is done 76wait_ready $PORT2 'thread_work_total{role="traverse"}' 1 77# And initial groom cycle 78wait_ready $PORT1 'thread_work_total{role="groom"}' 1 79 80export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT2 81# Use fresh cache for debuginfod-find client requests 82export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3 83mkdir -p $DEBUGINFOD_CACHE_PATH 84 85if type bsdtar 2>/dev/null; then 86 # copy in the deb files 87 cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D 88 kill -USR1 $PID2 89 wait_ready $PORT2 'thread_work_total{role="traverse"}' 2 90 wait_ready $PORT2 'thread_work_pending{role="scan"}' 0 91 wait_ready $PORT2 'thread_busy{role="scan"}' 0 92 93 # All debs need to be in the index 94 debs=$(find D -name \*.deb | wc -l) 95 wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs` 96 ddebs=$(find D -name \*.ddeb | wc -l) 97 wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs` 98 99 # ubuntu 100 archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" "" 101fi 102 103testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 104 105# send a request to stress XFF and User-Agent federation relay; 106# we'll grep for the two patterns in vlog$PORT1 107curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true 108 109grep UA:TESTCURL vlog$PORT1 110grep XFF:TESTXFF vlog$PORT1 111 112# confirm that first server can't resolve symlinked info in L/ but second can 113BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 114 -a L/foo | grep 'Build ID' | cut -d ' ' -f 7` 115file L/foo 116file -L L/foo 117export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 118rm -rf $DEBUGINFOD_CACHE_PATH 119testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 120rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file 121export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 122testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 123 124# test again with scheme free url 125export DEBUGINFOD_URLS=127.0.0.1:$PORT1 126rm -rf $DEBUGINFOD_CACHE_PATH 127testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 128rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file 129export DEBUGINFOD_URLS=127.0.0.1:$PORT2 130testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 131# test parallel queries in client 132rm -rf $DEBUGINFOD_CACHE_PATH 133export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE" 134 135testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 136 137# And generate a few errors into the second debuginfod's logs, for analysis just below 138curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true 139curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true 140# NB: this error is used to seed the 404 failure for the survive-404 tests 141 142# Confirm bad artifact types are rejected without leaving trace 143curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true 144(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false 145 146# Confirm that reused curl connections survive 404 errors. 147# The rm's force an uncached fetch (in both servers and client cache) 148rm -f .client_cache*/$BUILDID/debuginfo 149testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 150rm -f .client_cache*/$BUILDID/debuginfo 151testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 152testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 153testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 154rm -f .client_cache*/$BUILDID/debuginfo 155testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 156# Trigger a flood of requests against the same archive content file. 157# Use a file that hasn't been previously extracted in to make it 158# likely that even this test debuginfod will experience concurrency 159# and impose some "after-you" delays. 160(for i in `seq 100`; do 161 curl -s http://127.0.0.1:$PORT1/buildid/87c08d12c78174f1082b7c888b3238219b0eb265/executable >/dev/null & 162 done; 163 wait) 164curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_after_you.*' 165# If we could guarantee some minimum number of seconds of CPU time, we 166# could assert that the after_you metrics show some nonzero amount of 167# waiting. A few hundred ms is typical on this developer's workstation. 168 169######################################################################## 170# Trigger some some random activity, then trigger a clean shutdown. 171# We used to try to corrupt the database while the debuginfod server 172# was running and check it detected errors, but that was unreliably 173# and slightly dangerous since part of the database was already mapped 174# into memory. 175kill -USR1 $PID1 176wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 177wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 178wait_ready $PORT1 'thread_busy{role="scan"}' 0 179kill -USR2 $PID1 180wait_ready $PORT1 'thread_work_total{role="groom"}' 2 181curl -s http://127.0.0.1:$PORT1/buildid/beefbeefbeefd00dd00d/debuginfo > /dev/null || true 182 183kill -INT $PID1 $PID2 184wait $PID1 $PID2 185PID1=0 186PID2=0 187 188# Run the tests again without the servers running. The target file should 189# be found in the cache. 190 191tempfiles .debuginfod_* 192 193testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 194 195# check out the debuginfod logs for the new style status lines 196cat vlog$PORT2 197grep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog$PORT2 198grep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog$PORT2 199grep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog$PORT2 200grep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog$PORT2 201 202exit 0 203