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.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
This commit is contained in:
Stefano Stabellini committed 2024-08-13 16:05:05 -07:00
1 parent 35c64c3dce
commit c36efb7fce
10 files changed
+112 -71

No files matched your search

+7 -9
View File
@@ -77,18 +77,16 @@ EOF
# Run the test # Run the test
rm -f smoke.serial rm -f smoke.serial
set +e set +e
timeout -k 1 720 \ export QEMU_CMD="qemu-system-x86_64 \
qemu-system-x86_64 \
-cpu qemu64,+svm \ -cpu qemu64,+svm \
-m 2G -smp 2 \ -m 2G -smp 2 \
-monitor none -serial stdio \ -monitor none -serial stdio \
-nographic \ -nographic \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=binaries,bootfile=/pxelinux.0 |& \ -netdev user,id=n0,tftp=binaries,bootfile=/pxelinux.0"
# Remove carriage returns from the stdout output, as gitlab
# interface chokes on them
tee smoke.serial | sed 's/\r//'
set -e export QEMU_LOG="smoke.serial"
(grep -q "Domain-0" smoke.serial && grep -q "BusyBox" smoke.serial) || exit 1 export LOG_MSG="Domain-0"
exit 0 export PASSED="BusyBox"
./automation/scripts/qemu-key.exp
+45
View File
@@ -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
+8 -8
View File
@@ -78,9 +78,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d . -c config
rm -f ${serial_log} rm -f ${serial_log}
set +e set +e
echo " virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \ export QEMU_CMD="./qemu-system-arm \
timeout -k 1 720 \
./qemu-system-arm \
-machine virt \ -machine virt \
-machine virtualization=true \ -machine virtualization=true \
-smp 4 \ -smp 4 \
@@ -91,9 +89,11 @@ timeout -k 1 720 \
-no-reboot \ -no-reboot \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=./ \ -netdev user,id=n0,tftp=./ \
-bios /usr/lib/u-boot/qemu_arm/u-boot.bin |& \ -bios /usr/lib/u-boot/qemu_arm/u-boot.bin"
tee ${serial_log} | sed 's/\r//'
set -e export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
(grep -q "Domain-0" ${serial_log} && grep -q "^/ #" ${serial_log}) || exit 1 export QEMU_LOG="${serial_log}"
exit 0 export LOG_MSG="Domain-0"
export PASSED="/ #"
../automation/scripts/qemu-key.exp
+8 -8
View File
@@ -94,9 +94,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d binaries/ -c binaries/conf
# Run the test # Run the test
rm -f smoke.serial rm -f smoke.serial
set +e set +e
echo " virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \ export QEMU_CMD="./binaries/qemu-system-aarch64 \
timeout -k 1 720 \
./binaries/qemu-system-aarch64 \
-machine virtualization=true \ -machine virtualization=true \
-cpu cortex-a57 -machine type=virt \ -cpu cortex-a57 -machine type=virt \
-m 2048 -monitor none -serial stdio \ -m 2048 -monitor none -serial stdio \
@@ -104,9 +102,11 @@ timeout -k 1 720 \
-no-reboot \ -no-reboot \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=binaries \ -netdev user,id=n0,tftp=binaries \
-bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& \ -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin"
tee smoke.serial | sed 's/\r//'
set -e export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
(grep -q "Domain-0" smoke.serial && grep -q "BusyBox" smoke.serial) || exit 1 export QEMU_LOG="smoke.serial"
exit 0 export LOG_MSG="Domain-0"
export PASSED="BusyBox"
./automation/scripts/qemu-key.exp
@@ -5,7 +5,7 @@ set -ex
test_variant=$1 test_variant=$1
# Prompt to grep for to check if dom0 booted successfully # Prompt to grep for to check if dom0 booted successfully
dom0_prompt="^/ #" dom0_prompt="/ #"
serial_log="$(pwd)/smoke.serial" serial_log="$(pwd)/smoke.serial"
@@ -131,9 +131,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d . -c config
# Run the test # Run the test
rm -f ${serial_log} rm -f ${serial_log}
set +e set +e
echo " virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \ export QEMU_CMD="./qemu-system-arm \
timeout -k 1 240 \
./qemu-system-arm \
-machine virt \ -machine virt \
-machine virtualization=true \ -machine virtualization=true \
-smp 4 \ -smp 4 \
@@ -144,9 +142,11 @@ timeout -k 1 240 \
-no-reboot \ -no-reboot \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=./ \ -netdev user,id=n0,tftp=./ \
-bios /usr/lib/u-boot/qemu_arm/u-boot.bin |& \ -bios /usr/lib/u-boot/qemu_arm/u-boot.bin"
tee ${serial_log} | sed 's/\r//'
set -e export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
(grep -q "${dom0_prompt}" ${serial_log} && grep -q "${passed}" ${serial_log}) || exit 1 export QEMU_LOG="${serial_log}"
exit 0 export LOG_MSG="${dom0_prompt}"
export PASSED="${passed}"
../automation/scripts/qemu-key.exp
@@ -205,9 +205,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d binaries/ -c binaries/conf
# Run the test # Run the test
rm -f smoke.serial rm -f smoke.serial
set +e set +e
echo " virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \ export QEMU_CMD="./binaries/qemu-system-aarch64 \
timeout -k 1 240 \
./binaries/qemu-system-aarch64 \
-machine virtualization=true \ -machine virtualization=true \
-cpu cortex-a57 -machine type=virt,gic-version=$gic_version \ -cpu cortex-a57 -machine type=virt,gic-version=$gic_version \
-m 2048 -monitor none -serial stdio \ -m 2048 -monitor none -serial stdio \
@@ -215,9 +213,11 @@ timeout -k 1 240 \
-no-reboot \ -no-reboot \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=binaries \ -netdev user,id=n0,tftp=binaries \
-bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& \ -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin"
tee smoke.serial | sed 's/\r//'
set -e export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
(grep -q "^Welcome to Alpine Linux" smoke.serial && grep -q "${passed}" smoke.serial) || exit 1 export QEMU_LOG="smoke.serial"
exit 0 export LOG_MSG="Welcome to Alpine Linux"
export PASSED="${passed}"
./automation/scripts/qemu-key.exp
+6 -7
View File
@@ -11,8 +11,7 @@ machine=$1
rm -f ${serial_log} rm -f ${serial_log}
set +e set +e
timeout -k 1 20 \ export QEMU_CMD="qemu-system-ppc64 \
qemu-system-ppc64 \
-bios skiboot.lid \ -bios skiboot.lid \
-M $machine \ -M $machine \
-m 2g \ -m 2g \
@@ -21,9 +20,9 @@ qemu-system-ppc64 \
-monitor none \ -monitor none \
-nographic \ -nographic \
-serial stdio \ -serial stdio \
-kernel binaries/xen \ -kernel binaries/xen"
|& tee ${serial_log} | sed 's/\r//'
set -e export QEMU_LOG="${serial_log}"
(grep -q "Hello, ppc64le!" ${serial_log}) || exit 1 export PASSED="Hello, ppc64le!"
exit 0
./automation/scripts/qemu-key.exp
+6 -7
View File
@@ -6,15 +6,14 @@ set -ex
rm -f smoke.serial rm -f smoke.serial
set +e set +e
timeout -k 1 2 \ export QEMU_CMD="qemu-system-riscv64 \
qemu-system-riscv64 \
-M virt \ -M virt \
-smp 1 \ -smp 1 \
-nographic \ -nographic \
-m 2g \ -m 2g \
-kernel binaries/xen \ -kernel binaries/xen"
|& tee smoke.serial | sed 's/\r//'
set -e export QEMU_LOG="smoke.serial"
(grep -q "All set up" smoke.serial) || exit 1 export PASSED="All set up"
exit 0
./automation/scripts/qemu-key.exp
+8 -7
View File
@@ -16,11 +16,12 @@ esac
rm -f smoke.serial rm -f smoke.serial
set +e set +e
timeout -k 1 30 \ export QEMU_CMD="qemu-system-x86_64 -nographic -kernel binaries/xen \
qemu-system-x86_64 -nographic -kernel binaries/xen \
-initrd xtf/tests/example/$k \ -initrd xtf/tests/example/$k \
-append "loglvl=all console=com1 noreboot console_timestamps=boot $extra" \ -append \"loglvl=all console=com1 noreboot console_timestamps=boot $extra\" \
-m 512 -monitor none -serial file:smoke.serial -m 512 -monitor none -serial stdio"
set -e
grep -q 'Test result: SUCCESS' smoke.serial || exit 1 export QEMU_LOG="smoke.serial"
exit 0 export PASSED="Test result: SUCCESS"
./automation/scripts/qemu-key.exp
@@ -51,9 +51,7 @@ bash imagebuilder/scripts/uboot-script-gen -t tftp -d binaries/ -c binaries/conf
# Run the test # Run the test
rm -f smoke.serial rm -f smoke.serial
set +e set +e
echo " virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \ export QEMU_CMD="./binaries/qemu-system-aarch64 \
timeout -k 1 120 \
./binaries/qemu-system-aarch64 \
-machine virtualization=true \ -machine virtualization=true \
-cpu cortex-a57 -machine type=virt \ -cpu cortex-a57 -machine type=virt \
-m 2048 -monitor none -serial stdio \ -m 2048 -monitor none -serial stdio \
@@ -61,9 +59,10 @@ timeout -k 1 120 \
-no-reboot \ -no-reboot \
-device virtio-net-pci,netdev=n0 \ -device virtio-net-pci,netdev=n0 \
-netdev user,id=n0,tftp=binaries \ -netdev user,id=n0,tftp=binaries \
-bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& \ -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin"
tee smoke.serial | sed 's/\r//'
set -e export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
(grep -q "${passed}" smoke.serial) || exit 1 export QEMU_LOG="smoke.serial"
exit 0 export PASSED="${passed}"
./automation/scripts/qemu-key.exp
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.