Merge branch 'master' of git://git.denx.de/u-boot
[oweals/u-boot.git] / test / py / tests / test_net.py
index 9c46551e8cbf3e7804475d3234925422ec98cdda..293b73a496d35062d0d660c779559f1f6e29a047 100644 (file)
@@ -8,7 +8,7 @@
 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, this test
 will be automatically skipped.
@@ -43,19 +43,29 @@ env__net_static_env_vars = [
 # may be omitted or set to None if TFTP testing is not possible or desired.
 env__net_tftp_readable_file = {
     "fn": "ubtest-readable.bin",
+    "addr": 0x10000000,
     "size": 5058624,
     "crc32": "c2244b26",
 }
-'''
+
+# Details regarding a file that may be read from a NFS server. This variable
+# may be omitted or set to None if NFS testing is not possible or desired.
+env__net_nfs_readable_file = {
+    "fn": "ubtest-readable.bin",
+    "addr": 0x10000000,
+    "size": 5058624,
+    "crc32": "c2244b26",
+}
+"""
 
 net_set_up = False
 
 def test_net_pre_commands(u_boot_console):
-    '''Execute any commands required to enable network hardware.
+    """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:
@@ -67,11 +77,11 @@ def test_net_pre_commands(u_boot_console):
 
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
-    '''Test the dhcp command.
+    """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:
@@ -86,11 +96,11 @@ def test_net_dhcp(u_boot_console):
 
 @pytest.mark.buildconfigspec('net')
 def test_net_setup_static(u_boot_console):
-    '''Set up a static IP configuration.
+    """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:
@@ -104,38 +114,41 @@ def test_net_setup_static(u_boot_console):
 
 @pytest.mark.buildconfigspec('cmd_ping')
 def test_net_ping(u_boot_console):
-    '''Test the ping command.
+    """Test the ping command.
 
     The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
     is pinged. The test validates that the host is alive, as reported by the
     ping command's output.
-    '''
+    """
 
     if not net_set_up:
-        pytest.skip("Network not initialized")
+        pytest.skip('Network not initialized')
 
     output = u_boot_console.run_command('ping $serverip')
     assert 'is alive' in output
 
 @pytest.mark.buildconfigspec('cmd_net')
 def test_net_tftpboot(u_boot_console):
-    '''Test the tftpboot command.
+    """Test the tftpboot command.
 
     A file is downloaded from the TFTP server, its size and optionally its
     CRC32 are validated.
 
     The details of the file to download are provided by the boardenv_* file;
     see the comment at the beginning of this file.
-    '''
+    """
 
     if not net_set_up:
-        pytest.skip("Network not initialized")
+        pytest.skip('Network not initialized')
 
     f = u_boot_console.config.env.get('env__net_tftp_readable_file', None)
     if not f:
         pytest.skip('No TFTP readable file to read')
 
-    addr = u_boot_utils.find_ram_base(u_boot_console)
+    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 = '
@@ -153,3 +166,43 @@ def test_net_tftpboot(u_boot_console):
 
     output = u_boot_console.run_command('crc32 %x $filesize' % addr)
     assert expected_crc in output
+
+@pytest.mark.buildconfigspec('cmd_nfs')
+def test_net_nfs(u_boot_console):
+    """Test the nfs command.
+
+    A file is downloaded from the NFS server, its size and optionally its
+    CRC32 are validated.
+
+    The details of the file to download are provided by the boardenv_* file;
+    see the comment at the beginning of this file.
+    """
+
+    if not net_set_up:
+        pytest.skip('Network not initialized')
+
+    f = u_boot_console.config.env.get('env__net_nfs_readable_file', None)
+    if not f:
+        pytest.skip('No NFS readable file to read')
+
+    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('nfs %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