• 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=8500
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 -F -R $VERBOSE -p $PORT1 -d $DB \
36    -t0 -g0 -v F > vlog$PORT1 2>&1 &
37PID1=$!
38tempfiles vlog$PORT1
39errfiles vlog$PORT1
40
41# Server must become ready
42wait_ready $PORT1 'ready' 1
43export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
44
45# Be patient when run on a busy machine things might take a bit.
46export DEBUGINFOD_TIMEOUT=10
47
48# Check thread comm names
49ps -q $PID1 -e -L -o '%p %c %a'
50ps -q $PID1 -e -L -o '%p %c %a' | grep groom
51ps -q $PID1 -e -L -o '%p %c %a' | grep scan
52ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
53
54# Make sure the initial scan has finished.
55# Before moving files under the scan dirs.
56wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
57
58# We use -t0 and -g0 here to turn off time-based scanning & grooming.
59# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
60
61########################################################################
62
63# Compile a simple program, strip its debuginfo and save the build-id.
64# Also move the debuginfo into another directory so that elfutils
65# cannot find it without debuginfod.
66echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
67tempfiles p+r%o\$g.c
68# Create a subdirectory to confound source path names
69mkdir foobar
70gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
71testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
72BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
73          -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
74
75mv p+r%o\$g F
76mv p+r%o\$g.debug F
77
78kill -USR1 $PID1
79# Wait till both files are in the index.
80wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
81wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
82wait_ready $PORT1 'thread_busy{role="scan"}' 0
83
84########################################################################
85
86# Test whether elfutils, via the debuginfod client library dlopen hooks,
87# is able to fetch debuginfo from the local debuginfod.
88testrun ${abs_builddir}/debuginfod_build_id_find -e F/p+r%o\$g 1
89
90kill $PID1
91wait $PID1
92PID1=0
93
94exit 0
95