]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/tst-rtld-does-not-exist.sh
elf: Add ld.so test with non-existing program name
[thirdparty/glibc.git] / elf / tst-rtld-does-not-exist.sh
1 #!/bin/sh
2 # Check that running ld.so with a non-existing file prints an error.
3 # Copyright (C) 2024 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 export LC_ALL=C
21
22 rtld="$1"
23 tmp_out="$(mktemp)"
24
25 $rtld program-does-not-exist 2>"$tmp_out"
26 status=$?
27 echo "$rtld exit status: $status"
28 echo "output (with expected error):"
29 cat "$tmp_out"
30
31 if test $status -eq 127 \
32 && grep -q "^program-does-not-exist: error while loading shared libraries: program-does-not-exist: cannot open shared object file$" "$tmp_out" \
33 && test "$(wc -l < "$tmp_out")" -eq 1 ; then
34 status=0
35 else
36 status=1
37 fi
38 rm "$tmp_out"
39 exit $status