summaryrefslogtreecommitdiff
path: root/zephyr/zmake
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-02-24 17:33:09 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-28 18:28:49 +0000
commit8679d57fcada1ab04a202785c12824a86ca7a215 (patch)
tree3ee88155a9f68fc6a9c147c849eedc002ab6fd9e /zephyr/zmake
parent8cde76ad3745fef6708f7636a5ba39fad359ecdf (diff)
downloadchrome-ec-8679d57fcada1ab04a202785c12824a86ca7a215.tar.gz
zmake: Bring toolchains test to 100% coverage
Added some tests to cover 100% of zmake/toolchains.py BRANCH=None BUG=b:219062927 TEST=Ran tests with coverage Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I420d3535cbe3433e87ab8f7cb86c17aefca3765e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3491406 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/zmake')
-rw-r--r--zephyr/zmake/tests/test_toolchains.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/zephyr/zmake/tests/test_toolchains.py b/zephyr/zmake/tests/test_toolchains.py
index 788a7f2b66..910a5faa78 100644
--- a/zephyr/zmake/tests/test_toolchains.py
+++ b/zephyr/zmake/tests/test_toolchains.py
@@ -74,6 +74,13 @@ def zephyr_exists(mockfs):
@pytest.fixture
+def no_environ(monkeypatch):
+ """Clear all environment variables."""
+ environ = {}
+ monkeypatch.setattr(os, "environ", environ)
+
+
+@pytest.fixture
def fake_project(tmp_path):
"""Create a project that can be used in all the tests."""
return project.Project(
@@ -121,11 +128,8 @@ def test_llvm(fake_project, llvm_exists):
}
-def test_zephyr(fake_project: project.Project, zephyr_exists, monkeypatch):
+def test_zephyr(fake_project: project.Project, zephyr_exists, no_environ):
"""Test that the zephyr sdk can be found in a standard location."""
- environ = {}
- monkeypatch.setattr(os, "environ", environ)
-
chain = fake_project.get_toolchain(module_paths)
assert isinstance(chain, toolchains.ZephyrToolchain)
@@ -177,3 +181,25 @@ def test_toolchain_override(mockfs, fake_project):
config = chain.get_build_config()
assert isinstance(chain, toolchains.GenericToolchain)
assert config.cmake_defs == {"ZEPHYR_TOOLCHAIN_VARIANT": "foo"}
+
+
+def test_generic_toolchain():
+ """Verify that GenericToolchain.probe() returns False."""
+ chain = toolchains.GenericToolchain("name")
+ assert not chain.probe()
+
+
+def test_no_toolchains(fake_project: project.Project, mockfs, no_environ):
+ """Check for error when there are no toolchains."""
+ with pytest.raises(
+ OSError, match=r"No supported toolchains could be found on your system"
+ ):
+ fake_project.get_toolchain(module_paths)
+
+
+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"):
+ chain.get_build_config()