• 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
21set -x
22unset VALGRIND_CMD
23# This variable is essential and ensures no time-race for claiming ports occurs
24# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
25base=9600
26get_ports
27
28DB=${PWD}/.debuginfod_tmp.sqlite
29tempfiles $DB
30export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
31
32echo "int main() { return 0; }" > ${PWD}/prog.c
33# Create a subdirectory to confound source path names
34mkdir foobar
35gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../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`
40
41env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB -t0 -g0 ${PWD} > vlog$PORT1 2>&1 &
42PID1=$!
43tempfiles vlog$PORT1
44errfiles  vlog$PORT1
45wait_ready $PORT1 'ready' 1
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## PR27892
51# Ensure DEBUGINFOD_MAXSIZE is functional and sends back the correct http
52# code
53env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_RETRY_LIMIT=1 DEBUGINFOD_URLS="http://127.0.0.1:$PORT1/" DEBUGINFOD_MAXSIZE=1 \
54    ${abs_top_builddir}/debuginfod/debuginfod-find -v -v executable ${PWD}/prog 2> find-vlog$PORT1 || true
55tempfiles find-vlog$PORT1
56errfiles  find-vlog$PORT1
57echo "Checking maxsize"
58grep "using max size 1B" find-vlog$PORT1
59echo "Checking maxsize"
60grep 'serving file '$(realpath ${PWD})'/prog' vlog$PORT1
61echo "Checking maxsize"
62grep 'File too large' vlog$PORT1
63if [ -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID} ]; then
64  echo "File cached after maxsize check"
65  err
66fi
67# Ensure no file is downloaded for longer than DEBUGINFOD_MAXTIME
68env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS="http://127.0.0.1:$PORT1/" DEBUGINFOD_MAXTIME=1 \
69    ${abs_top_builddir}/debuginfod/debuginfod-find -v -v debuginfo ${PWD}/prog.debug 2> find-vlog$PORT1 || true
70tempfiles find-vlog$PORT1
71grep 'using max time' find-vlog$PORT1
72# Ensure p+r%o\$g.debug is NOT cached
73if [ -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID} ]; then
74  echo "File cached after maxtime check"
75  err
76fi
77
78kill $PID1
79wait $PID1
80PID1=0
81
82exit 0;
83