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 25mkdir F 26# This variable is essential and ensures no time-race for claiming ports occurs 27# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 28base=8500 29get_ports 30 31DB=${PWD}/.debuginfod_tmp.sqlite 32tempfiles $DB 33export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache 34 35env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod -F -R $VERBOSE -p $PORT1 -d $DB \ 36 -t0 -g0 -v F > vlog$PORT1 2>&1 & 37PID1=$! 38tempfiles vlog$PORT1 39errfiles vlog$PORT1 40 41# Server must become ready 42wait_ready $PORT1 'ready' 1 43export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing / 44 45# Check thread comm names 46ps -q $PID1 -e -L -o '%p %c %a' 47ps -q $PID1 -e -L -o '%p %c %a' | grep groom 48ps -q $PID1 -e -L -o '%p %c %a' | grep scan 49ps -q $PID1 -e -L -o '%p %c %a' | grep traverse 50 51# Make sure the initial scan has finished. 52# Before moving files under the scan dirs. 53wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 54 55# We use -t0 and -g0 here to turn off time-based scanning & grooming. 56# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process. 57 58######################################################################## 59 60# Compile a simple program, strip its debuginfo and save the build-id. 61# Also move the debuginfo into another directory so that elfutils 62# cannot find it without debuginfod. 63echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c 64tempfiles p+r%o\$g.c 65# Create a subdirectory to confound source path names 66mkdir foobar 67gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c 68testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g 69BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 70 -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7` 71 72mv p+r%o\$g F 73mv p+r%o\$g.debug F 74 75kill -USR1 $PID1 76# Wait till both files are in the index. 77wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 78wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 79wait_ready $PORT1 'thread_busy{role="scan"}' 0 80 81######################################################################## 82 83# Test whether elfutils, via the debuginfod client library dlopen hooks, 84# is able to fetch debuginfo from the local debuginfod. 85testrun ${abs_builddir}/debuginfod_build_id_find -e F/p+r%o\$g 1 86 87kill $PID1 88wait $PID1 89PID1=0 90 91exit 0 92