• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Be patient when run on a busy machine things might take a bit.
49export DEBUGINFOD_TIMEOUT=10
50
51# Check thread comm names
52ps -q $PID1 -e -L -o '%p %c %a' | grep groom
53ps -q $PID1 -e -L -o '%p %c %a' | grep scan
54ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
55
56# We use -t0 and -g0 here to turn off time-based scanning & grooming.
57# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
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.
64echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
65tempfiles p+r%o\$g.c
66# Create a subdirectory to confound source path names
67mkdir foobar
68gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
69testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
70BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
71          -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
72
73mv p+r%o\$g F
74mv p+r%o\$g.debug F
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 the cache default locations are correct
84mkdir tmphome
85
86# $HOME/.cache should be created.
87testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
88if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
89  echo "could not find cache in $PWD/tmphome/.cache"
90  err
91fi
92
93# $HOME/.cache should be found.
94testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
95if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
96  echo "could not find cache in $PWD/tmphome/.cache"
97  err
98fi
99# $XDG_CACHE_HOME should take priority over $HOME.cache.
100testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
101if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
102  echo "could not find cache in $PWD/tmpxdg/"
103  err
104fi
105
106# A cache at the old default location ($HOME/.debuginfod_client_cache) should take
107# priority over $HOME/.cache, $XDG_CACHE_HOME.
108cp -vr $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache || true
109# ||true is for tolerating errors, such a valgrind or something else
110#        leaving 000-perm files in there
111
112# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
113mkdir tmphome/.debuginfod_client_cache/deadbeef
114echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo
115filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef`
116cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo
117
118# $DEBUGINFO_CACHE_PATH should take priority over all else.
119testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
120if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then
121  echo "could not find cache in $PWD/tmpcache/"
122  err
123fi
124rm -rf ${PWD}/tmphome/ ${PWD}/tmpxdg ${PWD}/tmpcache
125
126kill $PID1
127wait $PID1
128PID1=0
129exit 0
130