Files
xen/automation/scripts/console.exp
T
Marek Marczykowski-Górecki 1e12cbd6af CI: fix waiting for final test message
Expect normally discards initial part of its buffer after matching the
patter, before looking for the next one. If both PASSED and LOG_MSG
happen to be in the buffer at the same time, depending on their order,
only one will be matched and the waiting for the other will timeout.
Example expect -d output of this happening (parts eclipsed for brevity):

    expect: does "\r\r\r\nWelcome to Alpine Linux 3.18\r\r\r\n...\r\r\r\r\n(domU) + echo 'pci test passed'\r\r\r\r\n(domU) pci test passed\r\r\r\r..." (spawn_id exp4) match regular expression "pci test passed"? Gate "pci test passed"? gate=yes re=yes
    ...
    Gate keeper glob pattern for '\nWelcome to Alpine Linux' is '
    Welcome to Alpine Linux'. Activating booster.
    expect: does "'\r\r\r\r\n(domU) pci test passed\r\r\r\r\n(domU)  [ ok ]\r\r\r\r\n(domU)  [ ok ]\r\r\r\r\n(domU) \r\r\r\r\r\n(domU) domU Welcome to Alpine Linux 3.18\r\r\r\r\n(domU) \rKernel 6.6.56 on an x86_64 (/dev/hvc0)\r\r\r\r\n(domU) \r\r\r\r\r\n" (spawn_id exp4) match regular expression "\nWelcome to Alpine Linux"? Gate "\nWelcome to Alpine Linux"? gate=no

Fix this by using -notransfer flag to keep matched part in the buffer.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Andrew Cooper <andrew.cooper3@citix.com>
2025-04-11 22:07:57 +01:00

69 lines
1.7 KiB
Plaintext
Executable File

#!/usr/bin/env expect
#
# Variables used by this script:
# - TEST_TIMEOUT: timeout between each *_MSG match
# - TEST_TIMEOUT_OVERRIDE: when set, overrides TEST_TIMEOUT
# - TEST_LOG: save console log to this file
# - TEST_CMD: commands that prints test system console output to stdout - in
# qemu tests that's usually qemu itself (with -serial stdio), in hardware
# tests that's a command to read serial console
# - UBOOT_CMD (optional): command to enter at u-boot prompt
# - BOOT_MSG (optional): initial Xen message to wait for (aka sign-of-life)
# - LOG_MSG (optional): final console message to wait for
# - PASSED: message to look for to consider test a success; if LOG_MSG is set,
# both LOG_MSG and PASSED must appear (in any order) for test to succeed
if {[info exists env(TEST_TIMEOUT_OVERRIDE)]} {
set timeout $env(TEST_TIMEOUT_OVERRIDE)
} elseif {[info exists env(TEST_TIMEOUT)]} {
set timeout $env(TEST_TIMEOUT)
} else {
set timeout 1500
}
log_file -a $env(TEST_LOG)
match_max 10000
eval spawn $env(TEST_CMD)
expect_after {
-re "(.*)\r" {
exp_continue -continue_timer
}
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(BOOT_MSG)]} {
expect -re "$env(BOOT_MSG)"
}
if {[info exists env(LOG_MSG)]} {
expect {
-re "$env(PASSED)" {
expect -notransfer -re "$env(LOG_MSG)"
exit 0
}
-re "$env(LOG_MSG)" {
expect -notransfer -re "$env(PASSED)"
exit 0
}
}
}
expect {
-re "$env(PASSED)" {
exit 0
}
}
expect eof