mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Run the complete test suite in pinned Ubuntu guests so cgroupfs and systemd coverage does not depend on the GitHub runner's hierarchy. Cross-compile static test binaries on the host to keep TCG execution practical. Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
54 lines
1.1 KiB
Bash
Executable File
54 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Stop a cgroup test VM started by boot-cgroup-test-vm.sh.
|
|
|
|
set -euo pipefail
|
|
|
|
readonly STATE_DIR="${1:?usage: stop-cgroup-test-vm.sh STATE_DIR}"
|
|
readonly PID_FILE="${STATE_DIR}/qemu.pid"
|
|
readonly DISK="${STATE_DIR}/root.qcow2"
|
|
|
|
if [[ ! -f "${PID_FILE}" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
pid="$(<"${PID_FILE}")"
|
|
if ! kill -0 "${pid}" 2>/dev/null; then
|
|
rm -f -- "${PID_FILE}"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ ! -r "/proc/${pid}/cmdline" ]]; then
|
|
echo "cannot verify process ${pid} from ${PID_FILE}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cmdline="$(tr '\0' '\n' <"/proc/${pid}/cmdline")"
|
|
if [[ "${cmdline}" != *"${DISK}"* ]]; then
|
|
echo "refusing to stop unrelated process ${pid} from stale ${PID_FILE}" >&2
|
|
rm -f -- "${PID_FILE}"
|
|
exit 0
|
|
fi
|
|
|
|
kill "${pid}"
|
|
|
|
for _ in {1..20}; do
|
|
if ! kill -0 "${pid}" 2>/dev/null; then
|
|
rm -f -- "${PID_FILE}"
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
kill -KILL "${pid}" 2>/dev/null || true
|
|
for _ in {1..20}; do
|
|
if ! kill -0 "${pid}" 2>/dev/null; then
|
|
rm -f -- "${PID_FILE}"
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "QEMU process ${pid} did not stop" >&2
|
|
exit 1
|