xref: /aosp_15_r20/external/elfutils/tests/run-debuginfod-extraction.sh (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
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 --scan-checkpoint=1 -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 accidentally 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# Take a dump if possible
65type sqlite3 2>/dev/null && sqlite3 $DB '.d'
66
67########################################################################
68# All rpms need to be in the index, except the dummy permission-000 one
69rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
70wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
71txz=$(find Z -name \*tar.xz | wc -l)
72wait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz
73tb2=$(find Z -name \*tar.bz2 | wc -l)
74wait_ready $PORT1 'scanned_files_total{source=".tar.bz2 archive"}' $tb2
75
76kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
77# Wait till both files are in the index and scan/index fully finished
78wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
79wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
80wait_ready $PORT1 'thread_busy{role="scan"}' 0
81
82# Expect all source files found in the rpms (they are all called hello.c :)
83# We will need to extract all rpms (in their own directory) and could all
84# sources referenced in the .debug files.
85mkdir extracted
86cd extracted
87subdir=0;
88newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
89for i in $newrpms; do
90    subdir=$[$subdir+1];
91    mkdir $subdir;
92    cd $subdir;
93    ls -lah ../$i
94    rpm2cpio ../$i | cpio -ivd;
95    cd ..;
96done
97sourcefiles=$(find -name \*\\.debug \
98              | env LD_LIBRARY_PATH=$ldpath xargs \
99                ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
100              | grep mtime: | wc --lines)
101cd ..
102rm -rf extracted
103
104wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
105
106kill $PID1
107wait $PID1
108PID1=0
109exit 0
110