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