This commit is contained in:
@@ -295,8 +295,63 @@ EOF
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
test_systemd() {
|
||||
echo "=== Testing systemd as init ==="
|
||||
|
||||
work="$(mktemp -d)"
|
||||
img="slim-test-systemd"
|
||||
|
||||
cat > "$work/slim-test.service" <<'SVC'
|
||||
[Unit]
|
||||
Description=slim systemd test
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/sh -c "echo SYSTEMD_TEST_OK > /dev/console; sleep 1; systemctl poweroff"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
SVC
|
||||
|
||||
cat > "$work/Containerfile" <<EOF
|
||||
FROM archlinux:latest
|
||||
COPY slim-test.service /etc/systemd/system/slim-test.service
|
||||
RUN mkdir -p /etc/systemd/system/multi-user.target.wants && \
|
||||
ln -sf /etc/systemd/system/slim-test.service \
|
||||
/etc/systemd/system/multi-user.target.wants/slim-test.service
|
||||
CMD ["/sbin/init"]
|
||||
EOF
|
||||
|
||||
echo "-- Building container image with systemd..."
|
||||
if ! podman build -t "$img" "$work" >/dev/null 2>&1; then
|
||||
report fail "systemd as init (podman build failed)"
|
||||
rm -rf "$work"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "-- Building slim VM..."
|
||||
if ! "$SLIM_BIN" build qcow2 "$img" >/dev/null 2>&1; then
|
||||
report fail "systemd as init (slim build failed)"
|
||||
cleanup "$img" "$img"
|
||||
rm -rf "$work"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "-- Booting VM (systemd as PID 1)..."
|
||||
output=$(timeout "$TIMEOUT" "$SLIM_BIN" run "$img" 2>&1 || true)
|
||||
check_output "$output" "SYSTEMD_TEST_OK" "systemd boots and runs service"
|
||||
check_output "$output" "reboot: Power down" "systemd shuts down cleanly"
|
||||
|
||||
cleanup "$img" "$img"
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
echo "Building slim..."
|
||||
cargo build 2>&1
|
||||
cargo build --release -p slim-init --target x86_64-unknown-linux-musl 2>&1
|
||||
cp target/x86_64-unknown-linux-musl/release/slim-init \
|
||||
"${XDG_DATA_HOME:-$HOME/.local/share}/slim-rs/slim-init"
|
||||
|
||||
test_distro "alpine" "alpine:latest" ""
|
||||
test_distro "archlinux" "archlinux:latest" "RUN pacman -Sy --noconfirm iproute2 wget; pacman -Sc --noconfirm"
|
||||
@@ -307,6 +362,8 @@ test_mount
|
||||
|
||||
test_service
|
||||
|
||||
test_systemd
|
||||
|
||||
echo ""
|
||||
echo "=== Results: $pass passed, $fail failed ==="
|
||||
[ "$fail" -eq 0 ]
|
||||
|
||||
Reference in New Issue
Block a user