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 # includes set -e 20 21# for test case debugging, uncomment: 22set -x 23 24DB=${PWD}/.debuginfod_tmp.sqlite 25tempfiles $DB 26export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 27 28# This variable is essential and ensures no time-race for claiming ports occurs 29# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 30base=9500 31get_ports 32mkdir F R 33env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -R -d $DB -p $PORT1 -t0 -g0 -v R F > vlog$PORT1 2>&1 & 34PID1=$! 35tempfiles vlog$PORT1 36errfiles vlog$PORT1 37# Server must become ready 38wait_ready $PORT1 'ready' 1 39export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing / 40######################################################################## 41 42# Compile a simple program, strip its debuginfo and save the build-id. 43# Also move the debuginfo into another directory so that elfutils 44# cannot find it without debuginfod. 45echo "int main() { return 0; }" > ${PWD}/prog.c 46tempfiles prog.c 47# Create a subdirectory to confound source path names 48mkdir foobar 49gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c 50 51mv prog F 52 53cp -rvp ${abs_srcdir}/debuginfod-rpms R 54if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones 55 rm -vrf R/debuginfod-rpms/fedora31 56fi 57 58kill -USR1 $PID1 59# Wait till both files are in the index and scan/index fully finished 60wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 61# All rpms need to be in the index, except the dummy permission-000 one 62rpms=$(find R -name \*rpm | grep -v nothing | wc -l) 63wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms 64kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs 65# Wait till both files are in the index and scan/index fully finished 66wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 67 68######################################################################## 69## PR27277 70# Make a simple request to the debuginfod server and check debuginfod-find's vlog to see if 71# the custom HTTP headers are received. 72rm -rf $DEBUGINFOD_CACHE_PATH 73env DEBUGINFOD_URLS="http://127.0.0.1:"$PORT1 LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find\ 74 -vvv executable F/prog > vlog-find$PORT1.1 2>&1 75tempfiles vlog-find$PORT1.1 76grep 'Content-Length: ' vlog-find$PORT1.1 77grep 'X-DEBUGINFOD-FILE: ' vlog-find$PORT1.1 78grep 'X-DEBUGINFOD-SIZE: ' vlog-find$PORT1.1 79 80# Check to see if an executable file located in an archive prints the file's description and archive 81env DEBUGINFOD_URLS="http://127.0.0.1:"$PORT1 LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find\ 82 -vvv executable c36708a78618d597dee15d0dc989f093ca5f9120 > vlog-find$PORT1.2 2>&1 83tempfiles vlog-find$PORT1.2 84grep 'Content-Length: ' vlog-find$PORT1.2 85grep 'X-DEBUGINFOD-FILE: ' vlog-find$PORT1.2 86grep 'X-DEBUGINFOD-SIZE: ' vlog-find$PORT1.2 87grep 'X-DEBUGINFOD-ARCHIVE: ' vlog-find$PORT1.2 88 89kill $PID1 90wait $PID1 91PID1=0 92exit 0 93