diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-09-21 14:08:36 -0700 |
---|---|---|
committer | Tom Hughes <tomhughes@chromium.org> | 2022-09-22 12:59:38 -0700 |
commit | c453fd704268ef72de871b0c5ac7a989de662334 (patch) | |
tree | fcf6ce5810f9ff9e3c8cce434812dd75492269ed /zephyr/zmake/tests | |
parent | 6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff) | |
parent | 28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff) | |
download | chrome-ec-c453fd704268ef72de871b0c5ac7a989de662334.tar.gz |
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file
./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release
Relevant changes:
git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp
board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint
util/getversion.sh
ded9307b79 util/getversion.sh: Fix version when not in a git repo
956055e692 board: change Google USB vendor info
71b2ef709d Update license boilerplate text in source code files
33e11afda0 Revert "fpsensor: Build fpsensor source file with C++"
c8d0360723 fpsensor: Build fpsensor source file with C++
bc113abd53 fpsensor: Fix g++ compiler error
150a58a0dc fpsensor: Fix fp_set_sensor_mode return type
b33b5ce85b fpsensor: Remove nested designators for C++ compatibility
2e864b2539 tree-wide: const-ify argv for console commands
56d8b360f9 test: Add test for get ikm failure when seed not set
3a3d6c3690 test: Add test for fpsensor trivial key failure
233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256
0a041b285b docs/fingerprint: Typo correction
c03fab67e2 docs/fingerprint: Fix the path of fputils.py
0b5d4baf5a util/getversion.sh: Fix empty file list handling
6e128fe760 FPMCU dev board environment with Satlab
3eb29b6aa5 builtin: Move ssize_t to sys/types.h
345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release
c25ffdb316 common: Conditionally support printf %l and %i modifiers
9a3c514b45 test: Add a test to check if the debugger is connected
54e603413f Move standard library tests to their own file
43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release
25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format
4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format
738de2b575 trng: Rename rand to trng_rand
14b8270edd docs/fingerprint: Update dragonclaw power numbers
0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format
f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format
a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format
5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format
c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format
eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format
6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format
e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format
58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format
7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format
21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format
98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format
a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format
84e53a65da board/nocturne_fp/board.h: Format with clang-format
73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format
0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format
1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format
dca9d74321 Revert "trng: Rename rand to trng_rand"
a6b0b3554f trng: Rename rand to trng_rand
28d0b75b70 third_party/boringssl: Remove unused header
BRANCH=None
BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294
BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908
BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010
BUG=b:246424843 b:234181908 b:131913998
TEST=`make -j buildall`
TEST=./util/run_device_tests.py --board dartmonkey
Test "aes": PASSED
Test "cec": PASSED
Test "cortexm_fpu": PASSED
Test "crc": PASSED
Test "flash_physical": PASSED
Test "flash_write_protect": PASSED
Test "fpsensor_hw": PASSED
Test "fpsensor_spi_ro": PASSED
Test "fpsensor_spi_rw": PASSED
Test "fpsensor_uart_ro": PASSED
Test "fpsensor_uart_rw": PASSED
Test "mpu_ro": PASSED
Test "mpu_rw": PASSED
Test "mutex": PASSED
Test "pingpong": PASSED
Test "printf": PASSED
Test "queue": PASSED
Test "rollback_region0": PASSED
Test "rollback_region1": PASSED
Test "rollback_entropy": PASSED
Test "rtc": PASSED
Test "sha256": PASSED
Test "sha256_unrolled": PASSED
Test "static_if": PASSED
Test "stdlib": PASSED
Test "system_is_locked_wp_on": PASSED
Test "system_is_locked_wp_off": PASSED
Test "timer_dos": PASSED
Test "utils": PASSED
Test "utils_str": PASSED
Test "panic_data_dartmonkey_v2.0.2887": PASSED
Test "panic_data_nocturne_fp_v2.2.64": PASSED
Test "panic_data_nami_fp_v2.2.144": PASSED
Force-Relevant-Builds: all
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'zephyr/zmake/tests')
-rw-r--r-- | zephyr/zmake/tests/conftest.py | 8 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_build_config.py | 44 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_generate_readme.py | 7 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_modules.py | 11 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_multiproc_executor.py | 2 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_multiproc_logging.py | 22 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_packers.py | 13 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_project.py | 21 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_reexec.py | 5 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_toolchains.py | 19 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_util.py | 9 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_version.py | 41 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_zmake.py | 49 |
13 files changed, 137 insertions, 114 deletions
diff --git a/zephyr/zmake/tests/conftest.py b/zephyr/zmake/tests/conftest.py index 38e34bef56..dfea10457c 100644 --- a/zephyr/zmake/tests/conftest.py +++ b/zephyr/zmake/tests/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -7,14 +7,14 @@ import os import pathlib -import hypothesis -import pytest - +import hypothesis # pylint:disable=import-error +import pytest # pylint:disable=import-error import zmake.zmake as zm hypothesis.settings.register_profile( "cq", suppress_health_check=hypothesis.HealthCheck.all() ) +hypothesis.settings.load_profile("cq") # pylint: disable=redefined-outer-name,unused-argument diff --git a/zephyr/zmake/tests/test_build_config.py b/zephyr/zmake/tests/test_build_config.py index 76cc0a2028..d8355da768 100644 --- a/zephyr/zmake/tests/test_build_config.py +++ b/zephyr/zmake/tests/test_build_config.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -10,10 +10,9 @@ import pathlib import string import tempfile -import hypothesis -import hypothesis.strategies as st -import pytest - +import hypothesis # pylint:disable=import-error +import hypothesis.strategies as st # pylint:disable=import-error +import pytest # pylint:disable=import-error import zmake.jobserver import zmake.util as util from zmake.build_config import BuildConfig @@ -36,17 +35,13 @@ config_dicts_at_least_one_entry = st.dictionaries( build_configs = st.builds( BuildConfig, - environ_defs=config_dicts, cmake_defs=config_dicts, kconfig_defs=config_dicts, kconfig_files=st.lists(paths), ) -build_configs_no_kconfig = st.builds( - BuildConfig, environ_defs=config_dicts, cmake_defs=config_dicts -) +build_configs_no_kconfig = st.builds(BuildConfig, cmake_defs=config_dicts) build_configs_with_at_least_one_kconfig = st.builds( BuildConfig, - environ_defs=config_dicts, cmake_defs=config_dicts, kconfig_defs=config_dicts_at_least_one_entry, ) @@ -70,19 +65,16 @@ def test_merge(coins, combined): return left, right # Split the original config into two - env1, env2 = split(combined.environ_defs.items()) cmake1, cmake2 = split(combined.cmake_defs.items()) kconf1, kconf2 = split(combined.kconfig_defs.items()) files1, files2 = split(combined.kconfig_files) config1 = BuildConfig( - environ_defs=dict(env1), cmake_defs=dict(cmake1), kconfig_defs=dict(kconf1), kconfig_files=files1, ) config2 = BuildConfig( - environ_defs=dict(env2), cmake_defs=dict(cmake2), kconfig_defs=dict(kconf2), kconfig_files=files2, @@ -92,7 +84,6 @@ def test_merge(coins, combined): merged = config1 | config2 # Assert that the merged split configs is the original config - assert merged.environ_defs == combined.environ_defs assert merged.cmake_defs == combined.cmake_defs assert merged.kconfig_defs == combined.kconfig_defs assert set(merged.kconfig_files) == set(combined.kconfig_files) @@ -158,12 +149,13 @@ def test_popen_cmake_no_kconfig(conf: BuildConfig, project_dir, build_dir): _, cmake_defs = parse_cmake_args(job_client.captured_argv) assert cmake_defs == conf.cmake_defs - assert job_client.captured_env == conf.environ_defs @hypothesis.given(build_configs_with_at_least_one_kconfig, paths, paths) @hypothesis.settings(deadline=60000) -def test_popen_cmake_kconfig_but_no_file(conf: BuildConfig, project_dir, build_dir): +def test_popen_cmake_kconfig_but_no_file( + conf: BuildConfig, project_dir, build_dir +): """Test that running popen_cmake with Kconfig definitions to write out, but no path to do so, should raise an error. """ @@ -184,7 +176,10 @@ def test_popen_cmake_kconfig(conf: BuildConfig, project_dir, build_dir): try: conf.popen_cmake( - job_client, project_dir, build_dir, kconfig_path=pathlib.Path(temp_path) + job_client, + project_dir, + build_dir, + kconfig_path=pathlib.Path(temp_path), ) _, cmake_defs = parse_cmake_args(job_client.captured_argv) @@ -199,7 +194,6 @@ def test_popen_cmake_kconfig(conf: BuildConfig, project_dir, build_dir): kconfig_files = set() assert cmake_defs == conf.cmake_defs - assert job_client.captured_env == conf.environ_defs assert kconfig_files == expected_kconfig_files kconfig_defs = util.read_kconfig_file(temp_path) @@ -215,7 +209,9 @@ def fake_kconfig_files(tmp_path): paths = [tmp_path / f"{letter}.conf" for letter in "ABCD"] for path, cfg_name in zip(paths, ("ONE", "TWO", "THREE", "FOUR")): - path.write_text(f"# Fake kconfig file for testing.\nCONFIG_{cfg_name}=y\n") + path.write_text( + f"# Fake kconfig file for testing.\nCONFIG_{cfg_name}=y\n" + ) return paths @@ -225,10 +221,6 @@ def test_build_config_json_stability(fake_kconfig_files): build configs. """ config_a = BuildConfig( - environ_defs={ - "A": "B", - "B": "C", - }, cmake_defs={ "Z": "Y", "X": "W", @@ -242,10 +234,6 @@ def test_build_config_json_stability(fake_kconfig_files): # Dict ordering is intentionally reversed in b. config_b = BuildConfig( - environ_defs={ - "B": "C", - "A": "B", - }, cmake_defs={ "X": "W", "Z": "Y", @@ -265,7 +253,7 @@ def test_build_config_json_inequality(): representation. """ config_a = BuildConfig(cmake_defs={"A": "B"}) - config_b = BuildConfig(environ_defs={"A": "B"}) + config_b = BuildConfig(kconfig_defs={"CONFIG_A": "y"}) assert config_a.as_json() != config_b.as_json() diff --git a/zephyr/zmake/tests/test_generate_readme.py b/zephyr/zmake/tests/test_generate_readme.py index cb4bcf6cc1..e7873f1980 100644 --- a/zephyr/zmake/tests/test_generate_readme.py +++ b/zephyr/zmake/tests/test_generate_readme.py @@ -1,4 +1,4 @@ -# Copyright 2022 The Chromium OS Authors. All rights reserved. +# Copyright 2022 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -6,8 +6,7 @@ Tests for the generate_readme.py file. """ -import pytest - +import pytest # pylint:disable=import-error import zmake.generate_readme as gen_readme @@ -34,7 +33,7 @@ def test_generate_readme_diff( expected_contents, actual_contents, return_code, -): # pylint: disable=too-many-arguments +): """Verify that the diff function can detect different text.""" def generate_readme(): diff --git a/zephyr/zmake/tests/test_modules.py b/zephyr/zmake/tests/test_modules.py index 600544d2e7..dc4c170535 100644 --- a/zephyr/zmake/tests/test_modules.py +++ b/zephyr/zmake/tests/test_modules.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -7,9 +7,8 @@ import pathlib import tempfile -import hypothesis -import hypothesis.strategies as st - +import hypothesis # pylint:disable=import-error +import hypothesis.strategies as st # pylint:disable=import-error import zmake.modules module_lists = st.lists( @@ -37,4 +36,6 @@ def test_locate_in_directory(modules): expected_modules[module] = module_dir - assert zmake.modules.locate_from_directory(modules_dir) == expected_modules + assert ( + zmake.modules.locate_from_directory(modules_dir) == expected_modules + ) diff --git a/zephyr/zmake/tests/test_multiproc_executor.py b/zephyr/zmake/tests/test_multiproc_executor.py index c905ef03ec..ff443e2f4b 100644 --- a/zephyr/zmake/tests/test_multiproc_executor.py +++ b/zephyr/zmake/tests/test_multiproc_executor.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/zephyr/zmake/tests/test_multiproc_logging.py b/zephyr/zmake/tests/test_multiproc_logging.py index 2694b6451e..88d029675b 100644 --- a/zephyr/zmake/tests/test_multiproc_logging.py +++ b/zephyr/zmake/tests/test_multiproc_logging.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -20,7 +20,9 @@ def test_read_output_from_pipe(): file_desc = io.TextIOWrapper(os.fdopen(pipe[0], "rb"), encoding="utf-8") logger = mock.Mock(spec=logging.Logger) logger.log.side_effect = lambda log_lvl, line: semaphore.release() - zmake.multiproc.LogWriter.log_output(logger, logging.DEBUG, file_desc, job_id="") + zmake.multiproc.LogWriter.log_output( + logger, logging.DEBUG, file_desc, job_id="" + ) os.write(pipe[1], "Hello\n".encode("utf-8")) semaphore.acquire() logger.log.assert_called_with(logging.DEBUG, "Hello") @@ -77,8 +79,12 @@ def test_read_output_from_second_pipe(): logger = mock.Mock(spec=logging.Logger) logger.log.side_effect = lambda log_lvl, fmt, id, line: semaphore.release() - zmake.multiproc.LogWriter.log_output(logger, logging.DEBUG, fds[0], job_id="0") - zmake.multiproc.LogWriter.log_output(logger, logging.ERROR, fds[1], job_id="1") + zmake.multiproc.LogWriter.log_output( + logger, logging.DEBUG, fds[0], job_id="0" + ) + zmake.multiproc.LogWriter.log_output( + logger, logging.ERROR, fds[1], job_id="1" + ) os.write(pipes[1][1], "Hello\n".encode("utf-8")) semaphore.acquire() @@ -102,8 +108,12 @@ def test_read_output_after_another_pipe_closed(): logger = mock.Mock(spec=logging.Logger) logger.log.side_effect = lambda log_lvl, fmt, id, line: semaphore.release() - zmake.multiproc.LogWriter.log_output(logger, logging.DEBUG, fds[0], job_id="0") - zmake.multiproc.LogWriter.log_output(logger, logging.ERROR, fds[1], job_id="1") + zmake.multiproc.LogWriter.log_output( + logger, logging.DEBUG, fds[0], job_id="0" + ) + zmake.multiproc.LogWriter.log_output( + logger, logging.ERROR, fds[1], job_id="1" + ) fds[0].close() os.write(pipes[1][1], "Hello\n".encode("utf-8")) diff --git a/zephyr/zmake/tests/test_packers.py b/zephyr/zmake/tests/test_packers.py index 43b63a908f..23bdb2bf6b 100644 --- a/zephyr/zmake/tests/test_packers.py +++ b/zephyr/zmake/tests/test_packers.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -7,10 +7,9 @@ import pathlib import tempfile -import hypothesis -import hypothesis.strategies as st -import pytest - +import hypothesis # pylint:disable=import-error +import hypothesis.strategies as st # pylint:disable=import-error +import pytest # pylint:disable=import-error import zmake.output_packers as packers # Strategies for use with hypothesis @@ -54,7 +53,7 @@ def test_file_size_in_bounds(data): """Test with file size limited.""" packer = FakePacker(100) with tempfile.TemporaryDirectory() as temp_dir_name: - file = pathlib.Path(temp_dir_name) / "zephyr.bin" + file = pathlib.Path(temp_dir_name) / "ec.bin" with open(file, "wb") as outfile: outfile.write(data) assert packer.check_packed_file_size(file=file, dir_map={}) == file @@ -66,7 +65,7 @@ def test_file_size_out_of_bounds(data): """Test with file size limited, and file exceeds limit.""" packer = FakePacker(100) with tempfile.TemporaryDirectory() as temp_dir_name: - file = pathlib.Path(temp_dir_name) / "zephyr.bin" + file = pathlib.Path(temp_dir_name) / "ec.bin" with open(file, "wb") as outfile: outfile.write(data) with pytest.raises(RuntimeError): diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py index b5facbc331..3225de1d75 100644 --- a/zephyr/zmake/tests/test_project.py +++ b/zephyr/zmake/tests/test_project.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -8,10 +8,9 @@ import pathlib import string import tempfile -import hypothesis -import hypothesis.strategies as st -import pytest - +import hypothesis # pylint:disable=import-error +import hypothesis.strategies as st # pylint:disable=import-error +import pytest # pylint:disable=import-error import zmake.modules import zmake.output_packers import zmake.project @@ -34,7 +33,9 @@ def test_find_dts_overlays(modules): with tempfile.TemporaryDirectory() as modpath: modpath = pathlib.Path(modpath) for board in boards: - dts_path = zmake.project.module_dts_overlay_name(modpath, board) + dts_path = zmake.project.module_dts_overlay_name( + modpath, board + ) dts_path.parent.mkdir(parents=True, exist_ok=True) dts_path.touch() setup_modules_and_dispatch( @@ -49,7 +50,9 @@ def test_find_dts_overlays(modules): board_file_mapping = {} for modpath, board_list in zip(module_paths, modules): for board in board_list: - file_name = zmake.project.module_dts_overlay_name(modpath, board) + file_name = zmake.project.module_dts_overlay_name( + modpath, board + ) files = board_file_mapping.get(board, set()) board_file_mapping[board] = files | {file_name} @@ -258,4 +261,6 @@ def test_kconfig_files(tmp_path, actual_files, config_files, expected_files): assert len(builds) == 1 _, config = builds[0] - assert sorted(f.name for f in config.kconfig_files) == sorted(expected_files) + assert sorted(f.name for f in config.kconfig_files) == sorted( + expected_files + ) diff --git a/zephyr/zmake/tests/test_reexec.py b/zephyr/zmake/tests/test_reexec.py index 5d7905cd8f..63aa76cb70 100644 --- a/zephyr/zmake/tests/test_reexec.py +++ b/zephyr/zmake/tests/test_reexec.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Test the zmake re-exec functionality.""" @@ -7,8 +7,7 @@ import os import sys import unittest.mock as mock -import pytest - +import pytest # pylint:disable=import-error import zmake.__main__ as main diff --git a/zephyr/zmake/tests/test_toolchains.py b/zephyr/zmake/tests/test_toolchains.py index 910a5faa78..ca40f482af 100644 --- a/zephyr/zmake/tests/test_toolchains.py +++ b/zephyr/zmake/tests/test_toolchains.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -7,8 +7,7 @@ import os import pathlib -import pytest - +import pytest # pylint:disable=import-error import zmake.output_packers import zmake.project as project import zmake.toolchains as toolchains @@ -138,9 +137,6 @@ def test_zephyr(fake_project: project.Project, zephyr_exists, no_environ): "ZEPHYR_TOOLCHAIN_VARIANT": "zephyr", "ZEPHYR_SDK_INSTALL_DIR": str(pathlib.Path("/opt/zephyr-sdk")), } - assert config.environ_defs == { - "ZEPHYR_SDK_INSTALL_DIR": str(pathlib.Path("/opt/zephyr-sdk")), - } def test_zephyr_from_env(mockfs, monkeypatch, fake_project): @@ -159,9 +155,6 @@ def test_zephyr_from_env(mockfs, monkeypatch, fake_project): "ZEPHYR_TOOLCHAIN_VARIANT": "zephyr", "ZEPHYR_SDK_INSTALL_DIR": str(zephyr_sdk_path), } - assert config.environ_defs == { - "ZEPHYR_SDK_INSTALL_DIR": str(zephyr_sdk_path), - } def test_host_toolchain(fake_project, host_toolchain_exists): @@ -197,9 +190,13 @@ def test_no_toolchains(fake_project: project.Project, mockfs, no_environ): fake_project.get_toolchain(module_paths) -def test_override_without_sdk(fake_project: project.Project, mockfs, no_environ): +def test_override_without_sdk( + fake_project: project.Project, mockfs, no_environ +): """Check for error override is set to zephyr, but it can't be found.""" chain = fake_project.get_toolchain(module_paths, override="zephyr") - with pytest.raises(RuntimeError, match=r"No installed Zephyr SDK was found"): + with pytest.raises( + RuntimeError, match=r"No installed Zephyr SDK was found" + ): chain.get_build_config() diff --git a/zephyr/zmake/tests/test_util.py b/zephyr/zmake/tests/test_util.py index 1ec0076162..c5efa2d18e 100644 --- a/zephyr/zmake/tests/test_util.py +++ b/zephyr/zmake/tests/test_util.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -7,10 +7,9 @@ import pathlib import tempfile -import hypothesis -import hypothesis.strategies as st -import pytest - +import hypothesis # pylint:disable=import-error +import hypothesis.strategies as st # pylint:disable=import-error +import pytest # pylint:disable=import-error import zmake.util as util # Strategies for use with hypothesis diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py index 9e00473752..d6202c0d85 100644 --- a/zephyr/zmake/tests/test_version.py +++ b/zephyr/zmake/tests/test_version.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -8,8 +8,7 @@ import datetime import subprocess import unittest.mock as mock -import pytest - +import pytest # pylint: disable=import-error import zmake.output_packers import zmake.project import zmake.version as version @@ -40,7 +39,9 @@ def _git_commit(repo, message="message!"): "GIT_COMMITTER_EMAIL": "bitdiddle@example.org", "GIT_COMMITTER_DATE": "Tue, 30 Aug 2005 10:50:30 -0700", } - subprocess.run(["git", "-C", repo, "commit", "-m", message], check=True, env=env) + subprocess.run( + ["git", "-C", repo, "commit", "-m", message], check=True, env=env + ) def _setup_example_repos(tmp_path): @@ -95,7 +96,9 @@ def test_version_string(tmp_path): """Test a that version string is as expected.""" project, zephyr_base, modules = _setup_example_repos(tmp_path) assert ( - version.get_version_string(project, zephyr_base, modules) + version.get_version_string( + project.config.project_name, zephyr_base, modules + ) == "prj_v2.6.4-ec:b5991f,os:377d26,mod1:02fd7a" ) @@ -104,7 +107,9 @@ def test_version_string_static(tmp_path): """Test a that version string with no git hashes.""" project, zephyr_base, modules = _setup_example_repos(tmp_path) assert ( - version.get_version_string(project, zephyr_base, modules, static=True) + version.get_version_string( + project.config.project_name, zephyr_base, modules, static=True + ) == "prj_v2.6.0-STATIC" ) @@ -128,7 +133,7 @@ def fake_date(): HEADER_VERSION_STR = "trogdor_v2.6.1004-cmsis:0dead0,hal_stm32:0beef0,os:ad00da" EXPECTED_HEADER = ( - "/* This file is automatically generated by zmake */\n" + "/* This file is automatically generated by zmake_tests */\n" '#define VERSION "trogdor_v2.6.1004-cmsis:0dead0,hal_stm32:0beef0,os:ad00da"\n' '#define CROS_EC_VERSION32 "trogdor_v2.6.1004-cmsis:0dead0,"\n' '#define BUILDER "toukmond@pokey"\n' @@ -137,7 +142,7 @@ EXPECTED_HEADER = ( ) HEADER_VERSION_STR_STATIC = "trogdor_v2.6.0-STATIC" EXPECTED_HEADER_STATIC = ( - "/* This file is automatically generated by zmake */\n" + "/* This file is automatically generated by zmake_tests */\n" '#define VERSION "trogdor_v2.6.0-STATIC"\n' '#define CROS_EC_VERSION32 "trogdor_v2.6.0-STATIC"\n' '#define BUILDER "reproducible@build"\n' @@ -150,7 +155,7 @@ def test_header_gen(fake_user_hostname, fake_date, tmp_path): """Test generating the version header.""" # Test the simple case (static=False, no existing header). output_file = tmp_path / "ec_version.h" - version.write_version_header(HEADER_VERSION_STR, output_file) + version.write_version_header(HEADER_VERSION_STR, output_file, "zmake_tests") assert output_file.read_text() == EXPECTED_HEADER @@ -158,7 +163,9 @@ def test_header_gen_reproducible_build(tmp_path): """Test that reproducible builds produce the right header.""" # With static=True this time. output_file = tmp_path / "ec_version.h" - version.write_version_header(HEADER_VERSION_STR_STATIC, output_file, static=True) + version.write_version_header( + HEADER_VERSION_STR_STATIC, output_file, "zmake_tests", static=True + ) assert output_file.read_text() == EXPECTED_HEADER_STATIC @@ -168,27 +175,31 @@ def test_header_gen_exists_not_changed(fake_user_hostname, fake_date, tmp_path): output_file = tmp_path / "ec_version.h" # First time, write and record mtime. - version.write_version_header(HEADER_VERSION_STR, output_file) + version.write_version_header(HEADER_VERSION_STR, output_file, "zmake_tests") expected_mtime = output_file.stat().st_mtime # Do another write (contents should be unchanged). - version.write_version_header(HEADER_VERSION_STR, output_file) + version.write_version_header(HEADER_VERSION_STR, output_file, "zmake_tests") # Assert we didn't write again. assert output_file.stat().st_mtime == expected_mtime -def test_header_gen_exists_needs_changes(fake_user_hostname, fake_date, tmp_path): +def test_header_gen_exists_needs_changes( + fake_user_hostname, fake_date, tmp_path +): """Test that the version file is changed, when needed.""" # Test we overwrite when it exists already and changes are needed. output_file = tmp_path / "ec_version.h" # First time, write and save contents. - version.write_version_header(HEADER_VERSION_STR, output_file) + version.write_version_header(HEADER_VERSION_STR, output_file, "zmake_tests") original_contents = output_file.read_text() # Do another write (contents should be changed). - version.write_version_header(HEADER_VERSION_STR_STATIC, output_file, static=True) + version.write_version_header( + HEADER_VERSION_STR_STATIC, output_file, "zmake_tests", static=True + ) # Assert we overwrote. assert output_file.read_text() != original_contents diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py index 4ca1d7f077..370e8d1bfa 100644 --- a/zephyr/zmake/tests/test_zmake.py +++ b/zephyr/zmake/tests/test_zmake.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -10,15 +10,14 @@ import pathlib import re import unittest.mock -import pytest -from testfixtures import LogCapture - +import pytest # pylint:disable=import-error import zmake.build_config import zmake.jobserver import zmake.multiproc as multiproc import zmake.output_packers import zmake.project import zmake.toolchains +from testfixtures import LogCapture # pylint:disable=import-error OUR_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -75,8 +74,7 @@ class FakeJobserver(zmake.jobserver.GNUMakeJobServer): fnames: Dict of regexp to filename. If the regexp matches the command, then the filename will be returned as the output. """ - super().__init__() - self.jobserver = zmake.jobserver.GNUMakeJobServer(jobs=2) + super().__init__(jobs=2) self.fnames = fnames def get_job(self): @@ -88,14 +86,21 @@ class FakeJobserver(zmake.jobserver.GNUMakeJobServer): """Ignores the provided command and just runs 'cat' instead""" for pattern, filename in self.fnames.items(): # Convert to a list of strings - cmd = [isinstance(c, pathlib.PosixPath) and c.as_posix() or c for c in cmd] + cmd = [ + isinstance(c, pathlib.PosixPath) and c.as_posix() or c + for c in cmd + ] if pattern.match(" ".join(cmd)): new_cmd = ["cat", filename] break else: raise Exception('No pattern matched "%s"' % " ".join(cmd)) - kwargs.pop("env", None) - return self.jobserver.popen(new_cmd, *args, **kwargs) + kwargs["env"] = {} + return super().popen(new_cmd, *args, **kwargs) + + def env(self): + """Runs test commands with an empty environment for simpler logs.""" + return {} def get_test_filepath(suffix): @@ -168,7 +173,9 @@ class TestFilters: expected = { "Configuring fakeproject:rw.", "Configuring fakeproject:ro.", - "Building fakeproject in {}/ec/build/zephyr/fakeproject.".format(tmp_path), + "Building fakeproject in {}/ec/build/zephyr/fakeproject.".format( + tmp_path + ), "Building fakeproject:ro: /usr/bin/ninja -C {}-ro".format( tmp_path / "ec/build/zephyr/fakeproject/build" ), @@ -179,7 +186,9 @@ class TestFilters: for suffix in ["ro", "rw"]: with open(get_test_filepath("%s_INFO" % suffix)) as file: for line in file: - expected.add("[fakeproject:{}]{}".format(suffix, line.strip())) + expected.add( + "[fakeproject:{}]{}".format(suffix, line.strip()) + ) # This produces an easy-to-read diff if there is a difference assert expected == set(recs) @@ -192,20 +201,24 @@ class TestFilters: expected = { "Configuring fakeproject:rw.", "Configuring fakeproject:ro.", - "Building fakeproject in {}/ec/build/zephyr/fakeproject.".format(tmp_path), + "Building fakeproject in {}/ec/build/zephyr/fakeproject.".format( + tmp_path + ), "Building fakeproject:ro: /usr/bin/ninja -C {}-ro".format( tmp_path / "ec/build/zephyr/fakeproject/build" ), "Building fakeproject:rw: /usr/bin/ninja -C {}-rw".format( tmp_path / "ec/build/zephyr/fakeproject/build" ), - "Running cat {}/files/sample_ro.txt".format(OUR_PATH), - "Running cat {}/files/sample_rw.txt".format(OUR_PATH), + "Running `env -i cat {}/files/sample_ro.txt`".format(OUR_PATH), + "Running `env -i cat {}/files/sample_rw.txt`".format(OUR_PATH), } for suffix in ["ro", "rw"]: with open(get_test_filepath(suffix)) as file: for line in file: - expected.add("[fakeproject:{}]{}".format(suffix, line.strip())) + expected.add( + "[fakeproject:{}]{}".format(suffix, line.strip()) + ) # This produces an easy-to-read diff if there is a difference assert expected == set(recs) @@ -219,7 +232,9 @@ class TestFilters: ) dt_errs = [rec for rec in recs if "adc" in rec] - assert "devicetree error: 'adc' is marked as required" in list(dt_errs)[0] + assert ( + "devicetree error: 'adc' is marked as required" in list(dt_errs)[0] + ) @pytest.mark.parametrize( @@ -265,7 +280,7 @@ class TestFilters: ) def test_list_projects( project_names, fmt, search_dir, expected_output, capsys, zmake_from_dir -): # pylint: disable=too-many-arguments +): """Test listing projects with default directory.""" fake_projects = { name: zmake.project.Project( |