• 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
25mkdir F
26# This variable is essential and ensures no time-race for claiming ports occurs
27# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
28base=9800
29get_ports
30
31DB=${PWD}/.debuginfod_tmp.sqlite
32tempfiles $DB
33export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
34
35env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
36    -t0 -g0 -v F > vlog$PORT1 2>&1 &
37PID1=$!
38tempfiles vlog$PORT1
39errfiles vlog$PORT1
40# Server must become ready
41wait_ready $PORT1 'ready' 1
42# And initial scan should be done
43wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
44
45export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
46
47# Check thread comm names
48ps -q $PID1 -e -L -o '%p %c %a' | grep groom
49ps -q $PID1 -e -L -o '%p %c %a' | grep scan
50ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
51
52########################################################################
53
54# Compile a simple program, strip its debuginfo and save the build-id.
55# Also move the debuginfo into another directory so that elfutils
56# cannot find it without debuginfod.
57echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
58tempfiles p+r%o\$g.c
59# Create a subdirectory to confound source path names
60mkdir foobar
61gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
62testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
63BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
64          -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
65
66mv p+r%o\$g F
67mv p+r%o\$g.debug F
68kill -USR1 $PID1
69# Wait till both files are in the index.
70wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
71wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
72wait_ready $PORT1 'thread_busy{role="scan"}' 0
73
74#######################################################################
75# Test whether debuginfod-find is able to fetch those files.
76rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
77filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
78cmp $filename F/p+r%o\$g.debug
79if [  `stat -c "%A" $filename` != "-r--------" ]; then
80    echo "cache file writable, boo"
81    err
82fi
83
84kill $PID1
85wait $PID1
86PID1=0
87
88exit 0
89