blob: fa34715e2651e83a4f15f151705ae1139b932f8f (
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
|
#!/bin/sh
set -eu
: "${CPU_LD:?}" "${CPU_RUN:?}"
TMP=${TMPDIR:-/tmp}/libmcpu-tool-inspection-$$
mkdir -p "$TMP/home/.mcpu/etc" "$TMP/root/lib"
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
HOME="$TMP/home"
export HOME
# --sys-root is self-contained, suppresses config files and needs no input.
"$CPU_LD" --sys-root="$TMP/root" --dump-config > "$TMP/ld-sysroot-config.txt"
"$CPU_RUN" --sys-root="$TMP/root" --dump-config > "$TMP/run-sysroot-config.txt"
cmp "$TMP/ld-sysroot-config.txt" "$TMP/run-sysroot-config.txt"
grep '^ runtime root: '"$TMP/root"'$' "$TMP/ld-sysroot-config.txt" >/dev/null
grep '^ configuration: disabled by --sys-root$' "$TMP/ld-sysroot-config.txt" >/dev/null
grep '^MCPU_LD_SYSTEM_LIBRARY_PATH = '"$TMP/root"'/lib;$' "$TMP/ld-sysroot-config.txt" >/dev/null
cat > "$TMP/search.expected" <<EOT
libraries:
$TMP/root/lib
EOT
"$CPU_LD" --sys-root="$TMP/root" --print-search-dirs > "$TMP/ld-search.txt"
"$CPU_RUN" --sys-root="$TMP/root" --print-search-dirs > "$TMP/run-search.txt"
cmp "$TMP/search.expected" "$TMP/ld-search.txt"
cmp "$TMP/search.expected" "$TMP/run-search.txt"
# The effective user configuration is visible and is identical in both tools.
cat > "$HOME/.mcpu/etc/mcpu-ld.conf" <<EOC
MCPU_LD_SYSTEM_LIBRARY_PATH = $TMP/user/lib;
EOC
"$CPU_LD" --dump-config > "$TMP/ld-user-config.txt"
"$CPU_RUN" --dump-config > "$TMP/run-user-config.txt"
cmp "$TMP/ld-user-config.txt" "$TMP/run-user-config.txt"
grep '^ config: '"$HOME/.mcpu/etc/mcpu-ld.conf"' \[read\]$' "$TMP/ld-user-config.txt" >/dev/null
grep '^MCPU_LD_SYSTEM_LIBRARY_PATH = '"$TMP/user/lib"';$' "$TMP/ld-user-config.txt" >/dev/null
cat > "$TMP/user-search.expected" <<EOT
libraries:
$TMP/user/lib
EOT
"$CPU_LD" --print-search-dirs > "$TMP/ld-user-search.txt"
"$CPU_RUN" --print-search-dirs > "$TMP/run-user-search.txt"
cmp "$TMP/user-search.expected" "$TMP/ld-user-search.txt"
cmp "$TMP/user-search.expected" "$TMP/run-user-search.txt"
# Empty effective system path means an empty search list; there is no fallback.
printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = ;' \
> "$HOME/.mcpu/etc/mcpu-ld.conf"
printf '%s\n' 'libraries:' > "$TMP/empty.expected"
"$CPU_LD" --print-search-dirs > "$TMP/ld-empty.txt"
"$CPU_RUN" --print-search-dirs > "$TMP/run-empty.txt"
cmp "$TMP/empty.expected" "$TMP/ld-empty.txt"
cmp "$TMP/empty.expected" "$TMP/run-empty.txt"
# A malformed config breaks normal inspection, but explicit suppression works.
printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = broken' \
> "$HOME/.mcpu/etc/mcpu-ld.conf"
if "$CPU_LD" --dump-config >/dev/null 2>&1; then
echo "mcpu-ld --dump-config unexpectedly accepted malformed configuration" >&2
exit 1
fi
if "$CPU_RUN" --print-search-dirs >/dev/null 2>&1; then
echo "mcpu-run --print-search-dirs unexpectedly accepted malformed configuration" >&2
exit 1
fi
"$CPU_LD" --no-config --dump-config > "$TMP/no-config.txt"
grep '^ configuration: disabled by --no-config$' "$TMP/no-config.txt" >/dev/null
"$CPU_RUN" --sys-root="$TMP/root" --print-search-dirs > /dev/null
# Both public help texts expose the same diagnostic actions.
"$CPU_LD" --help 2>&1 | grep -q -- '--dump-config'
"$CPU_LD" --help 2>&1 | grep -q -- '--print-search-dirs'
"$CPU_RUN" --help 2>&1 | grep -q -- '--dump-config'
"$CPU_RUN" --help 2>&1 | grep -q -- '--print-search-dirs'
exit 0
|