• 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
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# Be patient when run on a busy machine things might take a bit.
41export DEBUGINFOD_TIMEOUT=10
42
43# Check thread comm names
44ps -q $PID1 -e -L -o '%p %c %a' | grep groom
45ps -q $PID1 -e -L -o '%p %c %a' | grep scan
46ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
47
48########################################################################
49# PR25628
50rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
51
52# The query is designed to fail, while the 000-permission file should be created.
53testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
54if [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
55  echo "could not find cache in $DEBUGINFOD_CACHE_PATH"
56  err
57fi
58
59if [ `stat -c "%A" $DEBUGINFOD_CACHE_PATH/01234567/debuginfo` != "----------" ]; then
60  echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is readable"
61  err
62fi
63
64bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
65testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
66bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
67if [ "$bytecount_before" != "$bytecount_after" ]; then
68  echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} has changed."
69  err
70fi
71
72# set cache_miss_s to 0 and sleep 1 to make the mtime expire.
73echo 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s
74sleep 1
75bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
76testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
77bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
78if [ "$bytecount_before" == "$bytecount_after" ]; then
79  echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} should be incremented."
80  err
81fi
82
83kill $PID1
84wait $PID1
85PID1=0
86exit 0
87