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