Skip to content

Commit c40c8e6

Browse files
committed
[red] Cover isolated host mpy-cross reuse
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent c4b6705 commit c40c8e6

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎tests/firmware_tests/host/test_release_hardening.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ def __init__(self):
627627
self.fake_artifacts = self.root / "fake-artifacts"
628628
self.make_log = self.root / "make-invocations.log"
629629
self.make_environment_log = self.root / "make-environment.log"
630+
self.mpy_cross_environment_log = self.root / "mpy-cross-environment.log"
630631
self.esptool_log = self.root / "esptool-invocations.log"
631632
scripts = self.firmware / "scripts"
632633
scripts.mkdir(parents=True)
@@ -757,6 +758,8 @@ def __init__(self):
757758
"${MFLAGS-}" \
758759
"${GNUMAKEFLAGS-}" \
759760
"${MAKEOVERRIDES-}" >> "$PYBLE_MAKE_ENV_LOG"
761+
printf '%s\n' "${MICROPY_MPYCROSS-}" \
762+
>> "$PYBLE_MPY_CROSS_ENV_LOG"
760763
output=""
761764
for argument in "$@"; do
762765
case "$argument" in
@@ -836,7 +839,9 @@ def build(self) -> subprocess.CompletedProcess[str]:
836839
"PYBLE_FAKE_ARTIFACTS": str(self.fake_artifacts),
837840
"PYBLE_MAKE_LOG": str(self.make_log),
838841
"PYBLE_MAKE_ENV_LOG": str(self.make_environment_log),
842+
"PYBLE_MPY_CROSS_ENV_LOG": str(self.mpy_cross_environment_log),
839843
"PYBLE_ESPTOOL_LOG": str(self.esptool_log),
844+
"BUILD": str(self.root / "hostile-mpy-cross-build"),
840845
"CFLAGS_EXTRA": (
841846
"-ffile-prefix-map=/ambient/source=/HOSTILE "
842847
"-DHOSTILE_BUILD_FLAG=1"
@@ -883,6 +888,13 @@ def esptool_invocations(self) -> list[list[str]]:
883888
for line in self.esptool_log.read_text(encoding="utf-8").splitlines()
884889
]
885890

891+
def mpy_cross_environments(self) -> list[str]:
892+
if not self.mpy_cross_environment_log.exists():
893+
return []
894+
return self.mpy_cross_environment_log.read_text(
895+
encoding="utf-8"
896+
).splitlines()
897+
886898

887899
class BuildProvenanceEmissionTests(unittest.TestCase):
888900
def test_build_exercises_version_matched_recovery_subcommand(self):
@@ -981,6 +993,28 @@ def test_port_build_uses_only_stable_source_prefix_maps(self):
981993
finally:
982994
fixture.cleanup()
983995

996+
def test_port_build_reuses_the_explicitly_built_host_mpy_cross(self):
997+
fixture = BuildScriptFixture()
998+
try:
999+
completed = fixture.build()
1000+
self.assertEqual(completed.returncode, 0, completed.stdout)
1001+
self.assertEqual(
1002+
fixture.make_invocations()[0].count("BUILD=build"),
1003+
1,
1004+
"the host compiler build must ignore an ambient BUILD path",
1005+
)
1006+
expected = str(
1007+
fixture.upstream.resolve() / "mpy-cross" / "build" / "mpy-cross"
1008+
)
1009+
self.assertEqual(
1010+
fixture.mpy_cross_environments(),
1011+
["", expected, expected],
1012+
"port phases must use the admitted host compiler instead of "
1013+
"rebuilding it with the target BUILD inherited through make",
1014+
)
1015+
finally:
1016+
fixture.cleanup()
1017+
9841018
def test_build_rejects_host_source_paths_remaining_in_elf(self):
9851019
for label in ("retained MicroPython", "PyBLE", "selected build root"):
9861020
with self.subTest(source=label):

0 commit comments

Comments
 (0)