Skip to content

Commit 6bb8e98

Browse files
committed
Update initrd smoke test for async control channel
1 parent 18c23dd commit 6bb8e98

File tree

2 files changed

+88
-14
lines changed

2 files changed

+88
-14
lines changed

.github/workflows/amdsev-initrd-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
zstd \
5050
e2fsprogs \
5151
curl \
52+
socat \
5253
musl-tools \
5354
clang
5455

misc/AMDSEV/test-initrd.sh

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# ==============================================================================
55
#
66
# Runs a focused initrd boot smoke test without requiring the full SEV-SNP
7-
# launch path. Uses plain QEMU (no OVMF/SEV) and validates Katana RPC readiness.
7+
# launch path. Uses plain QEMU (no OVMF/SEV), starts Katana through the
8+
# async control channel, and validates RPC readiness.
89
#
910
# Usage:
1011
# ./test-initrd.sh [OPTIONS]
@@ -35,6 +36,7 @@ TEST_DISK_SIZE="${TEST_DISK_SIZE:-1G}"
3536
TEMP_DIR="$(mktemp -d /tmp/katana-amdsev-initrd-test.XXXXXX)"
3637
SERIAL_LOG="${TEMP_DIR}/serial.log"
3738
DISK_IMG="${TEMP_DIR}/test-disk.img"
39+
CONTROL_SOCKET="${TEMP_DIR}/katana-control.sock"
3840
QEMU_PID=""
3941

4042
usage() {
@@ -68,6 +70,80 @@ require_tool() {
6870
command -v "$tool" >/dev/null 2>&1 || die "Required tool not found: $tool"
6971
}
7072

73+
print_serial_output() {
74+
if [ -f "$SERIAL_LOG" ]; then
75+
echo "=== Serial output ===" >&2
76+
tail -n 200 "$SERIAL_LOG" >&2 || true
77+
fi
78+
}
79+
80+
assert_qemu_running() {
81+
local message="$1"
82+
if ! kill -0 "$QEMU_PID" 2>/dev/null; then
83+
warn "QEMU exited unexpectedly"
84+
print_serial_output
85+
die "$message"
86+
fi
87+
}
88+
89+
send_control_command() {
90+
local cmd="$1"
91+
printf '%s\n' "$cmd" | socat -T 5 - UNIX-CONNECT:"$CONTROL_SOCKET" 2>/dev/null | head -n 1 | tr -d '\r'
92+
}
93+
94+
wait_for_control_channel() {
95+
local response=""
96+
97+
for ((elapsed = 1; elapsed <= BOOT_TIMEOUT; elapsed++)); do
98+
assert_qemu_running "Boot smoke test failed"
99+
100+
if [ -S "$CONTROL_SOCKET" ]; then
101+
response="$(send_control_command status || true)"
102+
case "$response" in
103+
running\ *|stopped\ *)
104+
log "Control channel ready: $response"
105+
return 0
106+
;;
107+
esac
108+
fi
109+
110+
if (( elapsed % 5 == 0 )); then
111+
log "Waiting for control channel... (${elapsed}s/${BOOT_TIMEOUT}s)"
112+
fi
113+
sleep 1
114+
done
115+
116+
warn "Timed out waiting for control channel"
117+
print_serial_output
118+
die "Boot smoke test timed out"
119+
}
120+
121+
start_katana_via_control_channel() {
122+
local start_cmd="start --http.addr,0.0.0.0,--http.port,${VM_RPC_PORT},--tee.provider,sev-snp"
123+
local response=""
124+
125+
for ((elapsed = 1; elapsed <= BOOT_TIMEOUT; elapsed++)); do
126+
assert_qemu_running "Boot smoke test failed"
127+
128+
response="$(send_control_command "$start_cmd" || true)"
129+
case "$response" in
130+
ok\ started\ *|err\ already-running\ *)
131+
log "Katana start acknowledged: $response"
132+
return 0
133+
;;
134+
esac
135+
136+
if (( elapsed % 5 == 0 )); then
137+
log "Waiting for Katana start acknowledgement... (${elapsed}s/${BOOT_TIMEOUT}s)"
138+
fi
139+
sleep 1
140+
done
141+
142+
warn "Timed out waiting for Katana start acknowledgement"
143+
print_serial_output
144+
die "Boot smoke test timed out"
145+
}
146+
71147
cleanup() {
72148
local exit_code=$?
73149

@@ -160,6 +236,7 @@ run_boot_smoke_test() {
160236
require_tool curl
161237
require_tool mkfs.ext4
162238
require_tool truncate
239+
require_tool socat
163240

164241
truncate -s "$TEST_DISK_SIZE" "$DISK_IMG"
165242
mkfs.ext4 -q -F "$DISK_IMG"
@@ -181,7 +258,10 @@ run_boot_smoke_test() {
181258
-serial "file:$SERIAL_LOG" \
182259
-kernel "$KERNEL_FILE" \
183260
-initrd "$INITRD_FILE" \
184-
-append "console=ttyS0 katana.args=--http.addr,0.0.0.0,--http.port,${VM_RPC_PORT},--tee.provider,sev-snp" \
261+
-append "console=ttyS0" \
262+
-device virtio-serial-pci,id=virtio-serial0 \
263+
-chardev "socket,id=katanactl,path=${CONTROL_SOCKET},server=on,wait=off" \
264+
-device virtserialport,chardev=katanactl,name=org.katana.control.0 \
185265
-device virtio-scsi-pci,id=scsi0 \
186266
-drive "file=${DISK_IMG},format=raw,if=none,id=disk0,cache=none" \
187267
-device scsi-hd,drive=disk0,bus=scsi0.0 \
@@ -192,15 +272,11 @@ run_boot_smoke_test() {
192272
QEMU_PID=$!
193273
log "QEMU started with PID $QEMU_PID"
194274

275+
wait_for_control_channel
276+
start_katana_via_control_channel
277+
195278
for ((elapsed = 1; elapsed <= BOOT_TIMEOUT; elapsed++)); do
196-
if ! kill -0 "$QEMU_PID" 2>/dev/null; then
197-
warn "QEMU exited before RPC became ready"
198-
if [ -f "$SERIAL_LOG" ]; then
199-
echo "=== Serial output ===" >&2
200-
tail -n 200 "$SERIAL_LOG" >&2 || true
201-
fi
202-
die "Boot smoke test failed"
203-
fi
279+
assert_qemu_running "Boot smoke test failed"
204280

205281
response="$(curl -s --max-time 2 -X POST \
206282
-H "Content-Type: application/json" \
@@ -220,10 +296,7 @@ run_boot_smoke_test() {
220296

221297
if [ "$ready" -ne 1 ]; then
222298
warn "Timed out waiting for Katana RPC"
223-
if [ -f "$SERIAL_LOG" ]; then
224-
echo "=== Serial output ===" >&2
225-
tail -n 200 "$SERIAL_LOG" >&2 || true
226-
fi
299+
print_serial_output
227300
die "Boot smoke test timed out"
228301
fi
229302

0 commit comments

Comments
 (0)