xref: /aosp_15_r20/external/elfutils/tests/run-debuginfod-federation-sqlite.sh (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*7304104dSAndroid Build Coastguard Worker#
3*7304104dSAndroid Build Coastguard Worker# Copyright (C) 2019-2021 Red Hat, Inc.
4*7304104dSAndroid Build Coastguard Worker# This file is part of elfutils.
5*7304104dSAndroid Build Coastguard Worker#
6*7304104dSAndroid Build Coastguard Worker# This file is free software; you can redistribute it and/or modify
7*7304104dSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by
8*7304104dSAndroid Build Coastguard Worker# the Free Software Foundation; either version 3 of the License, or
9*7304104dSAndroid Build Coastguard Worker# (at your option) any later version.
10*7304104dSAndroid Build Coastguard Worker#
11*7304104dSAndroid Build Coastguard Worker# elfutils is distributed in the hope that it will be useful, but
12*7304104dSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of
13*7304104dSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*7304104dSAndroid Build Coastguard Worker# GNU General Public License for more details.
15*7304104dSAndroid Build Coastguard Worker#
16*7304104dSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License
17*7304104dSAndroid Build Coastguard Worker# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18*7304104dSAndroid Build Coastguard Worker
19*7304104dSAndroid Build Coastguard Worker. $srcdir/debuginfod-subr.sh
20*7304104dSAndroid Build Coastguard Worker
21*7304104dSAndroid Build Coastguard Worker# for test case debugging, uncomment:
22*7304104dSAndroid Build Coastguard Workerset -x
23*7304104dSAndroid Build Coastguard Workerunset VALGRIND_CMD
24*7304104dSAndroid Build Coastguard Worker
25*7304104dSAndroid Build Coastguard WorkerDB=${PWD}/.debuginfod_tmp.sqlite
26*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
27*7304104dSAndroid Build Coastguard Workertempfiles $DB
28*7304104dSAndroid Build Coastguard Worker
29*7304104dSAndroid Build Coastguard Worker# Clean old dirictories
30*7304104dSAndroid Build Coastguard Workermkdir D L F
31*7304104dSAndroid Build Coastguard Worker# not tempfiles F R L D Z - they are directories which we clean up manually
32*7304104dSAndroid Build Coastguard Workerln -s ${abs_builddir}/dwfllines L/foo   # any program not used elsewhere in this test
33*7304104dSAndroid Build Coastguard Worker
34*7304104dSAndroid Build Coastguard Worker########################################################################
35*7304104dSAndroid Build Coastguard Worker# Compile a simple program, strip its debuginfo and save the build-id.
36*7304104dSAndroid Build Coastguard Worker# Also move the debuginfo into another directory so that elfutils
37*7304104dSAndroid Build Coastguard Worker# cannot find it without debuginfod.
38*7304104dSAndroid Build Coastguard Workerecho "int main() { return 0; }" > ${PWD}/prog.c
39*7304104dSAndroid Build Coastguard Workertempfiles prog.c
40*7304104dSAndroid Build Coastguard Worker# Create a subdirectory to confound source path names
41*7304104dSAndroid Build Coastguard Workermkdir foobar
42*7304104dSAndroid Build Coastguard Workergcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
43*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
44*7304104dSAndroid Build Coastguard WorkerBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
45*7304104dSAndroid Build Coastguard Worker          -a prog | grep 'Build ID' | cut -d ' ' -f 7`
46*7304104dSAndroid Build Coastguard Worker
47*7304104dSAndroid Build Coastguard Workermv prog F
48*7304104dSAndroid Build Coastguard Workermv prog.debug F
49*7304104dSAndroid Build Coastguard Worker# This variable is essential and ensures no time-race for claiming ports occurs
50*7304104dSAndroid Build Coastguard Worker# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
51*7304104dSAndroid Build Coastguard Workerbase=9100
52*7304104dSAndroid Build Coastguard Workerget_ports
53*7304104dSAndroid Build Coastguard Worker# Launch server which will be unable to follow symlinks
54*7304104dSAndroid Build Coastguard Workerenv LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 &
55*7304104dSAndroid Build Coastguard WorkerPID1=$!
56*7304104dSAndroid Build Coastguard Workertempfiles vlog$PORT1
57*7304104dSAndroid Build Coastguard Workererrfiles vlog$PORT1
58*7304104dSAndroid Build Coastguard Worker
59*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'ready' 1
60*7304104dSAndroid Build Coastguard Worker
61*7304104dSAndroid Build Coastguard Worker# Wait till initial scan is done
62*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_total{role="traverse"}' 1
63*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_pending{role="scan"}' 0
64*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_busy{role="scan"}' 0
65*7304104dSAndroid Build Coastguard Worker
66*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
67*7304104dSAndroid Build Coastguard Workermkdir -p $DEBUGINFOD_CACHE_PATH
68*7304104dSAndroid Build Coastguard Worker# NB: run in -L symlink-following mode for the L subdir
69*7304104dSAndroid Build Coastguard Workerenv LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D F > vlog$PORT2 2>&1 &
70*7304104dSAndroid Build Coastguard WorkerPID2=$!
71*7304104dSAndroid Build Coastguard Workertempfiles vlog$PORT2
72*7304104dSAndroid Build Coastguard Workererrfiles vlog$PORT2
73*7304104dSAndroid Build Coastguard Workertempfiles ${DB}_2
74*7304104dSAndroid Build Coastguard Workerwait_ready $PORT2 'ready' 1
75*7304104dSAndroid Build Coastguard Worker# Wait till initial scan is done
76*7304104dSAndroid Build Coastguard Workerwait_ready $PORT2 'thread_work_total{role="traverse"}' 1
77*7304104dSAndroid Build Coastguard Worker# And initial groom cycle
78*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_total{role="groom"}' 1
79*7304104dSAndroid Build Coastguard Worker
80*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS='http://127.0.0.1:'$PORT2
81*7304104dSAndroid Build Coastguard Worker# Use fresh cache for debuginfod-find client requests
82*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
83*7304104dSAndroid Build Coastguard Workermkdir -p $DEBUGINFOD_CACHE_PATH
84*7304104dSAndroid Build Coastguard Worker
85*7304104dSAndroid Build Coastguard Workerif type bsdtar 2>/dev/null; then
86*7304104dSAndroid Build Coastguard Worker    # copy in the deb files
87*7304104dSAndroid Build Coastguard Worker    cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
88*7304104dSAndroid Build Coastguard Worker    kill -USR1 $PID2
89*7304104dSAndroid Build Coastguard Worker    wait_ready $PORT2 'thread_work_total{role="traverse"}' 2
90*7304104dSAndroid Build Coastguard Worker    wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
91*7304104dSAndroid Build Coastguard Worker    wait_ready $PORT2 'thread_busy{role="scan"}' 0
92*7304104dSAndroid Build Coastguard Worker
93*7304104dSAndroid Build Coastguard Worker    # All debs need to be in the index
94*7304104dSAndroid Build Coastguard Worker    debs=$(find D -name \*.deb | wc -l)
95*7304104dSAndroid Build Coastguard Worker    wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
96*7304104dSAndroid Build Coastguard Worker    ddebs=$(find D -name \*.ddeb | wc -l)
97*7304104dSAndroid Build Coastguard Worker    wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
98*7304104dSAndroid Build Coastguard Worker
99*7304104dSAndroid Build Coastguard Worker    # ubuntu
100*7304104dSAndroid Build Coastguard Worker    archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
101*7304104dSAndroid Build Coastguard Workerfi
102*7304104dSAndroid Build Coastguard Worker
103*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
104*7304104dSAndroid Build Coastguard Worker
105*7304104dSAndroid Build Coastguard Worker# send a request to stress XFF and User-Agent federation relay;
106*7304104dSAndroid Build Coastguard Worker# we'll grep for the two patterns in vlog$PORT1
107*7304104dSAndroid Build Coastguard Workercurl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
108*7304104dSAndroid Build Coastguard Worker
109*7304104dSAndroid Build Coastguard Workergrep UA:TESTCURL vlog$PORT1
110*7304104dSAndroid Build Coastguard Workergrep XFF:TESTXFF vlog$PORT1
111*7304104dSAndroid Build Coastguard Worker
112*7304104dSAndroid Build Coastguard Worker# confirm that first server can't resolve symlinked info in L/ but second can
113*7304104dSAndroid Build Coastguard WorkerBUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
114*7304104dSAndroid Build Coastguard Worker         -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
115*7304104dSAndroid Build Coastguard Workerfile L/foo
116*7304104dSAndroid Build Coastguard Workerfile -L L/foo
117*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
118*7304104dSAndroid Build Coastguard Workerrm -rf $DEBUGINFOD_CACHE_PATH
119*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
120*7304104dSAndroid Build Coastguard Workerrm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
121*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
122*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
123*7304104dSAndroid Build Coastguard Worker
124*7304104dSAndroid Build Coastguard Worker# test again with scheme free url
125*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS=127.0.0.1:$PORT1
126*7304104dSAndroid Build Coastguard Workerrm -rf $DEBUGINFOD_CACHE_PATH
127*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
128*7304104dSAndroid Build Coastguard Workerrm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
129*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS=127.0.0.1:$PORT2
130*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
131*7304104dSAndroid Build Coastguard Worker# test parallel queries in client
132*7304104dSAndroid Build Coastguard Workerrm -rf $DEBUGINFOD_CACHE_PATH
133*7304104dSAndroid Build Coastguard Workerexport DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
134*7304104dSAndroid Build Coastguard Worker
135*7304104dSAndroid Build Coastguard Workertestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
136*7304104dSAndroid Build Coastguard Worker
137*7304104dSAndroid Build Coastguard Worker# And generate a few errors into the second debuginfod's logs, for analysis just below
138*7304104dSAndroid Build Coastguard Workercurl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
139*7304104dSAndroid Build Coastguard Workercurl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
140*7304104dSAndroid Build Coastguard Worker# NB: this error is used to seed the 404 failure for the survive-404 tests
141*7304104dSAndroid Build Coastguard Worker
142*7304104dSAndroid Build Coastguard Worker# Confirm bad artifact types are rejected without leaving trace
143*7304104dSAndroid Build Coastguard Workercurl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true
144*7304104dSAndroid Build Coastguard Worker(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false
145*7304104dSAndroid Build Coastguard Worker
146*7304104dSAndroid Build Coastguard Worker# Confirm that reused curl connections survive 404 errors.
147*7304104dSAndroid Build Coastguard Worker# The rm's force an uncached fetch (in both servers and client cache)
148*7304104dSAndroid Build Coastguard Workerrm -f .client_cache*/$BUILDID/debuginfo
149*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
150*7304104dSAndroid Build Coastguard Workerrm -f .client_cache*/$BUILDID/debuginfo
151*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
152*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
153*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
154*7304104dSAndroid Build Coastguard Workerrm -f .client_cache*/$BUILDID/debuginfo
155*7304104dSAndroid Build Coastguard Workertestrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
156*7304104dSAndroid Build Coastguard Worker# Trigger a flood of requests against the same archive content file.
157*7304104dSAndroid Build Coastguard Worker# Use a file that hasn't been previously extracted in to make it
158*7304104dSAndroid Build Coastguard Worker# likely that even this test debuginfod will experience concurrency
159*7304104dSAndroid Build Coastguard Worker# and impose some "after-you" delays.
160*7304104dSAndroid Build Coastguard Workermaxreq=$[$(nproc) * 4]
161*7304104dSAndroid Build Coastguard Workermaxreq=$(( $maxreq > 64 ? 64 : $maxreq ))
162*7304104dSAndroid Build Coastguard Worker(for i in `seq $maxreq`; do
163*7304104dSAndroid Build Coastguard Worker    curl -s http://127.0.0.1:$PORT1/buildid/87c08d12c78174f1082b7c888b3238219b0eb265/executable >/dev/null &
164*7304104dSAndroid Build Coastguard Worker done;
165*7304104dSAndroid Build Coastguard Worker wait)
166*7304104dSAndroid Build Coastguard Workercurl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_after_you.*'
167*7304104dSAndroid Build Coastguard Worker# If we could guarantee some minimum number of seconds of CPU time, we
168*7304104dSAndroid Build Coastguard Worker# could assert that the after_you metrics show some nonzero amount of
169*7304104dSAndroid Build Coastguard Worker# waiting.  A few hundred ms is typical on this developer's workstation.
170*7304104dSAndroid Build Coastguard Worker
171*7304104dSAndroid Build Coastguard Worker########################################################################
172*7304104dSAndroid Build Coastguard Worker# Trigger some some random activity, then trigger a clean shutdown.
173*7304104dSAndroid Build Coastguard Worker# We used to try to corrupt the database while the debuginfod server
174*7304104dSAndroid Build Coastguard Worker# was running and check it detected errors, but that was unreliably
175*7304104dSAndroid Build Coastguard Worker# and slightly dangerous since part of the database was already mapped
176*7304104dSAndroid Build Coastguard Worker# into memory.
177*7304104dSAndroid Build Coastguard Workerkill -USR1 $PID1
178*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_total{role="traverse"}' 2
179*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_pending{role="scan"}' 0
180*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_busy{role="scan"}' 0
181*7304104dSAndroid Build Coastguard Workerkill -USR2 $PID1
182*7304104dSAndroid Build Coastguard Workerwait_ready $PORT1 'thread_work_total{role="groom"}' 2
183*7304104dSAndroid Build Coastguard Workercurl -s http://127.0.0.1:$PORT1/buildid/beefbeefbeefd00dd00d/debuginfo > /dev/null || true
184*7304104dSAndroid Build Coastguard Worker
185*7304104dSAndroid Build Coastguard Workerkill -INT $PID1 $PID2
186*7304104dSAndroid Build Coastguard Workerwait $PID1 $PID2
187*7304104dSAndroid Build Coastguard WorkerPID1=0
188*7304104dSAndroid Build Coastguard WorkerPID2=0
189*7304104dSAndroid Build Coastguard Worker
190*7304104dSAndroid Build Coastguard Worker# Run the tests again without the servers running. The target file should
191*7304104dSAndroid Build Coastguard Worker# be found in the cache.
192*7304104dSAndroid Build Coastguard Worker
193*7304104dSAndroid Build Coastguard Workertempfiles .debuginfod_*
194*7304104dSAndroid Build Coastguard Worker
195*7304104dSAndroid Build Coastguard Workertestrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
196*7304104dSAndroid Build Coastguard Worker
197*7304104dSAndroid Build Coastguard Worker# check out the debuginfod logs for the new style status lines
198*7304104dSAndroid Build Coastguard Workercat vlog$PORT2
199*7304104dSAndroid Build Coastguard Workergrep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog$PORT2
200*7304104dSAndroid Build Coastguard Workergrep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog$PORT2
201*7304104dSAndroid Build Coastguard Workergrep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog$PORT2
202*7304104dSAndroid Build Coastguard Workergrep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog$PORT2
203*7304104dSAndroid Build Coastguard Worker
204*7304104dSAndroid Build Coastguard Workerexit 0
205