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 25DB=${PWD}/.debuginfod_tmp.sqlite 26tempfiles $DB 27export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 28 29# Set up directories for scanning 30mkdir F 31mkdir R 32cp -rvp ${abs_srcdir}/debuginfod-rpms R 33 34# This variable is essential and ensures no time-race for claiming ports occurs 35# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 36base=13000 37get_ports 38 39# We use -t0 and -g0 here to turn off time-based scanning & grooming. 40# For testing purposes, we just sic SIGUSR1 at the process. 41 42env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \ 43 -R R -F F -p $PORT1 -d $DB -t0 -g0 -v F > vlog$PORT1 2>&1 & 44PID1=$! 45tempfiles vlog$PORT1 46errfiles vlog$PORT1 47# Server must become ready 48wait_ready $PORT1 'ready' 1 49# And initial scan should be done 50wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 51 52export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 53 54# Check thread comm names 55ps -q $PID1 -e -L -o '%p %c %a' | grep groom 56ps -q $PID1 -e -L -o '%p %c %a' | grep scan 57ps -q $PID1 -e -L -o '%p %c %a' | grep traverse 58 59######################################################################## 60 61# Compile a simple program, strip its debuginfo and save the build-id. 62# Also move the debuginfo into another directory so that elfutils 63# cannot find it without debuginfod. 64tempfiles prog.c 65echo "int main() { return 0; }" > ${PWD}/prog.c 66 67gcc -Wl,--build-id -g -o F/prog ${PWD}/prog.c 68 69testrun ${abs_top_builddir}/src/strip -g -f F/prog.debug ${PWD}/F/prog 70BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 71 -a F/prog | grep 'Build ID' | cut -d ' ' -f 7` 72 73kill -USR1 $PID1 74# Wait till both files are in the index. 75wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 76wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 77wait_ready $PORT1 'thread_busy{role="scan"}' 0 78 79######################################################################## 80 81# Build-id for a file in the one of the testsuite's F31 rpms 82RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 83 84# Download sections from files indexed with -F 85testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $BUILDID .debug_info 86testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $BUILDID .text 87 88# Download sections from files indexed with -R 89testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $RPM_BUILDID .debug_info 90testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $RPM_BUILDID .text 91 92# Verify that the downloaded files match the contents of the original sections 93tempfiles ${BUILDID}.debug_info 94objcopy F/prog.debug -O binary --only-section=.debug_info --set-section-flags .debug_info=alloc $BUILDID.debug_info 95cmp ${BUILDID}.debug_info ${DEBUGINFOD_CACHE_PATH}/${BUILDID}/section-.debug_info 96 97tempfiles ${BUILDID}.text 98objcopy F/prog -O binary --only-section=.text ${BUILDID}.text 99cmp ${BUILDID}.text ${DEBUGINFOD_CACHE_PATH}/${BUILDID}/section-.text 100 101# Download the original debuginfo/executable files. 102DEBUGFILE=`env LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $RPM_BUILDID` 103EXECFILE=`env LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID` 104testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv debuginfo $BUILDID 105testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv executable $BUILDID 106 107if test "$(arch)" == "x86_64"; then 108 tempfiles DEBUGFILE.debug_info 109 objcopy $DEBUGFILE -O binary --only-section=.debug_info --set-section-flags .debug_info=alloc DEBUGFILE.debug_info 110 testrun diff -u DEBUGFILE.debug_info ${DEBUGINFOD_CACHE_PATH}/${RPM_BUILDID}/section-.debug_info 111 112 tempfiles EXECFILE.text 113 objcopy $EXECFILE -O binary --only-section=.text EXECFILE.text 114 testrun diff -u EXECFILE.text ${DEBUGINFOD_CACHE_PATH}/${RPM_BUILDID}/section-.text 115fi 116 117# Kill the server. 118kill $PID1 119wait $PID1 120PID1=0 121 122# Delete the section files from the cache. 123rm -f ${DEBUGINFOD_CACHE_PATH}/${RPM_BUILDID}/section-.text 124rm -f ${DEBUGINFOD_CACHE_PATH}/${RPM_BUILDID}/section-.debug_info 125rm -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID}/section-.text 126rm -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID}/section-.debug_info 127 128# Verify that the client can extract sections from the debuginfo or executable 129# if they're already in the cache. 130testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $BUILDID .debug_info 131testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $BUILDID .text 132testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $RPM_BUILDID .debug_info 133testrun ${abs_top_builddir}/debuginfod/debuginfod-find -vvv section $RPM_BUILDID .text 134 135exit 0 136