diff --git a/tests/inout/script.expect b/tests/inout/script.expect index 35dd36e..1344ef3 100644 --- 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 index d59c564..5f382e4 100644 --- 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} | tee $out +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} early + +} | tee $out + ''