Alexander Graf | 343cccb | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 1 | # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. |
| 2 | # Copyright (c) 2016, Alexander Graf <agraf@suse.de> |
| 3 | # |
| 4 | # based on test_net.py. |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0 |
| 7 | |
| 8 | # Test efi loader implementation |
| 9 | |
| 10 | import pytest |
| 11 | import u_boot_utils |
| 12 | |
| 13 | """ |
| 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. |
| 17 | |
| 18 | For example: |
| 19 | |
| 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 |
| 24 | |
| 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 |
| 29 | |
| 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 |
| 32 | # set to False. |
| 33 | env__net_dhcp_server = True |
| 34 | |
| 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 |
| 37 | # an empty list. |
| 38 | env__net_static_env_vars = [ |
| 39 | ("ipaddr", "10.0.0.100"), |
| 40 | ("netmask", "255.255.255.0"), |
| 41 | ("serverip", "10.0.0.1"), |
| 42 | ] |
| 43 | |
| 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", |
| 48 | "size": 5058624, |
| 49 | "crc32": "c2244b26", |
| 50 | } |
| 51 | """ |
| 52 | |
| 53 | net_set_up = False |
| 54 | |
| 55 | def test_efi_pre_commands(u_boot_console): |
| 56 | """Execute any commands required to enable network hardware. |
| 57 | |
| 58 | These commands are provided by the boardenv_* file; see the comment at the |
| 59 | beginning of this file. |
| 60 | """ |
| 61 | |
| 62 | init_usb = u_boot_console.config.env.get('env__net_uses_usb', False) |
| 63 | if init_usb: |
| 64 | u_boot_console.run_command('usb start') |
| 65 | |
| 66 | init_pci = u_boot_console.config.env.get('env__net_uses_pci', False) |
| 67 | if init_pci: |
| 68 | u_boot_console.run_command('pci enum') |
| 69 | |
| 70 | @pytest.mark.buildconfigspec('cmd_dhcp') |
| 71 | def test_efi_dhcp(u_boot_console): |
| 72 | """Test the dhcp command. |
| 73 | |
| 74 | The boardenv_* file may be used to enable/disable this test; see the |
| 75 | comment at the beginning of this file. |
| 76 | """ |
| 77 | |
| 78 | test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False) |
| 79 | if not test_dhcp: |
| 80 | pytest.skip('No DHCP server available') |
| 81 | |
| 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 |
| 85 | |
| 86 | global net_set_up |
| 87 | net_set_up = True |
| 88 | |
| 89 | @pytest.mark.buildconfigspec('net') |
| 90 | def test_efi_setup_static(u_boot_console): |
| 91 | """Set up a static IP configuration. |
| 92 | |
| 93 | The configuration is provided by the boardenv_* file; see the comment at |
| 94 | the beginning of this file. |
| 95 | """ |
| 96 | |
| 97 | env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None) |
| 98 | if not env_vars: |
| 99 | pytest.skip('No static network configuration is defined') |
| 100 | |
| 101 | for (var, val) in env_vars: |
| 102 | u_boot_console.run_command('setenv %s %s' % (var, val)) |
| 103 | |
| 104 | global net_set_up |
| 105 | net_set_up = True |
| 106 | |
Alexander Graf | b548351 | 2016-11-17 22:40:10 +0100 | [diff] [blame^] | 107 | @pytest.mark.buildconfigspec('cmd_bootefi_hello_compile') |
Alexander Graf | 343cccb | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 108 | def test_efi_helloworld_net(u_boot_console): |
| 109 | """Run the helloworld.efi binary via TFTP. |
| 110 | |
| 111 | The helloworld.efi file is downloaded from the TFTP server and gets |
| 112 | executed. |
| 113 | """ |
| 114 | |
| 115 | if not net_set_up: |
| 116 | pytest.skip('Network not initialized') |
| 117 | |
| 118 | f = u_boot_console.config.env.get('env__efi_loader_helloworld_file', None) |
| 119 | if not f: |
| 120 | pytest.skip('No hello world binary specified in environment') |
| 121 | |
| 122 | addr = f.get('addr', None) |
| 123 | if not addr: |
| 124 | addr = u_boot_utils.find_ram_base(u_boot_console) + (1024 * 1024 * 4) |
| 125 | |
| 126 | fn = f['fn'] |
| 127 | output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn)) |
| 128 | expected_text = 'Bytes transferred = ' |
| 129 | sz = f.get('size', None) |
| 130 | if sz: |
| 131 | expected_text += '%d' % sz |
| 132 | assert expected_text in output |
| 133 | |
| 134 | expected_crc = f.get('crc32', None) |
| 135 | if not expected_crc: |
| 136 | return |
| 137 | |
| 138 | if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y': |
| 139 | return |
| 140 | |
| 141 | output = u_boot_console.run_command('crc32 %x $filesize' % addr) |
| 142 | assert expected_crc in output |
| 143 | |
| 144 | output = u_boot_console.run_command('bootefi %x' % addr) |
| 145 | expected_text = 'Hello, world' |
| 146 | assert expected_text in output |
| 147 | |
| 148 | @pytest.mark.buildconfigspec('cmd_bootefi_hello') |
| 149 | def test_efi_helloworld_builtin(u_boot_console): |
| 150 | """Run the builtin helloworld.efi binary. |
| 151 | |
| 152 | The helloworld.efi file is included in U-Boot, execute it using the |
| 153 | special "bootefi hello" command. |
| 154 | """ |
| 155 | |
| 156 | output = u_boot_console.run_command('bootefi hello') |
| 157 | expected_text = 'Hello, world' |
| 158 | assert expected_text in output |