• 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# This variable is essential and ensures no time-race for claiming ports occurs
25# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
26base=8100
27get_ports
28DB=${PWD}/.debuginfod_tmp.sqlite
29tempfiles $DB
30export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
31export DEBUGINFOD_TIMEOUT=10
32
33# Clean old dirictories
34mkdir R ${PWD}/F
35env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \
36    -F -R -d $DB -p $PORT1 -t0 -g0 -v R ${PWD}/F > vlog$PORT1 2>&1 &
37PID1=$!
38tempfiles vlog$PORT1
39errfiles vlog$PORT1
40# Server must become ready
41wait_ready $PORT1 'ready' 1
42# Be patient when run on a busy machine things might take a bit.
43
44# Check thread comm names
45ps -q $PID1 -e -L -o '%p %c %a' | grep groom
46ps -q $PID1 -e -L -o '%p %c %a' | grep scan
47ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
48
49# wait till the initial scan is done before triggering a new one
50# and before dropping new file into the scan dirs
51wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
52# Same for the initial groom cycle, we don't want it to be done
53# half way initializing the file setup
54wait_ready $PORT1 'thread_work_total{role="groom"}' 1
55
56# Build a non-stripped binary
57echo "int main() { return 0; }" > ${PWD}/F/prog.c
58gcc -Wl,--build-id -g -o ${PWD}/F/prog ${PWD}/F/prog.c
59BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
60          -a ${PWD}/F/prog | grep 'Build ID' | cut -d ' ' -f 7`
61tempfiles ${PWD}/F/prog ${PWD}/F/prog.c
62
63cp -rvp ${abs_srcdir}/debuginfod-rpms R
64if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
65    rm -vrf R/debuginfod-rpms/fedora31
66fi
67
68kill -USR1 $PID1
69# Now there should be 1 files 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
74cp -rvp ${abs_srcdir}/debuginfod-rpms R
75if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
76    rm -vrf R/debuginfod-rpms/fedora31
77fi
78
79tempfiles vlog3
80cp -rvp ${abs_srcdir}/debuginfod-tars Z
81kill -USR1 $PID1
82# Wait till both files are in the index and scan/index fully finished
83wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
84wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
85wait_ready $PORT1 'thread_busy{role="scan"}' 0
86########################################################################
87# All rpms need to be in the index, except the dummy permission-000 one
88rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
89wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
90txz=$(find Z -name \*tar.xz | wc -l)
91
92kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
93# Wait till both files are in the index and scan/index fully finished
94wait_ready $PORT1 'thread_work_total{role="traverse"}' 4
95wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
96wait_ready $PORT1 'thread_busy{role="scan"}' 0
97
98# Expect all source files found in the rpms (they are all called hello.c :)
99# We will need to extract all rpms (in their own directory) and could all
100# sources referenced in the .debug files.
101mkdir extracted
102cd extracted
103subdir=0;
104newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
105for i in $newrpms; do
106    subdir=$[$subdir+1];
107    mkdir $subdir;
108    cd $subdir;
109    ls -lah ../$i
110    rpm2cpio ../$i | cpio -ivd;
111    cd ..;
112done
113sourcefiles=$(find -name \*\\.debug \
114              | env LD_LIBRARY_PATH=$ldpath xargs \
115                ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
116              | grep mtime: | wc --lines)
117cd ..
118rm -rf extracted
119
120wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
121
122export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
123
124# common source file sha1
125SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
126# fedora31
127if [ $zstd = true ]; then
128    # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
129    # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
130    archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
131    archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
132fi
133# fedora30
134archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
135archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
136# rhel7
137archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
138archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
139# rhel6
140archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
141archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
142RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir
143
144# Drop some of the artifacts, run a groom cycle; confirm that
145# debuginfod has forgotten them, but remembers others
146rm -r R/debuginfod-rpms/rhel6/*
147
148kill -USR2 $PID1  # groom cycle
149## 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2
150wait_ready $PORT1 'thread_work_total{role="groom"}' 2
151# Expect 4 rpms containing 2 buildids to be deleted by the groom
152wait_ready $PORT1 'groomed_total{decision="stale"}' 4
153# Expect no more groom actions pending
154wait_ready $PORT1 'thread_work_pending{role="groom"}' 0
155
156rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
157
158# this is one of the buildids from the groom-deleted rpms
159testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
160
161# but this one was not deleted so should be still around
162testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID || true
163
164kill $PID1
165wait $PID1
166PID1=0
167exit 0
168