1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00
Files
incus/test/suites/fdleak.sh
Stéphane Graber 60b0a97720 tests: Standardize indentation
This is the result of: shfmt -w -i 4 -sr -l test/

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2025-07-31 15:15:11 -04:00

53 lines
1.3 KiB
Bash

test_fdleak() {
INCUS_FDLEAK_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${INCUS_FDLEAK_DIR}"
spawn_incus "${INCUS_FDLEAK_DIR}" true
pid=$(cat "${INCUS_FDLEAK_DIR}/incus.pid")
beforefds=$(/bin/ls "/proc/${pid}/fd" | wc -l)
(
set -e
# shellcheck disable=SC2034
INCUS_DIR=${INCUS_FDLEAK_DIR}
ensure_import_testimage
for i in $(seq 5); do
incus init testimage "leaktest${i}"
incus info "leaktest${i}"
incus start "leaktest${i}"
incus exec "leaktest${i}" -- ps -ef
incus stop "leaktest${i}" --force
incus delete "leaktest${i}"
done
incus list
incus query /internal/debug/gc
exit 0
)
# Check for open handles to liblxc lxc.log files.
! find "/proc/${pid}/fd" -ls | grep lxc.log || false
for i in $(seq 20); do
afterfds=$(/bin/ls "/proc/${pid}/fd" | wc -l)
leakedfds=$((afterfds - beforefds))
[ "${leakedfds}" -gt 5 ] || break
sleep 0.5
done
bad=0
# shellcheck disable=SC2015
[ "${leakedfds}" -gt 5 ] && bad=1 || true
if [ ${bad} -eq 1 ]; then
echo "${leakedfds} FDS leaked"
ls "/proc/${pid}/fd" -al
netstat -anp 2>&1 | grep "${pid}/"
false
fi
kill_incus "${INCUS_FDLEAK_DIR}"
}