• 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 R Z
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=8700
29get_ports
30
31DB=${PWD}/.debuginfod_tmp.sqlite
32tempfiles $DB
33export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
34
35env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d $DB -F -R -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT1 -t0 -g0 -v R Z > vlog$PORT1 2>&1 &
36PID1=$!
37tempfiles vlog$PORT1
38errfiles vlog$PORT1
39# Server must become ready
40wait_ready $PORT1 'ready' 1
41
42# Check thread comm names
43ps -q $PID1 -e -L -o '%p %c %a' | grep groom
44ps -q $PID1 -e -L -o '%p %c %a' | grep scan
45ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
46
47# Make sure the initial scan has finished before copying the new files in
48# We might remove some, which we don't want to be accidentially scanned.
49wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
50
51cp -rvp ${abs_srcdir}/debuginfod-rpms R
52if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
53    rm -vrf R/debuginfod-rpms/fedora31
54fi
55
56cp -rvp ${abs_srcdir}/debuginfod-tars Z
57
58kill -USR1 $PID1
59# Wait till both files are in the index and scan/index fully finished
60wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
61wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
62wait_ready $PORT1 'thread_busy{role="scan"}' 0
63
64########################################################################
65# All rpms need to be in the index, except the dummy permission-000 one
66rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
67wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
68txz=$(find Z -name \*tar.xz | wc -l)
69wait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz
70tb2=$(find Z -name \*tar.bz2 | wc -l)
71wait_ready $PORT1 'scanned_files_total{source=".tar.bz2 archive"}' $tb2
72
73kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
74# Wait till both files are in the index and scan/index fully finished
75wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
76wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
77wait_ready $PORT1 'thread_busy{role="scan"}' 0
78
79# Expect all source files found in the rpms (they are all called hello.c :)
80# We will need to extract all rpms (in their own directory) and could all
81# sources referenced in the .debug files.
82mkdir extracted
83cd extracted
84subdir=0;
85newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
86for i in $newrpms; do
87    subdir=$[$subdir+1];
88    mkdir $subdir;
89    cd $subdir;
90    ls -lah ../$i
91    rpm2cpio ../$i | cpio -ivd;
92    cd ..;
93done
94sourcefiles=$(find -name \*\\.debug \
95              | env LD_LIBRARY_PATH=$ldpath xargs \
96                ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
97              | grep mtime: | wc --lines)
98cd ..
99rm -rf extracted
100
101wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
102
103kill $PID1
104wait $PID1
105PID1=0
106exit 0
107