1da0c48c4Sopenharmony_ci#!/usr/bin/env bash 2da0c48c4Sopenharmony_ci# 3da0c48c4Sopenharmony_ci# Copyright (C) 2019-2021 Red Hat, Inc. 4da0c48c4Sopenharmony_ci# This file is part of elfutils. 5da0c48c4Sopenharmony_ci# 6da0c48c4Sopenharmony_ci# This file is free software; you can redistribute it and/or modify 7da0c48c4Sopenharmony_ci# it under the terms of the GNU General Public License as published by 8da0c48c4Sopenharmony_ci# the Free Software Foundation; either version 3 of the License, or 9da0c48c4Sopenharmony_ci# (at your option) any later version. 10da0c48c4Sopenharmony_ci# 11da0c48c4Sopenharmony_ci# elfutils is distributed in the hope that it will be useful, but 12da0c48c4Sopenharmony_ci# WITHOUT ANY WARRANTY; without even the implied warranty of 13da0c48c4Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14da0c48c4Sopenharmony_ci# GNU General Public License for more details. 15da0c48c4Sopenharmony_ci# 16da0c48c4Sopenharmony_ci# You should have received a copy of the GNU General Public License 17da0c48c4Sopenharmony_ci# along with this program. If not, see <http://www.gnu.org/licenses/>. 18da0c48c4Sopenharmony_ci 19da0c48c4Sopenharmony_ci. $srcdir/test-subr.sh # includes set -e 20da0c48c4Sopenharmony_ci 21da0c48c4Sopenharmony_citype curl 2>/dev/null || (echo "need curl"; exit 77) 22da0c48c4Sopenharmony_citype rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77) 23da0c48c4Sopenharmony_citype cpio 2>/dev/null || (echo "need cpio"; exit 77) 24da0c48c4Sopenharmony_citype bzcat 2>/dev/null || (echo "need bzcat"; exit 77) 25da0c48c4Sopenharmony_cibsdtar --version | grep -q zstd && zstd=true || zstd=false 26da0c48c4Sopenharmony_ciecho "zstd=$zstd bsdtar=`bsdtar --version`" 27da0c48c4Sopenharmony_ci 28da0c48c4Sopenharmony_ci# for test case debugging, uncomment: 29da0c48c4Sopenharmony_ci#set -x 30da0c48c4Sopenharmony_ciVERBOSE=-vvv 31da0c48c4Sopenharmony_ci 32da0c48c4Sopenharmony_ciDB=${PWD}/.debuginfod_tmp.sqlite 33da0c48c4Sopenharmony_citempfiles $DB 34da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 35da0c48c4Sopenharmony_ci 36da0c48c4Sopenharmony_ciPID1=0 37da0c48c4Sopenharmony_ciPID2=0 38da0c48c4Sopenharmony_ciPID3=0 39da0c48c4Sopenharmony_ci 40da0c48c4Sopenharmony_cicleanup() 41da0c48c4Sopenharmony_ci{ 42da0c48c4Sopenharmony_ci if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi 43da0c48c4Sopenharmony_ci if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi 44da0c48c4Sopenharmony_ci if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi 45da0c48c4Sopenharmony_ci 46da0c48c4Sopenharmony_ci rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp* 47da0c48c4Sopenharmony_ci exit_cleanup 48da0c48c4Sopenharmony_ci} 49da0c48c4Sopenharmony_ci 50da0c48c4Sopenharmony_ci# clean up trash if we were aborted early 51da0c48c4Sopenharmony_citrap cleanup 0 1 2 3 5 9 15 52da0c48c4Sopenharmony_ci 53da0c48c4Sopenharmony_cierrfiles_list= 54da0c48c4Sopenharmony_cierr() { 55da0c48c4Sopenharmony_ci for ports in $PORT1 $PORT2 56da0c48c4Sopenharmony_ci do 57da0c48c4Sopenharmony_ci echo $port metrics 58da0c48c4Sopenharmony_ci curl -s http://127.0.0.1:$port/metrics 59da0c48c4Sopenharmony_ci echo 60da0c48c4Sopenharmony_ci done 61da0c48c4Sopenharmony_ci for x in $errfiles_list 62da0c48c4Sopenharmony_ci do 63da0c48c4Sopenharmony_ci echo "$x" 64da0c48c4Sopenharmony_ci cat $x 65da0c48c4Sopenharmony_ci echo 66da0c48c4Sopenharmony_ci done 67da0c48c4Sopenharmony_ci} 68da0c48c4Sopenharmony_citrap err ERR 69da0c48c4Sopenharmony_ci 70da0c48c4Sopenharmony_cierrfiles() { 71da0c48c4Sopenharmony_ci errfiles_list="$errfiles_list $*" 72da0c48c4Sopenharmony_ci} 73da0c48c4Sopenharmony_ci 74da0c48c4Sopenharmony_ci 75da0c48c4Sopenharmony_ci 76da0c48c4Sopenharmony_ci# find an unused port number 77da0c48c4Sopenharmony_ciwhile true; do 78da0c48c4Sopenharmony_ci PORT1=`expr '(' $RANDOM % 1000 ')' + 9000` 79da0c48c4Sopenharmony_ci ss -atn | fgrep ":$PORT1" || break 80da0c48c4Sopenharmony_cidone 81da0c48c4Sopenharmony_ci 82da0c48c4Sopenharmony_ci# We want to run debuginfod in the background. We also want to start 83da0c48c4Sopenharmony_ci# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff 84da0c48c4Sopenharmony_ci# that the testrun alias sets. But: we if we just use 85da0c48c4Sopenharmony_ci# testrun .../debuginfod 86da0c48c4Sopenharmony_ci# it runs in a subshell, with different pid, so not helpful. 87da0c48c4Sopenharmony_ci# 88da0c48c4Sopenharmony_ci# So we gather the LD_LIBRARY_PATH with this cunning trick: 89da0c48c4Sopenharmony_cildpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'` 90da0c48c4Sopenharmony_ci 91da0c48c4Sopenharmony_cimkdir F R L D Z 92da0c48c4Sopenharmony_ci# not tempfiles F R L D Z - they are directories which we clean up manually 93da0c48c4Sopenharmony_ciln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test 94da0c48c4Sopenharmony_ci 95da0c48c4Sopenharmony_ciwait_ready() 96da0c48c4Sopenharmony_ci{ 97da0c48c4Sopenharmony_ci port=$1; 98da0c48c4Sopenharmony_ci what=$2; 99da0c48c4Sopenharmony_ci value=$3; 100da0c48c4Sopenharmony_ci timeout=20; 101da0c48c4Sopenharmony_ci 102da0c48c4Sopenharmony_ci echo "Wait $timeout seconds on $port for metric $what to change to $value" 103da0c48c4Sopenharmony_ci while [ $timeout -gt 0 ]; do 104da0c48c4Sopenharmony_ci mvalue="$(curl -s http://127.0.0.1:$port/metrics \ 105da0c48c4Sopenharmony_ci | grep "$what" | awk '{print $NF}')" 106da0c48c4Sopenharmony_ci if [ -z "$mvalue" ]; then mvalue=0; fi 107da0c48c4Sopenharmony_ci echo "metric $what: $mvalue" 108da0c48c4Sopenharmony_ci if [ "$mvalue" -eq "$value" ]; then 109da0c48c4Sopenharmony_ci break; 110da0c48c4Sopenharmony_ci fi 111da0c48c4Sopenharmony_ci sleep 0.5; 112da0c48c4Sopenharmony_ci ((timeout--)); 113da0c48c4Sopenharmony_ci done; 114da0c48c4Sopenharmony_ci 115da0c48c4Sopenharmony_ci if [ $timeout -eq 0 ]; then 116da0c48c4Sopenharmony_ci echo "metric $what never changed to $value on port $port" 117da0c48c4Sopenharmony_ci exit 1; 118da0c48c4Sopenharmony_ci fi 119da0c48c4Sopenharmony_ci} 120da0c48c4Sopenharmony_ci 121da0c48c4Sopenharmony_ci# create a bogus .rpm file to evoke a metric-visible error 122da0c48c4Sopenharmony_ci# Use a cyclic symlink instead of chmod 000 to make sure even root 123da0c48c4Sopenharmony_ci# would see an error (running the testsuite under root is NOT encouraged). 124da0c48c4Sopenharmony_ciln -s R/nothing.rpm R/nothing.rpm 125da0c48c4Sopenharmony_ci 126da0c48c4Sopenharmony_cienv 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 --fdcache-mintmp 0 -Z .tar.xz -Z .tar.bz2=bzcat -v R F Z L > vlog$PORT1 2>&1 & 127da0c48c4Sopenharmony_ciPID1=$! 128da0c48c4Sopenharmony_citempfiles vlog$PORT1 129da0c48c4Sopenharmony_cierrfiles vlog$PORT1 130da0c48c4Sopenharmony_ci# Server must become ready 131da0c48c4Sopenharmony_ciwait_ready $PORT1 'ready' 1 132da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing / 133da0c48c4Sopenharmony_ci 134da0c48c4Sopenharmony_ci# Be patient when run on a busy machine things might take a bit. 135da0c48c4Sopenharmony_ciexport DEBUGINFOD_TIMEOUT=10 136da0c48c4Sopenharmony_ci 137da0c48c4Sopenharmony_ci# Check thread comm names 138da0c48c4Sopenharmony_cips -q $PID1 -e -L -o '%p %c %a' | grep groom 139da0c48c4Sopenharmony_cips -q $PID1 -e -L -o '%p %c %a' | grep scan 140da0c48c4Sopenharmony_cips -q $PID1 -e -L -o '%p %c %a' | grep traverse 141da0c48c4Sopenharmony_ci 142da0c48c4Sopenharmony_ci# We use -t0 and -g0 here to turn off time-based scanning & grooming. 143da0c48c4Sopenharmony_ci# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process. 144da0c48c4Sopenharmony_ci 145da0c48c4Sopenharmony_ci######################################################################## 146da0c48c4Sopenharmony_ci 147da0c48c4Sopenharmony_ci# Compile a simple program, strip its debuginfo and save the build-id. 148da0c48c4Sopenharmony_ci# Also move the debuginfo into another directory so that elfutils 149da0c48c4Sopenharmony_ci# cannot find it without debuginfod. 150da0c48c4Sopenharmony_ciecho "int main() { return 0; }" > ${PWD}/prog.c 151da0c48c4Sopenharmony_citempfiles prog.c 152da0c48c4Sopenharmony_ci# Create a subdirectory to confound source path names 153da0c48c4Sopenharmony_cimkdir foobar 154da0c48c4Sopenharmony_cigcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c 155da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog 156da0c48c4Sopenharmony_ciBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 157da0c48c4Sopenharmony_ci -a prog | grep 'Build ID' | cut -d ' ' -f 7` 158da0c48c4Sopenharmony_ci 159da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 1 160da0c48c4Sopenharmony_cimv prog F 161da0c48c4Sopenharmony_cimv prog.debug F 162da0c48c4Sopenharmony_cikill -USR1 $PID1 163da0c48c4Sopenharmony_ci# Wait till both files are in the index. 164da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 2 165da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 166da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 167da0c48c4Sopenharmony_ci 168da0c48c4Sopenharmony_ci######################################################################## 169da0c48c4Sopenharmony_ci 170da0c48c4Sopenharmony_ci# Test whether elfutils, via the debuginfod client library dlopen hooks, 171da0c48c4Sopenharmony_ci# is able to fetch debuginfo from the local debuginfod. 172da0c48c4Sopenharmony_citestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 173da0c48c4Sopenharmony_ci 174da0c48c4Sopenharmony_ci######################################################################## 175da0c48c4Sopenharmony_ci 176da0c48c4Sopenharmony_ci# PR25628 177da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests 178da0c48c4Sopenharmony_ci 179da0c48c4Sopenharmony_ci# The query is designed to fail, while the 000-permission file should be created. 180da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true 181da0c48c4Sopenharmony_ciif [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then 182da0c48c4Sopenharmony_ci echo "could not find cache in $DEBUGINFOD_CACHE_PATH" 183da0c48c4Sopenharmony_ci exit 1 184da0c48c4Sopenharmony_cifi 185da0c48c4Sopenharmony_ci 186da0c48c4Sopenharmony_ciif [ -r $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then 187da0c48c4Sopenharmony_ci echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is readable" 188da0c48c4Sopenharmony_ci exit 1 189da0c48c4Sopenharmony_cifi 190da0c48c4Sopenharmony_ci 191da0c48c4Sopenharmony_cibytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` 192da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true 193da0c48c4Sopenharmony_cibytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` 194da0c48c4Sopenharmony_ciif [ "$bytecount_before" != "$bytecount_after" ]; then 195da0c48c4Sopenharmony_ci echo "http_responses_transfer_bytes_count{code="404"} has changed." 196da0c48c4Sopenharmony_ci exit 1 197da0c48c4Sopenharmony_cifi 198da0c48c4Sopenharmony_ci 199da0c48c4Sopenharmony_ci# set cache_miss_s to 0 and sleep 1 to make the mtime expire. 200da0c48c4Sopenharmony_ciecho 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s 201da0c48c4Sopenharmony_cisleep 1 202da0c48c4Sopenharmony_cibytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` 203da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true 204da0c48c4Sopenharmony_cibytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'` 205da0c48c4Sopenharmony_ciif [ "$bytecount_before" == "$bytecount_after" ]; then 206da0c48c4Sopenharmony_ci echo "http_responses_transfer_bytes_count{code="404"} should be incremented." 207da0c48c4Sopenharmony_ci exit 1 208da0c48c4Sopenharmony_cifi 209da0c48c4Sopenharmony_ci######################################################################## 210da0c48c4Sopenharmony_ci 211da0c48c4Sopenharmony_ci# Test whether debuginfod-find is able to fetch those files. 212da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests 213da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID` 214da0c48c4Sopenharmony_cicmp $filename F/prog.debug 215da0c48c4Sopenharmony_ciif [ -w $filename ]; then 216da0c48c4Sopenharmony_ci echo "cache file writable, boo" 217da0c48c4Sopenharmony_ci exit 1 218da0c48c4Sopenharmony_cifi 219da0c48c4Sopenharmony_ci 220da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog` 221da0c48c4Sopenharmony_cicmp $filename F/prog 222da0c48c4Sopenharmony_ci 223da0c48c4Sopenharmony_ci# raw source filename 224da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c` 225da0c48c4Sopenharmony_cicmp $filename ${PWD}/prog.c 226da0c48c4Sopenharmony_ci 227da0c48c4Sopenharmony_ci# and also the canonicalized one 228da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c` 229da0c48c4Sopenharmony_cicmp $filename ${PWD}/prog.c 230da0c48c4Sopenharmony_ci 231da0c48c4Sopenharmony_ci 232da0c48c4Sopenharmony_ci######################################################################## 233da0c48c4Sopenharmony_ci 234da0c48c4Sopenharmony_ci# Test whether the cache default locations are correct 235da0c48c4Sopenharmony_ci 236da0c48c4Sopenharmony_cimkdir tmphome 237da0c48c4Sopenharmony_ci 238da0c48c4Sopenharmony_ci# $HOME/.cache should be created. 239da0c48c4Sopenharmony_citestrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 240da0c48c4Sopenharmony_ciif [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then 241da0c48c4Sopenharmony_ci echo "could not find cache in $PWD/tmphome/.cache" 242da0c48c4Sopenharmony_ci exit 1 243da0c48c4Sopenharmony_cifi 244da0c48c4Sopenharmony_ci 245da0c48c4Sopenharmony_ci# $HOME/.cache should be found. 246da0c48c4Sopenharmony_citestrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID 247da0c48c4Sopenharmony_ciif [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then 248da0c48c4Sopenharmony_ci echo "could not find cache in $PWD/tmphome/.cache" 249da0c48c4Sopenharmony_ci exit 1 250da0c48c4Sopenharmony_cifi 251da0c48c4Sopenharmony_ci 252da0c48c4Sopenharmony_ci# $XDG_CACHE_HOME should take priority over $HOME.cache. 253da0c48c4Sopenharmony_citestrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 254da0c48c4Sopenharmony_ciif [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then 255da0c48c4Sopenharmony_ci echo "could not find cache in $PWD/tmpxdg/" 256da0c48c4Sopenharmony_ci exit 1 257da0c48c4Sopenharmony_cifi 258da0c48c4Sopenharmony_ci 259da0c48c4Sopenharmony_ci# A cache at the old default location ($HOME/.debuginfod_client_cache) should take 260da0c48c4Sopenharmony_ci# priority over $HOME/.cache, $XDG_CACHE_HOME. 261da0c48c4Sopenharmony_cicp -r $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache 262da0c48c4Sopenharmony_ci 263da0c48c4Sopenharmony_ci# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME. 264da0c48c4Sopenharmony_cimkdir tmphome/.debuginfod_client_cache/deadbeef 265da0c48c4Sopenharmony_ciecho ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo 266da0c48c4Sopenharmony_cifilename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef` 267da0c48c4Sopenharmony_cicmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo 268da0c48c4Sopenharmony_ci 269da0c48c4Sopenharmony_ci# $DEBUGINFO_CACHE_PATH should take priority over all else. 270da0c48c4Sopenharmony_citestrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 271da0c48c4Sopenharmony_ciif [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then 272da0c48c4Sopenharmony_ci echo "could not find cache in $PWD/tmpcache/" 273da0c48c4Sopenharmony_ci exit 1 274da0c48c4Sopenharmony_cifi 275da0c48c4Sopenharmony_ci 276da0c48c4Sopenharmony_ci######################################################################## 277da0c48c4Sopenharmony_ci 278da0c48c4Sopenharmony_ci# Add artifacts to the search paths and test whether debuginfod finds them while already running. 279da0c48c4Sopenharmony_ci 280da0c48c4Sopenharmony_ci# Build another, non-stripped binary 281da0c48c4Sopenharmony_ciecho "int main() { return 0; }" > ${PWD}/prog2.c 282da0c48c4Sopenharmony_citempfiles prog2.c 283da0c48c4Sopenharmony_cigcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c 284da0c48c4Sopenharmony_ciBUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 285da0c48c4Sopenharmony_ci -a prog2 | grep 'Build ID' | cut -d ' ' -f 7` 286da0c48c4Sopenharmony_ci 287da0c48c4Sopenharmony_cimv prog2 F 288da0c48c4Sopenharmony_cikill -USR1 $PID1 289da0c48c4Sopenharmony_ci# Now there should be 3 files in the index 290da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 3 291da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 292da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 293da0c48c4Sopenharmony_ci 294da0c48c4Sopenharmony_ci# Rerun same tests for the prog2 binary 295da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog` 296da0c48c4Sopenharmony_cicmp $filename F/prog2 297da0c48c4Sopenharmony_cicat vlog 298da0c48c4Sopenharmony_cigrep -q Progress vlog 299da0c48c4Sopenharmony_cigrep -q Downloaded.from vlog 300da0c48c4Sopenharmony_citempfiles vlog 301da0c48c4Sopenharmony_cifilename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2` 302da0c48c4Sopenharmony_cicmp $filename F/prog2 303da0c48c4Sopenharmony_cicat vlog2 304da0c48c4Sopenharmony_cigrep -q 'Downloading.*http' vlog2 305da0c48c4Sopenharmony_citempfiles vlog2 306da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c` 307da0c48c4Sopenharmony_cicmp $filename ${PWD}/prog2.c 308da0c48c4Sopenharmony_ci 309da0c48c4Sopenharmony_cicp -rvp ${abs_srcdir}/debuginfod-rpms R 310da0c48c4Sopenharmony_ciif [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones 311da0c48c4Sopenharmony_ci rm -vrf R/debuginfod-rpms/fedora31 312da0c48c4Sopenharmony_cifi 313da0c48c4Sopenharmony_ci 314da0c48c4Sopenharmony_cicp -rvp ${abs_srcdir}/debuginfod-tars Z 315da0c48c4Sopenharmony_cikill -USR1 $PID1 316da0c48c4Sopenharmony_ci# All rpms need to be in the index, except the dummy permission-000 one 317da0c48c4Sopenharmony_cirpms=$(find R -name \*rpm | grep -v nothing | wc -l) 318da0c48c4Sopenharmony_ciwait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms 319da0c48c4Sopenharmony_citxz=$(find Z -name \*tar.xz | wc -l) 320da0c48c4Sopenharmony_ciwait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz 321da0c48c4Sopenharmony_citb2=$(find Z -name \*tar.bz2 | wc -l) 322da0c48c4Sopenharmony_ciwait_ready $PORT1 'scanned_files_total{source=".tar.bz2 archive"}' $tb2 323da0c48c4Sopenharmony_ci 324da0c48c4Sopenharmony_cikill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs 325da0c48c4Sopenharmony_ci# Expect all source files found in the rpms (they are all called hello.c :) 326da0c48c4Sopenharmony_ci# We will need to extract all rpms (in their own directory) and could all 327da0c48c4Sopenharmony_ci# sources referenced in the .debug files. 328da0c48c4Sopenharmony_cimkdir extracted 329da0c48c4Sopenharmony_cicd extracted 330da0c48c4Sopenharmony_cisubdir=0; 331da0c48c4Sopenharmony_cinewrpms=$(find ../R -name \*\.rpm | grep -v nothing) 332da0c48c4Sopenharmony_cifor i in $newrpms; do 333da0c48c4Sopenharmony_ci subdir=$[$subdir+1]; 334da0c48c4Sopenharmony_ci mkdir $subdir; 335da0c48c4Sopenharmony_ci cd $subdir; 336da0c48c4Sopenharmony_ci ls -lah ../$i 337da0c48c4Sopenharmony_ci rpm2cpio ../$i | cpio -ivd; 338da0c48c4Sopenharmony_ci cd ..; 339da0c48c4Sopenharmony_cidone 340da0c48c4Sopenharmony_cisourcefiles=$(find -name \*\\.debug \ 341da0c48c4Sopenharmony_ci | env LD_LIBRARY_PATH=$ldpath xargs \ 342da0c48c4Sopenharmony_ci ${abs_top_builddir}/src/readelf --debug-dump=decodedline \ 343da0c48c4Sopenharmony_ci | grep mtime: | wc --lines) 344da0c48c4Sopenharmony_cicd .. 345da0c48c4Sopenharmony_cirm -rf extracted 346da0c48c4Sopenharmony_ci 347da0c48c4Sopenharmony_ciwait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles 348da0c48c4Sopenharmony_ci 349da0c48c4Sopenharmony_ci# Run a bank of queries against the debuginfod-rpms / debuginfod-debs test cases 350da0c48c4Sopenharmony_ci 351da0c48c4Sopenharmony_ciarchive_test() { 352da0c48c4Sopenharmony_ci __BUILDID=$1 353da0c48c4Sopenharmony_ci __SOURCEPATH=$2 354da0c48c4Sopenharmony_ci __SOURCESHA1=$3 355da0c48c4Sopenharmony_ci 356da0c48c4Sopenharmony_ci filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID` 357da0c48c4Sopenharmony_ci buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 358da0c48c4Sopenharmony_ci -a $filename | grep 'Build ID' | cut -d ' ' -f 7` 359da0c48c4Sopenharmony_ci test $__BUILDID = $buildid 360da0c48c4Sopenharmony_ci # check that timestamps are plausible - older than the near-present (tmpdir mtime) 361da0c48c4Sopenharmony_ci test $filename -ot `pwd` 362da0c48c4Sopenharmony_ci 363da0c48c4Sopenharmony_ci # run again to assure that fdcache is being enjoyed 364da0c48c4Sopenharmony_ci filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID` 365da0c48c4Sopenharmony_ci buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 366da0c48c4Sopenharmony_ci -a $filename | grep 'Build ID' | cut -d ' ' -f 7` 367da0c48c4Sopenharmony_ci test $__BUILDID = $buildid 368da0c48c4Sopenharmony_ci test $filename -ot `pwd` 369da0c48c4Sopenharmony_ci 370da0c48c4Sopenharmony_ci filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID` 371da0c48c4Sopenharmony_ci buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 372da0c48c4Sopenharmony_ci -a $filename | grep 'Build ID' | cut -d ' ' -f 7` 373da0c48c4Sopenharmony_ci test $__BUILDID = $buildid 374da0c48c4Sopenharmony_ci test $filename -ot `pwd` 375da0c48c4Sopenharmony_ci 376da0c48c4Sopenharmony_ci if test "x$__SOURCEPATH" != "x"; then 377da0c48c4Sopenharmony_ci filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH` 378da0c48c4Sopenharmony_ci hash=`cat $filename | sha1sum | awk '{print $1}'` 379da0c48c4Sopenharmony_ci test $__SOURCESHA1 = $hash 380da0c48c4Sopenharmony_ci test $filename -ot `pwd` 381da0c48c4Sopenharmony_ci fi 382da0c48c4Sopenharmony_ci} 383da0c48c4Sopenharmony_ci 384da0c48c4Sopenharmony_ci 385da0c48c4Sopenharmony_ci# common source file sha1 386da0c48c4Sopenharmony_ciSHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1 387da0c48c4Sopenharmony_ci# fedora31 388da0c48c4Sopenharmony_ciif [ $zstd = true ]; then 389da0c48c4Sopenharmony_ci # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it 390da0c48c4Sopenharmony_ci # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite 391da0c48c4Sopenharmony_ci archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA 392da0c48c4Sopenharmony_ci archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA 393da0c48c4Sopenharmony_cifi 394da0c48c4Sopenharmony_ci# fedora30 395da0c48c4Sopenharmony_ciarchive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA 396da0c48c4Sopenharmony_ciarchive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA 397da0c48c4Sopenharmony_ci# rhel7 398da0c48c4Sopenharmony_ciarchive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA 399da0c48c4Sopenharmony_ciarchive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA 400da0c48c4Sopenharmony_ci# rhel6 401da0c48c4Sopenharmony_ciarchive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA 402da0c48c4Sopenharmony_ciarchive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA 403da0c48c4Sopenharmony_ci# arch 404da0c48c4Sopenharmony_ciarchive_test cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb /usr/src/debug/hello.c 7a1334e086b97e5f124003a6cfb3ed792d10cdf4 405da0c48c4Sopenharmony_ci 406da0c48c4Sopenharmony_ciRPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir, for a later test 407da0c48c4Sopenharmony_ci 408da0c48c4Sopenharmony_ci 409da0c48c4Sopenharmony_ci######################################################################## 410da0c48c4Sopenharmony_ci 411da0c48c4Sopenharmony_ci# Drop some of the artifacts, run a groom cycle; confirm that 412da0c48c4Sopenharmony_ci# debuginfod has forgotten them, but remembers others 413da0c48c4Sopenharmony_ci 414da0c48c4Sopenharmony_cirm -r R/debuginfod-rpms/rhel6/* 415da0c48c4Sopenharmony_cikill -USR2 $PID1 # groom cycle 416da0c48c4Sopenharmony_ci# 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2 417da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="groom"}' 2 418da0c48c4Sopenharmony_ci# Expect 4 rpms containing 2 buildids to be deleted by the groom 419da0c48c4Sopenharmony_ciwait_ready $PORT1 'groomed_total{decision="stale"}' 4 420da0c48c4Sopenharmony_ci 421da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests 422da0c48c4Sopenharmony_ci 423da0c48c4Sopenharmony_ci# this is one of the buildids from the groom-deleted rpms 424da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true 425da0c48c4Sopenharmony_ci# but this one was not deleted so should be still around 426da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 427da0c48c4Sopenharmony_ci 428da0c48c4Sopenharmony_ci######################################################################## 429da0c48c4Sopenharmony_ci 430da0c48c4Sopenharmony_ci# PR26810: Now rename some files in the R directory, then rescan, so 431da0c48c4Sopenharmony_ci# there are two copies of the same buildid in the index, one for the 432da0c48c4Sopenharmony_ci# no-longer-existing file name, and one under the new name. 433da0c48c4Sopenharmony_ci 434da0c48c4Sopenharmony_ci# run a groom cycle to force server to drop its fdcache 435da0c48c4Sopenharmony_cikill -USR2 $PID1 # groom cycle 436da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="groom"}' 3 437da0c48c4Sopenharmony_ci# move it around a couple of times to make it likely to hit a nonexistent entry during iteration 438da0c48c4Sopenharmony_cimv R/debuginfod-rpms/rhel7 R/debuginfod-rpms/rhel7renamed 439da0c48c4Sopenharmony_cikill -USR1 $PID1 # scan cycle 440da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 6 441da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 442da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 443da0c48c4Sopenharmony_cimv R/debuginfod-rpms/rhel7renamed R/debuginfod-rpms/rhel7renamed2 444da0c48c4Sopenharmony_cikill -USR1 $PID1 # scan cycle 445da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 7 446da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 447da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 448da0c48c4Sopenharmony_cimv R/debuginfod-rpms/rhel7renamed2 R/debuginfod-rpms/rhel7renamed3 449da0c48c4Sopenharmony_cikill -USR1 $PID1 # scan cycle 450da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 8 451da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 452da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 453da0c48c4Sopenharmony_ci 454da0c48c4Sopenharmony_ci# retest rhel7 455da0c48c4Sopenharmony_ciarchive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA 456da0c48c4Sopenharmony_ciarchive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA 457da0c48c4Sopenharmony_ci 458da0c48c4Sopenharmony_ciegrep '(libc.error.*rhel7)|(bc1febfd03ca)|(f0aa15b8aba)' vlog$PORT1 459da0c48c4Sopenharmony_ci 460da0c48c4Sopenharmony_ci######################################################################## 461da0c48c4Sopenharmony_ci 462da0c48c4Sopenharmony_ci# Federation mode 463da0c48c4Sopenharmony_ci 464da0c48c4Sopenharmony_ci# find another unused port 465da0c48c4Sopenharmony_ciwhile true; do 466da0c48c4Sopenharmony_ci PORT2=`expr '(' $RANDOM % 1000 ')' + 9000` 467da0c48c4Sopenharmony_ci ss -atn | fgrep ":$PORT2" || break 468da0c48c4Sopenharmony_cidone 469da0c48c4Sopenharmony_ci 470da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2 471da0c48c4Sopenharmony_cimkdir -p $DEBUGINFOD_CACHE_PATH 472da0c48c4Sopenharmony_ci# NB: inherits the DEBUGINFOD_URLS to the first server 473da0c48c4Sopenharmony_ci# NB: run in -L symlink-following mode for the L subdir 474da0c48c4Sopenharmony_cienv LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d ${DB}_2 -p $PORT2 -L L D > vlog$PORT2 2>&1 & 475da0c48c4Sopenharmony_ciPID2=$! 476da0c48c4Sopenharmony_citempfiles vlog$PORT2 477da0c48c4Sopenharmony_cierrfiles vlog$PORT2 478da0c48c4Sopenharmony_citempfiles ${DB}_2 479da0c48c4Sopenharmony_ciwait_ready $PORT2 'ready' 1 480da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_work_total{role="traverse"}' 1 481da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_work_pending{role="scan"}' 0 482da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="scan"}' 0 483da0c48c4Sopenharmony_ci 484da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="http-buildid"}' 0 485da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="http-metrics"}' 1 486da0c48c4Sopenharmony_ci 487da0c48c4Sopenharmony_ci# have clients contact the new server 488da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 489da0c48c4Sopenharmony_ci 490da0c48c4Sopenharmony_ciif type bsdtar 2>/dev/null; then 491da0c48c4Sopenharmony_ci # copy in the deb files 492da0c48c4Sopenharmony_ci cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D 493da0c48c4Sopenharmony_ci kill -USR1 $PID2 494da0c48c4Sopenharmony_ci # All debs need to be in the index 495da0c48c4Sopenharmony_ci debs=$(find D -name \*.deb | wc -l) 496da0c48c4Sopenharmony_ci wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs` 497da0c48c4Sopenharmony_ci ddebs=$(find D -name \*.ddeb | wc -l) 498da0c48c4Sopenharmony_ci wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs` 499da0c48c4Sopenharmony_ci 500da0c48c4Sopenharmony_ci # ubuntu 501da0c48c4Sopenharmony_ci archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" "" 502da0c48c4Sopenharmony_cifi 503da0c48c4Sopenharmony_ci 504da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 505da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 506da0c48c4Sopenharmony_ci 507da0c48c4Sopenharmony_ci# send a request to stress XFF and User-Agent federation relay; 508da0c48c4Sopenharmony_ci# we'll grep for the two patterns in vlog$PORT1 509da0c48c4Sopenharmony_cicurl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true 510da0c48c4Sopenharmony_ci 511da0c48c4Sopenharmony_cigrep UA:TESTCURL vlog$PORT1 512da0c48c4Sopenharmony_cigrep XFF:TESTXFF vlog$PORT1 513da0c48c4Sopenharmony_ci 514da0c48c4Sopenharmony_ci 515da0c48c4Sopenharmony_ci# confirm that first server can't resolve symlinked info in L/ but second can 516da0c48c4Sopenharmony_ciBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 517da0c48c4Sopenharmony_ci -a L/foo | grep 'Build ID' | cut -d ' ' -f 7` 518da0c48c4Sopenharmony_cifile L/foo 519da0c48c4Sopenharmony_cifile -L L/foo 520da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 521da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 522da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 523da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file 524da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 525da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 526da0c48c4Sopenharmony_ci 527da0c48c4Sopenharmony_ci# test again with scheme free url 528da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=127.0.0.1:$PORT1 529da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 530da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 531da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file 532da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=127.0.0.1:$PORT2 533da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 534da0c48c4Sopenharmony_ci 535da0c48c4Sopenharmony_ci# test parallel queries in client 536da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3 537da0c48c4Sopenharmony_cimkdir -p $DEBUGINFOD_CACHE_PATH 538da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE" 539da0c48c4Sopenharmony_ci 540da0c48c4Sopenharmony_citestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1 541da0c48c4Sopenharmony_ci 542da0c48c4Sopenharmony_ci######################################################################## 543da0c48c4Sopenharmony_ci 544da0c48c4Sopenharmony_ci# Fetch some metrics 545da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/badapi 546da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics 547da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/metrics 548da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*error' 549da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*fdcache' 550da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/metrics | grep -q 'http_responses_total.*result.*upstream' 551da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_count' 552da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_sum' 553da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count' 554da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_sum' 555da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'fdcache_' 556da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'error_count' 557da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'traversed_total' 558da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'scanned_bytes_total' 559da0c48c4Sopenharmony_ci 560da0c48c4Sopenharmony_ci# And generate a few errors into the second debuginfod's logs, for analysis just below 561da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true 562da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true 563da0c48c4Sopenharmony_ci# NB: this error is used to seed the 404 failure for the survive-404 tests 564da0c48c4Sopenharmony_ci 565da0c48c4Sopenharmony_ci# Confirm bad artifact types are rejected without leaving trace 566da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true 567da0c48c4Sopenharmony_ci(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false 568da0c48c4Sopenharmony_ci 569da0c48c4Sopenharmony_ci# Confirm that reused curl connections survive 404 errors. 570da0c48c4Sopenharmony_ci# The rm's force an uncached fetch 571da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo 572da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 573da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo 574da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 575da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 576da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 577da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo 578da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 579da0c48c4Sopenharmony_ci 580da0c48c4Sopenharmony_ci# Confirm that some debuginfod client pools are being used 581da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT2/metrics | grep 'dc_pool_op.*reuse' 582da0c48c4Sopenharmony_ci 583da0c48c4Sopenharmony_ci######################################################################## 584da0c48c4Sopenharmony_ci# Corrupt the sqlite database and get debuginfod to trip across its errors 585da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'sqlite3.*reset' 586da0c48c4Sopenharmony_cils -al $DB 587da0c48c4Sopenharmony_cidd if=/dev/zero of=$DB bs=1 count=1 588da0c48c4Sopenharmony_cils -al $DB 589da0c48c4Sopenharmony_ci# trigger some random activity that's Sure to get sqlite3 upset 590da0c48c4Sopenharmony_cikill -USR1 $PID1 591da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 9 592da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 593da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 594da0c48c4Sopenharmony_cikill -USR2 $PID1 595da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="groom"}' 4 596da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/buildid/beefbeefbeefd00dd00d/debuginfo > /dev/null || true 597da0c48c4Sopenharmony_cicurl -s http://127.0.0.1:$PORT1/metrics | grep 'error_count.*sqlite' 598da0c48c4Sopenharmony_ci 599da0c48c4Sopenharmony_ci######################################################################## 600da0c48c4Sopenharmony_ci 601da0c48c4Sopenharmony_ci# Run the tests again without the servers running. The target file should 602da0c48c4Sopenharmony_ci# be found in the cache. 603da0c48c4Sopenharmony_ci 604da0c48c4Sopenharmony_cikill -INT $PID1 $PID2 605da0c48c4Sopenharmony_ciwait $PID1 $PID2 606da0c48c4Sopenharmony_ciPID1=0 607da0c48c4Sopenharmony_ciPID2=0 608da0c48c4Sopenharmony_citempfiles .debuginfod_* 609da0c48c4Sopenharmony_ci 610da0c48c4Sopenharmony_citestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1 611da0c48c4Sopenharmony_ci 612da0c48c4Sopenharmony_ci# check out the debuginfod logs for the new style status lines 613da0c48c4Sopenharmony_ci# cat vlog$PORT2 614da0c48c4Sopenharmony_cigrep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog$PORT2 615da0c48c4Sopenharmony_cigrep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog$PORT2 616da0c48c4Sopenharmony_cigrep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog$PORT2 617da0c48c4Sopenharmony_cigrep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog$PORT2 618da0c48c4Sopenharmony_ci 619da0c48c4Sopenharmony_ci######################################################################## 620da0c48c4Sopenharmony_ci 621da0c48c4Sopenharmony_ci# Add some files to the cache that do not fit its naming format. 622da0c48c4Sopenharmony_ci# They should survive cache cleaning. 623da0c48c4Sopenharmony_cimkdir $DEBUGINFOD_CACHE_PATH/malformed 624da0c48c4Sopenharmony_citouch $DEBUGINFOD_CACHE_PATH/malformed0 625da0c48c4Sopenharmony_citouch $DEBUGINFOD_CACHE_PATH/malformed/malformed1 626da0c48c4Sopenharmony_ci 627da0c48c4Sopenharmony_ci# A valid format for an empty buildid subdirectory 628da0c48c4Sopenharmony_cimkdir $DEBUGINFOD_CACHE_PATH/00000000 629da0c48c4Sopenharmony_citouch -d '1970-01-01' $DEBUGINFOD_CACHE_PATH/00000000 # old enough to guarantee nukage 630da0c48c4Sopenharmony_ci 631da0c48c4Sopenharmony_ci# Trigger a cache clean and run the tests again. The clients should be unable to 632da0c48c4Sopenharmony_ci# find the target. 633da0c48c4Sopenharmony_ciecho 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s 634da0c48c4Sopenharmony_ciecho 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s 635da0c48c4Sopenharmony_ci 636da0c48c4Sopenharmony_citestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 637da0c48c4Sopenharmony_ci 638da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 && false || true 639da0c48c4Sopenharmony_ci 640da0c48c4Sopenharmony_ciif [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \ 641da0c48c4Sopenharmony_ci || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then 642da0c48c4Sopenharmony_ci echo "unrelated files did not survive cache cleaning" 643da0c48c4Sopenharmony_ci exit 1 644da0c48c4Sopenharmony_cifi 645da0c48c4Sopenharmony_ci 646da0c48c4Sopenharmony_ciif [ -d $DEBUGINFOD_CACHE_PATH/00000000 ]; then 647da0c48c4Sopenharmony_ci echo "failed to rmdir old cache dir" 648da0c48c4Sopenharmony_ci exit 1 649da0c48c4Sopenharmony_cifi 650da0c48c4Sopenharmony_ci 651da0c48c4Sopenharmony_ci# Test debuginfod without a path list; reuse $PORT1 652da0c48c4Sopenharmony_cienv LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F & 653da0c48c4Sopenharmony_ciPID3=$! 654da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 1 655da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 656da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 657da0c48c4Sopenharmony_cikill -int $PID3 658da0c48c4Sopenharmony_ciwait $PID3 659da0c48c4Sopenharmony_ciPID3=0 660da0c48c4Sopenharmony_ci 661da0c48c4Sopenharmony_ci######################################################################## 662da0c48c4Sopenharmony_ci# Test fetching a file using file:// . No debuginfod server needs to be run for 663da0c48c4Sopenharmony_ci# this test. 664da0c48c4Sopenharmony_cilocal_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path 665da0c48c4Sopenharmony_cimkdir -p ${local_dir} 666da0c48c4Sopenharmony_ciecho "int main() { return 0; }" > ${local_dir}/main.c 667da0c48c4Sopenharmony_ci 668da0c48c4Sopenharmony_ci# first test that is doesn't work, when no DEBUGINFOD_URLS is set 669da0c48c4Sopenharmony_ciDEBUGINFOD_URLS="" 670da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true 671da0c48c4Sopenharmony_ci 672da0c48c4Sopenharmony_ci# Now test is with proper DEBUGINFOD_URLS 673da0c48c4Sopenharmony_ciDEBUGINFOD_URLS="file://${PWD}/mocktree/" 674da0c48c4Sopenharmony_cifilename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c` 675da0c48c4Sopenharmony_cicmp $filename ${local_dir}/main.c 676da0c48c4Sopenharmony_ci 677da0c48c4Sopenharmony_ciexit 0 678