|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 3/5] automation: Add the expect script with test case for FVP
On Thu, 7 Dec 2023, Henry Wang wrote:
> To interact with the FVP (for example entering the U-Boot shell
> and transferring the files by TFTP), we need to connect the
> corresponding port by the telnet first. Use an expect script to
> simplify the automation of the whole "interacting with FVP" stuff.
>
> The expect script will firstly detect the IP of the host, then
> connect to the telnet port of the FVP, set the `serverip` and `ipaddr`
> for the TFTP service in the U-Boot shell, and finally boot Xen from
> U-Boot and wait for the expected results by Xen, Dom0 and DomU.
I am not an expert in "expect" but this script looks great
> Signed-off-by: Henry Wang <Henry.Wang@xxxxxxx>
> ---
> .../expect/fvp-base-smoke-dom0-arm64.exp | 73 +++++++++++++++++++
> 1 file changed, 73 insertions(+)
> create mode 100755 automation/scripts/expect/fvp-base-smoke-dom0-arm64.exp
>
> diff --git a/automation/scripts/expect/fvp-base-smoke-dom0-arm64.exp
> b/automation/scripts/expect/fvp-base-smoke-dom0-arm64.exp
> new file mode 100755
> index 0000000000..25d9a5f81c
> --- /dev/null
> +++ b/automation/scripts/expect/fvp-base-smoke-dom0-arm64.exp
> @@ -0,0 +1,73 @@
> +#!/usr/bin/expect
> +
> +set timeout 2000
> +
> +# Command to use to run must be given as first argument
> +# if options are required, quotes must be used:
> +# xxx.exp "cmd opt1 opt2"
> +set runcmd [lindex $argv 0]
> +
> +# Maximum number of line to be printed, this can be used to prevent runs to
> +# go forever on errors when Xen is rebooting
> +set maxline 1000
> +
> +# Configure slow parameters used with send -s
> +# This allows us to slow down console writes to prevent issues with slow
> +# emulators or targets.
> +# Format here is: {NUM TIME} which reads as wait TIME seconds each NUM of
> +# characters, here we send 1 char each 100ms
> +set send_slow {1 .1}
> +
> +proc test_boot {{maxline} {host_ip}} {
> + expect_after {
> + -re "(.*)\r" {
> + if {$maxline != 0} {
> + set maxline [expr {$maxline - 1}]
> + if {$maxline <= 0} {
> + send_user "ERROR-Toomuch!\n"
> + exit 2
> + }
> + }
> + exp_continue
> + }
> + timeout {send_user "ERROR-Timeout!\n"; exit 3}
> + eof {send_user "ERROR-EOF!\n"; exit 4}
> + }
Why do we need this "expect_after" ?
> + # Extract the telnet port numbers from FVP output, because the telnet
> ports
> + # are not guaranteed to be fixed numbers.
> + expect -re {terminal_0: Listening for serial connection on port [0-9]+}
> + set terminal_0 $expect_out(0,string)
> + if {[regexp {port (\d+)} $terminal_0 match port_0]} {
> + puts "terminal_0 port is $port_0"
> + } else {
> + puts "terminal_0 port not found"
> + exit 5
> + }
> +
> + spawn bash -c "telnet localhost $port_0"
> + expect -re "Hit any key to stop autoboot.*"
> + send -s " \r"
> + send -s "setenv serverip $host_ip; setenv ipaddr $host_ip; tftpb
> 0x80200000 boot.scr; source 0x80200000\r"
> +
> + # Initial Xen boot
> + expect -re "\(XEN\).*Freed .* init memory."
> +
> + # Dom0 and DomU
> + expect -re "Domain-0.*"
> + expect -re "BusyBox.*"
> + expect -re "/ #.*"
This is clear, excellent
> +}
> +
> +# Get host IP
> +spawn bash -c "hostname -I | awk '{print \$1}'"
> +expect -re {(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})}
Why d{1,3}?
> +set host_ip $expect_out(0,string)
> +
> +# Start the FVP and run the test
> +spawn bash -c "$runcmd"
> +
> +test_boot 2000 "$host_ip"
> +
> +send_user "\nExecution with SUCCESS\n"
Won't this always return SUCCESS even in case of failure?
> +exit 0
> --
> 2.25.1
>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |