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

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Sep 18 21:29:59 UTC 2017


The necessary parameters for running Python tests on qemu are
tedious to find.

The patch adds examples for u-boot-test-console and
u-boot-test-reset.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
v2
	Include all necessary information to run tests for qemu-x86_defconfig
	in a separate chapter.
---
 test/py/README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/test/py/README.md b/test/py/README.md
index 829c7efbb2..f71f59fdc5 100644
--- a/test/py/README.md
+++ b/test/py/README.md
@@ -252,6 +252,92 @@ https://github.com/swarren/uboot-test-hooks contains some working example hook
 scripts, and may be useful as a reference when implementing hook scripts for
 your platform. These scripts are not considered part of U-Boot itself.
 
+##### Running tests for qemu-x86\_defconfig
+
+We build u-boot.rom with
+
+    export BUILD_ROM=y
+    make mrproper
+    make qemu-x86_defconfig
+    make
+
+We create directory `../u-boot-test` for the script files below and `../tftp`
+for the tftp server.
+
+We copy helloworld.efi to the tftp directory.
+
+    cp lib/efi_loader/helloworld.efi ../tftp.
+
+In the script directory we create:
+
+File `u-boot-test-console` chmod 755
+
+    #!/bin/sh
+    touch /tmp/u-boot-monitor-socket
+    qemu-system-x86_64 -bios u-boot.rom -nographic -netdev \
+      user,id=eth0,tftp=../tftp,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
+      -device e1000,netdev=eth0 -machine pc-i440fx-2.8 \
+      -monitor unix:/tmp/u-boot-monitor-socket,server,nowait
+
+This script is executed when the tests commence. It starts qemu with a network
+and a tftp server enabled. The control console is directed to the Unix socket
+`/tmp/u-boot-monitor-socket`.
+
+File `u-boot-test-flash` chmod 755
+
+    #!/bin/sh
+    echo ... u-boot-test-flash ...
+
+This script serves to initialize the board. Nothing needs to be done here as we
+pass u-boot.rom as a parameter in `u-boot-test-console`.
+
+File `u-boot-test-quit` chmod 755
+
+    #!/bin/sh
+    echo quit | socat - UNIX-CONNECT:/tmp/u-boot-monitor-socket
+
+This script is called when all tests are completed. The `quit` command is
+passed to the qemu control console to terminate the qemu session.
+
+File `u-boot-test-reset` chmod 755
+
+    #!/bin/sh
+    echo QEMU resetting >> a
+    echo system_reset | socat - UNIX-CONNECT:/tmp/u-boot-monitor-socket
+    sleep 1
+    true
+
+This script is called when a board reset is needed. The `system_reset` command
+is passed to the qemu control console to reboot the qemu instance. The `sleep`
+command ensures that the system reset is completed before the Python test script
+continues. The script must return true (0) to signal success.
+
+Empty file `__init__.py`
+
+This file makes Python recognize the directory as a package directory.
+
+File `u_boot_boardenv_qemu_x86.py`
+
+    env__net_dhcp_server = True
+    env__efi_loader_helloworld_file = {
+      "fn": "helloworld.efi",
+      "size": 4298,
+      "crc32": "55d96ef8",
+    }
+
+The parameter `env__net_dhcp_server` enables the network tests. The parameter
+`env__efi_loader_helloworld_file` is needed to make the file `helloworld.efi`
+available which is loaded from the tftp server in `test_efi_loader.py`.
+
+The fields size and crc32 have to be updated to match the actual values. The
+`crc32` command can be used to determine the latter.
+
+We now can run the Python tests with
+
+    export PATH=$(pwd)/../u-boot-test:/usr/bin:/bin
+    export PYTHONPATH=$(pwd)/../u-boot-test
+    ./test/py/test.py --bd=qemu-x86 --build-dir=.
+
 ### Board-type-specific configuration
 
 Each board has a different configuration and behaviour. Many of these
-- 
2.11.0



More information about the U-Boot mailing list