diff options
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/tests/bootstd/flash1.img.xz | bin | 0 -> 4924 bytes | |||
-rw-r--r-- | test/py/tests/test_env.py | 2 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_basic.py | 5 | ||||
-rw-r--r-- | test/py/tests/test_spi.py | 12 | ||||
-rw-r--r-- | test/py/tests/test_usb.py | 171 | ||||
-rw-r--r-- | test/py/tests/test_ut.py | 55 |
6 files changed, 146 insertions, 99 deletions
diff --git a/test/py/tests/bootstd/flash1.img.xz b/test/py/tests/bootstd/flash1.img.xz Binary files differnew file mode 100644 index 00000000000..29b78c62a9b --- /dev/null +++ b/test/py/tests/bootstd/flash1.img.xz diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index 00bcccd65ff..4471db7d9cb 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -488,7 +488,7 @@ def test_env_ext4(state_test_env): assert 'Loading Environment from EXT4... OK' in response response = c.run_command('ext4ls host 0:0') - assert '8192 uboot.env' in response + assert '8192 uboot.env' in response response = c.run_command('env info') assert 'env_valid = valid' in response diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py index 71f3e86fb18..b5f4704172a 100644 --- a/test/py/tests/test_fs/test_basic.py +++ b/test/py/tests/test_fs/test_basic.py @@ -33,10 +33,7 @@ class TestFsBasic(object): # In addition, test with a nonexistent directory to see if we crash. output = u_boot_console.run_command( '%sls host 0:0 invalid_d' % fs_type) - if fs_type == 'ext4': - assert('Can not find directory' in output) - else: - assert('' == output) + assert('' == output) def test_fs2(self, u_boot_console, fs_obj_basic): """ diff --git a/test/py/tests/test_spi.py b/test/py/tests/test_spi.py index 3160d58540f..caca9303271 100644 --- a/test/py/tests/test_spi.py +++ b/test/py/tests/test_spi.py @@ -693,4 +693,16 @@ def test_spi_negative(u_boot_console): u_boot_console, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ ) + # Read to relocation address + output = u_boot_console.run_command('bdinfo') + m = re.search('relocaddr\s*= (.+)', output) + res_area = int(m.group(1), 16) + + start = 0 + size = 0x2000 + error_msg = 'ERROR: trying to overwrite reserved memory' + flash_ops( + u_boot_console, 'read', start, size, res_area, 1, error_msg, EXPECTED_READ + ) + i = i + 1 diff --git a/test/py/tests/test_usb.py b/test/py/tests/test_usb.py index fb3d20f0826..2397fd3c2e7 100644 --- a/test/py/tests/test_usb.py +++ b/test/py/tests/test_usb.py @@ -288,6 +288,47 @@ def test_usb_fatls_fatinfo(u_boot_console): if not part_detect: pytest.skip('No %s partition detected' % fs.upper()) +def usb_fatload_fatwrite(u_boot_console, fs, x, part): + addr = u_boot_utils.find_ram_base(u_boot_console) + size = random.randint(4, 1 * 1024 * 1024) + output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) + m = re.search('==> (.+?)', output) + if not m: + pytest.fail('CRC32 failed') + expected_crc32 = m.group(1) + + file = '%s_%d' % ('uboot_test', size) + output = u_boot_console.run_command( + '%swrite usb %d:%s %x %s %x' % (fs, x, part, addr, file, size) + ) + assert 'Unable to write' not in output + assert 'Error' not in output + assert 'overflow' not in output + expected_text = '%d bytes written' % size + assert expected_text in output + + alignment = int( + u_boot_console.config.buildconfig.get( + 'config_sys_cacheline_size', 128 + ) + ) + offset = random.randrange(alignment, 1024, alignment) + output = u_boot_console.run_command( + '%sload usb %d:%s %x %s' % (fs, x, part, addr + offset, file) + ) + assert 'Invalid FAT entry' not in output + assert 'Unable to read file' not in output + assert 'Misaligned buffer address' not in output + expected_text = '%d bytes read' % size + assert expected_text in output + + output = u_boot_console.run_command( + 'crc32 %x $filesize' % (addr + offset) + ) + assert expected_crc32 in output + + return file, size, expected_crc32 + @pytest.mark.buildconfigspec('cmd_usb') @pytest.mark.buildconfigspec('cmd_fat') @pytest.mark.buildconfigspec('cmd_memory') @@ -309,49 +350,11 @@ def test_usb_fatload_fatwrite(u_boot_console): for part in partitions: part_detect = 1 - addr = u_boot_utils.find_ram_base(u_boot_console) - size = random.randint(4, 1 * 1024 * 1024) - output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) - m = re.search('==> (.+?)', output) - if not m: - pytest.fail('CRC32 failed') - expected_crc32 = m.group(1) - - file = '%s_%d' % ('uboot_test', size) - output = u_boot_console.run_command( - '%swrite usb %d:%s %x %s %x' % (fs, x, part, addr, file, size) - ) - assert 'Unable to write' not in output - assert 'Error' not in output - assert 'overflow' not in output - expected_text = '%d bytes written' % size - assert expected_text in output - - alignment = int( - u_boot_console.config.buildconfig.get( - 'config_sys_cacheline_size', 128 - ) - ) - offset = random.randrange(alignment, 1024, alignment) - output = u_boot_console.run_command( - '%sload usb %d:%s %x %s' % (fs, x, part, addr + offset, file) - ) - assert 'Invalid FAT entry' not in output - assert 'Unable to read file' not in output - assert 'Misaligned buffer address' not in output - expected_text = '%d bytes read' % size - assert expected_text in output - - output = u_boot_console.run_command( - 'crc32 %x $filesize' % (addr + offset) - ) - assert expected_crc32 in output + usb_fatload_fatwrite(u_boot_console, fs, x, part) if not part_detect: pytest.skip('No %s partition detected' % fs.upper()) - return file, size - @pytest.mark.buildconfigspec('cmd_usb') @pytest.mark.buildconfigspec('cmd_ext4') def test_usb_ext4ls(u_boot_console): @@ -380,9 +383,42 @@ def test_usb_ext4ls(u_boot_console): if not part_detect: pytest.skip('No %s partition detected' % fs.upper()) +def usb_ext4load_ext4write(u_boot_console, fs, x, part): + addr = u_boot_utils.find_ram_base(u_boot_console) + size = random.randint(4, 1 * 1024 * 1024) + output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) + m = re.search('==> (.+?)', output) + if not m: + pytest.fail('CRC32 failed') + expected_crc32 = m.group(1) + file = '%s_%d' % ('uboot_test', size) + + output = u_boot_console.run_command( + '%swrite usb %d:%s %x /%s %x' % (fs, x, part, addr, file, size) + ) + assert 'Unable to write' not in output + assert 'Error' not in output + assert 'overflow' not in output + expected_text = '%d bytes written' % size + assert expected_text in output + + offset = random.randrange(128, 1024, 128) + output = u_boot_console.run_command( + '%sload usb %d:%s %x /%s' % (fs, x, part, addr + offset, file) + ) + expected_text = '%d bytes read' % size + assert expected_text in output + + output = u_boot_console.run_command( + 'crc32 %x $filesize' % (addr + offset) + ) + assert expected_crc32 in output + + return file, size, expected_crc32 + @pytest.mark.buildconfigspec('cmd_usb') @pytest.mark.buildconfigspec('cmd_ext4') -@pytest.mark.buildconfigspec('ext4_write') +@pytest.mark.buildconfigspec('cmd_ext4_write') @pytest.mark.buildconfigspec('cmd_memory') def test_usb_ext4load_ext4write(u_boot_console): devices, controllers, storage_device = test_usb_part(u_boot_console) @@ -402,41 +438,11 @@ def test_usb_ext4load_ext4write(u_boot_console): for part in partitions: part_detect = 1 - addr = u_boot_utils.find_ram_base(u_boot_console) - size = random.randint(4, 1 * 1024 * 1024) - output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) - m = re.search('==> (.+?)', output) - if not m: - pytest.fail('CRC32 failed') - expected_crc32 = m.group(1) - file = '%s_%d' % ('uboot_test', size) - - output = u_boot_console.run_command( - '%swrite usb %d:%s %x /%s %x' % (fs, x, part, addr, file, size) - ) - assert 'Unable to write' not in output - assert 'Error' not in output - assert 'overflow' not in output - expected_text = '%d bytes written' % size - assert expected_text in output - - offset = random.randrange(128, 1024, 128) - output = u_boot_console.run_command( - '%sload usb %d:%s %x /%s' % (fs, x, part, addr + offset, file) - ) - expected_text = '%d bytes read' % size - assert expected_text in output - - output = u_boot_console.run_command( - 'crc32 %x $filesize' % (addr + offset) - ) - assert expected_crc32 in output + usb_ext4load_ext4write(u_boot_console, fs, x, part) if not part_detect: pytest.skip('No %s partition detected' % fs.upper()) - return file, size - @pytest.mark.buildconfigspec('cmd_usb') @pytest.mark.buildconfigspec('cmd_ext2') def test_usb_ext2ls(u_boot_console): @@ -469,11 +475,10 @@ def test_usb_ext2ls(u_boot_console): @pytest.mark.buildconfigspec('cmd_usb') @pytest.mark.buildconfigspec('cmd_ext2') @pytest.mark.buildconfigspec('cmd_ext4') -@pytest.mark.buildconfigspec('ext4_write') +@pytest.mark.buildconfigspec('cmd_ext4_write') @pytest.mark.buildconfigspec('cmd_memory') def test_usb_ext2load(u_boot_console): devices, controllers, storage_device = test_usb_part(u_boot_console) - file, size = test_usb_ext4load_ext4write(u_boot_console) if not devices: pytest.skip('No devices detected') @@ -491,12 +496,9 @@ def test_usb_ext2load(u_boot_console): for part in partitions: part_detect = 1 + file, size, expected_crc32 = \ + usb_ext4load_ext4write(u_boot_console, 'ext4', x, part) addr = u_boot_utils.find_ram_base(u_boot_console) - output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) - m = re.search('==> (.+?)', output) - if not m: - pytest.fail('CRC32 failed') - expected_crc32 = m.group(1) offset = random.randrange(128, 1024, 128) output = u_boot_console.run_command( @@ -543,6 +545,7 @@ def test_usb_ls(u_boot_console): pytest.skip('No partition detected') @pytest.mark.buildconfigspec('cmd_usb') +@pytest.mark.buildconfigspec('cmd_ext4_write') @pytest.mark.buildconfigspec('cmd_fs_generic') def test_usb_load(u_boot_console): devices, controllers, storage_device = test_usb_part(u_boot_console) @@ -565,15 +568,11 @@ def test_usb_load(u_boot_console): addr = u_boot_utils.find_ram_base(u_boot_console) if fs == 'fat': - file, size = test_usb_fatload_fatwrite(u_boot_console) + file, size, expected_crc32 = \ + usb_fatload_fatwrite(u_boot_console, fs, x, part) elif fs == 'ext4': - file, size = test_usb_ext4load_ext4write(u_boot_console) - - output = u_boot_console.run_command('crc32 %x %x' % (addr, size)) - m = re.search('==> (.+?)', output) - if not m: - pytest.fail('CRC32 failed') - expected_crc32 = m.group(1) + file, size, expected_crc32 = \ + usb_ext4load_ext4write(u_boot_console, fs, x, part) offset = random.randrange(128, 1024, 128) output = u_boot_console.run_command( diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 39aa1035e34..6d44191976b 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -28,21 +28,22 @@ def mkdir_cond(dirname): if not os.path.exists(dirname): os.mkdir(dirname) -def setup_image(cons, mmc_dev, part_type, second_part=False): +def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'): """Create a 20MB disk image with a single partition Args: cons (ConsoleBase): Console to use - mmc_dev (int): MMC device number to use, e.g. 1 + devnum (int): Device number to use, e.g. 1 part_type (int): Partition type, e.g. 0xc for FAT32 second_part (bool): True to contain a small second partition + basename (str): Base name to use in the filename, e.g. 'mmc' Returns: tuple: str: Filename of MMC image str: Directory name of 'mnt' directory """ - fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img') + fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img') mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') mkdir_cond(mnt) @@ -78,16 +79,17 @@ def mount_image(cons, fname, mnt, fstype): u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}') return loop -def copy_prepared_image(cons, mmc_dev, fname): +def copy_prepared_image(cons, devnum, fname, basename='mmc'): """Use a prepared image since we cannot create one Args: cons (ConsoleBase): Console touse - mmc_dev (int): MMC device number + devnum (int): device number fname (str): Filename of MMC image + basename (str): Base name to use in the filename, e.g. 'mmc' """ infname = os.path.join(cons.config.source_dir, - f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz') + f'test/py/tests/bootstd/{basename}{devnum}.img.xz') u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}']) def setup_bootmenu_image(cons): @@ -208,8 +210,6 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} cons, f'echo here {kernel} {symlink}') os.symlink(kernel, symlink) - u_boot_utils.run_and_log( - cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}') complete = True except ValueError as exc: @@ -549,6 +549,44 @@ def test_ut_dm_init(u_boot_console): with open(fn, 'wb') as fh: fh.write(data) + +def setup_efi_image(cons): + """Create a 20MB disk image with an EFI app on it""" + devnum = 1 + basename = 'flash' + fname, mnt = setup_image(cons, devnum, 0xc, second_part=True, + basename=basename) + + loop = None + mounted = False + complete = False + try: + loop = mount_image(cons, fname, mnt, 'ext4') + mounted = True + efi_dir = os.path.join(mnt, 'EFI') + mkdir_cond(efi_dir) + bootdir = os.path.join(efi_dir, 'BOOT') + mkdir_cond(bootdir) + efi_src = os.path.join(cons.config.build_dir, + f'lib/efi_loader/testapp.efi') + efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') + with open(efi_src, 'rb') as inf: + with open(efi_dst, 'wb') as outf: + outf.write(inf.read()) + complete = True + except ValueError as exc: + print(f'Falled to create image, failing back to prepared copy: {exc}') + + finally: + if mounted: + 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) + + if not complete: + copy_prepared_image(cons, devnum, fname, basename) + + @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(u_boot_console): @@ -559,6 +597,7 @@ def test_ut_dm_init_bootstd(u_boot_console): setup_cedit_file(u_boot_console) setup_cros_image(u_boot_console) setup_android_image(u_boot_console) + setup_efi_image(u_boot_console) # Restart so that the new mmc1.img is picked up u_boot_console.restart_uboot() |