1#!/bin/bash
2#
3# Copyright (C) 2019-2020 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/test-subr.sh  # includes set -e
20
21type curl 2>/dev/null || (echo "need curl"; exit 77)
22type rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77)
23type bzcat 2>/dev/null || (echo "need bzcat"; exit 77)
24bsdtar --version | grep -q zstd && zstd=true || zstd=false
25echo "zstd=$zstd bsdtar=`bsdtar --version`"
26
27# for test case debugging, uncomment:
28#set -x
29#VERBOSE=-vvvv
30
31DB=${PWD}/.debuginfod_tmp.sqlite
32tempfiles $DB
33export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
34
35PID1=0
36PID2=0
37PID3=0
38
39cleanup()
40{
41  if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi
42  if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
43  if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
44
45  rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp*
46  exit_cleanup
47}
48
49# clean up trash if we were aborted early
50trap cleanup 0 1 2 3 5 9 15
51
52# find an unused port number
53while true; do
54    PORT1=`expr '(' $RANDOM % 1000 ')' + 9000`
55    ss -atn | fgrep ":$PORT1" || break
56done
57
58# We want to run debuginfod in the background.  We also want to start
59# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff
60# that the testrun alias sets.  But: we if we just use
61#    testrun .../debuginfod
62# it runs in a subshell, with different pid, so not helpful.
63#
64# So we gather the LD_LIBRARY_PATH with this cunning trick:
65ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'`
66
67mkdir F R L D Z
68# not tempfiles F R L D Z - they are directories which we clean up manually
69ln -s ${abs_builddir}/dwfllines L/foo   # any program not used elsewhere in this test
70
71wait_ready()
72{
73  port=$1;
74  what=$2;
75  value=$3;
76  timeout=20;
77
78  echo "Wait $timeout seconds on $port for metric $what to change to $value"
79  while [ $timeout -gt 0 ]; do
80    mvalue="$(curl -s http://127.0.0.1:$port/metrics \
81              | grep "$what" | awk '{print $NF}')"
82    if [ -z "$mvalue" ]; then mvalue=0; fi
83      echo "metric $what: $mvalue"
84      if [ "$mvalue" -eq "$value" ]; then
85        break;
86    fi
87    sleep 0.5;
88    ((timeout--));
89  done;
90
91  if [ $timeout -eq 0 ]; then
92      echo "metric $what never changed to $value on port $port"
93      curl -s http://127.0.0.1:$port/metrics
94    exit 1;
95  fi
96}
97
98env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -R -d $DB -p $PORT1 -t0 -g0 --fdcache-fds 1 --fdcache-mbs 2 -Z .tar.xz -Z .tar.bz2=bzcat -v R F Z L > vlog4 2>&1 &
99PID1=$!
100tempfiles vlog4
101# Server must become ready
102wait_ready $PORT1 'ready' 1
103export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
104
105# Be patient when run on a busy machine things might take a bit.
106export DEBUGINFOD_TIMEOUT=10
107
108# We use -t0 and -g0 here to turn off time-based scanning & grooming.
109# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
110
111########################################################################
112
113# Compile a simple program, strip its debuginfo and save the build-id.
114# Also move the debuginfo into another directory so that elfutils
115# cannot find it without debuginfod.
116echo "int main() { return 0; }" > ${PWD}/prog.c
117tempfiles prog.c
118# Create a subdirectory to confound source path names
119mkdir foobar
120gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
121testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
122BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
123          -a prog | grep 'Build ID' | cut -d ' ' -f 7`
124
125wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
126mv prog F
127mv prog.debug F
128kill -USR1 $PID1
129# Wait till both files are in the index.
130wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
131wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
132wait_ready $PORT1 'thread_busy{role="scan"}' 0
133
134########################################################################
135
136# Test whether elfutils, via the debuginfod client library dlopen hooks,
137# is able to fetch debuginfo from the local debuginfod.
138testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
139
140########################################################################
141
142# Test whether debuginfod-find is able to fetch those files.
143rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
144filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
145cmp $filename F/prog.debug
146
147filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
148cmp $filename F/prog
149
150# raw source filename
151filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
152cmp $filename  ${PWD}/prog.c
153
154# and also the canonicalized one
155filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
156cmp $filename  ${PWD}/prog.c
157
158
159########################################################################
160
161# Test whether the cache default locations are correct
162
163mkdir tmphome
164
165# $HOME/.cache should be created.
166testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
167if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
168  echo "could not find cache in $PWD/tmphome/.cache"
169  exit 1
170fi
171
172# $HOME/.cache should be found.
173testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
174if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
175  echo "could not find cache in $PWD/tmphome/.cache"
176  exit 1
177fi
178
179# $XDG_CACHE_HOME should take priority over $HOME.cache.
180testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
181if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
182  echo "could not find cache in $PWD/tmpxdg/"
183  exit 1
184fi
185
186# A cache at the old default location ($HOME/.debuginfod_client_cache) should take
187# priority over $HOME/.cache, $XDG_CACHE_HOME.
188cp -r $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache
189
190# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
191mkdir tmphome/.debuginfod_client_cache/deadbeef
192echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo
193filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef`
194cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo
195
196# $DEBUGINFO_CACHE_PATH should take priority over all else.
197testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
198if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then
199  echo "could not find cache in $PWD/tmpcache/"
200  exit 1
201fi
202
203########################################################################
204
205# Add artifacts to the search paths and test whether debuginfod finds them while already running.
206
207# Build another, non-stripped binary
208echo "int main() { return 0; }" > ${PWD}/prog2.c
209tempfiles prog2.c
210gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
211BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
212          -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
213
214mv prog2 F
215kill -USR1 $PID1
216# Now there should be 3 files in the index
217wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
218wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
219wait_ready $PORT1 'thread_busy{role="scan"}' 0
220
221# Rerun same tests for the prog2 binary
222filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
223cmp $filename F/prog2
224cat vlog
225grep -q Progress vlog
226grep -q Downloaded.from vlog
227tempfiles vlog
228filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
229cmp $filename F/prog2
230cat vlog2
231grep -q 'Downloading.*http' vlog2
232tempfiles vlog2
233filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
234cmp $filename ${PWD}/prog2.c
235
236cp -rvp ${abs_srcdir}/debuginfod-rpms R
237if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
238    rm -vrf R/debuginfod-rpms/fedora31
239fi
240
241cp -rvp ${abs_srcdir}/debuginfod-tars Z
242kill -USR1 $PID1
243# All rpms need to be in the index
244rpms=$(find R -name \*rpm | wc -l)
245wait_ready $PORT1 'scanned_total{source=".rpm archive"}' $rpms
246txz=$(find Z -name \*tar.xz | wc -l)
247wait_ready $PORT1 'scanned_total{source=".tar.xz archive"}' $txz
248tb2=$(find Z -name \*tar.bz2 | wc -l)
249wait_ready $PORT1 'scanned_total{source=".tar.bz2 archive"}' $tb2
250
251kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
252# Expect all source files found in the rpms (they are all called hello.c :)
253# We will need to extract all rpms (in their own directory) and could all
254# sources referenced in the .debug files.
255mkdir extracted
256cd extracted
257subdir=0;
258newrpms=$(find ../R -name \*\.rpm)
259for i in $newrpms; do
260    subdir=$[$subdir+1];
261    mkdir $subdir;
262    cd $subdir;
263    ls -lah ../$i
264    rpm2cpio ../$i | cpio -ivd;
265    cd ..;
266done
267sourcefiles=$(find -name \*\\.debug \
268	      | env LD_LIBRARY_PATH=$ldpath xargs \
269		${abs_top_builddir}/src/readelf --debug-dump=decodedline \
270	      | grep mtime: | wc --lines)
271cd ..
272rm -rf extracted
273
274wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
275
276# Run a bank of queries against the debuginfod-rpms / debuginfod-debs test cases
277
278archive_test() {
279    __BUILDID=$1
280    __SOURCEPATH=$2
281    __SOURCESHA1=$3
282
283    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
284    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
285             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
286    test $__BUILDID = $buildid
287    # check that timestamps are plausible - older than the near-present (tmpdir mtime)
288    test $filename -ot `pwd`
289
290    # run again to assure that fdcache is being enjoyed
291    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
292    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
293             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
294    test $__BUILDID = $buildid
295    test $filename -ot `pwd`
296
297    filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID`
298    buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
299             -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
300    test $__BUILDID = $buildid
301    test $filename -ot `pwd`
302
303    if test "x$__SOURCEPATH" != "x"; then
304        filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH`
305        hash=`cat $filename | sha1sum | awk '{print $1}'`
306        test $__SOURCESHA1 = $hash
307        test $filename -ot `pwd`
308    fi
309}
310
311
312# common source file sha1
313SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
314# fedora31
315if [ $zstd = true ]; then
316    # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
317    # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
318    archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
319    archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
320fi
321# fedora30
322archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
323archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
324# rhel7
325archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
326archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
327# rhel6
328archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
329archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
330# arch
331archive_test cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb /usr/src/debug/hello.c 7a1334e086b97e5f124003a6cfb3ed792d10cdf4
332
333RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir, for a later test
334
335
336########################################################################
337
338# Drop some of the artifacts, run a groom cycle; confirm that
339# debuginfod has forgotten them, but remembers others
340
341rm -r R/debuginfod-rpms/rhel6/*
342kill -USR2 $PID1  # groom cycle
343# Expect 3 rpms to be deleted by the groom
344# 1 groom already took place at/soon-after startup, so -USR2 makes 2
345wait_ready $PORT1 'thread_work_total{role="groom"}' 2
346wait_ready $PORT1 'groom{statistic="file d/e"}' 3
347
348rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
349
350testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
351
352testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2
353
354########################################################################
355
356# Federation mode
357
358# find another unused port
359while true; do
360    PORT2=`expr '(' $RANDOM % 1000 ')' + 9000`
361    ss -atn | fgrep ":$PORT2" || break
362done
363
364export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
365mkdir -p $DEBUGINFOD_CACHE_PATH
366# NB: inherits the DEBUGINFOD_URLS to the first server
367# NB: run in -L symlink-following mode for the L subdir
368env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d ${DB}_2 -p $PORT2 -L L D > vlog3 2>&1 &
369PID2=$!
370tempfiles vlog3
371tempfiles ${DB}_2
372wait_ready $PORT2 'ready' 1
373wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
374wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
375wait_ready $PORT2 'thread_busy{role="scan"}' 0
376
377# have clients contact the new server
378export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
379
380if type bsdtar 2>/dev/null; then
381    # copy in the deb files
382    cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
383    kill -USR1 $PID2
384    # All debs need to be in the index
385    debs=$(find D -name \*.deb | wc -l)
386    wait_ready $PORT2 'scanned_total{source=".deb archive"}' `expr $debs`
387    ddebs=$(find D -name \*.ddeb | wc -l)
388    wait_ready $PORT2 'scanned_total{source=".ddeb archive"}' `expr $ddebs`
389
390    # ubuntu
391    archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
392fi
393
394rm -rf $DEBUGINFOD_CACHE_PATH
395testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
396
397# send a request to stress XFF and User-Agent federation relay;
398# we'll grep for the two patterns in vlog4
399curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
400
401grep UA:TESTCURL vlog4
402grep XFF:TESTXFF vlog4
403
404
405# confirm that first server can't resolve symlinked info in L/ but second can
406BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
407         -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
408file L/foo
409file -L L/foo
410export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
411rm -rf $DEBUGINFOD_CACHE_PATH
412testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
413export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
414testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
415
416
417# test parallel queries in client
418export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
419mkdir -p $DEBUGINFOD_CACHE_PATH
420export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
421
422testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
423
424########################################################################
425
426# Fetch some metrics
427curl -s http://127.0.0.1:$PORT1/badapi
428curl -s http://127.0.0.1:$PORT1/metrics
429curl -s http://127.0.0.1:$PORT2/metrics
430curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*error'
431curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*fdcache'
432curl -s http://127.0.0.1:$PORT2/metrics | grep -q 'http_responses_total.*result.*upstream'
433curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_count'
434curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_sum'
435curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count'
436curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_sum'
437
438# And generate a few errors into the second debuginfod's logs, for analysis just below
439curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
440curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
441
442
443########################################################################
444
445# Run the tests again without the servers running. The target file should
446# be found in the cache.
447
448kill -INT $PID1 $PID2
449wait $PID1 $PID2
450PID1=0
451PID2=0
452tempfiles .debuginfod_*
453
454testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
455
456# check out the debuginfod logs for the new style status lines
457# cat vlog3
458grep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog3
459grep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog3
460grep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog3
461grep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog3
462
463########################################################################
464
465# Add some files to the cache that do not fit its naming format.
466# They should survive cache cleaning.
467mkdir $DEBUGINFOD_CACHE_PATH/malformed
468touch $DEBUGINFOD_CACHE_PATH/malformed0
469touch $DEBUGINFOD_CACHE_PATH/malformed/malformed1
470
471# Trigger a cache clean and run the tests again. The clients should be unable to
472# find the target.
473echo 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s
474echo 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s
475
476testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
477
478testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 && false || true
479
480if [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \
481    || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then
482  echo "unrelated files did not survive cache cleaning"
483  exit 1
484fi
485
486# Test debuginfod without a path list; reuse $PORT1
487env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F &
488PID3=$!
489wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
490wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
491wait_ready $PORT1 'thread_busy{role="scan"}' 0
492kill -int $PID3
493wait $PID3
494PID3=0
495
496########################################################################
497# Test fetching a file using file:// . No debuginfod server needs to be run for
498# this test.
499local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
500mkdir -p ${local_dir}
501echo "int main() { return 0; }" > ${local_dir}/main.c
502
503# first test that is doesn't work, when no DEBUGINFOD_URLS is set
504DEBUGINFOD_URLS=""
505testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
506
507# Now test is with proper DEBUGINFOD_URLS
508DEBUGINFOD_URLS="file://${PWD}/mocktree/"
509filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
510cmp $filename ${local_dir}/main.c
511
512exit 0
513