summaryrefslogtreecommitdiff
path: root/elf/tst-dl-debug-exclude.sh
blob: 9837ffcea8e0793334396bbc254d06b7e7006b7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# Test for LD_DEBUG category exclusion.
# Copyright (C) 2026 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
#
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <https://www.gnu.org/licenses/>.

# This script verifies the LD_DEBUG category exclusion functionality.
# It checks that:
# 1. Categories can be excluded using the '-' prefix.
# 2. Options are processed sequentially, meaning the last specified
#    option for a category (enable or exclude) takes precedence.

set -e

common_objpfx="$1"
test_wrapper_env="$2"
rtld_prefix="$3"
run_program_env="$4"
test_program="$5"

debug_output="${common_objpfx}elf/tst-dl-debug-exclude.debug"
rm -f "${debug_output}".*

# Run the test program with LD_DEBUG=all,-tls.
# We expect general logs but no TLS logs.
eval "${test_wrapper_env}" LD_DEBUG=all,-tls LD_DEBUG_OUTPUT="${debug_output}" \
    "${rtld_prefix}" "${test_program}"

fail=0

# 1. Check that general logs are present (e.g., file loading)
if ! grep -q 'file=' "${debug_output}".*; then
  echo "FAIL: 'file=' message not found (LD_DEBUG=all failed)"
  fail=1
fi

# 2. Check that TLS logs are NOT present
if grep -q 'tls: ' "${debug_output}".*; then
  echo "FAIL: TLS message found (exclusion of -tls failed)"
  fail=1
fi

rm -f "${debug_output}".*
# 3. Check for LD_DEBUG=all,-tls,tls (ordering verification)
# We expect TLS logs to BE present
eval "${test_wrapper_env}" LD_DEBUG=all,-tls,tls LD_DEBUG_OUTPUT="${debug_output}" \
    "${rtld_prefix}" "${test_program}"

if ! grep -q 'tls: ' "${debug_output}".*; then
  echo "FAIL: TLS message not found (ordering -tls,tls failed)"
  fail=1
fi

rm -f "${debug_output}".*
# 4. Check for LD_DEBUG=tls,-tls
# We expect TLS logs to NOT be present
eval "${test_wrapper_env}" LD_DEBUG=tls,-tls LD_DEBUG_OUTPUT="${debug_output}" \
    "${rtld_prefix}" "${test_program}"

if grep -q 'tls: ' "${debug_output}".*; then
  echo "FAIL: TLS message found (ordering tls,-tls failed)"
  fail=1
fi

if [ $fail -ne 0 ]; then
  echo "Test FAILED"
  cat "${debug_output}".*
  rm -f "${debug_output}".*
  exit 1
fi

echo "Test PASSED"
rm -f "${debug_output}".*
exit 0