diff options
Diffstat (limited to 'test/py/tests')
| -rw-r--r-- | test/py/tests/test_android/test_abootimg.py | 136 | ||||
| -rw-r--r-- | test/py/tests/test_efi_bootmgr/conftest.py | 6 | ||||
| -rw-r--r-- | test/py/tests/test_efi_capsule/capsule_defs.py | 2 | ||||
| -rw-r--r-- | test/py/tests/test_efi_capsule/conftest.py | 28 | ||||
| -rw-r--r-- | test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py | 35 | ||||
| -rw-r--r-- | test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py | 41 | ||||
| -rw-r--r-- | test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py | 38 | ||||
| -rw-r--r-- | test/py/tests/test_efi_fit.py | 4 | ||||
| -rw-r--r-- | test/py/tests/test_efi_secboot/conftest.py | 6 | ||||
| -rw-r--r-- | test/py/tests/test_efi_secboot/defs.py | 2 | ||||
| -rw-r--r-- | test/py/tests/test_efi_selftest.py | 2 | ||||
| -rw-r--r-- | test/py/tests/test_hush_if_test.py | 13 | ||||
| -rw-r--r-- | test/py/tests/test_net.py | 56 | ||||
| -rw-r--r-- | test/py/tests/test_ut.py | 4 | 
14 files changed, 273 insertions, 100 deletions
| diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py index 43a7099c466..6a8ff34538b 100644 --- a/test/py/tests/test_android/test_abootimg.py +++ b/test/py/tests/test_android/test_abootimg.py @@ -32,6 +32,23 @@ Now one can obtain original boot.img from this hex dump like this:      $ xxd -r -p boot.img.gz.hex boot.img.gz      $ gunzip -9 boot.img.gz + +For boot image header version 4, these tests rely on two images that are generated +using the same steps above : + +1- boot.img : +    $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img  \ +                --cmdline "cmdline test" --dtb ./dtb.img   \ +                --os_version R --os_patch_level 2019-06-05 \ +                --header_version 4 --output ./boot.img + +2- vendor_boot.img +    $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img  \ +                --cmdline "cmdline test" --dtb ./dtb.img   \ +                --os_version R --os_patch_level 2019-06-05 \ +                --pagesize 4096  --vendor_ramdisk ./ramdisk.img \ +                --header_version 4 --vendor_boot ./vboot.img \ +  """  # boot.img.gz hex dump @@ -44,6 +61,24 @@ b7762ffff07d345446c1281805e8a0868d81e117a45e111c0d8dc101b253  9c03c41a0c90f17fe85400986d82452b6c3680198a192a0ce17c3610ae34  d4a9820881a70f3873f35352731892f3730b124b32937252a96bb9119ae5  463a5546f82c1f05a360148c8251300a462e000085bf67f200200000""" + +# boot img v4 hex dump +boot_img_hex = """1f8b080827b0cd630203626f6f742e696d6700edd8bd0d82601885d1d7c4 +58d8c808b88195bd098d8d246e40e42b083f1aa0717be99d003d277916b8 +e5bddc8a7b792d8e8788c896ce9b88d32ebe6c971e7ddd3543cae734cd01 +c0ffc84c0000b0766d1a87d4e5afeadd3dab7a6f10000000f84163d5d7cd +d43a000000000000000060c53e7544995700400000""" + +# vendor boot image v4 hex dump +vboot_img_hex = """1f8b0808baaecd63020376626f6f742e696d6700edd8310b824018c6f1b3 +222a08f41b3436b4280dcdd19c11d16ee9109d18d59042d047ec8b04cd0d +d19d5a4345534bf6ffc173ef29272f38e93b1d0ec67dd79d548462aa1cd2 +d5d20b0000f8438678f90c18d584b8a4bbb3a557991ecb2a0000f80d6b2f +f4179b656be5c532f2fc066f040000000080e23936af2755f62a3d918df1 +db2a7ab67f9ffdeb7df7cda3465ecb79c4ce7e5c577562bb9364b74449a5 +1e467e20c53c0a57de763193c1779b3b4fcd9d4ee27c6a0e00000000c0ff +309ffea7010000000040f1dc004129855400400000""" +  # Expected response for "abootimg dtb_dump" command  dtb_dump_resp="""## DTB area contents (concat format):   - DTB #0: @@ -56,15 +91,21 @@ dtb_dump_resp="""## DTB area contents (concat format):       (DTB)compatible = y2,z2"""  # Address in RAM where to load the boot image ('abootimg' looks in $loadaddr)  loadaddr = 0x1000 +# Address in RAM where to load the vendor boot image ('abootimg' looks in $vloadaddr) +vloadaddr= 0x10000  # Expected DTB #1 offset from the boot image start address  dtb1_offset = 0x187d +# Expected DTB offset from the vendor boot image start address +dtb2_offset = 0x207d  # DTB #1 start address in RAM  dtb1_addr = loadaddr + dtb1_offset +# DTB #2 start address in RAM +dtb2_addr = vloadaddr + dtb2_offset  class AbootimgTestDiskImage(object):      """Disk image used by abootimg tests.""" -    def __init__(self, u_boot_console): +    def __init__(self, u_boot_console, image_name, hex_img):          """Initialize a new AbootimgDiskImage object.          Args: @@ -74,13 +115,13 @@ class AbootimgTestDiskImage(object):              Nothing.          """ -        gz_hex = u_boot_console.config.persistent_data_dir + '/boot.img.gz.hex' -        gz = u_boot_console.config.persistent_data_dir + '/boot.img.gz' +        gz_hex = u_boot_console.config.persistent_data_dir + '/' + image_name  + '.gz.hex' +        gz = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz' -        filename = 'boot.img' +        filename = image_name          persistent = u_boot_console.config.persistent_data_dir + '/' + filename          self.path = u_boot_console.config.result_dir  + '/' + filename - +        u_boot_console.log.action('persistent is ' + persistent)          with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):              if os.path.exists(persistent):                  u_boot_console.log.action('Disk image file ' + persistent + @@ -89,19 +130,17 @@ class AbootimgTestDiskImage(object):                  u_boot_console.log.action('Generating ' + persistent)                  f = open(gz_hex, "w") -                f.write(img_hex) +                f.write(hex_img)                  f.close() -                  cmd = ('xxd', '-r', '-p', gz_hex, gz)                  u_boot_utils.run_and_log(u_boot_console, cmd) -                  cmd = ('gunzip', '-9', gz)                  u_boot_utils.run_and_log(u_boot_console, cmd)          cmd = ('cp', persistent, self.path)          u_boot_utils.run_and_log(u_boot_console, cmd) -gtdi = None +gtdi1 = None  @pytest.fixture(scope='function')  def abootimg_disk_image(u_boot_console):      """pytest fixture to provide a AbootimgTestDiskImage object to tests. @@ -109,10 +148,36 @@ def abootimg_disk_image(u_boot_console):      function-scoped. However, we don't need to actually do any function-scope      work, so this simply returns the same object over and over each time.""" -    global gtdi -    if not gtdi: -        gtdi = AbootimgTestDiskImage(u_boot_console) -    return gtdi +    global gtdi1 +    if not gtdi1: +        gtdi1 = AbootimgTestDiskImage(u_boot_console, 'boot.img', img_hex) +    return gtdi1 + +gtdi2 = None +@pytest.fixture(scope='function') +def abootimgv4_disk_image_vboot(u_boot_console): +    """pytest fixture to provide a AbootimgTestDiskImage object to tests. +    This is function-scoped because it uses u_boot_console, which is also +    function-scoped. However, we don't need to actually do any function-scope +    work, so this simply returns the same object over and over each time.""" + +    global gtdi2 +    if not gtdi2: +        gtdi2 = AbootimgTestDiskImage(u_boot_console, 'vendor_boot.img', vboot_img_hex) +    return gtdi2 + +gtdi3 = None +@pytest.fixture(scope='function') +def abootimgv4_disk_image_boot(u_boot_console): +    """pytest fixture to provide a AbootimgTestDiskImage object to tests. +    This is function-scoped because it uses u_boot_console, which is also +    function-scoped. However, we don't need to actually do any function-scope +    work, so this simply returns the same object over and over each time.""" + +    global gtdi3 +    if not gtdi3: +        gtdi3 = AbootimgTestDiskImage(u_boot_console, 'bootv4.img', boot_img_hex) +    return gtdi3  @pytest.mark.boardspec('sandbox')  @pytest.mark.buildconfigspec('android_boot_image') @@ -157,3 +222,48 @@ def test_abootimg(abootimg_disk_image, u_boot_console):      u_boot_console.run_command('fdt get value v / model')      response = u_boot_console.run_command('env print v')      assert response == 'v=x2' + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('android_boot_image') +@pytest.mark.buildconfigspec('cmd_abootimg') +@pytest.mark.buildconfigspec('cmd_fdt') +@pytest.mark.requiredtool('xxd') +@pytest.mark.requiredtool('gunzip') +def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, u_boot_console): +    """Test the 'abootimg' command with boot image header v4.""" + +    cons = u_boot_console +    cons.log.action('Loading disk image to RAM...') +    cons.run_command('setenv loadaddr 0x%x' % (loadaddr)) +    cons.run_command('setenv vloadaddr 0x%x' % (vloadaddr)) +    cons.run_command('host load hostfs - 0x%x %s' % (vloadaddr, +	abootimgv4_disk_image_vboot.path)) +    cons.run_command('host load hostfs - 0x%x %s' % (loadaddr, +        abootimgv4_disk_image_boot.path)) +    cons.run_command('abootimg addr 0x%x 0x%x' % (loadaddr, vloadaddr)) +    cons.log.action('Testing \'abootimg get ver\'...') +    response = cons.run_command('abootimg get ver') +    assert response == "4" +    cons.run_command('abootimg get ver v') +    response = cons.run_command('env print v') +    assert response == 'v=4' + +    cons.log.action('Testing \'abootimg get recovery_dtbo\'...') +    response = cons.run_command('abootimg get recovery_dtbo a') +    assert response == 'Error: header version must be >= 1 and <= 2 to get dtbo' + +    cons.log.action('Testing \'abootimg get dtb_load_addr\'...') +    cons.run_command('abootimg get dtb_load_addr a') +    response = cons.run_command('env print a') +    assert response == 'a=11f00000' + +    cons.log.action('Testing \'abootimg get dtb --index\'...') +    cons.run_command('abootimg get dtb --index=1 dtb2_start') +    response = cons.run_command('env print dtb2_start') +    correct_str = "dtb2_start=%x" % (dtb2_addr) +    assert response == correct_str + +    cons.run_command('fdt addr $dtb2_start') +    cons.run_command('fdt get value v / model') +    response = cons.run_command('env print v') +    assert response == 'v=x2' diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py index a0a754afbe1..eabafa54298 100644 --- a/test/py/tests/test_efi_bootmgr/conftest.py +++ b/test/py/tests/test_efi_bootmgr/conftest.py @@ -1,7 +1,6 @@  # SPDX-License-Identifier:      GPL-2.0+ -"""Fixture for UEFI bootmanager test -""" +"""Fixture for UEFI bootmanager test."""  import os  import shutil @@ -10,8 +9,7 @@ import pytest  @pytest.fixture(scope='session')  def efi_bootmgr_data(u_boot_config): -    """Set up a file system to be used in UEFI bootmanager -       tests +    """Set up a file system to be used in UEFI bootmanager tests.      Args:          u_boot_config -- U-boot configuration. diff --git a/test/py/tests/test_efi_capsule/capsule_defs.py b/test/py/tests/test_efi_capsule/capsule_defs.py index 59b40f11bd1..3cc695e29b5 100644 --- a/test/py/tests/test_efi_capsule/capsule_defs.py +++ b/test/py/tests/test_efi_capsule/capsule_defs.py @@ -1,5 +1,7 @@  # SPDX-License-Identifier:      GPL-2.0+ +"""Directoreis used for authentication and capsule tests.""" +  # Directories  CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'  CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule' diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py index 4879f2b5c24..a337e629362 100644 --- a/test/py/tests/test_efi_capsule/conftest.py +++ b/test/py/tests/test_efi_capsule/conftest.py @@ -2,31 +2,23 @@  # Copyright (c) 2020, Linaro Limited  # Author: AKASHI Takahiro <takahiro.akashi@linaro.org> -import os -import os.path -import re -from subprocess import call, check_call, check_output, CalledProcessError -import pytest -from capsule_defs import * +"""Fixture for UEFI capsule test.""" -# -# Fixture for UEFI capsule test -# +from subprocess import call, check_call, CalledProcessError +import pytest +from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR, EFITOOLS_PATH  @pytest.fixture(scope='session')  def efi_capsule_data(request, u_boot_config): -    """Set up a file system to be used in UEFI capsule and -       authentication test. +    """Set up a file system and return path to image. -    Args: -        request: Pytest request object. -        u_boot_config: U-boot configuration. +    The function sets up a file system to be used in UEFI capsule and +    authentication test and returns a path to disk image to be used +    for testing. -    Return: -        A path to disk image to be used for testing +    request -- Pytest request object. +    u_boot_config -- U-boot configuration.      """ -    global CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR -      mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'      data_dir = mnt_point + CAPSULE_DATA_DIR      install_dir = mnt_point + CAPSULE_INSTALL_DIR diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py index d28b53a1a15..9ee152818d6 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py @@ -1,16 +1,13 @@  # SPDX-License-Identifier:      GPL-2.0+  # Copyright (c) 2020, Linaro Limited  # Author: AKASHI Takahiro <takahiro.akashi@linaro.org> -# -# U-Boot UEFI: Firmware Update Test -""" +"""U-Boot UEFI: Firmware Update Test  This test verifies capsule-on-disk firmware update for FIT images  """ -from subprocess import check_call, check_output, CalledProcessError  import pytest -from capsule_defs import * +from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR  @pytest.mark.boardspec('sandbox_flattree') @@ -24,15 +21,18 @@ from capsule_defs import *  @pytest.mark.buildconfigspec('cmd_nvedit_efi')  @pytest.mark.buildconfigspec('cmd_sf')  @pytest.mark.slow -class TestEfiCapsuleFirmwareFit(object): +class TestEfiCapsuleFirmwareFit(): +    """Test capsule-on-disk firmware update for FIT images +    """ +      def test_efi_capsule_fw1(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 1 - Update U-Boot and U-Boot environment on SPI Flash -                      but with an incorrect GUID value in the capsule -                      No update should happen -                      0x100000-0x150000: U-Boot binary (but dummy) -                      0x150000-0x200000: U-Boot environment (but dummy) +        """Test Case 1 +        Update U-Boot and U-Boot environment on SPI Flash +        but with an incorrect GUID value in the capsule +        No update should happen +        0x100000-0x150000: U-Boot binary (but dummy) +        0x150000-0x200000: U-Boot environment (but dummy)          """          # other tests might have run and the          # system might not be in a clean state. @@ -74,8 +74,6 @@ class TestEfiCapsuleFirmwareFit(object):          capsule_early = u_boot_config.buildconfig.get(              'config_efi_capsule_on_disk_early') -        capsule_auth = u_boot_config.buildconfig.get( -            'config_efi_capsule_authenticate')          # reboot          u_boot_console.restart_uboot(expect_reset = capsule_early) @@ -107,11 +105,12 @@ class TestEfiCapsuleFirmwareFit(object):      def test_efi_capsule_fw2(              self, u_boot_config, u_boot_console, efi_capsule_data): +        """Test Case 2 +        Update U-Boot and U-Boot environment on SPI Flash +        0x100000-0x150000: U-Boot binary (but dummy) +        0x150000-0x200000: U-Boot environment (but dummy)          """ -        Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash -                      0x100000-0x150000: U-Boot binary (but dummy) -                      0x150000-0x200000: U-Boot environment (but dummy) -        """ +          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 2-a, before reboot'):              output = u_boot_console.run_command_list([ diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py index 8c2d616fd06..ba8429e83cb 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py @@ -3,10 +3,8 @@  # Copyright (c) 2022, Arm Limited  # Author: AKASHI Takahiro <takahiro.akashi@linaro.org>,  #         adapted to FIT images by Vincent Stehlé <vincent.stehle@arm.com> -# -# U-Boot UEFI: Firmware Update (Signed capsule with FIT images) Test -""" +"""U-Boot UEFI: Firmware Update (Signed capsule with FIT images) Test  This test verifies capsule-on-disk firmware update  with signed capsule files containing FIT images  """ @@ -25,15 +23,18 @@ from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR  @pytest.mark.buildconfigspec('cmd_nvedit_efi')  @pytest.mark.buildconfigspec('cmd_sf')  @pytest.mark.slow -class TestEfiCapsuleFirmwareSignedFit(object): +class TestEfiCapsuleFirmwareSignedFit(): +    """Capsule-on-disk firmware update test +    """ +      def test_efi_capsule_auth1(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 1 - Update U-Boot on SPI Flash, FIT image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 1 +        Update U-Boot on SPI Flash, FIT image format +        x150000: U-Boot binary (but dummy) -                      If the capsule is properly signed, the authentication -                      should pass and the firmware be updated. +        If the capsule is properly signed, the authentication +        should pass and the firmware be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 1-a, before reboot'): @@ -103,13 +104,13 @@ class TestEfiCapsuleFirmwareSignedFit(object):      def test_efi_capsule_auth2(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 2 - Update U-Boot on SPI Flash, FIT image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 2 +        Update U-Boot on SPI Flash, FIT image format +        0x100000-0x150000: U-Boot binary (but dummy) -                      If the capsule is signed but with an invalid key, -                      the authentication should fail and the firmware -                      not be updated. +        If the capsule is signed but with an invalid key, +        the authentication should fail and the firmware +        not be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 2-a, before reboot'): @@ -182,12 +183,12 @@ class TestEfiCapsuleFirmwareSignedFit(object):      def test_efi_capsule_auth3(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 3 - Update U-Boot on SPI Flash, FIT image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 3 +        Update U-Boot on SPI Flash, FIT image format +        0x100000-0x150000: U-Boot binary (but dummy) -                      If the capsule is not signed, the authentication -                      should fail and the firmware not be updated. +        If the capsule is not signed, the authentication +        should fail and the firmware not be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 3-a, before reboot'): diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py index 2bbaa9cc55f..710d9925a30 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py @@ -1,10 +1,8 @@  # SPDX-License-Identifier:      GPL-2.0+  # Copyright (c) 2021, Linaro Limited  # Author: AKASHI Takahiro <takahiro.akashi@linaro.org> -# -# U-Boot UEFI: Firmware Update (Signed capsule with raw images) Test -""" +"""U-Boot UEFI: Firmware Update (Signed capsule with raw images) Test  This test verifies capsule-on-disk firmware update  with signed capsule files containing raw images  """ @@ -23,15 +21,17 @@ from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR  @pytest.mark.buildconfigspec('cmd_nvedit_efi')  @pytest.mark.buildconfigspec('cmd_sf')  @pytest.mark.slow -class TestEfiCapsuleFirmwareSignedRaw(object): +class TestEfiCapsuleFirmwareSignedRaw(): +    """Firmware Update (Signed capsule with raw images) Test +    """ +      def test_efi_capsule_auth1(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 1 - Update U-Boot on SPI Flash, raw image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 1 - Update U-Boot on SPI Flash, raw image format +        0x100000-0x150000: U-Boot binary (but dummy) -                      If the capsule is properly signed, the authentication -                      should pass and the firmware be updated. +        If the capsule is properly signed, the authentication +        should pass and the firmware be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 1-a, before reboot'): @@ -100,13 +100,12 @@ class TestEfiCapsuleFirmwareSignedRaw(object):      def test_efi_capsule_auth2(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 2 - Update U-Boot on SPI Flash, raw image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 2 - Update U-Boot on SPI Flash, raw image format +        0x100000-0x150000: U-Boot binary (but dummy) -                      If the capsule is signed but with an invalid key, -                      the authentication should fail and the firmware -                      not be updated. +        If the capsule is signed but with an invalid key, +        the authentication should fail and the firmware +        not be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 2-a, before reboot'): @@ -179,12 +178,11 @@ class TestEfiCapsuleFirmwareSignedRaw(object):      def test_efi_capsule_auth3(              self, u_boot_config, u_boot_console, efi_capsule_data): -        """ -        Test Case 3 - Update U-Boot on SPI Flash, raw image format -                      0x100000-0x150000: U-Boot binary (but dummy) +        """Test Case 3 - Update U-Boot on SPI Flash, raw image format +        0x100000-0x150000: U-Boot binary (but dummy) -                      If the capsule is not signed, the authentication -                      should fail and the firmware not be updated. +        If the capsule is not signed, the authentication +        should fail and the firmware not be updated.          """          disk_img = efi_capsule_data          with u_boot_console.log.section('Test Case 3-a, before reboot'): diff --git a/test/py/tests/test_efi_fit.py b/test/py/tests/test_efi_fit.py index 92d071f7839..7b7c98fb04c 100644 --- a/test/py/tests/test_efi_fit.py +++ b/test/py/tests/test_efi_fit.py @@ -433,11 +433,13 @@ def test_efi_fit_launch(u_boot_console):      sys_arch = cons.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]      is_sandbox = sys_arch == 'sandbox' +    if is_sandbox: +        old_dtb = cons.config.dtb +      try:          if is_sandbox:              # Use our own device tree file, will be restored afterwards.              control_dtb = make_dtb('internal', False) -            old_dtb = cons.config.dtb              cons.config.dtb = control_dtb          # Run tests diff --git a/test/py/tests/test_efi_secboot/conftest.py b/test/py/tests/test_efi_secboot/conftest.py index 65cde7a2f23..30ff7029438 100644 --- a/test/py/tests/test_efi_secboot/conftest.py +++ b/test/py/tests/test_efi_secboot/conftest.py @@ -2,7 +2,7 @@  # Copyright (c) 2019, Linaro Limited  # Author: AKASHI Takahiro <takahiro.akashi@linaro.org> -""" Fixture for UEFI secure boot test """ +"""Fixture for UEFI secure boot test."""  from subprocess import call, check_call, CalledProcessError  import pytest @@ -132,7 +132,9 @@ def efi_boot_env(request, u_boot_config):  @pytest.fixture(scope='session')  def efi_boot_env_intca(request, u_boot_config): -    """Set up a file system to be used in UEFI secure boot test +    """Set up file system for secure boot test. + +    Set up a file system to be used in UEFI secure boot test      of intermediate certificates.      Args: diff --git a/test/py/tests/test_efi_secboot/defs.py b/test/py/tests/test_efi_secboot/defs.py index b7a2a118511..6a2317e295b 100644 --- a/test/py/tests/test_efi_secboot/defs.py +++ b/test/py/tests/test_efi_secboot/defs.py @@ -1,5 +1,7 @@  # SPDX-License-Identifier:      GPL-2.0+ +"""Constants used for secure boot test.""" +  # Owner guid  GUID = '11111111-2222-3333-4444-123456789abc' diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index e92d63cde6e..43f24245582 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -7,7 +7,7 @@  import pytest  @pytest.mark.buildconfigspec('cmd_bootefi_selftest') -def test_efi_selftest(u_boot_console): +def test_efi_selftest_base(u_boot_console):      """Run UEFI unit tests      u_boot_console -- U-Boot console diff --git a/test/py/tests/test_hush_if_test.py b/test/py/tests/test_hush_if_test.py index 37c1608bb22..3b4b6fcaf40 100644 --- a/test/py/tests/test_hush_if_test.py +++ b/test/py/tests/test_hush_if_test.py @@ -182,3 +182,16 @@ def test_hush_if_test_host_file_exists(u_boot_console):      expr = 'test -e hostfs - ' + test_file      exec_hush_if(u_boot_console, expr, False) + +def test_hush_var(u_boot_console): +    """Test the set and unset of variables""" +    u_boot_console.run_command('ut_var_nonexistent=') +    u_boot_console.run_command('ut_var_exists=1') +    u_boot_console.run_command('ut_var_unset=1') +    exec_hush_if(u_boot_console, 'test -z "$ut_var_nonexistent"', True) +    exec_hush_if(u_boot_console, 'test -z "$ut_var_exists"', False) +    exec_hush_if(u_boot_console, 'test -z "$ut_var_unset"', False) +    exec_hush_if(u_boot_console, 'ut_var_unset=', True) +    exec_hush_if(u_boot_console, 'test -z "$ut_var_unset"', True) +    u_boot_console.run_command('ut_var_exists=') +    u_boot_console.run_command('ut_var_unset=') diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py index 9ca6743afd9..cd4b4dc53cb 100644 --- a/test/py/tests/test_net.py +++ b/test/py/tests/test_net.py @@ -9,7 +9,7 @@ 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 +which network environment is available for testing. Without this, this test  will be automatically skipped.  For example: @@ -29,6 +29,11 @@ env__net_uses_pci = True  # set to False.  env__net_dhcp_server = True +# True if a DHCPv6 server is attached to the network, and should be tested. +# If DHCPv6 testing is not possible or desired, this variable may be omitted or +# set to False. +env__net_dhcp6_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. @@ -55,9 +60,15 @@ env__net_nfs_readable_file = {      'size': 5058624,      'crc32': 'c2244b26',  } + +# True if a router advertisement service is connected to the network, and should +# be tested. If router advertisement testing is not possible or desired, this +variable may be omitted or set to False. +env__router_on_net = True  """  net_set_up = False +net6_set_up = False  def test_net_pre_commands(u_boot_console):      """Execute any commands required to enable network hardware. @@ -93,6 +104,25 @@ def test_net_dhcp(u_boot_console):      global net_set_up      net_set_up = True +@pytest.mark.buildconfigspec('cmd_dhcp6') +def test_net_dhcp6(u_boot_console): +    """Test the dhcp6 command. + +    The boardenv_* file may be used to enable/disable this test; see the +    comment at the beginning of this file. +    """ + +    test_dhcp6 = u_boot_console.config.env.get('env__net_dhcp6_server', False) +    if not test_dhcp6: +        pytest.skip('No DHCP6 server available') + +    u_boot_console.run_command('setenv autoload no') +    output = u_boot_console.run_command('dhcp6') +    assert 'DHCP6 client bound to ' in output + +    global net6_set_up +    net6_set_up = True +  @pytest.mark.buildconfigspec('net')  def test_net_setup_static(u_boot_console):      """Set up a static IP configuration. @@ -126,6 +156,30 @@ def test_net_ping(u_boot_console):      output = u_boot_console.run_command('ping $serverip')      assert 'is alive' in output +@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY') +def test_net_network_discovery(u_boot_console): +    """Test the network discovery feature of IPv6. + +    An IPv6 network command (ping6 in this case) is run to make U-Boot send a +    router solicitation packet, receive a router advertisement message, and +    parse it. +    A router advertisement service needs to be running for this test to succeed. +    U-Boot receives the RA, processes it, and if successful, assigns the gateway +    IP and prefix length. +    The configuration is provided by the boardenv_* file; see the comment at +    the beginning of this file. +    """ + +    router_on_net = u_boot_console.config.env.get('env__router_on_net', False) +    if not router_on_net: +        pytest.skip('No router on network') + +    fake_host_ip = 'fe80::215:5dff:fef6:2ec6' +    output = u_boot_console.run_command('ping6 ' + fake_host_ip) +    assert 'ROUTER SOLICITATION 1' in output +    assert 'Set gatewayip6:' in output +    assert '0000:0000:0000:0000:0000:0000:0000:0000' not in output +  @pytest.mark.buildconfigspec('cmd_net')  def test_net_tftpboot(u_boot_console):      """Test the tftpboot command. diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index e8c8a6d6bd5..0b45863b438 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -213,7 +213,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}                str(exc))      finally:          if mounted: -            u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt) +            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)          if loop:              u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) @@ -274,7 +274,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)                str(exc))      finally:          if mounted: -            u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt) +            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)          if loop:              u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) | 
