summaryrefslogtreecommitdiff
path: root/zephyr/zmake/tests
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2021-09-13 16:56:53 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-20 17:33:46 +0000
commit695b3c909c4846493eacd324e9c26933847372d1 (patch)
treeff71549a6720d8c68a3b142c6f9186d6a7c4d79b /zephyr/zmake/tests
parent438f1748043d9b9869a8986ac06208e0102554a8 (diff)
downloadchrome-ec-695b3c909c4846493eacd324e9c26933847372d1.tar.gz
zmake: Trim short version on full hashes
The ec_version.h contains both a long build string and also a 31 char string. Change the short string to omit the commit count, and only include full hashes, i.e. hayato_v2.6-ec:5bd1aa,os:ade7b4 not hayato_v2.6.73670-ec:5bd1aa,os: Change test to be a real version string with hashes of the right length. BUG=None BRANCH=None TEST=./zephyr/zmake/run_tests.sh Change-Id: I18d73345036933594b8c74187796c3727f868629 Signed-off-by: Jeremy Bettis <jbettis@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3160464 Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/zmake/tests')
-rw-r--r--zephyr/zmake/tests/test_version.py90
-rw-r--r--zephyr/zmake/tests/test_zmake.py2
2 files changed, 68 insertions, 24 deletions
diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py
index a238a8ac02..b9d2ec0d4b 100644
--- a/zephyr/zmake/tests/test_version.py
+++ b/zephyr/zmake/tests/test_version.py
@@ -88,17 +88,17 @@ def _setup_example_repos(tmp_path):
def test_version_string(tmp_path):
project, zephyr_base, modules = _setup_example_repos(tmp_path)
- assert (
- version.get_version_string(project, zephyr_base, modules)
- == "prj_v2.6.4-ec:b5991f,os:377d26,mod1:02fd7a"
+ assert version.get_version_string(project, zephyr_base, modules) == (
+ "prj_v2.6.4-ec:b5991f,os:377d26,mod1:02fd7a",
+ "prj_v2.6-ec:b5991f,os:377d26",
)
def test_version_string_static(tmp_path):
project, zephyr_base, modules = _setup_example_repos(tmp_path)
- assert (
- version.get_version_string(project, zephyr_base, modules, static=True)
- == "prj_v2.6.0-STATIC"
+ assert version.get_version_string(project, zephyr_base, modules, static=True) == (
+ "prj_v2.6.0-STATIC",
+ "prj_v2.6.0-STATIC",
)
@@ -117,17 +117,36 @@ def fake_date():
yield
-HEADER_VERSION_STR = "trogdor_v2.6.1004-cmsis:0dead0,hal_stm32:0beef0,os:ad00da"
+HEADER_VERSION_STR = (
+ "hayato_v2.6.73670-ec:5bd1aa,os:ade7b4,cmsis:c3bd20,hal_stm32:f8ff8d"
+)
+SHORT_HEADER_VERSION_STR = "hayato_v2.6-ec:5bd1aa,os:ade7b4"
EXPECTED_HEADER = (
"/* This file is automatically generated by zmake */\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 VERSION "hayato_v2.6.73670-ec:5bd1aa,os:ade7b4,cmsis:c3bd20,'
+ 'hal_stm32:f8ff8d"\n'
+ '#define CROS_EC_VERSION32 "hayato_v2.6-ec:5bd1aa,os:ade7b4"\n'
+ '#define BUILDER "toukmond@pokey"\n'
+ '#define DATE "2021-06-28 03:18:53"\n'
+ '#define CROS_FWID_MISSING_STR "CROS_FWID_MISSING"\n'
+ "#define CROS_FWID32 CROS_FWID_MISSING_STR\n"
+)
+HEADER_VERSION_STR2 = (
+ "herobrine_npcx9_v2.6.73695-ec:7b0169,os:862339,cmsis:c3bd20,hal_stm32:f8ff8d"
+)
+SHORT_HEADER_VERSION_STR2 = "herobrine_npcx9_v2.6-ec:7b0169"
+EXPECTED_HEADER2 = (
+ "/* This file is automatically generated by zmake */\n"
+ '#define VERSION "herobrine_npcx9_v2.6.73695-ec:7b0169,os:862339,'
+ 'cmsis:c3bd20,hal_stm32:f8ff8d"\n'
+ '#define CROS_EC_VERSION32 "herobrine_npcx9_v2.6-ec:7b0169"\n'
'#define BUILDER "toukmond@pokey"\n'
'#define DATE "2021-06-28 03:18:53"\n'
'#define CROS_FWID_MISSING_STR "CROS_FWID_MISSING"\n'
"#define CROS_FWID32 CROS_FWID_MISSING_STR\n"
)
HEADER_VERSION_STR_STATIC = "trogdor_v2.6.0-STATIC"
+SHORT_HEADER_VERSION_STR_STATIC = "trogdor_v2.6.0-STATIC"
EXPECTED_HEADER_STATIC = (
"/* This file is automatically generated by zmake */\n"
'#define VERSION "trogdor_v2.6.0-STATIC"\n'
@@ -139,18 +158,32 @@ EXPECTED_HEADER_STATIC = (
)
-def test_header_gen(fake_user_hostname, fake_date, tmp_path):
+@pytest.mark.parametrize(
+ "version_str,short_version_str,expected_header,static",
+ [
+ (HEADER_VERSION_STR, SHORT_HEADER_VERSION_STR, EXPECTED_HEADER, False),
+ (HEADER_VERSION_STR2, SHORT_HEADER_VERSION_STR2, EXPECTED_HEADER2, False),
+ (
+ HEADER_VERSION_STR_STATIC,
+ SHORT_HEADER_VERSION_STR_STATIC,
+ EXPECTED_HEADER_STATIC,
+ True,
+ ),
+ ],
+)
+def test_header_gen(
+ fake_user_hostname,
+ fake_date,
+ tmp_path,
+ version_str,
+ short_version_str,
+ expected_header,
+ static,
+):
# 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)
- assert output_file.read_text() == EXPECTED_HEADER
-
-
-def test_header_gen_reproducible_build(tmp_path):
- # With static=True this time.
- output_file = tmp_path / "ec_version.h"
- version.write_version_header(HEADER_VERSION_STR_STATIC, output_file, static=True)
- assert output_file.read_text() == EXPECTED_HEADER_STATIC
+ version.write_version_header(version_str, short_version_str, output_file, static)
+ assert output_file.read_text() == expected_header
def test_header_gen_exists_not_changed(fake_user_hostname, fake_date, tmp_path):
@@ -158,11 +191,15 @@ 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, SHORT_HEADER_VERSION_STR, output_file
+ )
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, SHORT_HEADER_VERSION_STR, output_file
+ )
# Assert we didn't write again.
assert output_file.stat().st_mtime == expected_mtime
@@ -173,11 +210,18 @@ def test_header_gen_exists_needs_changes(fake_user_hostname, fake_date, tmp_path
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, SHORT_HEADER_VERSION_STR, output_file
+ )
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,
+ SHORT_HEADER_VERSION_STR_STATIC,
+ output_file,
+ 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 641f9f3db9..e57a4f5ed3 100644
--- a/zephyr/zmake/tests/test_zmake.py
+++ b/zephyr/zmake/tests/test_zmake.py
@@ -141,7 +141,7 @@ EXTRAVERSION =
"""
)
zephyr_base.resolve = mock.Mock(return_value=pathlib.Path(tmpname))
- with patch("zmake.version.get_version_string", return_value="123"):
+ with patch("zmake.version.get_version_string", return_value=("123", "123")):
with patch.object(zmake.project, "Project", return_value=FakeProject()):
if use_configure:
zmk.configure(