[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.17] automation: use expect to run QEMU



commit 1db6ce307b2ded04aa1f97cada1512c4395f7b51
Author:     Stefano Stabellini <stefano.stabellini@xxxxxxx>
AuthorDate: Wed Aug 14 17:57:54 2024 -0700
Commit:     Stefano Stabellini <stefano.stabellini@xxxxxxx>
CommitDate: Fri Aug 16 16:03:31 2024 -0700

    automation: use expect to run QEMU
    
    Use expect to invoke QEMU so that we can terminate the test as soon as
    we get the right string in the output instead of waiting until the
    final timeout.
    
    For timeout, instead of an hardcoding the value, use a Gitlab CI
    variable "QEMU_TIMEOUT" that can be changed depending on the latest
    status of the Gitlab CI runners.
    
    [This backport skips the PPC and RISC scripts as well as the XTF
    scripts on x86]
    
    Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
    Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
    master commit: c36efb7fcea6ef9f31a20e60ec79ed3ae293feee
    master date: 2024-08-09 23:59:20 -0700
---
 automation/scripts/qemu-alpine-arm64.sh  | 15 ++++++-----
 automation/scripts/qemu-alpine-x86_64.sh | 13 ++++-----
 automation/scripts/qemu-key.exp          | 45 ++++++++++++++++++++++++++++++++
 automation/scripts/qemu-smoke-arm32.sh   | 12 ++++-----
 automation/scripts/qemu-smoke-arm64.sh   | 15 ++++++-----
 5 files changed, 74 insertions(+), 26 deletions(-)

diff --git a/automation/scripts/qemu-alpine-arm64.sh 
b/automation/scripts/qemu-alpine-arm64.sh
index e191de3765..c76155edf9 100755
--- a/automation/scripts/qemu-alpine-arm64.sh
+++ b/automation/scripts/qemu-alpine-arm64.sh
@@ -95,9 +95,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d 
binaries/ -c binaries/conf
 # Run the test
 rm -f smoke.serial
 set +e
-echo "  virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \
-timeout -k 1 720 \
-./binaries/qemu-system-aarch64 \
+export QEMU_CMD="./binaries/qemu-system-aarch64 \
     -machine virtualization=true \
     -cpu cortex-a57 -machine type=virt \
     -m 2048 -monitor none -serial stdio \
@@ -105,8 +103,11 @@ timeout -k 1 720 \
     -no-reboot \
     -device virtio-net-pci,netdev=n0 \
     -netdev user,id=n0,tftp=binaries \
-    -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& tee smoke.serial
+    -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin"
+
+export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 
0x40000000"
+export QEMU_LOG="smoke.serial"
+export LOG_MSG="Domain-0"
+export PASSED="BusyBox"
 
-set -e
-(grep -q "Domain-0" smoke.serial && grep -q "BusyBox" smoke.serial) || exit 1
-exit 0
+./automation/scripts/qemu-key.exp
diff --git a/automation/scripts/qemu-alpine-x86_64.sh 
b/automation/scripts/qemu-alpine-x86_64.sh
index 8c8d0b0cd7..17eae877cf 100755
--- a/automation/scripts/qemu-alpine-x86_64.sh
+++ b/automation/scripts/qemu-alpine-x86_64.sh
@@ -77,15 +77,16 @@ EOF
 # Run the test
 rm -f smoke.serial
 set +e
-timeout -k 1 720 \
-qemu-system-x86_64 \
+export QEMU_CMD="qemu-system-x86_64 \
     -cpu qemu64,+svm \
     -m 2G -smp 2 \
     -monitor none -serial stdio \
     -nographic \
     -device virtio-net-pci,netdev=n0 \
-    -netdev user,id=n0,tftp=binaries,bootfile=/pxelinux.0 |& tee smoke.serial
+    -netdev user,id=n0,tftp=binaries,bootfile=/pxelinux.0"
 
