diff options
Diffstat (limited to 'test/py/tests/test_ut.py')
| -rw-r--r-- | test/py/tests/test_ut.py | 186 |
1 files changed, 100 insertions, 86 deletions
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 98641a46c1d..dce5a37dd35 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -17,6 +17,7 @@ import pytest import utils # pylint: disable=E0611 from tests import fs_helper +from fs_helper import DiskHelper, FsHelper from test_android import test_abootimg def mkdir_cond(dirname): @@ -45,7 +46,6 @@ def setup_bootmenu_image(ubman): This is modelled on Armbian 22.08 Jammy """ mmc_dev = 4 - fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0x83) script = '''# DO NOT EDIT THIS FILE # @@ -121,7 +121,9 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} # Recompile with: # mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr ''' - bootdir = os.path.join(mnt, 'boot') + fsh = FsHelper(ubman.config, 'ext4', 18, 'mmc') + fsh.setup() + bootdir = os.path.join(fsh.srcdir, 'boot') mkdir_cond(bootdir) cmd_fname = os.path.join(bootdir, 'boot.cmd') scr_fname = os.path.join(bootdir, 'boot.scr') @@ -150,36 +152,30 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} utils.run_and_log( ubman, f'echo here {kernel} {symlink}') os.symlink(kernel, symlink) + fsh.mk_fs() + img = DiskHelper(ubman.config, mmc_dev, 'mmc', True) + img.add_fs(fsh, DiskHelper.EXT4) + img.create() + fsh.cleanup() - fsfile = 'ext18M.img' - utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') - utils.run_and_log(ubman, f'mkfs.ext4 {fsfile} -d {mnt}') - copy_partition(ubman, fsfile, fname) - utils.run_and_log(ubman, f'rm -rf {mnt}') - utils.run_and_log(ubman, f'rm -f {fsfile}') -def setup_bootflow_image(ubman): - """Create a 20MB disk image with a single FAT partition""" - mmc_dev = 1 - fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0xc, second_part=True) +def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, + script): + """Create a 20MB disk image with a single FAT partition - vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' - initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' - dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' - script = '''# extlinux.conf generated by appliance-creator -ui menu.c32 -menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. -menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. -menu hidden -timeout 20 -totaltimeout 600 + Args: + ubman (ConsoleBase): Console to use + devnum (int): Device number to use, e.g. 1 + basename (str): Base name to use in the filename, e.g. 'mmc' + vmlinux (str): Kernel filename + initrd (str): Ramdisk filename + dtbdir (str or None): Devicetree filename + script (str): Script to place in the extlinux.conf file + """ + fsh = FsHelper(ubman.config, 'vfat', 18, prefix=basename) + fsh.setup() -label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) - kernel /%s - append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB - fdtdir /%s/ - initrd /%s''' % (vmlinux, dtbdir, initrd) - ext = os.path.join(mnt, 'extlinux') + ext = os.path.join(fsh.srcdir, 'extlinux') mkdir_cond(ext) conf = os.path.join(ext, 'extlinux.conf') @@ -191,24 +187,57 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) fd.write(gzip.compress(b'vmlinux')) mkimage = ubman.config.build_dir + '/tools/mkimage' utils.run_and_log( - ubman, f'{mkimage} -f auto -d {inf} {os.path.join(mnt, vmlinux)}') + ubman, f'{mkimage} -f auto -d {inf} {os.path.join(fsh.srcdir, vmlinux)}') - with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd: + with open(os.path.join(fsh.srcdir, initrd), 'w', encoding='ascii') as fd: print('initrd', file=fd) - mkdir_cond(os.path.join(mnt, dtbdir)) + if dtbdir: + mkdir_cond(os.path.join(fsh.srcdir, dtbdir)) - dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb') - utils.run_and_log( - ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') + dtb_file = os.path.join(fsh.srcdir, f'{dtbdir}/sandbox.dtb') + utils.run_and_log( + ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') + + fsh.mk_fs() - fsfile = 'vfat18M.img' - utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') - utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') - utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) - copy_partition(ubman, fsfile, fname) - utils.run_and_log(ubman, f'rm -rf {mnt}') - utils.run_and_log(ubman, f'rm -f {fsfile}') + img = DiskHelper(ubman.config, devnum, basename, True) + img.add_fs(fsh, DiskHelper.VFAT, bootable=True) + + ext4 = FsHelper(ubman.config, 'ext4', 1, prefix=basename) + ext4.setup() + ext4.mk_fs() + + img.add_fs(ext4, DiskHelper.EXT4) + img.create() + fsh.cleanup() + +def setup_fedora_image(ubman, devnum, basename): + """Create a 20MB Fedora disk image with a single FAT partition + + Args: + ubman (ConsoleBase): Console to use + devnum (int): Device number to use, e.g. 1 + basename (str): Base name to use in the filename, e.g. 'mmc' + """ + vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' + initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' + dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' + script = '''# extlinux.conf generated by appliance-creator +ui menu.c32 +menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. +menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. +menu hidden +timeout 20 +totaltimeout 600 + +label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) + kernel /%s + append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB + fdtdir /%s/ + initrd /%s''' % (vmlinux, dtbdir, initrd) + setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, + script) def setup_cros_image(ubman): """Create a 20MB disk image with ChromiumOS partitions""" @@ -513,8 +542,8 @@ def test_ut_dm_init(ubman): utils.run_and_log( ubman, f'sfdisk {fn}', stdin=b'type=83') - fs_helper.mk_fs(ubman.config, 'ext2', 0x200000, '2MB', None) - fs_helper.mk_fs(ubman.config, 'fat32', 0x100000, '1MB', None) + FsHelper(ubman.config, 'ext2', 2, '2MB').mk_fs() + FsHelper(ubman.config, 'fat32', 1, '1MB').mk_fs() mmc_dev = 6 fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') @@ -532,11 +561,9 @@ def test_ut_dm_init(ubman): def setup_efi_image(ubman): """Create a 20MB disk image with an EFI app on it""" devnum = 1 - basename = 'flash' - fname, mnt = fs_helper.setup_image(ubman, devnum, 0xc, second_part=True, - basename=basename) - - efi_dir = os.path.join(mnt, 'EFI') + fsh = FsHelper(ubman.config, 'vfat', 18, 'flash') + fsh.setup() + efi_dir = os.path.join(fsh.srcdir, 'EFI') mkdir_cond(efi_dir) bootdir = os.path.join(efi_dir, 'BOOT') mkdir_cond(bootdir) @@ -546,66 +573,53 @@ def setup_efi_image(ubman): with open(efi_src, 'rb') as inf: with open(efi_dst, 'wb') as outf: outf.write(inf.read()) - fsfile = 'vfat18M.img' - utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') - utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') - utils.run_and_log(ubman, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) - copy_partition(ubman, fsfile, fname) - utils.run_and_log(ubman, f'rm -rf {mnt}') - utils.run_and_log(ubman, f'rm -f {fsfile}') + + fsh.mk_fs() + + img = DiskHelper(ubman.config, devnum, 'flash', True) + img.add_fs(fsh, DiskHelper.VFAT) + img.create() + fsh.cleanup() + def setup_rauc_image(ubman): """Create a 40MB disk image with an A/B RAUC system on it""" mmc_dev = 10 - fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') - mnt = ubman.config.persistent_data_dir - - spec = 'type=c, size=8M, start=1M, bootable\n' \ - 'type=83, size=10M\n' \ - 'type=c, size=8M, bootable\n' \ - 'type=83, size=10M' - utils.run_and_log(ubman, f'qemu-img create {fname} 40M') - utils.run_and_log(ubman, ['sh', '-c', f'printf "{spec}" | sfdisk {fname}']) + boot = FsHelper(ubman.config, 'fat32', 8, 'rauc_boot') + boot.setup() # Generate boot script script = '# dummy boot script' - bootdir = os.path.join(mnt, 'boot') - utils.run_and_log(ubman, f'mkdir -p {bootdir}') - cmd_fname = os.path.join(bootdir, 'boot.cmd') - scr_fname = os.path.join(bootdir, 'boot.scr') + cmd_fname = os.path.join(boot.srcdir, 'boot.cmd') + scr_fname = os.path.join(boot.srcdir, 'boot.scr') with open(cmd_fname, 'w', encoding='ascii') as outf: print(script, file=outf) mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') utils.run_and_log( ubman, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}') - utils.run_and_log(ubman, f'rm -f {cmd_fname}') - - # Generate empty rootfs - rootdir = os.path.join(mnt, 'root') - utils.run_and_log(ubman, f'mkdir -p {rootdir}') + os.remove(cmd_fname) + boot.mk_fs() - # Create boot filesystem image with boot script in it and copy to disk image - fsfile = f'rauc_boot.fat32.img' - fs_helper.mk_fs(ubman.config, 'fat32', 0x800000, fsfile.split('.')[0], bootdir) - utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=1 conv=notrunc') - utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=19 conv=notrunc') - utils.run_and_log(ubman, f'rm -f {scr_fname}') + root = FsHelper(ubman.config, 'ext4', 10, 'rauc_root') + root.mk_fs() - # Create empty root filesystem image and copy to disk image - fsfile = f'rauc_root.ext4.img' - fs_helper.mk_fs(ubman.config, 'ext4', 0xa00000, fsfile.split('.')[0], rootdir) - utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=9 conv=notrunc') - utils.run_and_log(ubman, f'dd if={mnt}/{fsfile} of=mmc{mmc_dev}.img bs=1M seek=27 conv=notrunc') - utils.run_and_log(ubman, f'rm -f {fsfile}') + img = DiskHelper(ubman.config, mmc_dev, 'mmc', True) + img.add_fs(boot, DiskHelper.VFAT, bootable=True) + img.add_fs(root, DiskHelper.EXT4) + img.add_fs(boot, DiskHelper.VFAT, bootable=True) + img.add_fs(root, DiskHelper.EXT4) + img.create() + boot.cleanup() + root.cleanup() @pytest.mark.buildconfigspec('cmd_bootflow') @pytest.mark.buildconfigspec('sandbox') def test_ut_dm_init_bootstd(ubman): """Initialise data for bootflow tests""" - setup_bootflow_image(ubman) + setup_fedora_image(ubman, 1, 'mmc') setup_bootmenu_image(ubman) setup_cedit_file(ubman) setup_cros_image(ubman) |
