[U-Boot] [PATCH 1/1] test/py: provide example scripts for integrating qemu

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Sep 18 19:55:31 UTC 2017


On 09/18/2017 08:27 PM, Stephen Warren wrote:
> On 09/17/2017 01:32 PM, Heinrich Schuchardt wrote:
>> The necessary parameters for running Python tests on qemu are
>> tediouus to find.
> 
> Nit: tedious
> 
> Let's wrap the commit description to 72-74 characters; it's rather
> narrow right now.
> 
>>
>> The patch adds examples for u-boot-test-console and
>> u-boot-test-reset.
> 
>> diff --git a/test/py/README.md b/test/py/README.md
>> index 829c7efbb2..f3ad10df5a 100644
>> --- a/test/py/README.md
>> +++ b/test/py/README.md
>> @@ -197,6 +197,23 @@ simulator includes a virtual reset button! If
>> not, you can launch the
>>   simulator from `u-boot-test-reset` instead, while arranging for this
>> console
>>   process to always communicate with the current simulator instance.
> 
> Rather that adding these examples into a section that details one of the
> individual hook scripts, let's create a new section "Simple qemu
> example" and put it right before or after the existing "Examples" section.
Ok

> 
>> +With qemu you can use the parameter -monitor to connect the control
>> console to a
>> +Unix socket, e.g.
> 
> Let's state what filename the following example should be saved to;
> u-boot-test-console.

sure

> 
>> +    #!/bin/sh
>> +    touch /tmp/u-boot-monitor-socket
>> +    qemu-system-x86_64 -bios build-qemu-x86/u-boot.rom -nographic
>> -netdev \
>> +   
>> user,id=eth0,tftp=../tftp,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
> 
> Let's indent the continuation lines so it's more obvious this is a
> multi-line command:
> 
> asdfsd fsjkl fsfj lssfjdasdfsjl \
>     asdfsd fsjkl fsfj lssfjdasdfsjl \
>     asdfsd fsjkl fsfj lssfjdasdfsjl \
> 
> I think this (and the other) script should "exec" the commands to avoid
> leaving the shell instance around.

Is this really needed? It just adds complexity.
You cannot execute anything in the lines after exec,
e.g. deleting the socket file.

> 
> This example seems to enable networking support in qemu, and a TFTP
> server. I believe you'll need to provide an example Python board
> configuration so that test/py knows to enable the network tests.

tftp is used for testing bootefi hello

Empty file
__init__.py

u_boot_boardenv_qemu_x86.py
env__net_dhcp_server = True
env__efi_loader_helloworld_file = {
        "fn": "helloworld.efi",
        "size": 4298,
        "crc32": "55d96ef8",
}

This is another file needed:

u-boot-test-quit
#!/bin/sh
echo quit | socat - UNIX-CONNECT:/tmp/u-boot-monitor-socket

The following script comes in handy to create the .py file:

#!/bin/bash
echo env__efi_loader_$(basename $1 | sed 's/\./_/g') = \{
echo '    "fn":' $(basename $1)
echo '    "len":' $(stat --printf="%s" $1)
echo '    "crc32":' $(crc32 $1)
echo \}

> 
>> +    -device e1000,netdev=eth0 -machine pc-i440fx-2.8 \
>> +    -monitor unix:/tmp/u-boot-monitor-socket,server,nowait
>> +
>> +In `u-boot-test-reset` call the socat command to send a system reset:
>> +
>> +    #!/bin/sh
>> +    echo system_reset | socat - UNIX-CONNECT:/tmp/u-boot-monitor-socket
>> +    sleep 1
>> +    true
> 
> Why is the sleep needed?

This avoids race conditions.
Qemu will need some milliseconds to actually shut down qemu.
I want to be sure that Python does not execute any command before this
is completed.

> The true command shouldn't have any effect
> given set -e isn't in use.

man dash:
The shell will return the exit status of the last command executed.

If the last command is false running the test suite fails.

> 
> I only see examples for u-boot-test-console and u-boot-test-reset. I
> believe you need to provide a dummy/empty u-boot-test-flash too.
> 
Yes this is what I used:

#!/bin/sh
echo ... u-boot-test-flash ...


More information about the U-Boot mailing list