[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


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Fri, 8 Dec 2023 02:03:38 +0000
  • Accept-language: zh-CN, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4yDdnjYY8SRcq+Lgzn0MCbOIasGqyqgSv4HG62GMTAo=; b=FjSoVxUedpxX0hnqq23GfU1BZkU4mgwfIVBYCnk+ndkvEtZH5JLTR5ic5TT6Ty2q6rG3UgCB0Uku417s0jlfNoo3TjOPoVOuLeRvklhbZPO19bKfCjxh+3dflwymSUNs7vP/2jjpIkdbvM1ZMaVmAgKWksbGyx/6Ioya94YEQS61VADYbyZhDJXhw40WrDEmg/QLnKpLsaAi36JcdkiWNeeN7nSH+NMNFMgbb+YPnUtEI891pYNRtid9o/dWsJYqTP8PhdyHVpk1/6jZNob6fkYMFUPy5Lo7w8mfHGxvzR0BIG+UiFywvF6npCgp+hnKAhRebQmyiyBwgavS6cl+Bg==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4yDdnjYY8SRcq+Lgzn0MCbOIasGqyqgSv4HG62GMTAo=; b=cDH0PpVkpmrdHJQxYPu+N1MYsnJuBBcouW8ItjRzeN13+U+PscGcqiWX4enhQtIjEmneUhzencn5evg2Nr5O+hsHaNV5ftwcCWzVTbxY3S+newNo40AXLcWKLBVx0YkGROc5vZLhz+PViKJLsLxzmrbJM/sR97pG3TKq0TxEUzq41HtWB4c7dL60MwrHXu6LTJeGz6YDEn+bn8zxHrFAiAVdrnVp91azIHFdLImN1/XqmfvIy6VHkBC/vjb91o/isrvyX7aTxeM527ERU3fsNQJRqD4PKmEqVTiBIkiDeyrKOOMfJ2YxXqab+7f8eQ8dxXKZMZ+SCr1FrkX+R9kLeg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=bFosfbhr+ViiyPW2ku3XkOR9TydiZyS5bdS2ymnoouZaaSULtIJlM+sFZ6LTJwEgI5FzE6K2SXFHWVGpgi1rbTowlQUbmecl3x8SSzjRYyZaImYDd8SpiOMxhMmqF5uZJMoggrPwVjfQOgs3pY5VRd79hMLPrVWQtS5dWdqKrHJf4/OcPHtxkcpw3fUgEdQHXgdorlcDPRxOeSKzlnHb0XpLZExwGE4osf6MUDMi+v+8o8+F4YCLjqPgFx8rOgHg1UA8X/maMQf0ngblScStmlSb1r5mHPeB7Jhwgbl1hhd08HEayjiAtD0q+C8Ay6a6hF6PnJUEjyLpyHEA113lOQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kLA/jpEsF7PpS+Gj9iz95fSFB8UDQo0Zo4WR2GbmSeeRlaJliQ5jQnIbHbkfeqauNgxhrOQk1iXzSOWvj5TGOZJhM5ZSfr+ktW9hzenjhoIsP2zwIblZMdy0PuPDs5j4sjdkQvmnqbSlojQJMVyar3JoHjIFBWn2zOlIVyWfPrdZIiEyPoXRDVI9sxrYJxW1HE3fAnPvzu+WfexwguMLktBu4myAePP75oSUozSpM3TkRmlTlv3Y6Btmy1M5JYr0uTXJ4qqQpmMIabovEPDQtHZCJxEs6tlIiYeWExdtyN4X1D7u0rX/n0f9WQ9Zj3CxuNZIPcNPKWbFSp4pCHnRfw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>
  • Delivery-date: Fri, 08 Dec 2023 02:04:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHaKRTRSAbthQjm9k2SM6wWsGqHurCenEEAgAAHDIA=
  • Thread-topic: [PATCH 3/5] automation: Add the expect script with test case for FVP

Hi Stefano,

> On Dec 8, 2023, at 09:38, Stefano Stabellini <sstabellini@xxxxxxxxxx> wrote:
> 
> 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
>> 
>> +
>> +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" ?

It is basically for the error handling. Either there is too many characters 
triggered
by some misconfiguration of Xen/Kernel leading to Xen/Kernel constantly reboots,
or the code stuck somehow, we have a way to stop the script instead of waiting 
in
the infinity loop.

>> +    # 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}?

I think that is because the IP pattern, we at least have one digit and at most 
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?

IMHO, if things fails, we have various exit code (1-5) for each failure case. 
For example,
if the FVP port somehow cannot be found, we exit with error code 5. This will 
basically lead
us to the only case where the failure is caused by the script fails to wait for 
the expected
string/regexp, and this case we have the timeout failure triggered by my 
above-mentioned
expect_after block.

Kind regards,
Henry

>> +exit 0
>> -- 
>> 2.25.1
>> 




 


Rackspace

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