diff options
Diffstat (limited to 'zephyr/zmake/tests/test_version.py')
-rw-r--r-- | zephyr/zmake/tests/test_version.py | 41 |
1 files changed, 26 insertions, 15 deletions
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 |