xref: /aosp_15_r20/external/elfutils/tests/run-debuginfod-negative-cache.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
24DB=${PWD}/.debuginfod_tmp.sqlite
25tempfiles $DB
26export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
27# This variable is essential and ensures no time-race for claiming ports occurs
28# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
29base=8000
30get_ports
31env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
32    -t0 -g0 -v ${PWD} > vlog$PORT1 2>&1 &
33PID1=$!
34tempfiles vlog$PORT1
35errfiles vlog$PORT1
36# Server must become ready
37wait_ready $PORT1 'ready' 1
38export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
39
40# Check thread comm names
41ps -q $PID1 -e -L -o '%p %c %a' | grep groom
42ps -q $PID1 -e -L -o '%p %c %a' | grep scan
43ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
44
45########################################################################
46# PR25628
47rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
48
49# The query is designed to fail, while the empty file should be created.
50testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
51if [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
52  echo "could not find cache in $DEBUGINFOD_CACHE_PATH"
53  err
54fi
55
56if [ `stat -c "%s" $DEBUGINFOD_CACHE_PATH/01234567/debuginfo` != 0 ]; then
57  echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is not empty"
58  err
59fi
60
61bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
62testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
63bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
64if [ "$bytecount_before" != "$bytecount_after" ]; then
65  echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} has changed."
66  err
67fi
68
69# set cache_miss_s to 0 and sleep 1 to make the mtime expire.
70echo 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s
71sleep 1
72bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
73testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
74bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
75if [ "$bytecount_before" == "$bytecount_after" ]; then
76  echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} should be incremented."
77  err
78fi
79
80kill $PID1
81wait $PID1
82PID1=0
83exit 0
84