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/debuginfod-subr.sh 20da0c48c4Sopenharmony_ci 21da0c48c4Sopenharmony_ci# for test case debugging, uncomment: 22da0c48c4Sopenharmony_ciset -x 23da0c48c4Sopenharmony_ciunset VALGRIND_CMD 24da0c48c4Sopenharmony_ci 25da0c48c4Sopenharmony_ciDB=${PWD}/.debuginfod_tmp.sqlite 26da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 27da0c48c4Sopenharmony_citempfiles $DB 28da0c48c4Sopenharmony_ci 29da0c48c4Sopenharmony_ci# Clean old dirictories 30da0c48c4Sopenharmony_cimkdir D L F 31da0c48c4Sopenharmony_cimkdir -p $DEBUGINFOD_CACHE_PATH 32da0c48c4Sopenharmony_ci# not tempfiles F R L D Z - they are directories which we clean up manually 33da0c48c4Sopenharmony_ciln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test 34da0c48c4Sopenharmony_ci# This variable is essential and ensures no time-race for claiming ports occurs 35da0c48c4Sopenharmony_ci# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 36da0c48c4Sopenharmony_cibase=8900 37da0c48c4Sopenharmony_ciget_ports 38da0c48c4Sopenharmony_ci# Launch server which will be unable to follow symlinks 39da0c48c4Sopenharmony_cienv LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 & 40da0c48c4Sopenharmony_ciPID1=$! 41da0c48c4Sopenharmony_citempfiles vlog$PORT1 42da0c48c4Sopenharmony_cierrfiles vlog$PORT1 43da0c48c4Sopenharmony_ci 44da0c48c4Sopenharmony_ciwait_ready $PORT1 'ready' 1 45da0c48c4Sopenharmony_ci# Make sure initial scan was done 46da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 1 47da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 48da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 49da0c48c4Sopenharmony_ci 50da0c48c4Sopenharmony_ci######################################################################## 51da0c48c4Sopenharmony_ci# Compile a simple program, strip its debuginfo and save the build-id. 52da0c48c4Sopenharmony_ci# Also move the debuginfo into another directory so that elfutils 53da0c48c4Sopenharmony_ci# cannot find it without debuginfod. 54da0c48c4Sopenharmony_ciecho "int main() { return 0; }" > ${PWD}/prog.c 55da0c48c4Sopenharmony_citempfiles prog.c 56da0c48c4Sopenharmony_ci# Create a subdirectory to confound source path names 57da0c48c4Sopenharmony_cimkdir foobar 58da0c48c4Sopenharmony_cigcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c 59da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog 60da0c48c4Sopenharmony_ciBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 61da0c48c4Sopenharmony_ci -a prog | grep 'Build ID' | cut -d ' ' -f 7` 62da0c48c4Sopenharmony_ci 63da0c48c4Sopenharmony_cimv prog F 64da0c48c4Sopenharmony_cimv prog.debug F 65da0c48c4Sopenharmony_ci 66da0c48c4Sopenharmony_cikill -USR1 $PID1 67da0c48c4Sopenharmony_ci# Wait till both files are in the index. 68da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_total{role="traverse"}' 2 69da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_work_pending{role="scan"}' 0 70da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="scan"}' 0 71da0c48c4Sopenharmony_ci 72da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="http-buildid"}' 0 73da0c48c4Sopenharmony_ciwait_ready $PORT1 'thread_busy{role="http-metrics"}' 1 74da0c48c4Sopenharmony_ci 75da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2 76da0c48c4Sopenharmony_cimkdir -p $DEBUGINFOD_CACHE_PATH 77da0c48c4Sopenharmony_ci 78da0c48c4Sopenharmony_ci# NB: run in -L symlink-following mode for the L subdir 79da0c48c4Sopenharmony_cienv 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 & 80da0c48c4Sopenharmony_ciPID2=$! 81da0c48c4Sopenharmony_citempfiles vlog$PORT2 82da0c48c4Sopenharmony_cierrfiles vlog$PORT2 83da0c48c4Sopenharmony_citempfiles ${DB}_2 84da0c48c4Sopenharmony_ci 85da0c48c4Sopenharmony_ciwait_ready $PORT2 'ready' 1 86da0c48c4Sopenharmony_ci 87da0c48c4Sopenharmony_ci# Make sure initial scan was done 88da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_work_total{role="traverse"}' 1 89da0c48c4Sopenharmony_cikill -USR1 $PID2 90da0c48c4Sopenharmony_ci# Wait till both files are in the index. 91da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_work_total{role="traverse"}' 2 92da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_work_pending{role="scan"}' 0 93da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="scan"}' 0 94da0c48c4Sopenharmony_ci 95da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="http-buildid"}' 0 96da0c48c4Sopenharmony_ciwait_ready $PORT2 'thread_busy{role="http-metrics"}' 1 97da0c48c4Sopenharmony_ci 98da0c48c4Sopenharmony_ci# have clients contact the new server 99da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 100da0c48c4Sopenharmony_ci# Use fresh cache for debuginfod-find client requests 101da0c48c4Sopenharmony_ciexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3 102da0c48c4Sopenharmony_cimkdir -p $DEBUGINFOD_CACHE_PATH 103da0c48c4Sopenharmony_ci 104da0c48c4Sopenharmony_ciif type bsdtar 2>/dev/null; then 105da0c48c4Sopenharmony_ci # copy in the deb files 106da0c48c4Sopenharmony_ci cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D 107da0c48c4Sopenharmony_ci kill -USR1 $PID2 108da0c48c4Sopenharmony_ci wait_ready $PORT2 'thread_work_total{role="traverse"}' 3 109da0c48c4Sopenharmony_ci wait_ready $PORT2 'thread_work_pending{role="scan"}' 0 110da0c48c4Sopenharmony_ci wait_ready $PORT2 'thread_busy{role="scan"}' 0 111da0c48c4Sopenharmony_ci 112da0c48c4Sopenharmony_ci # All debs need to be in the index 113da0c48c4Sopenharmony_ci debs=$(find D -name \*.deb | wc -l) 114da0c48c4Sopenharmony_ci wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs` 115da0c48c4Sopenharmony_ci ddebs=$(find D -name \*.ddeb | wc -l) 116da0c48c4Sopenharmony_ci wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs` 117da0c48c4Sopenharmony_ci 118da0c48c4Sopenharmony_ci # ubuntu 119da0c48c4Sopenharmony_ci archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" "" 120da0c48c4Sopenharmony_cifi 121da0c48c4Sopenharmony_ci 122da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 123da0c48c4Sopenharmony_ci 124da0c48c4Sopenharmony_ci# send a request to stress XFF and User-Agent federation relay; 125da0c48c4Sopenharmony_ci# we'll grep for the two patterns in vlog$PORT1 126da0c48c4Sopenharmony_cicurl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true 127da0c48c4Sopenharmony_ci 128da0c48c4Sopenharmony_cigrep UA:TESTCURL vlog$PORT1 129da0c48c4Sopenharmony_cigrep XFF:TESTXFF vlog$PORT1 130da0c48c4Sopenharmony_ci 131da0c48c4Sopenharmony_ci# confirm that first server can't resolve symlinked info in L/ but second can 132da0c48c4Sopenharmony_ciBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 133da0c48c4Sopenharmony_ci -a L/foo | grep 'Build ID' | cut -d ' ' -f 7` 134da0c48c4Sopenharmony_cifile L/foo 135da0c48c4Sopenharmony_cifile -L L/foo 136da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 137da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 138da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 139da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file 140da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 141da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 142da0c48c4Sopenharmony_ci 143da0c48c4Sopenharmony_ci# test again with scheme free url 144da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=127.0.0.1:$PORT1 145da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 146da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true 147da0c48c4Sopenharmony_cirm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file 148da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS=127.0.0.1:$PORT2 149da0c48c4Sopenharmony_citestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 150da0c48c4Sopenharmony_ci 151da0c48c4Sopenharmony_ci# test parallel queries in client 152da0c48c4Sopenharmony_cirm -rf $DEBUGINFOD_CACHE_PATH 153da0c48c4Sopenharmony_ciexport DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE" 154da0c48c4Sopenharmony_ci 155da0c48c4Sopenharmony_citestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1 156da0c48c4Sopenharmony_ci 157da0c48c4Sopenharmony_cikill $PID1 158da0c48c4Sopenharmony_cikill $PID2 159da0c48c4Sopenharmony_ciwait $PID1 160da0c48c4Sopenharmony_ciwait $PID2 161da0c48c4Sopenharmony_ciPID1=0 162da0c48c4Sopenharmony_ciPID2=0 163da0c48c4Sopenharmony_ci 164da0c48c4Sopenharmony_ciexit 0 165