commit 723ef73d5ada8d5cebbb5b7e8acb1ca3c6cc33bc
parent 3d4e7829292dfadccf38b298294e990a3e35d1b3
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 27 Apr 2024 22:41:30 +0100
inout: test hotplug and coldplug
Diffstat:
2 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/tests/inout/script.expect b/tests/inout/script.expect
@@ -1,16 +1,38 @@
set timeout 10
+set when [lindex $argv 0];
+
+spawn socat -,echo=0,icanon=1 unix-connect:vm/monitor
+set monitor_id $spawn_id
+
+spawn socat unix-connect:vm/console -
+set console_id $spawn_id
+
proc chat {instr outstr} {
expect {
$instr { send $outstr }
timeout { exit 1 }
}
}
-spawn socat -,echo=0,icanon=1 unix-connect:vm/monitor
-set monitor_id $spawn_id
-spawn socat unix-connect:vm/console -
-set console_id $spawn_id
+proc adddevice { } {
+ global monitor_id console_id spawn_id
+ set spawn_id $monitor_id
+
+ chat "QEMU" "device_add usb-storage,bus=xhci.0,drive=usbstick\n"
+ chat "(qemu)" "version\r"
+
+ set spawn_id $console_id
+ expect {
+ "sda: sda1" { }
+ timeout { exit 1 }
+ }
+}
+
+if { $when eq "early" } {
+ adddevice
+}
+
expect "BusyBox"
chat "#" "PS1=RE\\ADY_\\ ; stty -echo \r"
@@ -18,19 +40,13 @@ chat "READY_" "tail -f /run/uncaught-logs/current & \rs6-rc -b -a list\r"
chat "mount" "\r"
-set spawn_id $monitor_id
-chat "QEMU" "device_add usb-storage,bus=xhci.0,drive=usbstick\n"
-chat "(qemu)" "version\r"
-
-set spawn_id $console_id
-
-expect {
- "sda: sda1" { }
- timeout { exit 1 }
+if { $when eq "late" } {
+ adddevice
}
-
send "\r"
+set timeout 20
+
chat "READY_" "sleep 3; grep /srv /proc/mounts && hostname\r"
expect {
diff --git a/tests/inout/test.nix b/tests/inout/test.nix
@@ -23,6 +23,15 @@ dd if=/dev/zero of=./vm/stick.img bs=1M count=38
dd if=./vm/stick.e2fs of=./vm/stick.img bs=512 seek=34 conv=notrunc
parted -s ./vm/stick.img -- mklabel gpt mkpart backup-disk ext2 34s -0M
+{
+
+${img}/run.sh --background ./vm --flag -device --flag usb-ehci,id=xhci --flag -drive --flag if=none,id=usbstick,format=raw,file=$(pwd)/vm/stick.img
+expect ${./script.expect} late
+kill $(cat ./vm/pid)
+
${img}/run.sh --background ./vm --flag -device --flag usb-ehci,id=xhci --flag -drive --flag if=none,id=usbstick,format=raw,file=$(pwd)/vm/stick.img
-expect ${./script.expect} | tee $out
+expect ${./script.expect} early
+
+} | tee $out
+
''