From 9c572f661fbd4cb7e9becc0bb19b25d589e14c76 Mon Sep 17 00:00:00 2001 From: pengshanyu Date: Mon, 23 Mar 2026 14:46:38 +0800 Subject: [PATCH] improve cleanup Signed-off-by: pengshanyu --- tests/ffi/common/prepare.sh | 25 ++++++++++++++++++++----- tests/ffi/memory/test.sh | 4 +++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/ffi/common/prepare.sh b/tests/ffi/common/prepare.sh index 6079feb9..562d4ff8 100644 --- a/tests/ffi/common/prepare.sh +++ b/tests/ffi/common/prepare.sh @@ -34,18 +34,33 @@ prepare_test() { disk_cleanup() { # Clean large size files created by tests inside qm part - remove_file=$(find /var/qm -size +2G) - exec_cmd "rm -rf $remove_file" + remove_file=$(find /var/qm -size +2G) + if [ -n "${remove_file}" ]; then + exec_cmd "rm -rf ${remove_file}" + fi # Remove all containers in qm (don't care about stop in clean-up) - exec_cmd "podman exec -it qm /usr/bin/podman rm -af" + exec_cmd "podman exec qm /usr/bin/podman rm -af" if test -d "${DROP_IN_DIR}"; then exec_cmd "rm -rf ${DROP_IN_DIR}" fi exec_cmd "systemctl daemon-reload" exec_cmd "systemctl restart qm" # Clean large size files created by tests inside host part - remove_file=$(find /root -size +1G) - exec_cmd "rm -f $remove_file" + remove_file=$(find /root -size +1G) + if [ -n "${remove_file}" ]; then + exec_cmd "rm -f ${remove_file}" + fi +} + +# Remove all containers in host, then disk_cleanup. +# e.g. trap 'cleanup_host_then_qm ffi-asil' EXIT +cleanup_host_then_qm() { + local container_name + for container_name in "$@"; do + [ -n "${container_name}" ] || continue + podman rm -f "${container_name}" >/dev/null 2>&1 || true + done + disk_cleanup } reload_config() { diff --git a/tests/ffi/memory/test.sh b/tests/ffi/memory/test.sh index 105701c8..dd86104c 100644 --- a/tests/ffi/memory/test.sh +++ b/tests/ffi/memory/test.sh @@ -4,7 +4,9 @@ . ../common/prepare.sh -trap disk_cleanup EXIT +# Remove ffi-asil to free host RAM, then do disk_cleanup +trap 'cleanup_host_then_qm ffi-asil' EXIT + prepare_test exec_cmd "podman run -d --rm --replace -d --name ffi-asil \