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 29mkdir F 30mkdir -p $DEBUGINFOD_CACHE_PATH 31# This variable is essential and ensures no time-race for claiming ports occurs 32# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test 33base=9700 34get_ports 35 36env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \ 37 -t0 -g0 -v F > vlog$PORT1 2>&1 & 38PID1=$! 39tempfiles vlog$PORT1 40errfiles vlog$PORT1 41# Server must become ready 42wait_ready $PORT1 'ready' 1 43# And initial scan should be done 44wait_ready $PORT1 'thread_work_total{role="traverse"}' 1 45 46export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing / 47 48# Check thread comm names 49ps -q $PID1 -e -L -o '%p %c %a' | grep groom 50ps -q $PID1 -e -L -o '%p %c %a' | grep scan 51ps -q $PID1 -e -L -o '%p %c %a' | grep traverse 52 53# We use -t0 and -g0 here to turn off time-based scanning & grooming. 54# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process. 55 56######################################################################## 57 58# Compile a simple program, strip its debuginfo and save the build-id. 59# Also move the debuginfo into another directory so that elfutils 60# cannot find it without debuginfod. 61echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c 62tempfiles p+r%o\$g.c 63# Create a subdirectory to confound source path names 64mkdir foobar 65gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c 66testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g 67BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \ 68 -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7` 69 70mv p+r%o\$g F 71mv p+r%o\$g.debug F 72kill -USR1 $PID1 73# Wait till both files are in the index. 74wait_ready $PORT1 'thread_work_total{role="traverse"}' 2 75wait_ready $PORT1 'thread_work_pending{role="scan"}' 0 76wait_ready $PORT1 'thread_busy{role="scan"}' 0 77 78######################################################################## 79 80# Test whether the cache default locations are correct 81mkdir tmphome 82 83# $HOME/.cache should be created. 84testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 85if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then 86 echo "could not find cache in $PWD/tmphome/.cache" 87 err 88fi 89 90# $HOME/.cache should be found. 91testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID 92if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then 93 echo "could not find cache in $PWD/tmphome/.cache" 94 err 95fi 96# $XDG_CACHE_HOME should take priority over $HOME.cache. 97testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 98if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then 99 echo "could not find cache in $PWD/tmpxdg/" 100 err 101fi 102 103# A cache at the old default location ($HOME/.debuginfod_client_cache) should take 104# priority over $HOME/.cache, $XDG_CACHE_HOME. 105cp -vr $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache || true 106# ||true is for tolerating errors, such a valgrind or something else 107# leaving negative-hit files in there 108 109# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME. 110mkdir tmphome/.debuginfod_client_cache/deadbeef 111echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo 112filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef` 113cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo 114 115# $DEBUGINFO_CACHE_PATH should take priority over all else. 116testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID 117if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then 118 echo "could not find cache in $PWD/tmpcache/" 119 err 120fi 121rm -rf ${PWD}/tmphome/ ${PWD}/tmpxdg ${PWD}/tmpcache 122 123kill $PID1 124wait $PID1 125PID1=0 126exit 0 127