Files
cgroups-rs/ci/qemu/build-static-test-binaries.sh
Xuewei Niu c2abd0229d ci: Test cgroup v1 and v2 in QEMU
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>
2026-07-28 06:23:16 -05:00

60 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Build portable test executables on the GitHub runner. The executables are
# copied into the cgroup VM and run there, avoiding a Rust build under QEMU
# software emulation.
set -euo pipefail
readonly TARGET="x86_64-unknown-linux-musl"
readonly OUTPUT_DIR="${1:?usage: build-static-test-binaries.sh OUTPUT_DIR}"
if [[ -e "${OUTPUT_DIR}" ]]; then
echo "output directory already exists: ${OUTPUT_DIR}" >&2
exit 1
fi
mkdir -p "${OUTPUT_DIR}"
messages="$(mktemp)"
executables="$(mktemp)"
manifest="$(mktemp)"
trap 'rm -f "${messages}" "${executables}" "${manifest}"' EXIT
cargo test \
--all-features \
--target "${TARGET}" \
--no-run \
--message-format=json >"${messages}"
jq -r '
select(
.reason == "compiler-artifact"
and .profile.test == true
and .executable != null
)
| .executable
' "${messages}" | sort -u >"${executables}"
if [[ ! -s "${executables}" ]]; then
echo "cargo did not produce any test executables" >&2
exit 1
fi
while IFS= read -r executable; do
destination="${OUTPUT_DIR}/$(basename "${executable}")"
cp "${executable}" "${destination}"
strip "${destination}"
if readelf -l "${destination}" | grep -q "Requesting program interpreter"; then
echo "test executable is dynamically linked: ${destination}" >&2
exit 1
fi
done <"${executables}"
find "${OUTPUT_DIR}" -maxdepth 1 -type f -printf '%f\n' | sort >"${manifest}"
mv "${manifest}" "${OUTPUT_DIR}/manifest"
echo "Built $(wc -l <"${OUTPUT_DIR}/manifest") static test executables:"
sed 's/^/ /' "${OUTPUT_DIR}/manifest"