1 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
2 # Copyright (c) 2016, Alexander Graf <agraf@suse.de>
4 # based on test_net.py.
6 # SPDX-License-Identifier: GPL-2.0
8 # Test efi loader implementation
14 Note: This test relies on boardenv_* containing configuration values to define
15 which the network environment available for testing. Without this, the parts
16 that rely on network will be automatically skipped.
20 # Boolean indicating whether the Ethernet device is attached to USB, and hence
21 # USB enumeration needs to be performed prior to network tests.
22 # This variable may be omitted if its value is False.
23 env__net_uses_usb = False
25 # Boolean indicating whether the Ethernet device is attached to PCI, and hence
26 # PCI enumeration needs to be performed prior to network tests.
27 # This variable may be omitted if its value is False.
28 env__net_uses_pci = True
30 # True if a DHCP server is attached to the network, and should be tested.
31 # If DHCP testing is not possible or desired, this variable may be omitted or
33 env__net_dhcp_server = True
35 # A list of environment variables that should be set in order to configure a
36 # static IP. If solely relying on DHCP, this variable may be omitted or set to
38 env__net_static_env_vars = [
39 ("ipaddr", "10.0.0.100"),
40 ("netmask", "255.255.255.0"),
41 ("serverip", "10.0.0.1"),
44 # Details regarding a file that may be read from a TFTP server. This variable
45 # may be omitted or set to None if TFTP testing is not possible or desired.
46 env__efi_loader_helloworld_file = {
47 "fn": "lib/efi_loader/helloworld.efi",
55 def test_efi_pre_commands(u_boot_console):
56 """Execute any commands required to enable network hardware.
58 These commands are provided by the boardenv_* file; see the comment at the
59 beginning of this file.
62 init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
64 u_boot_console.run_command('usb start')
66 init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
68 u_boot_console.run_command('pci enum')
70 @pytest.mark.buildconfigspec('cmd_dhcp')
71 def test_efi_dhcp(u_boot_console):
72 """Test the dhcp command.
74 The boardenv_* file may be used to enable/disable this test; see the
75 comment at the beginning of this file.
78 test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
80 pytest.skip('No DHCP server available')
82 u_boot_console.run_command('setenv autoload no')
83 output = u_boot_console.run_command('dhcp')
84 assert 'DHCP client bound to address ' in output
89 @pytest.mark.buildconfigspec('net')
90 def test_efi_setup_static(u_boot_console):
91 """Set up a static IP configuration.
93 The configuration is provided by the boardenv_* file; see the comment at
94 the beginning of this file.
97 env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
99 pytest.skip('No static network configuration is defined')
101 for (var, val) in env_vars:
102 u_boot_console.run_command('setenv %s %s' % (var, val))
107 @pytest.mark.buildconfigspec('cmd_bootefi_hello')
108 def test_efi_helloworld_net(u_boot_console):
109 """Run the helloworld.efi binary via TFTP.
111 The helloworld.efi file is downloaded from the TFTP server and gets
116 pytest.skip('Network not initialized')
118 f = u_boot_console.config.env.get('env__efi_loader_helloworld_file', None)
120 pytest.skip('No hello world binary specified in environment')
122 addr = f.get('addr', None)
124 addr = u_boot_utils.find_ram_base(u_boot_console) + (1024 * 1024 * 4)
127 output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
128 expected_text = 'Bytes transferred = '
129 sz = f.get('size', None)
131 expected_text += '%d' % sz
132 assert expected_text in output
134 expected_crc = f.get('crc32', None)
138 if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
141 output = u_boot_console.run_command('crc32 %x $filesize' % addr)
142 assert expected_crc in output
144 output = u_boot_console.run_command('bootefi %x' % addr)
145 expected_text = 'Hello, world'
146 assert expected_text in output
148 @pytest.mark.buildconfigspec('cmd_bootefi_hello')
149 def test_efi_helloworld_builtin(u_boot_console):
150 """Run the builtin helloworld.efi binary.
152 The helloworld.efi file is included in U-Boot, execute it using the
153 special "bootefi hello" command.
156 output = u_boot_console.run_command('bootefi hello')
157 expected_text = 'Hello, world'
158 assert expected_text in output