• 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
26export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
27tempfiles $DB
28
29# Clean old dirictories
30mkdir D L F
31mkdir -p $DEBUGINFOD_CACHE_PATH
32# not tempfiles F R L D Z - they are directories which we clean up manually
33ln -s ${abs_builddir}/dwfllines L/foo   # any program not used elsewhere in this test
34# This variable is essential and ensures no time-race for claiming ports occurs
35# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
36base=8900
37get_ports
38# Launch server which will be unable to follow symlinks
39env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 &
40PID1=$!
41tempfiles vlog$PORT1
42errfiles vlog$PORT1
43
44wait_ready $PORT1 'ready' 1
45# Make sure initial scan was done
46wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
47wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
48wait_ready $PORT1 'thread_busy{role="scan"}' 0
49
50########################################################################
51# Compile a simple program, strip its debuginfo and save the build-id.
52# Also move the debuginfo into another directory so that elfutils
53# cannot find it without debuginfod.
54echo "int main() { return 0; }" > ${PWD}/prog.c
55tempfiles prog.c
56# Create a subdirectory to confound source path names
57mkdir foobar
58gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
59testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
60BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
61          -a prog | grep 'Build ID' | cut -d ' ' -f 7`
62
63mv prog F
64mv prog.debug F
65
66kill -USR1 $PID1
67# Wait till both files are in the index.
68wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
69wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
70wait_ready $PORT1 'thread_busy{role="scan"}' 0
71
72wait_ready $PORT1 'thread_busy{role="http-buildid"}' 0
73wait_ready $PORT1 'thread_busy{role="http-metrics"}' 1
74
75export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
76mkdir -p $DEBUGINFOD_CACHE_PATH
77
78# NB: run in -L symlink-following mode for the L subdir
79env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D > vlog$PORT2 2>&1 &
80PID2=$!
81tempfiles vlog$PORT2
82errfiles vlog$PORT2
83tempfiles ${DB}_2
84
85wait_ready $PORT2 'ready' 1
86
87# Make sure initial scan was done
88wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
89kill -USR1 $PID2
90# Wait till both files are in the index.
91wait_ready $PORT2 'thread_work_total{role="traverse"}' 2
92wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
93wait_ready $PORT2 'thread_busy{role="scan"}' 0
94
95wait_ready $PORT2 'thread_busy{role="http-buildid"}' 0
96wait_ready $PORT2 'thread_busy{role="http-metrics"}' 1
97
98# have clients contact the new server
99export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
100# Use fresh cache for debuginfod-find client requests
101export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
102mkdir -p $DEBUGINFOD_CACHE_PATH
103
104if type bsdtar 2>/dev/null; then
105    # copy in the deb files
106    cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
107    kill -USR1 $PID2
108    wait_ready $PORT2 'thread_work_total{role="traverse"}' 3
109    wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
110    wait_ready $PORT2 'thread_busy{role="scan"}' 0
111
112    # All debs need to be in the index
113    debs=$(find D -name \*.deb | wc -l)
114    wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
115    ddebs=$(find D -name \*.ddeb | wc -l)
116    wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
117
118    # ubuntu
119    archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
120fi
121
122testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
123
124# send a request to stress XFF and User-Agent federation relay;
125# we'll grep for the two patterns in vlog$PORT1
126curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
127
128grep UA:TESTCURL vlog$PORT1
129grep XFF:TESTXFF vlog$PORT1
130
131# confirm that first server can't resolve symlinked info in L/ but second can
132BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
133         -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
134file L/foo
135file -L L/foo
136export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
137rm -rf $DEBUGINFOD_CACHE_PATH
138testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
139rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
140export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
141testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
142
143# test again with scheme free url
144export DEBUGINFOD_URLS=127.0.0.1:$PORT1
145rm -rf $DEBUGINFOD_CACHE_PATH
146testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
147rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
148export DEBUGINFOD_URLS=127.0.0.1:$PORT2
149testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
150
151# test parallel queries in client
152rm -rf $DEBUGINFOD_CACHE_PATH
153export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
154
155testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
156
157kill $PID1
158kill $PID2
159wait $PID1
160wait $PID2
161PID1=0
162PID2=0
163
164exit 0
165