Add Binman code-coverage test to CI
v2 cover Add Binman code-coverage test to CI
Binman has 100% code coverage to ensure that future changes and refactors do not break existing entry types. This is a critical feature, given that it is relied on to produce images for all sorts of different SoCs and vendors.
With the NXP additions the 'binman test -T' step was missed, so the Binman coverage test is currently failing.
This series provides a means to close the testing gap. It cannot be applied until the tests are added, which should happen before -next is applied to -master
Changes in v2:
- Add new patch to fix a few typos in toolchain code
- Add to azure also (oops)
- Add to buildman requirements instead
- Fix 'envronment' typo
Simon Glass (6):
buildman: Add python3-coverage
buildman: Add python3-pycryptodome
buildman: Fix a few typos in toolchain code
buildman: Support building within a Python venv
u_boot_pylib: Use correct coverage tool within venv
CI: Run code-coverage test for Binman
.azure-pipelines.yml | 5 +- .gitlab-ci.yml | 4 +- tools/buildman/bsettings.py | 3 ++ tools/buildman/requirements.txt | 2 + tools/buildman/test.py | 83 +++++++++++++++++++++++++++++++++ tools/buildman/toolchain.py | 35 +++++++++++--- tools/u_boot_pylib/test_util.py | 11 +++-- 7 files changed, 132 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/6 buildman: Add python3-coverage
Add this package so we can run code-coverage tests for Binman.
---
Changes in v2:
- Add to buildman requirements instead
tools/buildman/requirements.txt | 1 + 1 file changed, 1 insertion(+)
tools/buildman/requirements.txt +1 -0
@@ -1,3 +1,4 @@ +coverage==6.2 jsonschema==4.17.3 pyyaml==6.0 yamllint==1.26.3
Signature · 1 line
2.34.1
Re: [PATCH v2 1/6] buildman: Add python3-coverage
Quoted 3 lines · Simon Glass
Add this package so we can run code-coverage tests for Binman.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 2/6 buildman: Add python3-pycryptodome
In reply to Simon GlassThis is used by some Binman entry types, so add it to allow more tests to pass.
---
Changes in v2:
- Add to buildman requirements instead
tools/buildman/requirements.txt | 1 + 1 file changed, 1 insertion(+)
tools/buildman/requirements.txt +1 -0
@@ -1,4 +1,5 @@ coverage==6.2 jsonschema==4.17.3 +pycryptodome==3.20 pyyaml==6.0 yamllint==1.26.3
Signature · 1 line
2.34.1
Re: [PATCH v2 2/6] buildman: Add python3-pycryptodome
Quoted 4 lines · Simon Glass
This is used by some Binman entry types, so add it to allow more tests to pass.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 3/6 buildman: Fix a few typos in toolchain code
In reply to Simon GlassFix 'Thie' and capitalise 'unicode'.
---
Changes in v2:
- Add new patch to fix a few typos in toolchain code
tools/buildman/toolchain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/buildman/toolchain.py +2 -2
@@ -175,9 +175,9 @@ class Toolchain: def MakeEnvironment(self, full_path): """Returns an environment for using the toolchain. - Thie takes the current environment and adds CROSS_COMPILE so that + This takes the current environment and adds CROSS_COMPILE so that the tool chain will operate correctly. This also disables localized - output and possibly unicode encoded output of all build tools by + output and possibly Unicode encoded output of all build tools by adding LC_ALL=C. Note that os.environb is used to obtain the environment, since in some
Signature · 1 line
2.34.1
PATCH v2 4/6 buildman: Support building within a Python venv
In reply to Simon GlassThe Python virtualenv tool sets up a few things in the environment, putting its path first in the PATH environment variable and setting up a sys.prefix different from the sys.base_prefix value.
At present buildman puts the toolchain path first in PATH so that it can be found easily during the build. For sandbox this causes problems since /usr/bin/gcc (for example) results in '/usr/bin' being prepended to the PATH variable. As a result, the venv is partially disabled.
The result is that sandbox builds within a venv ignore the venv, e.g. when looking for packages.
Correct this by detecting the venv and adding the toolchain path after the venv path.
---
Changes in v2:
- Fix 'envronment' typo
tools/buildman/bsettings.py | 3 ++ tools/buildman/test.py | 83 +++++++++++++++++++++++++++++++++++++ tools/buildman/toolchain.py | 31 ++++++++++++-- 3 files changed, 113 insertions(+), 4 deletions(-)
tools/buildman/bsettings.py +3 -0
@@ -31,6 +31,9 @@ def setup(fname=''): def add_file(data): settings.readfp(io.StringIO(data)) +def add_section(name): + settings.add_section(name) + def get_items(section): """Get the items from a section of the config.
tools/buildman/test.py +83 -0
95 lines not on this page · raw message
tools/buildman/toolchain.py +27 -4
@@ -172,13 +172,14 @@ class Toolchain: else: raise ValueError('Unknown arg to GetEnvArgs (%d)' % which) - def MakeEnvironment(self, full_path): + def MakeEnvironment(self, full_path, env=None): """Returns an environment for using the toolchain. This takes the current environment and adds CROSS_COMPILE so that the tool chain will operate correctly. This also disables localized output and possibly Unicode encoded output of all build tools by - adding LC_ALL=C. + adding LC_ALL=C. For the case where full_path is False, it prepends + the toolchain to PATH Note that os.environb is used to obtain the environment, since in some cases the environment many contain non-ASCII characters and we see
@@ -187,15 +188,21 @@ class Toolchain: UnicodeEncodeError: 'utf-8' codec can't encode characters in position 569-570: surrogates not allowed + When running inside a Python venv, care is taken not to put the + toolchain path before the venv path, so that builds initiated by + buildman will still respect the venv. + Args: full_path: Return the full path in CROSS_COMPILE and don't set PATH + env (dict of bytes): Original environment, used for testing Returns: Dict containing the (bytes) environment to use. This is based on the current environment, with changes as needed to CROSS_COMPILE, PATH and LC_ALL. """ - env = dict(os.environb) + env = dict(env or os.environb) + wrapper = self.GetWrapper() if self.override_toolchain:
@@ -206,7 +213,23 @@ class Toolchain: wrapper + os.path.join(self.path, self.cross)) else: env[b'CROSS_COMPILE'] = tools.to_bytes(wrapper + self.cross) - env[b'PATH'] = tools.to_bytes(self.path) + b':' + env[b'PATH'] + + # Detect a Python virtualenv and avoid defeating it + if sys.prefix != sys.base_prefix: + paths = env[b'PATH'].split(b':') + new_paths = [] + to_insert = tools.to_bytes(self.path) + insert_after = tools.to_bytes(sys.prefix) + for path in paths: + new_paths.append(path) + if to_insert and path.startswith(insert_after): + new_paths.append(to_insert) + to_insert = None + if to_insert: + new_paths.append(to_insert) + env[b'PATH'] = b':'.join(new_paths) + else: + env[b'PATH'] = tools.to_bytes(self.path) + b':' + env[b'PATH'] env[b'LC_ALL'] = b'C'
Signature · 1 line
2.34.1
PATCH v2 5/6 u_boot_pylib: Use correct coverage tool within venv
In reply to Simon GlassWhen running within a Python venv we must use the 'coverage' tool (which is within the venv) so that the venv packages are used in preference to system packages. Otherwise the coverage tests run in a different environment from the normal tests and may fail due to missing packages.
Handle this by detecting the venv and changing the tool name.
---
(no changes since v1)
tools/u_boot_pylib/test_util.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
tools/u_boot_pylib/test_util.py +8 -3
@@ -60,12 +60,17 @@ def run_test_coverage(prog, filter_fname, exclude_list, build_dir, required=None prefix = '' if build_dir: prefix = 'PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools ' % build_dir - cmd = ('%spython3-coverage run ' - '--omit "%s" %s %s %s %s' % (prefix, ','.join(glob_list), + + # Detect a Python virtualenv and use 'coverage' instead + covtool = ('python3-coverage' if sys.prefix == sys.base_prefix else + 'coverage') + + cmd = ('%s%s run ' + '--omit "%s" %s %s %s %s' % (prefix, covtool, ','.join(glob_list), prog, extra_args or '', test_cmd, single_thread or '-P1')) os.system(cmd) - stdout = command.output('python3-coverage', 'report') + stdout = command.output(covtool, 'report') lines = stdout.splitlines() if required: # Convert '/path/to/name.py' just the module name 'name'
Signature · 1 line
2.34.1
PATCH v2 6/6 CI: Run code-coverage test for Binman
In reply to Simon GlassBinman includes a good set of tests covering all of its functionality. This includes a code-coverage test.
However to date the code-coverage test has not been checked automatically by CI, relying on people to run 'binman test -T' themselves.
Plug the gap to avoid bugs creeping in future.
---
Changes in v2:
- Add to azure also (oops)
.azure-pipelines.yml | 5 ++++- .gitlab-ci.yml | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-)
.azure-pipelines.yml +4 -1
@@ -128,7 +128,10 @@ stages: export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH} ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR} -w --board tools-only set -ex - ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools test + export TOOLPATH="--toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools --toolpath /opt/coreboot" + ./tools/binman/binman ${TOOLPATH} test + # Avoid "Permission denied: 'cov'" error by using a temporary file + COVERAGE_FILE=/tmp/.coverage ./tools/binman/binman ${TOOLPATH} test -T ./tools/buildman/buildman -t ./tools/dtoc/dtoc -t ./tools/patman/patman test
.gitlab-ci.yml +3 -1
@@ -201,7 +201,9 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites: ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR} -w --board tools-only; set -e; - ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools test; + export TOOLPATH="--toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools --toolpath /opt/coreboot"; + ./tools/binman/binman ${TOOLPATH} test; + ./tools/binman/binman ${TOOLPATH} test -T; ./tools/buildman/buildman -t; ./tools/dtoc/dtoc -t; ./tools/patman/patman test;
Signature · 1 line
2.34.1