-set -e
-(grep -q "Domain-0" smoke.serial && grep -q "BusyBox" smoke.serial) || exit 1
-exit 0
+export QEMU_LOG="smoke.serial"
+export LOG_MSG="Domain-0"
+export PASSED="BusyBox"
+
+./automation/scripts/qemu-key.exp
diff --git a/automation/scripts/qemu-key.exp b/automation/scripts/qemu-key.exp
new file mode 100755
index 0000000000..35eb903a31
--- /dev/null
+++ b/automation/scripts/qemu-key.exp
@@ -0,0 +1,45 @@
+#!/usr/bin/expect -f
+
+set timeout $env(QEMU_TIMEOUT)
+
+log_file -a $env(QEMU_LOG)
+
+match_max 10000
+
+eval spawn $env(QEMU_CMD)
+
+expect_after {
+    -re "(.*)\r" {
+        exp_continue
+    }
+    timeout {send_error "ERROR-Timeout!\n"; exit 1}
+    eof {send_error "ERROR-EOF!\n"; exit 1}
+}
+
+if {[info exists env(UBOOT_CMD)]} {
+    expect "=>"
+
+    send "$env(UBOOT_CMD)\r"
+}
+
+if {[info exists env(LOG_MSG)]} {
+    expect {
+        "$env(PASSED)" {
+            expect "$env(LOG_MSG)"
+            exit 0
+        }
+        "$env(LOG_MSG)" {
+            expect "$env(PASSED)"
+            exit 0
+        }
+    }
+}
+
+expect {
+    "$env(PASSED)" {
+        exit 0
+    }
+}
+
+expect eof
+
diff --git a/automation/scripts/qemu-smoke-arm32.sh 
b/automation/scripts/qemu-smoke-arm32.sh
index 5da9533bcf..20ea90936f 100755
--- a/automation/scripts/qemu-smoke-arm32.sh
+++ b/automation/scripts/qemu-smoke-arm32.sh
@@ -55,8 +55,7 @@ dtc -I dts -O dtb virt.dts > virt.dtb
 
 rm -f smoke.serial
 set +e
-timeout -k 1 240 \
-./qemu-system-arm \
+export QEMU_CMD="./qemu-system-arm \
    -machine virt \
    -machine virtualization=true \
    -smp 4 \
@@ -68,8 +67,9 @@ timeout -k 1 240 \
    -no-reboot \
    -kernel ./xen \
    -device loader,file=./vmlinuz,addr=0x1000000 \
-   -device loader,file=./initrd.gz,addr=0x3200000 |& tee smoke.serial
+   -device loader,file=./initrd.gz,addr=0x3200000"
+
+export QEMU_LOG="smoke.serial"
+export PASSED="/ #"
 
-set -e
-(grep -q "^/ #" smoke.serial) || exit 1
-exit 0
+../automation/scripts/qemu-key.exp
diff --git a/automation/scripts/qemu-smoke-arm64.sh 
b/automation/scripts/qemu-smoke-arm64.sh
index 2b59346fdc..a9b0c22a3a 100755
--- a/automation/scripts/qemu-smoke-arm64.sh
+++ b/automation/scripts/qemu-smoke-arm64.sh
@@ -144,9 +144,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d 
binaries/ -c binaries/conf
 # Run the test
 rm -f smoke.serial
 set +e
-echo "  virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \
-timeout -k 1 240 \
-./binaries/qemu-system-aarch64 \
+export QEMU_CMD="./binaries/qemu-system-aarch64 \
     -machine virtualization=true \
     -cpu cortex-a57 -machine type=virt \
     -m 2048 -monitor none -serial stdio \
@@ -154,8 +152,11 @@ timeout -k 1 240 \
     -no-reboot \
     -device virtio-net-pci,netdev=n0 \
     -netdev user,id=n0,tftp=binaries \
-    -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& tee smoke.serial
+    -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin"
+
+export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 
0x40000000"
+export QEMU_LOG="smoke.serial"
+export LOG_MSG="Welcome to Alpine Linux"
+export PASSED="${passed}"
 
-set -e
-(grep -q "^Welcome to Alpine Linux" smoke.serial && grep -q "${passed}" 
smoke.serial) || exit 1
-exit 0
+./automation/scripts/qemu-key.exp
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.17



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.