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# This variable is essential and ensures no time-race for claiming ports occurs 25# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 26base=8100 27get_ports 28DB=${PWD}/.debuginfod_tmp.sqlite 29tempfiles $DB 30export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 31 32# Clean old dirictories 33mkdir R ${PWD}/F 34env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \ 35 -F -R -d $DB -p $PORT1 -t0 -g0 -v R ${PWD}/F > vlog$PORT1 2>&1 & 36PID1=$! 37tempfiles vlog$PORT1 38errfiles vlog$PORT1 39# Server must become ready 40wait_ready $PORT1 'ready' 1 41# Be patient when run on a busy machine things might take a bit. 42 43# Check thread comm names 44ps -q $PID1 -e -L -o '%p %c %a' | grep groom 45ps -q $PID1 -e -L -o '%p %c %a' | grep scan 46ps -q $PID1 -e -L -o '%p %c %a' | grep traverse 47 48# wait till the initial scan is done before triggering a new one 49# and before dropping new file into the scan dirs 50wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 51# Same for the initial groom cycle, we don't want it to be done 52# half way initializing the file setup 53wait_ready $PORT1 'thread_work_total{role="groom"}' 1 54 55# Build a non-stripped binary 56echo "int main() { return 0; }" > ${PWD}/F/prog.c 57gcc -Wl,--build-id -g -o ${PWD}/F/prog ${PWD}/F/prog.c 58BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 59 -a ${PWD}/F/prog | grep 'Build ID' | cut -d ' ' -f 7` 60tempfiles ${PWD}/F/prog ${PWD}/F/prog.c 61 62cp -rvp ${abs_srcdir}/debuginfod-rpms R 63if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones 64 rm -vrf R/debuginfod-rpms/fedora31 65fi 66 67kill -USR1 $PID1 68# Now there should be 1 files in the index 69wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 70wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 71wait_ready $PORT1 'thread_busy{role="scan"}' 0 72 73cp -rvp ${abs_srcdir}/debuginfod-rpms R 74if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones 75 rm -vrf R/debuginfod-rpms/fedora31 76fi 77 78tempfiles vlog3 79cp -rvp ${abs_srcdir}/debuginfod-tars Z 80kill -USR1 $PID1 81# Wait till both files are in the index and scan/index fully finished 82wait_ready $PORT1 'thread_work_total{role="traverse"}' 3 83wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 84wait_ready $PORT1 'thread_busy{role="scan"}' 0 85######################################################################## 86# All rpms need to be in the index, except the dummy permission-000 one 87rpms=$(find R -name \*rpm | grep -v nothing | wc -l) 88wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms 89txz=$(find Z -name \*tar.xz | wc -l) 90 91kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs 92# Wait till both files are in the index and scan/index fully finished 93wait_ready $PORT1 'thread_work_total{role="traverse"}' 4 94wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 95wait_ready $PORT1 'thread_busy{role="scan"}' 0 96 97# Expect all source files found in the rpms (they are all called hello.c :) 98# We will need to extract all rpms (in their own directory) and could all 99# sources referenced in the .debug files. 100mkdir extracted 101cd extracted 102subdir=0; 103newrpms=$(find ../R -name \*\.rpm | grep -v nothing) 104for i in $newrpms; do 105 subdir=$[$subdir+1]; 106 mkdir $subdir; 107 cd $subdir; 108 ls -lah ../$i 109 rpm2cpio ../$i | cpio -ivd; 110 cd ..; 111done 112sourcefiles=$(find -name \*\\.debug \ 113 | env LD_LIBRARY_PATH=$ldpath xargs \ 114 ${abs_top_builddir}/src/readelf --debug-dump=decodedline \ 115 | grep mtime: | wc --lines) 116cd .. 117rm -rf extracted 118 119wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles 120 121export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 122 123# common source file sha1 124SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1 125# fedora31 126if [ $zstd = true ]; then 127 # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it 128 # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite 129 archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA 130 archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA 131fi 132# fedora30 133archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA 134archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA 135# rhel7 136archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA 137archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA 138# rhel6 139archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA 140archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA 141RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir 142 143# Drop some of the artifacts, run a groom cycle; confirm that 144# debuginfod has forgotten them, but remembers others 145rm -r R/debuginfod-rpms/rhel6/* 146 147kill -USR2 $PID1 # groom cycle 148## 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2 149wait_ready $PORT1 'thread_work_total{role="groom"}' 2 150# Expect 4 rpms containing 2 buildids to be deleted by the groom 151wait_ready $PORT1 'groomed_total{decision="stale"}' 4 152# Expect no more groom actions pending 153wait_ready $PORT1 'thread_work_pending{role="groom"}' 0 154 155rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests 156 157# this is one of the buildids from the groom-deleted rpms 158testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true 159 160# but this one was not deleted so should be still around 161testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID || true 162 163kill $PID1 164wait $PID1 165PID1=0 166exit 0 167