public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 4/6] tests: Add efi_loader hello world test
Date: Thu, 17 Nov 2016 18:31:05 +0100	[thread overview]
Message-ID: <1479403867-54792-5-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1479403867-54792-1-git-send-email-agraf@suse.de>

Now that we have working network tests and a hello world efi application
built inside our tree, we can automatically test that efi binary running
inside of U-Boot.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 test/py/tests/test_efi_loader.py | 158 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)
 create mode 100644 test/py/tests/test_efi_loader.py

diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
new file mode 100644
index 0000000..1c42653
--- /dev/null
+++ b/test/py/tests/test_efi_loader.py
@@ -0,0 +1,158 @@
+# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+# Copyright (c) 2016, Alexander Graf <agraf@suse.de>
+#
+# based on test_net.py.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+# Test efi loader implementation
+
+import pytest
+import u_boot_utils
+
+"""
+Note: This test relies on boardenv_* containing configuration values to define
+which the network environment available for testing. Without this, the parts
+that rely on network will be automatically skipped.
+
+For example:
+
+# Boolean indicating whether the Ethernet device is attached to USB, and hence
+# USB enumeration needs to be performed prior to network tests.
+# This variable may be omitted if its value is False.
+env__net_uses_usb = False
+
+# Boolean indicating whether the Ethernet device is attached to PCI, and hence
+# PCI enumeration needs to be performed prior to network tests.
+# This variable may be omitted if its value is False.
+env__net_uses_pci = True
+
+# True if a DHCP server is attached to the network, and should be tested.
+# If DHCP testing is not possible or desired, this variable may be omitted or
+# set to False.
+env__net_dhcp_server = True
+
+# A list of environment variables that should be set in order to configure a
+# static IP. If solely relying on DHCP, this variable may be omitted or set to
+# an empty list.
+env__net_static_env_vars = [
+    ("ipaddr", "10.0.0.100"),
+    ("netmask", "255.255.255.0"),
+    ("serverip", "10.0.0.1"),
+]
+
+# Details regarding a file that may be read from a TFTP server. This variable
+# may be omitted or set to None if TFTP testing is not possible or desired.
+env__efi_loader_helloworld_file = {
+    "fn": "lib/efi_loader/helloworld.efi",
+    "size": 5058624,
+    "crc32": "c2244b26",
+}
+"""
+
+net_set_up = False
+
+def test_efi_pre_commands(u_boot_console):
+    """Execute any commands required to enable network hardware.
+
+    These commands are provided by the boardenv_* file; see the comment at the
+    beginning of this file.
+    """
+
+    init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
+    if init_usb:
+        u_boot_console.run_command('usb start')
+
+    init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
+    if init_pci:
+        u_boot_console.run_command('pci enum')
+
+ at pytest.mark.buildconfigspec('cmd_dhcp')
+def test_efi_dhcp(u_boot_console):
+    """Test the dhcp command.
+
+    The boardenv_* file may be used to enable/disable this test; see the
+    comment at the beginning of this file.
+    """
+
+    test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+    if not test_dhcp:
+        pytest.skip('No DHCP server available')
+
+    u_boot_console.run_command('setenv autoload no')
+    output = u_boot_console.run_command('dhcp')
+    assert 'DHCP client bound to address ' in output
+
+    global net_set_up
+    net_set_up = True
+
+ at pytest.mark.buildconfigspec('net')
+def test_efi_setup_static(u_boot_console):
+    """Set up a static IP configuration.
+
+    The configuration is provided by the boardenv_* file; see the comment at
+    the beginning of this file.
+    """
+
+    env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
+    if not env_vars:
+        pytest.skip('No static network configuration is defined')
+
+    for (var, val) in env_vars:
+        u_boot_console.run_command('setenv %s %s' % (var, val))
+
+    global net_set_up
+    net_set_up = True
+
+ at pytest.mark.buildconfigspec('cmd_bootefi_hello')
+def test_efi_helloworld_net(u_boot_console):
+    """Run the helloworld.efi binary via TFTP.
+
+    The helloworld.efi file is downloaded from the TFTP server and gets
+    executed.
+    """
+
+    if not net_set_up:
+        pytest.skip('Network not initialized')
+
+    f = u_boot_console.config.env.get('env__efi_loader_helloworld_file', None)
+    if not f:
+        pytest.skip('No hello world binary specified in environment')
+
+    addr = f.get('addr', None)
+    if not addr:
+        addr = u_boot_utils.find_ram_base(u_boot_console) + (1024 * 1024 * 4)
+
+    fn = f['fn']
+    output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+    expected_text = 'Bytes transferred = '
+    sz = f.get('size', None)
+    if sz:
+        expected_text += '%d' % sz
+    assert expected_text in output
+
+    expected_crc = f.get('crc32', None)
+    if not expected_crc:
+        return
+
+    if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
+        return
+
+    output = u_boot_console.run_command('crc32 %x $filesize' % addr)
+    assert expected_crc in output
+
+    output = u_boot_console.run_command('bootefi %x' % addr)
+    expected_text = 'Hello, world'
+    assert expected_text in output
+
+ at pytest.mark.buildconfigspec('cmd_bootefi_hello')
+def test_efi_helloworld_builtin(u_boot_console):
+    """Run the builtin helloworld.efi binary.
+
+    The helloworld.efi file is included in U-Boot, execute it using the
+    special "bootefi hello" command.
+    """
+
+    output = u_boot_console.run_command('bootefi hello')
+    expected_text = 'Hello, world'
+    assert expected_text in output
-- 
1.8.5.6

  parent reply	other threads:[~2016-11-17 17:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-17 17:31 [U-Boot] [PATCH v2 0/6] efi_laoder: Add travis test coverage Alexander Graf
2016-11-17 17:31 ` [U-Boot] [PATCH v2 1/6] tests: net: Offset downloads to 4MB Alexander Graf
2016-11-19 13:48   ` Simon Glass
2016-11-21 13:54   ` Tom Rini
2016-11-27 14:54   ` [U-Boot] [U-Boot,v2,1/6] " Tom Rini
2016-11-17 17:31 ` [U-Boot] [PATCH v2 2/6] Travis: Expose build dir as variable Alexander Graf
2016-11-21 13:56   ` Tom Rini
2016-11-27 14:54   ` [U-Boot] [U-Boot,v2,2/6] " Tom Rini
2016-11-17 17:31 ` [U-Boot] [PATCH v2 3/6] travis: Add python path for environments Alexander Graf
2016-11-21 13:56   ` Tom Rini
2016-11-27 14:55   ` [U-Boot] [U-Boot, v2, " Tom Rini
2016-11-17 17:31 ` Alexander Graf [this message]
2016-11-19 13:48   ` [U-Boot] [PATCH v2 4/6] tests: Add efi_loader hello world test Simon Glass
2016-11-21 13:57   ` Tom Rini
2016-11-27 14:55   ` [U-Boot] [U-Boot, v2, " Tom Rini
2016-11-17 17:31 ` [U-Boot] [PATCH v2 5/6] efi_loader: Allow to compile helloworld.efi w/o bundling it Alexander Graf
2016-11-17 21:40   ` [U-Boot] [PATCH v3 " Alexander Graf
2016-11-21 13:58     ` Tom Rini
2016-11-27 14:55     ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-11-19 13:48   ` [U-Boot] [PATCH v2 " Simon Glass
2016-11-19 14:13     ` Alexander Graf
2016-11-19 20:02       ` Simon Glass
2016-11-19 21:47         ` Alexander Graf
2016-11-19 23:56           ` Simon Glass
2016-11-20  0:13             ` Alexander Graf
2016-11-22 17:50               ` Simon Glass
2016-11-22 18:27                 ` Tom Rini
2016-11-22 18:48                   ` Alexander Graf
2016-11-22 20:49                 ` Alexander Graf
2016-11-17 17:31 ` [U-Boot] [PATCH v2 6/6] Travis: Remove sleep test from integratorcp_cm926ejs-qemu test Alexander Graf
2016-11-21 14:00   ` Tom Rini
2016-11-27 14:55   ` [U-Boot] [U-Boot, v2, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479403867-54792-5-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox