Improve pytest runtime
cover Improve pytest runtime
Hey all,
One thing that Simon Glass has noted is that our pytest run time keeps getting longer. Looking at:
https://source.denx.de/u-boot/u-boot/-/pipelines/25011/test_report?job_name=sandbox%20test.py%3A%20%5Bfast%20amd64%5D
we can see that some of the longest running tests are a little puzzling. It turns out that we have two ways of making filesystem images without requiring root access and one of them is significantly slower than the other. This series changes us from using virt-make-fs to only using the mk_fs helper that currently resides in test_ut.py which uses standard userspace tools. The final result can be seen at:
https://source.denx.de/u-boot/u-boot/-/pipelines/25015/test_report?job_name=sandbox%20test.py%3A%20%5Bfast%20amd64%5D
and the tests changed here now run much quicker.
Signature · 1 line
Tom
PATCH 1/10 test/py: Rework test_cat to not use virt-make-fs
The problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
--- test/py/tests/test_cat.py | 37 ++++++++++++++++++++++++++++++ test/py/tests/test_cat/conftest.py | 36 ----------------------------- test/py/tests/test_cat/test_cat.py | 20 ---------------- 3 files changed, 37 insertions(+), 56 deletions(-) create mode 100644 test/py/tests/test_cat.py delete mode 100644 test/py/tests/test_cat/conftest.py delete mode 100644 test/py/tests/test_cat/test_cat.py
test/py/tests/test_cat.py new file +37 -0
@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ + +""" Unit test for cat command +""" + +import pytest +from subprocess import call, check_call, CalledProcessError +from tests import fs_helper + [email protected]('sandbox') [email protected]('cmd_cat') +def test_cat(u_boot_console): + """ Unit test for cat + + Args: + u_boot_console -- U-Boot console + """ + try: + scratch_dir = u_boot_console.config.persistent_data_dir + '/scratch' + + check_call('mkdir -p %s' % scratch_dir, shell=True) + + with open(scratch_dir + '/hello', 'w', encoding = 'ascii') as file: + file.write('hello world\n') + + cat_data = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, + 'test_cat', scratch_dir) + response = u_boot_console.run_command_list([ f'host bind 0 {cat_data}', + 'cat host 0 hello']) + assert 'hello world' in response + except CalledProcessError as err: + pytest.skip('Preparing test_cat image failed') + call('rm -f %s' % cat_data, shell=True) + return + finally: + call('rm -rf %s' % scratch_dir, shell=True) + call('rm -f %s' % cat_data, shell=True)
test/py/tests/test_cat/conftest.py deleted +0 -36
@@ -1,36 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -"""Fixture for cat command test -""" - -import os -import shutil -from subprocess import check_call, CalledProcessError -import pytest - [email protected](scope='session') -def cat_data(u_boot_config): - """Set up a file system to be used in cat tests - - Args: - u_boot_config -- U-Boot configuration. - """ - mnt_point = u_boot_config.persistent_data_dir + '/test_cat' - image_path = u_boot_config.persistent_data_dir + '/cat.img' - - try: - os.mkdir(mnt_point, mode = 0o755) - - with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: - file.write('hello world\n') - - check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', - shell=True) - - yield image_path - except CalledProcessError: - pytest.skip('Setup failed') - finally: - shutil.rmtree(mnt_point) - if os.path.exists(image_path): - os.remove(image_path)
test/py/tests/test_cat/test_cat.py deleted +0 -20
@@ -1,20 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -""" Unit test for cat command -""" - -import pytest - [email protected]('sandbox') [email protected]('cmd_cat') -def test_cat(u_boot_console, cat_data): - """ Unit test for cat - - Args: - u_boot_console -- U-Boot console - cat_data -- Path to the disk image used for testing. - """ - response = u_boot_console.run_command_list([ - f'host bind 0 {cat_data}', - 'cat host 0 hello']) - assert 'hello world' in response
Signature · 1 line
2.43.0
PATCH 2/10 test/py: Rework test_xxd to not use virt-make-fs
In reply to Tom RiniThe problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
--- test/py/tests/test_xxd.py | 40 ++++++++++++++++++++++++++++++ test/py/tests/test_xxd/conftest.py | 36 --------------------------- test/py/tests/test_xxd/test_xxd.py | 23 ----------------- 3 files changed, 40 insertions(+), 59 deletions(-) create mode 100644 test/py/tests/test_xxd.py delete mode 100644 test/py/tests/test_xxd/conftest.py delete mode 100644 test/py/tests/test_xxd/test_xxd.py
test/py/tests/test_xxd.py new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0+ + +""" Unit test for xxd command +""" + +import pytest +from subprocess import call, check_call, CalledProcessError +from tests import fs_helper + [email protected]('sandbox') [email protected]('cmd_xxd') +def test_xxd(u_boot_console): + """ Unit test for xxd + + Args: + u_boot_console -- U-Boot console + """ + try: + scratch_dir = u_boot_console.config.persistent_data_dir + '/scratch' + + check_call('mkdir -p %s' % scratch_dir, shell=True) + + with open(scratch_dir + '/hello', 'w', encoding = 'ascii') as file: + file.write('hello world\n\x00\x01\x02\x03\x04\x05') + + xxd_data = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, + 'test_xxd', scratch_dir) + response = u_boot_console.run_command_list([ f'host bind 0 {xxd_data}', + 'xxd host 0 hello']) + + assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \ + '00000010: 04 05 ..' \ + in response + except CalledProcessError as err: + pytest.skip('Preparing test_xxd image failed') + call('rm -f %s' % xxd_data, shell=True) + return + finally: + call('rm -rf %s' % scratch_dir, shell=True) + call('rm -f %s' % xxd_data, shell=True)
test/py/tests/test_xxd/conftest.py deleted +0 -36
@@ -1,36 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -"""Fixture for xxd command test -""" - -import os -import shutil -from subprocess import check_call, CalledProcessError -import pytest - [email protected](scope='session') -def xxd_data(u_boot_config): - """Set up a file system to be used in xxd tests - - Args: - u_boot_config -- U-Boot configuration. - """ - mnt_point = u_boot_config.persistent_data_dir + '/test_xxd' - image_path = u_boot_config.persistent_data_dir + '/xxd.img' - - try: - os.mkdir(mnt_point, mode = 0o755) - - with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: - file.write('hello world\n\x00\x01\x02\x03\x04\x05') - - check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', - shell=True) - - yield image_path - except CalledProcessError: - pytest.skip('Setup failed') - finally: - shutil.rmtree(mnt_point) - if os.path.exists(image_path): - os.remove(image_path)
test/py/tests/test_xxd/test_xxd.py deleted +0 -23
@@ -1,23 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -""" Unit test for xxd command -""" - -import pytest - [email protected]('sandbox') [email protected]('cmd_xxd') -def test_xxd(u_boot_console, xxd_data): - """ Unit test for xxd - - Args: - u_boot_console -- U-Boot console - xxd_data -- Path to the disk image used for testing. - """ - response = u_boot_console.run_command_list([ - f'host bind 0 {xxd_data}', - 'xxd host 0 hello']) - - assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \ - '00000010: 04 05 ..' \ - in response
Signature · 1 line
2.43.0
PATCH 3/10 test/py/tests: Move "setup_image" from test_ut.py to fs_helper.py
In reply to Tom RiniThe generic function in test_ut.py to create a disk image with partition table can be useful outside of test_ut.py so move it to be available more clearly.
To make this a bit more easily used library function, make use of check_call directly rather than calling things though u_boot_utils. In turn, to more easily handle stdin here, use the shell "printf" utility to pass sfdisk the specification to create as we do not have an actual file descriptor to use here.
---
Cc: Simon Glass <[email protected]>
--- test/py/tests/fs_helper.py | 34 +++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 39 +++++--------------------------------- 2 files changed, 39 insertions(+), 34 deletions(-)
test/py/tests/fs_helper.py +34 -0
@@ -69,6 +69,40 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): call(f'rm -f {fs_img}', shell=True) raise +def setup_image(config, devnum, part_type, img_size=20, second_part=False, + basename='mmc'): + """Create a disk image with a single partition + + Args: + config (u_boot_config): U-Boot configuration + devnum (int): Device number to use, e.g. 1 + part_type (int): Partition type, e.g. 0xc for FAT32 + img_size (int): Image size in MiB + 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 scratch directory + """ + fname = os.path.join(config.source_dir, f'{basename}{devnum}.img') + mnt = os.path.join(config.persistent_data_dir, 'scratch') + + spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' + if second_part: + spec += '\ntype=c' + + try: + check_call(f'mkdir -p {mnt}', shell=True) + check_call(f'qemu-img create {fname} 20M', shell=True) + check_call(f'printf "{spec}" | sfdisk {fname}', shell=True) + except CalledProcessError: + call(f'rm -f {fname}', shell=True) + raise + + return fname, mnt + # Just for trying out if __name__ == "__main__": import collections
test/py/tests/test_ut.py +5 -34
@@ -27,43 +27,13 @@ def mkdir_cond(dirname): if not os.path.exists(dirname): os.mkdir(dirname) -def setup_image(cons, devnum, part_type, img_size=20, second_part=False, - basename='mmc'): - """Create a disk image with a single partition - - Args: - cons (ConsoleBase): Console to use - devnum (int): Device number to use, e.g. 1 - part_type (int): Partition type, e.g. 0xc for FAT32 - img_size (int): Image size in MiB - 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 scratch directory - """ - fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img') - mnt = os.path.join(cons.config.persistent_data_dir, 'scratch') - mkdir_cond(mnt) - - spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' - if second_part: - spec += '\ntype=c' - - u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M') - u_boot_utils.run_and_log(cons, f'sfdisk {fname}', - stdin=spec.encode('utf-8')) - return fname, mnt - def setup_bootmenu_image(cons): """Create a 20MB disk image with a single ext4 partition This is modelled on Armbian 22.08 Jammy """ mmc_dev = 4 - fname, mnt = setup_image(cons, mmc_dev, 0x83) + fname, mnt = fs_helper.setup_image(cons.config, mmc_dev, 0x83) script = '''# DO NOT EDIT THIS FILE #
@@ -179,7 +149,8 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} def setup_bootflow_image(cons): """Create a 20MB disk image with a single FAT partition""" mmc_dev = 1 - fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True) + fname, mnt = fs_helper.setup_image(cons.config, mmc_dev, 0xc, + second_part=True) vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
@@ -545,8 +516,8 @@ 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) + fname, mnt = fs_helper.setup_image(cons.config, devnum, 0xc, + second_part=True, basename=basename) efi_dir = os.path.join(mnt, 'EFI') mkdir_cond(efi_dir)
Signature · 1 line
2.43.0
PATCH 4/10 test/py: Fix two problems with setup_image
In reply to Tom RiniThere are two issues with this function currently. One is that while we can be passed an image size to use, we always called qemu-img with 20M as the size. Fix this by using the size parameter. The second issue is that reserving 2MiB at the end is not enough room to add a GPT (and the backup GPT that goes on the end) so reserve 4MiB off the end and make all of the existing callers use 16M rather than 18M.
---
Cc: Simon Glass <[email protected]>
--- test/py/tests/fs_helper.py | 4 ++-- test/py/tests/test_ut.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-)
test/py/tests/fs_helper.py +2 -2
@@ -89,13 +89,13 @@ def setup_image(config, devnum, part_type, img_size=20, second_part=False, fname = os.path.join(config.source_dir, f'{basename}{devnum}.img') mnt = os.path.join(config.persistent_data_dir, 'scratch') - spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable' + spec = f'type={part_type:x}, size={img_size - 4}M, start=1M, bootable' if second_part: spec += '\ntype=c' try: check_call(f'mkdir -p {mnt}', shell=True) - check_call(f'qemu-img create {fname} 20M', shell=True) + check_call(f'qemu-img create {fname} {img_size}M', shell=True) check_call(f'printf "{spec}" | sfdisk {fname}', shell=True) except CalledProcessError: call(f'rm -f {fname}', shell=True)
test/py/tests/test_ut.py +6 -6
@@ -139,8 +139,8 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} cons, f'echo here {kernel} {symlink}') os.symlink(kernel, symlink) - fsfile = 'ext18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + fsfile = 'ext16M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 16M {fsfile}') u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}') u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1') u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
@@ -191,8 +191,8 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) u_boot_utils.run_and_log( cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') - fsfile = 'vfat18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + fsfile = 'vfat16M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 16M {fsfile}') u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
@@ -529,8 +529,8 @@ def setup_efi_image(cons): with open(efi_src, 'rb') as inf: with open(efi_dst, 'wb') as outf: outf.write(inf.read()) - fsfile = 'vfat18M.img' - u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}') + fsfile = 'vfat16M.img' + u_boot_utils.run_and_log(cons, f'fallocate -l 16M {fsfile}') u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}') u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
Signature · 1 line
2.43.0
PATCH 5/10 test/py: Rework test_efi_bootmgr to not use virt-make-fs
In reply to Tom RiniThe problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
---
The default git settings don't detect the rename so well here because of all of the spacing changes as well. I found I had to use "git show -M05 -w" in order to get something that confirmed the test itself wasn't changed.
--- test/py/tests/test_efi_bootmgr.py | 71 +++++++++++++++++++ test/py/tests/test_efi_bootmgr/conftest.py | 38 ---------- .../test_efi_bootmgr/test_efi_bootmgr.py | 44 ------------ 3 files changed, 71 insertions(+), 82 deletions(-) create mode 100644 test/py/tests/test_efi_bootmgr.py delete mode 100644 test/py/tests/test_efi_bootmgr/conftest.py delete mode 100644 test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
test/py/tests/test_efi_bootmgr.py new file +71 -0
@@ -0,0 +1,71 @@ +# SPDX-License-Identifier: GPL-2.0+ +""" Unit test for UEFI bootmanager +""" + +import shutil +import pytest +from subprocess import call, check_call, CalledProcessError +from tests import fs_helper + [email protected]('sandbox') [email protected]('cmd_efidebug') [email protected]('cmd_bootefi_bootmgr') [email protected] +def test_efi_bootmgr(u_boot_console): + """ Unit test for UEFI bootmanager + The efidebug command is used to set up UEFI load options. + The bootefi bootmgr loads initrddump.efi as a payload. + The crc32 of the loaded initrd.img is checked + + Args: + u_boot_console -- U-Boot console + """ + try: + efi_bootmgr_data, mnt = fs_helper.setup_image(u_boot_console.config, 0, + 0xc, + basename='test_efi_bootmgr') + + with open(mnt + '/initrd-1.img', 'w', encoding = 'ascii') as file: + file.write("initrd 1") + + with open(mnt + '/initrd-2.img', 'w', encoding = 'ascii') as file: + file.write("initrd 2") + + shutil.copyfile(u_boot_console.config.build_dir + '/lib/efi_loader/initrddump.efi', + mnt + '/initrddump.efi') + + fsfile = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, + 'test_efi_bootmgr', mnt) + check_call(f'dd if={fsfile} of={efi_bootmgr_data} bs=1M seek=1', shell=True) + + u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data}') + + u_boot_console.run_command(cmd = 'efidebug boot add ' \ + '-b 0001 label-1 host 0:1 initrddump.efi ' \ + '-i host 0:1 initrd-1.img -s nocolor') + u_boot_console.run_command(cmd = 'efidebug boot dump') + u_boot_console.run_command(cmd = 'efidebug boot order 0001') + u_boot_console.run_command(cmd = 'bootefi bootmgr') + response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False) + assert 'crc32: 0x181464af' in response + u_boot_console.run_command(cmd = 'exit', wait_for_echo=False) + + u_boot_console.run_command(cmd = 'efidebug boot add ' \ + '-B 0002 label-2 host 0:1 initrddump.efi ' \ + '-I host 0:1 initrd-2.img -s nocolor') + u_boot_console.run_command(cmd = 'efidebug boot dump') + u_boot_console.run_command(cmd = 'efidebug boot order 0002') + u_boot_console.run_command(cmd = 'bootefi bootmgr') + response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False) + assert 'crc32: 0x811d3515' in response + u_boot_console.run_command(cmd = 'exit', wait_for_echo=False) + + u_boot_console.run_command(cmd = 'efidebug boot rm 0001') + u_boot_console.run_command(cmd = 'efidebug boot rm 0002') + except CalledProcessError as err: + pytest.skip('Preparing test_efi_bootmgr image failed') + call('rm -f %s' % efi_bootmgr_data, shell=True) + return + finally: + call('rm -rf %s' % mnt, shell=True) + call('rm -f %s' % efi_bootmgr_data, shell=True)
test/py/tests/test_efi_bootmgr/conftest.py deleted +0 -38
@@ -1,38 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -"""Fixture for UEFI bootmanager test.""" - -import os -import shutil -from subprocess import check_call -import pytest - [email protected](scope='session') -def efi_bootmgr_data(u_boot_config): - """Set up a file system to be used in UEFI bootmanager tests. - - Args: - u_boot_config -- U-Boot configuration. - - Return: - A path to disk image to be used for testing - """ - mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr' - image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr.img' - - shutil.rmtree(mnt_point, ignore_errors=True) - os.mkdir(mnt_point, mode = 0o755) - - with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file: - file.write("initrd 1") - - with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file: - file.write("initrd 2") - - shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi', - mnt_point + '/initrddump.efi') - - check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', - shell=True) - - return image_path
test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py deleted +0 -44
44 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 6/10 test/py: Rework test_eficonfig to not use virt-make-fs
In reply to Tom RiniThe problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
As this test already had a number of internal functions, add a prepare_image function to do this part of the test.
---
I noted to Heinrich in private that this test is currently disabled. I re-enabled it locally to verify that the disk image is created correctly still.
---
.../{test_eficonfig => }/test_eficonfig.py | 53 ++++++++++++++++---
test/py/tests/test_eficonfig/conftest.py | 40 --------------
2 files changed, 46 insertions(+), 47 deletions(-)
rename test/py/tests/{test_eficonfig => }/test_eficonfig.py (89%)
delete mode 100644 test/py/tests/test_eficonfig/conftest.pytest/py/tests/test_eficonfig.py renamed from test/py/tests/test_eficonfig/test_eficonfig.py +46 -7
@@ -2,13 +2,57 @@ """ Unit test for UEFI menu-driven configuration """ +import pytest +import shutil import pytest import time +from subprocess import call, check_call, CalledProcessError +from tests import fs_helper @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_eficonfig') @pytest.mark.buildconfigspec('cmd_bootefi_bootmgr') -def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): +def test_efi_eficonfig(u_boot_console): + + def prepare_image(u_boot_config): + """Set up a file system to be used in UEFI "eficonfig" command + tests. This creates a disk image with the following files: + initrd-1.img + initrd-2.img + initrddump.efi + + Args: + u_boot_config -- U-Boot configuration. + + Return: + A path to disk image to be used for testing + + """ + try: + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, + 0xc, + basename='test_eficonfig') + + with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file: + file.write("initrd 1") + + with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file: + file.write("initrd 2") + + shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi', + mnt_point + '/initrddump.efi') + + fsfile = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, + 'test_eficonfig', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) + + yield image_path + except CalledProcessError as err: + pytest.skip('Preparing test_eficonfig image failed') + call('rm -f %s' % image_path, shell=True) + finally: + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s' % image_path, shell=True) def send_user_input_and_wait(user_str, expect_str): time.sleep(0.1) # TODO: does not work correctly without sleep
@@ -57,12 +101,6 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): Args: u_boot_console -- U-Boot console - efi__data -- Path to the disk image used for testing. - Test disk image has following files. - initrd-1.img - initrd-2.img - initrddump.efi - """ # This test passes for unknown reasons in the bowels of U-Boot. It needs to # be replaced with a unit test.
@@ -71,6 +109,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # Restart the system to clean the previous state u_boot_console.restart_uboot() + efi_eficonfig_data = prepare_image(u_boot_console.config) with u_boot_console.temporary_timeout(500): # # Test Case 1: Check the menu is displayed
test/py/tests/test_eficonfig/conftest.py deleted +0 -40
@@ -1,40 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -"""Fixture for UEFI eficonfig test -""" - -import os -import shutil -from subprocess import check_call -import pytest - [email protected](scope='session') -def efi_eficonfig_data(u_boot_config): - """Set up a file system to be used in UEFI "eficonfig" command - tests - - Args: - u_boot_config -- U-Boot configuration. - - Return: - A path to disk image to be used for testing - """ - mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig' - image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img' - - shutil.rmtree(mnt_point, ignore_errors=True) - os.mkdir(mnt_point, mode = 0o755) - - with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file: - file.write("initrd 1") - - with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file: - file.write("initrd 2") - - shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi', - mnt_point + '/initrddump.efi') - - check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', - shell=True) - - return image_path
Signature · 1 line
2.43.0
Re: [PATCH 06/10] test/py: Rework test_eficonfig to not use virt-make-fs
Hi Tom,
I've never really looked at our fs helper functions but this looks reasonable
Quoted 158 lines · Tom Rini
The problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the
fs_helperfunctions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.As this test already had a number of internal functions, add a
prepare_imagefunction to do this part of the test.Signed-off-by Tom Rini <[email protected]>---
I noted to Heinrich in private that this test is currently disabled. I re-enabled it locally to verify that the disk image is created correctly still.Cc Ilias Apalodimas <[email protected]>Cc Heinrich Schuchardt <[email protected]>--- .../{test_eficonfig => }/test_eficonfig.py | 53 ++++++++++++++++--- test/py/tests/test_eficonfig/conftest.py | 40 -------------- 2 files changed, 46 insertions(+), 47 deletions(-) rename test/py/tests/{test_eficonfig => }/test_eficonfig.py (89%) delete mode 100644 test/py/tests/test_eficonfig/conftest.pytest/py/tests/test_eficonfig.py renamed from test/py/tests/test_eficonfig/test_eficonfig.py +46
-7@@ -2,13 +2,57 @@ """ Unit test for UEFI menu-driven configuration """ +import pytest +import shutil import pytest import time +from subprocess import call, check_call, CalledProcessError +from tests import fs_helper @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_eficonfig') @pytest.mark.buildconfigspec('cmd_bootefi_bootmgr') -def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): +def test_efi_eficonfig(u_boot_console): + + def prepare_image(u_boot_config): + """Set up a file system to be used in UEFI "eficonfig" command + tests. This creates a disk image with the following files: + initrd-1.img + initrd-2.img + initrddump.efi + + Args: + u_boot_config -- U-Boot configuration. + + Return: + A path to disk image to be used for testing + + """ + try: + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, + 0xc, + basename='test_eficonfig') + + with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file: + file.write("initrd 1") + + with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file: + file.write("initrd 2") + + shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi', + mnt_point + '/initrddump.efi') + + fsfile = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, + 'test_eficonfig', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) + + yield image_path + except CalledProcessError as err: + pytest.skip('Preparing test_eficonfig image failed') + call('rm -f %s' % image_path, shell=True) + finally: + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s' % image_path, shell=True) def send_user_input_and_wait(user_str, expect_str): time.sleep(0.1) # TODO: does not work correctly without sleep@@ -57,12 +101,6 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): Args: u_boot_console -- U-Boot console - efi__data -- Path to the disk image used for testing. - Test disk image has following files. - initrd-1.img - initrd-2.img - initrddump.efi - """ # This test passes for unknown reasons in the bowels of U-Boot. It needs to # be replaced with a unit test.@@ -71,6 +109,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # Restart the system to clean the previous state u_boot_console.restart_uboot() + efi_eficonfig_data = prepare_image(u_boot_console.config) with u_boot_console.temporary_timeout(500): # # Test Case 1: Check the menu is displayedtest/py/tests/test_eficonfig/conftest.py deleted +0
-41@@ -1,40 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ - -"""Fixture for UEFI eficonfig test -""" - -import os -import shutil -from subprocess import check_call -import pytest - [email protected](scope='session') -def efi_eficonfig_data(u_boot_config): - """Set up a file system to be used in UEFI "eficonfig" command - tests - - Args: - u_boot_config -- U-Boot configuration. - - Return: - A path to disk image to be used for testing - """ - mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig' - image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img' - - shutil.rmtree(mnt_point, ignore_errors=True) - os.mkdir(mnt_point, mode = 0o755) - - with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file: - file.write("initrd 1") - - with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file: - file.write("initrd 2") - - shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi', - mnt_point + '/initrddump.efi') - - check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', - shell=True) - - return image_path --
Quoted 2 lines
2.43.0
PATCH 7/10 test/py: Rework test_efi_capsule to not use virt-make-fs
In reply to Tom RiniThe problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
The main change here is that our mount point directory has changed from "test_efi_capsule" to "scratch" and so we need to update other functions too. As the disk image that we get created doesn't have a GPT, invoke sgdisk to do a conversion first.
---
I tested this as much as I could with an empty board/sandbox/capsule_pub_esl_good.esl which did show me a few issues along the way so I am reasonably confident, but this really does need to be tested on a platform where all tests are run for real.
--- .../tests/test_efi_capsule/capsule_common.py | 2 +- test/py/tests/test_efi_capsule/conftest.py | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-)
test/py/tests/test_efi_capsule/capsule_common.py +1 -1
@@ -136,7 +136,7 @@ def do_reboot_dtb_specified(u_boot_config, u_boot_console, dtb_filename): u_boot_console -- A console connection to U-Boot. dtb_filename -- DTB file name. """ - mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule' + mnt_point = u_boot_config.persistent_data_dir + '/scratch' u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \ + f'/{dtb_filename}' u_boot_console.restart_uboot()
test/py/tests/test_efi_capsule/conftest.py +13 -8
@@ -7,6 +7,7 @@ import os from subprocess import call, check_call, CalledProcessError +from tests import fs_helper import pytest from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR, EFITOOLS_PATH
@@ -21,12 +22,12 @@ def efi_capsule_data(request, u_boot_config): request -- Pytest request object. u_boot_config -- U-Boot configuration. """ - 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 - image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img' - try: + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_capsule') + data_dir = mnt_point + CAPSULE_DATA_DIR + install_dir = mnt_point + CAPSULE_INSTALL_DIR + # Create a target device check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
@@ -88,11 +89,15 @@ def efi_capsule_data(request, u_boot_config): check_call('cp %s/Test* %s' % (u_boot_config.build_dir, data_dir), shell=True) os.environ['PYTHONPATH'] = pythonpath - # Create a disk image with EFI system partition - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' % - (mnt_point, image_path), shell=True) + # Create a 16MiB partition as the EFI system partition in the disk + # image + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_capsule', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) + check_call('sgdisk --mbrtogpt %s' % image_path, shell=True) check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' % image_path, shell=True) + call('rm -f %s' % fsfile, shell=True) except CalledProcessError as exception: pytest.skip('Setup failed: %s' % exception.cmd)
Signature · 1 line
2.43.0
Re: [PATCH 07/10] test/py: Rework test_efi_capsule to not use virt-make-fs
Quoted 88 lines · Tom Rini
The problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the
fs_helperfunctions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.The main change here is that our mount point directory has changed from "
test_efi_capsule" to "scratch" and so we need to update other functions too. As the disk image that we get created doesn't have a GPT, invoke sgdisk to do a conversion first.Signed-off-by Tom Rini <[email protected]>---
I tested this as much as I could with an empty board/sandbox/capsule_pub_esl_good.esl which did show me a few issues along the way so I am reasonably confident, but this really does need to be tested on a platform where all tests are run for real.Cc Ilias Apalodimas <[email protected]>Cc Heinrich Schuchardt <[email protected]>--- .../tests/test_efi_capsule/capsule_common.py | 2 +- test/py/tests/test_efi_capsule/conftest.py | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-)test/py/tests/test_efi_capsule/capsule_common.py +1
-1@@ -136,7 +136,7 @@ def do_reboot_dtb_specified(u_boot_config, u_boot_console, dtb_filename): u_boot_console -- A console connection to U-Boot. dtb_filename -- DTB file name. """ - mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule' + mnt_point = u_boot_config.persistent_data_dir + '/scratch' u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \ + f'/{dtb_filename}' u_boot_console.restart_uboot()test/py/tests/test_efi_capsule/conftest.py +13
-9@@ -7,6 +7,7 @@ import os from subprocess import call, check_call, CalledProcessError +from tests import fs_helper import pytest from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR, EFITOOLS_PATH@@ -21,12 +22,12 @@ def efi_capsule_data(request, u_boot_config): request -- Pytest request object. u_boot_config -- U-Boot configuration. """ - 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 - image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img' - try: + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_capsule') + data_dir = mnt_point + CAPSULE_DATA_DIR + install_dir = mnt_point + CAPSULE_INSTALL_DIR + # Create a target device check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)@@ -88,11 +89,15 @@ def efi_capsule_data(request, u_boot_config): check_call('cp %s/Test* %s' % (u_boot_config.build_dir, data_dir), shell=True) os.environ['PYTHONPATH'] = pythonpath - # Create a disk image with EFI system partition - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' % - (mnt_point, image_path), shell=True) + # Create a 16MiB partition as the EFI system partition in the disk + # image + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_capsule', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) + check_call('sgdisk --mbrtogpt %s' % image_path, shell=True) check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' % image_path, shell=True) + call('rm -f %s' % fsfile, shell=True) except CalledProcessError as exception: pytest.skip('Setup failed: %s' % exception.cmd) --
Quoted 2 lines
2.43.0
PATCH 8/10 test/py: Rework test_efi_secboot to not use virt-make-fs
In reply to Tom RiniThe problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the fs_helper functions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.
---
Cc: Ilias Apalodimas <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
--- test/py/tests/test_efi_secboot/conftest.py | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-)
test/py/tests/test_efi_secboot/conftest.py +15 -17
@@ -5,6 +5,7 @@ """Fixture for UEFI secure boot test.""" from subprocess import call, check_call, CalledProcessError +from tests import fs_helper import pytest from defs import *
@@ -19,13 +20,10 @@ def efi_boot_env(request, u_boot_config): Return: A path to disk image to be used for testing """ - image_path = u_boot_config.persistent_data_dir - image_path = image_path + '/test_efi_secboot.img' try: - mnt_point = u_boot_config.build_dir + '/mnt_efisecure' - check_call('rm -rf {}'.format(mnt_point), shell=True) - check_call('mkdir -p {}'.format(mnt_point), shell=True) + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_secboot') # suffix # *.key: RSA private key in PEM
@@ -123,9 +121,9 @@ def efi_boot_env(request, u_boot_config): % (mnt_point, EFITOOLS_PATH), shell=True) - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format( - mnt_point, image_path), shell=True) - check_call('rm -rf {}'.format(mnt_point), shell=True) + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_secboot', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) except CalledProcessError as exception: pytest.skip('Setup failed: %s' % exception.cmd)
@@ -133,7 +131,8 @@ def efi_boot_env(request, u_boot_config): else: yield image_path finally: - call('rm -f %s' % image_path, shell=True) + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s %s' % (image_path, fsfile), shell=True) # # Fixture for UEFI secure boot test of intermediate certificates
@@ -154,13 +153,10 @@ def efi_boot_env_intca(request, u_boot_config): Return: A path to disk image to be used for testing """ - image_path = u_boot_config.persistent_data_dir - image_path = image_path + '/test_efi_secboot_intca.img' try: - mnt_point = u_boot_config.persistent_data_dir + '/mnt_efi_secboot_intca' - check_call('rm -rf {}'.format(mnt_point), shell=True) - check_call('mkdir -p {}'.format(mnt_point), shell=True) + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_secboot_intca') # Create signature database # PK
@@ -242,8 +238,9 @@ def efi_boot_env_intca(request, u_boot_config): check_call('cd %s; cat TestSub.crt TestRoot.crt > TestSubRoot.crt; %ssbsign --key TestCert.key --cert TestCert.crt --addcert TestSubRoot.crt --out helloworld.efi.signed_abc helloworld.efi' % (mnt_point, SBSIGN_PATH), shell=True) - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format(mnt_point, image_path), shell=True) - check_call('rm -rf {}'.format(mnt_point), shell=True) + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_secboot_intca', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) except CalledProcessError as e: pytest.skip('Setup failed: %s' % e.cmd)
@@ -251,4 +248,5 @@ def efi_boot_env_intca(request, u_boot_config): else: yield image_path finally: - call('rm -f %s' % image_path, shell=True) + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s %s' % (image_path, fsfile), shell=True)
Signature · 1 line
2.43.0
Re: [PATCH 08/10] test/py: Rework test_efi_secboot to not use virt-make-fs
Quoted 101 lines · Tom Rini
The problem with using "virt-make-fs" to make a filesystem image is that it is extremely slow. Switch to using the
fs_helperfunctions we have instead from the filesystem tests as these can add files to images and are significantly faster and still do not require root access.Signed-off-by Tom Rini <[email protected]>---
Cc: Ilias Apalodimas <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>--- test/py/tests/test_efi_secboot/conftest.py | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-)test/py/tests/test_efi_secboot/conftest.py +15
-18@@ -5,6 +5,7 @@ """Fixture for UEFI secure boot test.""" from subprocess import call, check_call, CalledProcessError +from tests import fs_helper import pytest from defs import *@@ -19,13 +20,10 @@ def efi_boot_env(request, u_boot_config): Return: A path to disk image to be used for testing """ - image_path = u_boot_config.persistent_data_dir - image_path = image_path + '/test_efi_secboot.img' try: - mnt_point = u_boot_config.build_dir + '/mnt_efisecure' - check_call('rm -rf {}'.format(mnt_point), shell=True) - check_call('mkdir -p {}'.format(mnt_point), shell=True) + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_secboot') # suffix # *.key: RSA private key in PEM@@ -123,9 +121,9 @@ def efi_boot_env(request, u_boot_config): % (mnt_point, EFITOOLS_PATH), shell=True) - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format( - mnt_point, image_path), shell=True) - check_call('rm -rf {}'.format(mnt_point), shell=True) + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_secboot', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) except CalledProcessError as exception: pytest.skip('Setup failed: %s' % exception.cmd)@@ -133,7 +131,8 @@ def efi_boot_env(request, u_boot_config): else: yield image_path finally: - call('rm -f %s' % image_path, shell=True) + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s %s' % (image_path, fsfile), shell=True) # # Fixture for UEFI secure boot test of intermediate certificates@@ -154,13 +153,10 @@ def efi_boot_env_intca(request, u_boot_config): Return: A path to disk image to be used for testing """ - image_path = u_boot_config.persistent_data_dir - image_path = image_path + '/test_efi_secboot_intca.img' try: - mnt_point = u_boot_config.persistent_data_dir + '/mnt_efi_secboot_intca' - check_call('rm -rf {}'.format(mnt_point), shell=True) - check_call('mkdir -p {}'.format(mnt_point), shell=True) + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, 0xc, + basename='test_efi_secboot_intca') # Create signature database # PK@@ -242,8 +238,9 @@ def efi_boot_env_intca(request, u_boot_config): check_call('cd %s; cat TestSub.crt TestRoot.crt > TestSubRoot.crt; %ssbsign --key TestCert.key --cert TestCert.crt --addcert TestSubRoot.crt --out helloworld.efi.signed_abc helloworld.efi' % (mnt_point, SBSIGN_PATH), shell=True) - check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format(mnt_point, image_path), shell=True) - check_call('rm -rf {}'.format(mnt_point), shell=True) + fsfile = fs_helper.mk_fs(u_boot_config, 'vfat', 0x1000000, + 'test_efi_secboot_intca', mnt_point) + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True) except CalledProcessError as e: pytest.skip('Setup failed: %s' % e.cmd)@@ -251,4 +248,5 @@ def efi_boot_env_intca(request, u_boot_config): else: yield image_path finally: - call('rm -f %s' % image_path, shell=True) + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s %s' % (image_path, fsfile), shell=True) --
Quoted 2 lines
2.43.0
PATCH 9/10 doc/develop/py_testing.rst: Update section on filesystem images
In reply to Tom RiniNow that we have no users of "virt-make-fs" nor users of "sudo" for creating disk images update the documentation. We remove packages that are no longer required (and related text) as well as be firm in our wording around not using "sudo".
---
Cc: Heinrich Schuchardt <[email protected]>
--- doc/develop/py_testing.rst | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
doc/develop/py_testing.rst +3 -19
@@ -41,13 +41,11 @@ will be required. The following is an incomplete list: * dfu-util * dtc * openssl -* sudo OR guestmount * e2fsprogs * util-linux * coreutils * dosfstools * efitools -* guestfs-tools * mount * mtools * sbsigntool
@@ -64,23 +62,9 @@ The test script supports either: physical board, attach to the board's console stream, and reset the board. Further details are described later. -The usage of command 'sudo' should be avoided in tests. To create disk images -use command virt-make-fs which is provided by package guestfs-tools. This -command creates a virtual machine with QEMU in which the disk image is -generated. - -Command virt-make-fs needs read access to the current kernel. On Ubuntu only -root has this privilege. You can add a script /etc/initramfs-tools/hooks/vmlinuz -with the following content to overcome the problem: - -.. code-block:: bash - - #!/bin/sh - echo "chmod a+r vmlinuz-*" - chmod a+r /boot/vmlinuz-* - -The script should be chmod 755. It will be invoked whenever the initial RAM file -system is updated. +The usage of the command 'sudo' is not allowed in tests. To create disk images +we have helper functions located in `test/py/tests/fs_helper.py` which is to be +used in any tests that require disk images. Using `virtualenv` to provide requirements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.43.0
Re: [PATCH 09/10] doc/develop/py_testing.rst: Update section on filesystem images
Am 7. März 2025 00:17:11 MEZ schrieb Tom Rini <[email protected]>:
Quoted 42 lines
Now that we have no users of "virt-make-fs" nor users of "sudo" for creating disk images update the documentation. We remove packages that are no longer required (and related text) as well as be firm in our wording around not using "sudo".
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
---doc/develop/py_testing.rst| 22 +++-------------------1 file changed, 3 insertions(+), 19 deletions(-)doc/develop/py_testing.rst +0
-10@@ -41,13 +41,11 @@ will be required. The following is an incomplete list: * dfu-util * dtc * openssl -* sudo OR guestmount * e2fsprogs * util-linux * coreutils * dosfstools * efitools -* guestfs-tools * mount * mtools * sbsigntool@@ -64,23 +62,9 @@ The test script supports either: physical board, attach to the board's console stream, and reset the board. Further details are described later. -The usage of command 'sudo' should be avoided in tests. To create disk images -use command virt-make-fs which is provided by package guestfs-tools. This -command creates a virtual machine with QEMU in which the disk image is -generated. - -Command virt-make-fs needs read access to the current kernel. On Ubuntu only -root has this privilege. You can add a script /etc/initramfs-tools/hooks/vmlinuz -with the following content to overcome the problem:
doc/develop/py_testing.rst The test script supports either: · line 65
Quoted 10 lines
doc/develop/py_testing.rst +1
-9- -.. code-block:: bash - - #!/bin/sh - echo "chmod a+r vmlinuz-*" - chmod a+r /boot/vmlinuz-* - -The script should be chmod 755. It will be invoked whenever the initial RAM file -system is updated. +The usage of the command 'sudo' is not allowed in tests. To create disk images
Can we add the reasoning here:
Using elevated priviledges can lead to security concerns. Furthermore not all users may have administrator rights. Therefore the command 'sudo' must not be used in tests.
doc/develop/py_testing.rst The test script supports either: · line 66
Quoted 1 line
doc/develop/py_testing.rst +1
-0+we have helper functions located in `test/py/tests/fs_helper.py` which is to be
%s/is to be/shall be/
I would rather use 'shall' in accordance with RFC 2119 for clarity.
doc/develop/py_testing.rst The test script supports either: · line 67
Quoted 1 line
doc/develop/py_testing.rst +1
-0+used in any tests that require disk images.
%s/require/require creating/
We have tests coming with prepared images (efi_selftest_disk_image.h). Other tests might require a downloaded ISO (see the pmem patch series).
Best regards
Heinrich
Quoted 3 lines
Using
virtualenvto provide requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Re: [PATCH 09/10] doc/develop/py_testing.rst: Update section on filesystem images
Quoted 62 lines · Heinrich Schuchardt
Am 7. März 2025 00:17:11 MEZ schrieb Tom Rini <[email protected]>:
Quoted 42 lines
Now that we have no users of "virt-make-fs" nor users of "sudo" for creating disk images update the documentation. We remove packages that are no longer required (and related text) as well as be firm in our wording around not using "sudo".
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
---doc/develop/py_testing.rst| 22 +++-------------------1 file changed, 3 insertions(+), 19 deletions(-)doc/develop/py_testing.rst +0
-10@@ -41,13 +41,11 @@ will be required. The following is an incomplete list: * dfu-util * dtc * openssl -* sudo OR guestmount * e2fsprogs * util-linux * coreutils * dosfstools * efitools -* guestfs-tools * mount * mtools * sbsigntool@@ -64,23 +62,9 @@ The test script supports either: physical board, attach to the board's console stream, and reset the board. Further details are described later. -The usage of command 'sudo' should be avoided in tests. To create disk images -use command virt-make-fs which is provided by package guestfs-tools. This -command creates a virtual machine with QEMU in which the disk image is -generated. - -Command virt-make-fs needs read access to the current kernel. On Ubuntu only -root has this privilege. You can add a script /etc/initramfs-tools/hooks/vmlinuz -with the following content to overcome the problem:doc/develop/py_testing.rst The test script supports either: · line 65
Quoted 10 lines
doc/develop/py_testing.rst +1
-9- -.. code-block:: bash - - #!/bin/sh - echo "chmod a+r vmlinuz-*" - chmod a+r /boot/vmlinuz-* - -The script should be chmod 755. It will be invoked whenever the initial RAM file -system is updated. +The usage of the command 'sudo' is not allowed in tests. To create disk imagesCan we add the reasoning here:
Using elevated priviledges can lead to security concerns. Furthermore not all users may have administrator rights. Therefore the command 'sudo' must not be used in tests.
doc/develop/py_testing.rst The test script supports either: · line 66
Quoted 1 line
doc/develop/py_testing.rst +1
-0+we have helper functions located in `test/py/tests/fs_helper.py` which is to be%s/is to be/shall be/
Quoted 7 lines
I would rather use 'shall' in accordance with RFC 2119 for clarity.
doc/develop/py_testing.rst The test script supports either: · line 67
Quoted 1 line
doc/develop/py_testing.rst +1
-0+used in any tests that require disk images.%s/require/require creating/
We have tests coming with prepared images (
efi_selftest_disk_image.h). Other tests might require a downloaded ISO (see the pmem patch series).
Good points all, thanks.
Signature · 1 line
Tom
Re: [PATCH 09/10] doc/develop/py_testing.rst: Update section on filesystem images
In reply to Heinrich SchuchardtQuoted 62 lines · Heinrich Schuchardt
Am 7. März 2025 00:17:11 MEZ schrieb Tom Rini <[email protected]>:
Quoted 42 lines
Now that we have no users of "virt-make-fs" nor users of "sudo" for creating disk images update the documentation. We remove packages that are no longer required (and related text) as well as be firm in our wording around not using "sudo".
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
---doc/develop/py_testing.rst| 22 +++-------------------1 file changed, 3 insertions(+), 19 deletions(-)doc/develop/py_testing.rst +0
-10@@ -41,13 +41,11 @@ will be required. The following is an incomplete list: * dfu-util * dtc * openssl -* sudo OR guestmount * e2fsprogs * util-linux * coreutils * dosfstools * efitools -* guestfs-tools * mount * mtools * sbsigntool@@ -64,23 +62,9 @@ The test script supports either: physical board, attach to the board's console stream, and reset the board. Further details are described later. -The usage of command 'sudo' should be avoided in tests. To create disk images -use command virt-make-fs which is provided by package guestfs-tools. This -command creates a virtual machine with QEMU in which the disk image is -generated. - -Command virt-make-fs needs read access to the current kernel. On Ubuntu only -root has this privilege. You can add a script /etc/initramfs-tools/hooks/vmlinuz -with the following content to overcome the problem:doc/develop/py_testing.rst The test script supports either: · line 65
Quoted 10 lines
doc/develop/py_testing.rst +1
-9- -.. code-block:: bash - - #!/bin/sh - echo "chmod a+r vmlinuz-*" - chmod a+r /boot/vmlinuz-* - -The script should be chmod 755. It will be invoked whenever the initial RAM file -system is updated. +The usage of the command 'sudo' is not allowed in tests. To create disk imagesCan we add the reasoning here:
Using elevated priviledges can lead to security concerns. Furthermore not all users may have administrator rights. Therefore the command 'sudo' must not be used in tests.
doc/develop/py_testing.rst The test script supports either: · line 66
Quoted 1 line
doc/develop/py_testing.rst +1
-0+we have helper functions located in `test/py/tests/fs_helper.py` which is to be%s/is to be/shall be/
Quoted 7 lines
I would rather use 'shall' in accordance with RFC 2119 for clarity.
doc/develop/py_testing.rst The test script supports either: · line 67
Quoted 1 line
doc/develop/py_testing.rst +1
-0+used in any tests that require disk images.%s/require/require creating/
We have tests coming with prepared images (
efi_selftest_disk_image.h). Other tests might require a downloaded ISO (see the pmem patch series).
All good points I've now addressed in v2.
Signature · 1 line
Tom
PATCH 10/10 Dockerfile: Update to drop virt-make-fs packages
In reply to Tom RiniNow that we do not need nor want people to use virt-make-fs for filesystem tests, remove the related packages from the installation list.
--- tools/docker/Dockerfile | 5 ----- 1 file changed, 5 deletions(-)
tools/docker/Dockerfile +0 -5
@@ -91,7 +91,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ libconfuse-dev \ libgit2-dev \ libjson-glib-dev \ - libguestfs-tools \ libgnutls28-dev \ libgnutls30 \ liblz4-tool \
@@ -105,7 +104,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ libtool \ libudev-dev \ libusb-1.0-0-dev \ - linux-image-generic \ lzma-alone \ lzop \ mount \
@@ -142,9 +140,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ xxd \ zip -# Make kernels readable for libguestfs tools to work correctly -RUN chmod +r /boot/vmlinu* - # Build GRUB UEFI targets for ARM & RISC-V, 32-bit and 64-bit RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \ cd /tmp/grub && \
Signature · 1 line
2.43.0