rtld: properly handle root directory in load path (bug 30435)
[platform/upstream/glibc.git] / elf / tst-ldconfig-p.sh
1 #!/bin/sh
2 # Test that ldconfig -p prints something useful.
3 # Copyright (C) 2023 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
19
20 # Check that the newly built ldconfig -p can dump the system
21 # /etc/ld.so.cache file.  This should always work even if the ABIs are
22 # not compatible, except in a cross-endian build (that presumably
23 # involves emulation when running ldconfig).
24
25 common_objpfx=$1
26 sysconfdir=$2
27 test_wrapper_env=$3
28 run_program_env=$4
29
30 if ! test -r "${sysconfdir}/ld.so.cache"; then
31     echo "warning: ${sysconfdir}/ld.so.cache does not exist, test skipped"
32     exit 77
33 fi
34
35 testout="${common_objpfx}elf/tst-ldconfig-p.out"
36 # Truncate file.
37 : > "$testout"
38
39 ${test_wrapper_env} \
40 ${run_program_env} \
41 ${common_objpfx}elf/ldconfig -p \
42   $testroot/lib >>"$testout" 2>>"$testout"
43 status=$?
44 echo "info: ldconfig exit status: $status" >>"$testout"
45
46 errors=0
47 case $status in
48     (0)
49         if head -n 1 "$testout" | \
50                 grep -q "libs found in cache \`${sysconfdir}/ld.so.cache'\$" ; then
51             echo "info: initial string found" >>"$testout"
52         else
53             echo "error: initial string not found" >>"$testout"
54             errors=1
55         fi
56         if grep -q "^   libc\.so\..* => " "$testout"; then
57             echo "info: libc.so.* string found" >>"$testout"
58         else
59             echo "error: libc.so.* string not found" >>"$testout"
60             errors=1
61         fi
62         ;;
63     (1)
64         if head -n 1 "$testout" | \
65                 grep -q ": Cache file has wrong endianness\.$" ; then
66             echo "info: cache file has wrong endianess" >> "$testout"
67         else
68             echo "error: unexpected ldconfig error message" >> "$testout"
69             errors=1
70         fi
71         ;;
72     (*)
73         echo "error: unexpected exit status" >> "$testout"
74         errors=1
75         ;;
76 esac
77
78 exit $errors