Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines: test: ldd-check: cleanups #39042

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 65 additions & 21 deletions pipelines/test/ldd-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pipeline:
runs: |
set +x
set -f
info() { echo "INFO[ldd-check]:" "$@"; }
error() { echo "ERROR[ldd-check]:" "$@"; exit 1; }
fail() { echo "FAIL[ldd-check]:" "$@"; fails=$((fails+1)); }
pass() { echo "PASS[ldd-check]:" "$@"; passes=$((passes+1)); }
Expand All @@ -38,51 +39,94 @@ pipeline:
passes=0
files="${{inputs.files}}"
packages="${{inputs.packages}}"
verbose="${{inputs.verbose}}"
case "$verbose" in
VERBOSE="${{inputs.verbose}}"
case "$VERBOSE" in
true|false) :;;
*) error "verbose must be 'true' or 'false'. found '$verbose'";;
*) error "VERBOSE must be 'true' or 'false'. found '$VERBOSE'";;
esac
[ -n "${files}${packages}" ] || error "No files or packages specified"

export LANG=C
test_file() {
outf="$tmpd/out"
[ -e "$f" ] || { fail "$f: does not exist"; continue; }
[ -f "$f" ] || { fail "$f: not a file"; continue; }
ldd "$f" > "$outf" || { fail "$f: ldd exited $?"; continue; }

vmsg() {
[ "$VERBOSE" = "false" ] || echo "$@"
}

failormsg() {
local cond="$1" msg="$2"
case "$cond" in
true|false) :;;
*) error "cond=$cond - expected true or false";;
esac
[ "$cond" = "true" ] && fail "$msg"
vmsg "$msg"
}

check_output() {
local file="$1" outf="$2" errf="$3"
missing=$(awk \
'$0 ~ /=> not found/ { miss = miss " " $1; }; END { printf("%s\n", miss); }' \
"$outf") || error "$f: parsing with awk failed $?";
if [ "$verbose" = "true" ]; then
'$0 ~ /=> not found/ { miss = miss " " $1; };
END { printf("%s\n", miss); }' "$outf") ||
error "$f: parsing with awk failed $?";
if [ "$VERBOSE" = "true" ]; then
echo "> $ ldd $f"
sed 's,^,> ,' "$outf"
fi
[ -z "$missing" ] && { pass "$f"; continue; }
fail "$f: missing ${missing# }"
[ -z "$missing" ] || fail "$f: missing ${missing# }"
pass "$f"
}

check_file() {
local f="$1" insist_dyn="$2" rc="0"
local outf="$tmpd/ldd.stdout" errf="$tmpd/ldd.sterr"
if [ ! -e "$f" ]; then
failormsg "$insist_dyn" "$f: did not exist"
return 0
fi
if [ ! -f "$f" ]; then
failormsg "$insist_dyn" "$f: is not a file"
return 0
fi

ldd "$f" >$outf 2>$errf || rc=$?

if [ $rc -eq 1 ]; then
if grep -q 'not a dynamic executable' "$errf"; then
failormsg "$insist_dyn" "$f: not a dynamic exectuable"
return 0
fi
echo "> $ ldd $f"
sed 's,^,> ,' "$outf" "$errf"
error "$f: ldd exited $rc"
elif [ $rc -ne 0 ]; then
echo "> $ ldd $f"
sed 's,^,> ,' "$outf" "$errf"
error "$1: unexpected exit code $rc"
fi

check_output "$f" "$outf" "$errf"
}

test_files_in() {
local f=""
echo "[ldd-check] Testing binaries in package $pkg"
apk info -eq "$pkg" > /dev/null || \
{ fail "Package $pkg is not installed"; continue; }
apk info -eq "$pkg" > /dev/null ||
error "Package $pkg is not installed";
apk info -Lq "$pkg" > "$tmpd/$pkg.list"
while read f; do
[ -n "$f" ] || continue
f="/$f"
[ -f "$f" ] || continue
ldd "$f" > /dev/null 2>&1 || continue
test_file "$f"
check_file "/$f" false
done < "$tmpd/$pkg.list"
}

set -- $files
for f in "$@"; do
test_file "$f"
check_file "$f" true
done
set -- $packages
for pkg in "$@"; do
test_files_in "$pkg"
done
echo "tested $((passes+fails)) files with ldd. $passes passes. $fails fails."
info "tested $((passes+fails)) files with ldd." \
"$passes passes. $fails fails."
exit $fails
Loading