• 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
56kill -USR1 $PID1
57wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
58wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
59wait_ready $PORT1 'thread_busy{role="scan"}' 0
60
61# Check thread comm names
62ps -q $PID1 -e -L -o '%p %c %a' | grep groom
63ps -q $PID1 -e -L -o '%p %c %a' | grep scan
64ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
65
66# Add artifacts to the search paths and test whether debuginfod finds them while already running.
67# Build another, non-stripped binary
68echo "int main() { return 0; }" > ${PWD}/prog2.c
69tempfiles prog2.c
70gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
71#testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
72BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
73          -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
74mv prog2 F
75#mv prog2.debug F
76tempfiles F/prog2 F/prog2.debug
77
78kill -USR1 $PID1
79# Now there should be 3 files in the index
80wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
81wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
82wait_ready $PORT1 'thread_busy{role="scan"}' 0
83
84########################################################################
85
86# Test whether debuginfod-find is able to fetch those files.
87rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
88filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
89cmp $filename F/prog.debug
90
91filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
92cmp $filename F/prog
93
94# raw source filename
95filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
96cmp $filename  ${PWD}/prog.c
97
98# and also the canonicalized one
99filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
100cmp $filename  ${PWD}/prog.c
101
102# Rerun same tests for the prog2 binary
103filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
104cmp $filename F/prog2
105grep -q Progress vlog
106grep -q Downloaded.from vlog
107tempfiles vlog
108filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
109cmp $filename F/prog2
110grep -q 'Downloading.*http' vlog2
111tempfiles vlog2
112filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
113cmp $filename ${PWD}/prog2.c
114
115
116kill $PID1
117wait $PID1
118PID1=0
119exit 0
120