summaryrefslogtreecommitdiff
path: root/zephyr/zmake/tests/test_project.py
diff options
context:
space:
mode:
authorScott Collyer <scollyer@google.com>2021-11-23 15:04:49 -0800
committerScott Collyer <scollyer@google.com>2021-11-23 15:04:49 -0800
commit817cf2223b0b33c91ca6e369b644cbc4d6c361e3 (patch)
treef698bbab73d87af25f9fdc2d49f50a0c25111a79 /zephyr/zmake/tests/test_project.py
parent6da8436a8ce04a7f88f80049a10638e1b8f6439d (diff)
parent0349a5b6d95308141754523708a2d11d8bacce4c (diff)
downloadchrome-ec-817cf2223b0b33c91ca6e369b644cbc4d6c361e3.tar.gz
Merge remote-tracking branch 'cros/main' into firmware-gwc-fsi
Change-Id: Id9b5b5cb1db7428cd9f12452d73842d8c1f2705a
Diffstat (limited to 'zephyr/zmake/tests/test_project.py')
-rw-r--r--zephyr/zmake/tests/test_project.py208
1 files changed, 133 insertions, 75 deletions
diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py
index 2442ceedf6..f7688784e7 100644
--- a/zephyr/zmake/tests/test_project.py
+++ b/zephyr/zmake/tests/test_project.py
@@ -11,28 +11,13 @@ import hypothesis.strategies as st
import pytest
import zmake.modules
+import zmake.output_packers
import zmake.project
board_names = st.text(alphabet=set(string.ascii_lowercase) | {"_"}, min_size=1)
sets_of_board_names = st.lists(st.lists(board_names, unique=True))
-class TemporaryProject(tempfile.TemporaryDirectory):
- """A temporary project wrapper.
-
- Args:
- config: The config dictionary to be used with the project.
- """
-
- def __init__(self, config):
- self.config = config
- super().__init__()
-
- def __enter__(self):
- project_path = pathlib.Path(super().__enter__())
- return zmake.project.Project(project_path, config_dict=self.config)
-
-
@hypothesis.given(sets_of_board_names)
@hypothesis.settings(deadline=None)
def test_find_dts_overlays(modules):
@@ -67,21 +52,21 @@ def test_find_dts_overlays(modules):
board_file_mapping[board] = files | {file_name}
for board, expected_dts_files in board_file_mapping.items():
- with TemporaryProject(
- {
- "board": board,
- "output-type": "elf",
- "supported-toolchains": ["llvm"],
- "supported-zephyr-versions": ["v2.6"],
- }
- ) as project:
- config = project.find_dts_overlays(dict(enumerate(module_paths)))
-
- actual_dts_files = set(
- config.cmake_defs.get("DTC_OVERLAY_FILE", "").split(";")
+ project = zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name=board,
+ zephyr_board=board,
+ output_packer=zmake.output_packers.ElfPacker,
+ supported_toolchains=["llvm"],
+ project_dir=pathlib.Path("/fakebuild"),
)
+ )
+ config = project.find_dts_overlays(dict(enumerate(module_paths)))
+ actual_dts_files = set(
+ config.cmake_defs.get("DTC_OVERLAY_FILE", "").split(";")
+ )
- assert actual_dts_files == set(map(str, expected_dts_files))
+ assert actual_dts_files == set(map(str, expected_dts_files))
setup_modules_and_dispatch(modules, testcase)
@@ -101,16 +86,17 @@ def test_prune_modules(modules):
for name in zmake.modules.known_modules
}
- with TemporaryProject(
- {
- "board": "native_posix",
- "output-type": "elf",
- "supported-toolchains": ["coreboot-sdk"],
- "supported-zephyr-versions": ["v2.6"],
- "modules": modules,
- }
- ) as project:
- assert set(project.prune_modules(module_paths)) == set(modules)
+ project = zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name="prunetest",
+ zephyr_board="native_posix",
+ output_packer=zmake.output_packers.ElfPacker,
+ supported_toolchains=["coreboot-sdk"],
+ project_dir=pathlib.Path("/fake"),
+ modules=modules,
+ ),
+ )
+ assert set(project.prune_modules(module_paths)) == set(modules)
def test_prune_modules_unavailable():
@@ -122,17 +108,18 @@ def test_prune_modules_unavailable():
"hal_stm32": pathlib.Path("/mod/halstm"),
}
- with TemporaryProject(
- {
- "board": "native_posix",
- "output-type": "elf",
- "supported-toolchains": ["coreboot-sdk"],
- "supported-zephyr-versions": ["v2.6"],
- "modules": ["hal_stm32", "cmsis"],
- }
- ) as project:
- with pytest.raises(KeyError):
- project.prune_modules(module_paths)
+ project = zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name="prunetest",
+ zephyr_board="native_posix",
+ output_packer=zmake.output_packers.ElfPacker,
+ supported_toolchains=["coreboot-sdk"],
+ project_dir=pathlib.Path("/fake"),
+ modules=["hal_stm32", "cmsis"],
+ ),
+ )
+ with pytest.raises(KeyError):
+ project.prune_modules(module_paths)
def test_find_projects_empty(tmp_path):
@@ -141,33 +128,104 @@ def test_find_projects_empty(tmp_path):
assert len(projects) == 0
-YAML_FILE = """
-supported-zephyr-versions:
- - v2.6
-supported-toolchains:
- - coreboot-sdk
-output-type: npcx
+CONFIG_FILE_1 = """
+register_raw_project(project_name="one", zephyr_board="one")
+register_host_test(test_name="two")
+register_npcx_project(project_name="three", zephyr_board="three")
+register_binman_project(project_name="four", zephyr_board="four")
+"""
+
+CONFIG_FILE_2 = """
+register_raw_project(
+ project_name="five",
+ zephyr_board="foo",
+ dts_overlays=[here / "gpio.dts"],
+)
"""
def test_find_projects(tmp_path):
"""Test the find_projects method when there are projects."""
- dir = tmp_path.joinpath("one")
- dir.mkdir()
- dir.joinpath("zmake.yaml").write_text("board: one\n" + YAML_FILE)
- tmp_path.joinpath("two").mkdir()
- dir = tmp_path.joinpath("two/a")
- dir.mkdir()
- dir.joinpath("zmake.yaml").write_text("board: twoa\nis-test: true\n" + YAML_FILE)
- dir = tmp_path.joinpath("two/b")
- dir.mkdir()
- dir.joinpath("zmake.yaml").write_text("board: twob\n" + YAML_FILE)
- projects = list(zmake.project.find_projects(tmp_path))
- projects.sort(key=lambda x: x.project_dir)
- assert len(projects) == 3
- assert projects[0].project_dir == tmp_path.joinpath("one")
- assert projects[1].project_dir == tmp_path.joinpath("two/a")
- assert projects[2].project_dir == tmp_path.joinpath("two/b")
- assert not projects[0].config.is_test
- assert projects[1].config.is_test
- assert not projects[2].config.is_test
+ cf1_dir = tmp_path / "cf1"
+ cf1_dir.mkdir()
+ (cf1_dir / "BUILD.py").write_text(CONFIG_FILE_1)
+
+ cf2_bb_dir = tmp_path / "cf2_bb"
+ cf2_bb_dir.mkdir()
+ cf2_dir = cf2_bb_dir / "cf2"
+ cf2_dir.mkdir()
+ (cf2_dir / "BUILD.py").write_text(CONFIG_FILE_2)
+
+ projects = zmake.project.find_projects(tmp_path)
+ assert len(projects) == 5
+ assert projects["one"].config.project_dir == cf1_dir
+ assert not projects["one"].config.is_test
+
+ assert projects["test-two"].config.project_dir == cf1_dir
+ assert projects["test-two"].config.zephyr_board == "native_posix"
+ assert projects["test-two"].config.is_test
+
+ assert projects["three"].config.project_dir == cf1_dir
+ assert not projects["three"].config.is_test
+ assert projects["three"].config.zephyr_board == "three"
+
+ assert projects["four"].config.project_dir == cf1_dir
+ assert not projects["four"].config.is_test
+ assert projects["four"].config.zephyr_board == "four"
+
+ assert projects["five"].config.project_dir == cf2_dir
+ assert not projects["five"].config.is_test
+ assert projects["five"].config.zephyr_board == "foo"
+
+
+def test_find_projects_name_conflict(tmp_path):
+ """When two projects define the same name, that should be an error."""
+ cf1_dir = tmp_path / "cf1"
+ cf1_dir.mkdir()
+ (cf1_dir / "BUILD.py").write_text(CONFIG_FILE_2)
+
+ cf2_dir = tmp_path / "cf2"
+ cf2_dir.mkdir()
+ (cf2_dir / "BUILD.py").write_text(CONFIG_FILE_2)
+
+ with pytest.raises(KeyError):
+ zmake.project.find_projects(tmp_path)
+
+
+@pytest.mark.parametrize(
+ ("actual_files", "config_files", "expected_files"),
+ [
+ (["prj_link.conf"], [], []),
+ (["prj.conf"], [], ["prj.conf"]),
+ (
+ ["prj.conf", "cfg.conf"],
+ ["prj.conf", "cfg.conf"],
+ ["prj.conf", "cfg.conf"],
+ ),
+ (
+ ["prj.conf", "prj_samus.conf", "prj_link.conf"],
+ ["prj_link.conf"],
+ ["prj.conf", "prj_link.conf"],
+ ),
+ ],
+)
+def test_kconfig_files(tmp_path, actual_files, config_files, expected_files):
+ for name in actual_files:
+ (tmp_path / name).write_text("")
+
+ project = zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name="samus",
+ zephyr_board="lm4",
+ output_packer=zmake.output_packers.RawBinPacker,
+ supported_toolchains=["coreboot-sdk"],
+ project_dir=tmp_path,
+ kconfig_files=[tmp_path / name for name in config_files],
+ ),
+ )
+
+ builds = list(project.iter_builds())
+ assert len(builds) == 1
+
+ _, config = builds[0]
+ assert sorted(f.name for f in config.kconfig_files) == sorted(expected_files)