• 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# 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=8400
27get_ports
28mkdir F
29
30DB=${PWD}/.debuginfod_tmp.sqlite
31tempfiles $DB
32export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
33
34echo 'int main(int argc, char * argv){ return 0; }' > ${PWD}/prog.c
35gcc -Wl,--build-id -g -o prog ${PWD}/prog.c
36testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
37tempfiles prog prog.debug prog.c
38BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
39          -a prog | grep 'Build ID' | cut -d ' ' -f 7`
40export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
41env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d $DB -F -p $PORT1 -t0 -g0 -v F > vlog$PORT1 2>&1 &
42PID1=$!
43tempfiles vlog$PORT1
44errfiles vlog$PORT1
45
46# Server must become ready
47wait_ready $PORT1 'ready' 1
48# And the initial scan should have been done before moving
49# files under the scan dirs.
50wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
51
52mv prog F
53mv prog.debug F
54tempfiles prog/F
55
56# Be patient when run on a busy machine things might take a bit.
57export DEBUGINFOD_TIMEOUT=10
58
59kill -USR1 $PID1
60wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
61wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
62wait_ready $PORT1 'thread_busy{role="scan"}' 0
63
64# Check thread comm names
65ps -q $PID1 -e -L -o '%p %c %a' | grep groom
66ps -q $PID1 -e -L -o '%p %c %a' | grep scan
67ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
68
69# Add artifacts to the search paths and test whether debuginfod finds them while already running.
70# Build another, non-stripped binary
71echo "int main() { return 0; }" > ${PWD}/prog2.c
72tempfiles prog2.c
73gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
74#testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
75BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
76          -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
77mv prog2 F
78#mv prog2.debug F
79tempfiles F/prog2 F/prog2.debug
80
81kill -USR1 $PID1
82# Now there should be 3 files in the index
83wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
84wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
85wait_ready $PORT1 'thread_busy{role="scan"}' 0
86
87########################################################################
88
89# Test whether debuginfod-find is able to fetch those files.
90rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
91filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
92cmp $filename F/prog.debug
93
94filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
95cmp $filename F/prog
96
97# raw source filename
98filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
99cmp $filename  ${PWD}/prog.c
100
101# and also the canonicalized one
102filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
103cmp $filename  ${PWD}/prog.c
104
105# Rerun same tests for the prog2 binary
106filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
107cmp $filename F/prog2
108grep -q Progress vlog
109grep -q Downloaded.from vlog
110tempfiles vlog
111filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
112cmp $filename F/prog2
113grep -q 'Downloading.*http' vlog2
114tempfiles vlog2
115filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
116cmp $filename ${PWD}/prog2.c
117
118
119kill $PID1
120wait $PID1
121PID1=0
122exit 0
123