summaryrefslogtreecommitdiff
path: root/zephyr/zmake/tests
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-06-08 23:50:54 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-10 21:30:45 +0000
commit297a01b67e5405c80b12a83ac8c12511841918a0 (patch)
tree10bdf567713b1016af75fadd44a3e5be7f40cf75 /zephyr/zmake/tests
parent2ce3beec20501d1975acb69053d724c6b391f849 (diff)
downloadchrome-ec-297a01b67e5405c80b12a83ac8c12511841918a0.tar.gz
zmake: test final file output size
Zephyr's build allows the image to consume the full flash size (CONFIG_FLASH_SIZE) since it doesn't assume anything about how chromium lays out the images (using RO/RW). This means that in systems with 512Kb of flash space, images taking up more than 256Kb will successfully build (even though the final image will be larger than 512Kb). Add a check in the output packers for the final size. This test ignores by default the .elf extension. BRANCH=none BUG=b:190435084 TEST=Added unit tests TEST=build brya Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I94f1657d0ff44d79920ae5e8e7f11edf1580de05 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2948169 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'zephyr/zmake/tests')
-rw-r--r--zephyr/zmake/tests/test_packers.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/zephyr/zmake/tests/test_packers.py b/zephyr/zmake/tests/test_packers.py
new file mode 100644
index 0000000000..21361a925f
--- /dev/null
+++ b/zephyr/zmake/tests/test_packers.py
@@ -0,0 +1,51 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import hypothesis
+import hypothesis.strategies as st
+import pathlib
+import pytest
+import tempfile
+import unittest.mock as mock
+
+import zmake.output_packers as packers
+
+# Strategies for use with hypothesis
+absolute_path = st.from_regex(regex=r"\A/[\w/]*\Z")
+
+@hypothesis.given(absolute_path)
+@hypothesis.settings(deadline=60000)
+def test_file_size_unbounded(path):
+ packer = packers.BasePacker(project=None)
+ packer._is_size_bound = mock.Mock(name='_is_size_bound', return_value=False)
+ file = pathlib.Path(path) / 'zephyr.bin'
+ assert packer._check_packed_file_size(file=file, dirs={}) == file
+ packer._is_size_bound.assert_called_once_with(file)
+
+@hypothesis.given(st.binary(min_size=5, max_size=100))
+@hypothesis.settings(deadline=60000)
+def test_file_size_in_bounds(data):
+ packer = packers.BasePacker(project=None)
+ packer._is_size_bound = mock.Mock(name='_is_size_bound', return_value=True)
+ packer._get_max_image_bytes = mock.Mock(name='_get_max_image_bytes',
+ return_value=100)
+ with tempfile.TemporaryDirectory() as temp_dir_name:
+ file = pathlib.Path(temp_dir_name) / 'zephyr.bin'
+ with open(file, 'wb') as f:
+ f.write(data)
+ assert packer._check_packed_file_size(file=file, dirs={}) == file
+
+@hypothesis.given(st.binary(min_size=101, max_size=200))
+@hypothesis.settings(deadline=60000)
+def test_file_size_out_of_bounds(data):
+ packer = packers.BasePacker(project=None)
+ packer._is_size_bound = mock.Mock(name='_is_size_bound', return_value=True)
+ packer._get_max_image_bytes = mock.Mock(name='_get_max_image_bytes',
+ return_value=100)
+ with tempfile.TemporaryDirectory() as temp_dir_name:
+ file = pathlib.Path(temp_dir_name) / 'zephyr.bin'
+ with open(file, 'wb') as f:
+ f.write(data)
+ with pytest.raises(RuntimeError):
+ packer._check_packed_file_size(file=file, dirs={}) \ No newline at end of file