test/py: Document required tools/packages
PATCH 1/3 test/py: Document required tools/packages
From: Stephen Warren <[email protected]>
Some tests rely on external tools. Mention these in the test/py README.
---
This series was developed on top of, and depends on for diff context, my previous patch "test/py: gpt: make use of infra-structure".
test/py/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
test/py/README.md +6 -1
@@ -22,12 +22,17 @@ need to implement various "hook" scripts that are called by the test suite at the appropriate time. On Debian or Debian-like distributions, the following packages are required. -Similar package names should exist in other distributions. +Some packages are required to execute any test, and others only for specific +tests. Similar package names should exist in other distributions. | Package | Version tested (Ubuntu 14.04) | | -------------- | ----------------------------- | | python | 2.7.5-5ubuntu3 | | python-pytest | 2.5.1-1 | +| gdisk | 0.8.8-1ubuntu0.1 | +| dfu-util | 0.5-1 | +| dtc | 1.4.0+dfsg-1 | +| openssl | 1.0.1f-1ubuntu2.22 | The test script supports either:
Signature · 1 line
2.14.1
PATCH 2/3 test/py: provide more information about test skip reason
From: Stephen Warren <[email protected]>
When skipping tests, explicitly mention the board type or config option that caused the skip. This will help people understand/fix any issues.
--- test/py/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
test/py/conftest.py +3 -3
@@ -429,12 +429,12 @@ def setup_boardspec(item): for board in mark.args: if board.startswith('!'): if ubconfig.board_type == board[1:]: - pytest.skip('board not supported') + pytest.skip('board "%s" not supported' % ubconfig.board_type) return else: required_boards.append(board) if required_boards and ubconfig.board_type not in required_boards: - pytest.skip('board not supported') + pytest.skip('board "%s" not supported' % ubconfig.board_type) def setup_buildconfigspec(item): """Process any 'buildconfigspec' marker for a test.
@@ -455,7 +455,7 @@ def setup_buildconfigspec(item): return for option in mark.args: if not ubconfig.buildconfig.get('config_' + option.lower(), None): - pytest.skip('.config feature not enabled') + pytest.skip('.config feature "%s" not enabled' % option.lower()) def start_test_section(item): anchors[item.name] = log.start_section(item.name)
Signature · 1 line
2.14.1
PATCH 2/3 test/py: provide more information about test skip reason
Quoted 6 lines · Stephen Warren
From: Stephen Warren <[email protected]>
When skipping tests, explicitly mention the board type or config option that caused the skip. This will help people understand/fix any issues.
Signed-off-by Stephen Warren <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170929/d93a9afb/attachment.sig>
PATCH 3/3 test/py: add skip marker for reliance on tools
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
Some tests use external tools (executables) during their operation. Add a test.py mark to indicate this. This allows those tests to be skipped if the required tool is not present.
--- test/py/conftest.py | 29 +++++++++++++++++++++++++++++ test/py/tests/test_dfu.py | 1 + test/py/tests/test_fit.py | 1 + test/py/tests/test_gpt.py | 13 ++++++++----- test/py/tests/test_vboot.py | 4 ++++ 5 files changed, 43 insertions(+), 5 deletions(-)
test/py/conftest.py +29 -0
@@ -457,6 +457,34 @@ def setup_buildconfigspec(item): if not ubconfig.buildconfig.get('config_' + option.lower(), None): pytest.skip('.config feature "%s" not enabled' % option.lower()) +def tool_is_in_path(tool): + for path in os.environ["PATH"].split(os.pathsep): + fn = os.path.join(path, tool) + if os.path.isfile(fn) and os.access(fn, os.X_OK): + return True + return False + +def setup_requiredtool(item): + """Process any 'requiredtool' marker for a test. + + Such a marker lists some external tool (binary, executable, application) + that the test requires. If tests are being executed on a system that + doesn't have the required tool, the test is marked to be skipped. + + Args: + item: The pytest test item. + + Returns: + Nothing. + """ + + mark = item.get_marker('requiredtool') + if not mark: + return + for tool in mark.args: + if not tool_is_in_path(tool): + pytest.skip('tool "%s" not in $PATH' % tool) + def start_test_section(item): anchors[item.name] = log.start_section(item.name)
@@ -476,6 +504,7 @@ def pytest_runtest_setup(item): start_test_section(item) setup_boardspec(item) setup_buildconfigspec(item) + setup_requiredtool(item) def pytest_runtest_protocol(item, nextitem): """pytest hook: Called to execute a test.
test/py/tests/test_dfu.py +1 -0
@@ -113,6 +113,7 @@ test_sizes_default = ( first_usb_dev_port = None @pytest.mark.buildconfigspec('cmd_dfu') + at pytest.mark.requiredtool('dfu-util') def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): """Test the "dfu" command; the host system must be able to enumerate a USB device when "dfu" is running, various DFU transfers are tested, and the
test/py/tests/test_fit.py +1 -0
@@ -111,6 +111,7 @@ sb save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('fit_signature') + at pytest.mark.requiredtool('dtc') def test_fit(u_boot_console): def make_fname(leaf): """Make a temporary filename
test/py/tests/test_gpt.py +8 -5
@@ -38,15 +38,14 @@ class GptTestDiskImage(object): fd = os.open(self.path, os.O_RDWR | os.O_CREAT) os.ftruncate(fd, 4194304) os.close(fd) - sgdisk = '/sbin/sgdisk' - cmd = (sgdisk, '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe', + cmd = ('sgdisk', '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe', self.path) u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = (sgdisk, '--new=1:2048:2560', self.path) + cmd = ('sgdisk', '--new=1:2048:2560', self.path) u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = (sgdisk, '--new=2:4096:4608', self.path) + cmd = ('sgdisk', '--new=2:4096:4608', self.path) u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = (sgdisk, '-l', self.path) + cmd = ('sgdisk', '-l', self.path) u_boot_utils.run_and_log(u_boot_console, cmd) gtdi = None
@@ -64,6 +63,7 @@ def state_disk_image(u_boot_console): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') + at pytest.mark.requiredtool('sgdisk') def test_gpt_guid(state_disk_image, u_boot_console): """Test the gpt guid command."""
@@ -73,6 +73,7 @@ def test_gpt_guid(state_disk_image, u_boot_console): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') + at pytest.mark.requiredtool('sgdisk') def test_gpt_save_guid(state_disk_image, u_boot_console): """Test the gpt guid command to save GUID into a string."""
@@ -86,6 +87,7 @@ def test_gpt_save_guid(state_disk_image, u_boot_console): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @pytest.mark.buildconfigspec('cmd_gpt_rename') + at pytest.mark.requiredtool('sgdisk') def test_gpt_rename_partition(state_disk_image, u_boot_console): """Test the gpt rename command to write partition names."""
@@ -101,6 +103,7 @@ def test_gpt_rename_partition(state_disk_image, u_boot_console): @pytest.mark.buildconfigspec('cmd_gpt') @pytest.mark.buildconfigspec('cmd_gpt_rename') @pytest.mark.buildconfigspec('cmd_part') + at pytest.mark.requiredtool('sgdisk') def test_gpt_swap_partitions(state_disk_image, u_boot_console): """Test the gpt swap command to exchange two partition names."""
test/py/tests/test_vboot.py +4 -0
@@ -31,6 +31,10 @@ import u_boot_utils as util @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('fit_signature') + at pytest.mark.requiredtool('dtc') + at pytest.mark.requiredtool('fdtget') + at pytest.mark.requiredtool('fdtput') + at pytest.mark.requiredtool('openssl') def test_vboot(u_boot_console): """Test verified boot signing with mkimage and verification with 'bootm'.
Signature · 1 line
2.14.1
PATCH 3/3 test/py: add skip marker for reliance on tools
Quoted 7 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Some tests use external tools (executables) during their operation. Add a
test.pymark to indicate this. This allows those tests to be skipped if the required tool is not present.Signed-off-by Stephen Warren <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170929/8c93b7f1/attachment.sig>
PATCH 1/3 test/py: Document required tools/packages
In reply to Stephen WarrenQuoted 5 lines · Stephen Warren
From: Stephen Warren <[email protected]>
Some tests rely on external tools. Mention these in the test/py README.
Signed-off-by Stephen Warren <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170929/1b8d06d3/attachment.sig>