test(core): only start Tropic model if the Trezor emulator needs it
What changed, and why it matters
This commit changes test infrastructure so that the Tropic01 model (a separate emulator component) is only started when the Trezor emulator being tested actually supports it. Previously it was started by default. There is no indication this fixes a security vulnerability; it appears to be a test optimization.
No security action required; this is a test-infrastructure optimization. Reviewers may verify it does not break tests for Tropic-capable emulators.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies core/emu.py, tests/conftest.py, and tests/emulators.py. It changes the default of –tropic-emulator from True to None, then derives the actual value from emulator.properties().get(‘tropic’, False). In tests, a new fixture tropic_model_port replaces tropic_model and only starts the Tropic01 model if EmulatorWrapper.executable_is_tropic_capable() returns True. This avoids unnecessary Tropic model startup for emulator variants that do not need it.
Changed components
core/emu.pytests/conftest.pytests/emulators.pyInspect captured patch +25 / −8
diff --git a/core/emu.py b/core/emu.py
index 5c968c20..06bb3feb 100755
--- a/core/emu.py
+++ b/core/emu.py
@@ -143,7 +143,7 @@ def _from_env(name: str) -> bool:
@click.option("-s", "--slip0014", is_flag=True, help="Initialize device with SLIP-14 seed (all all all...)")
@click.option("-S", "--script-gdb-file", type=click.Path(exists=True, dir_okay=False), help="Run gdb with an init file")
@click.option("-t", "--temporary-profile", is_flag=True, help="Create an empty temporary profile")
-@click.option("--tropic-emulator/--no-tropic-emulator", default=True, help="Start Tropic01 model")
+@click.option("--tropic-emulator/--no-tropic-emulator", default=None, help="Start Tropic01 model")
@click.option("--tropic-emulator-config", type=click.Path(exists=True, dir_okay=False), default=TROPIC_MODEL_CONFIG, help="Tropic01 model configuration file")
@click.option("-V", "--valgrind", is_flag=True, help="Use valgrind instead of debugger (-D)")
@click.option("-w", "--watch", is_flag=True, help="Restart emulator if sources change")
@@ -172,7 +172,7 @@ def cli(
slip0014: bool,
script_gdb_file: str | Path | None,
temporary_profile: bool,
- tropic_emulator: bool,
+ tropic_emulator: bool | None,
tropic_emulator_config: Path,
valgrind: bool,
watch: bool,
@@ -299,6 +299,8 @@ def cli(
os.environ["TREZOR_MEMPERF"] = "1"
tropic_model = None
+ if tropic_emulator is None:
+ tropic_emulator = emulator.properties().get("tropic", False)
if tropic_emulator:
tropic_model = TropicModel(
profile_dir=str(profile_dir),
diff --git a/tests/conftest.py b/tests/conftest.py
index fdbd432d..04696c97 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -96,8 +96,19 @@ def _get_worker_id(request: pytest.FixtureRequest) -> int:
@pytest.fixture(scope="session")
-def tropic_model(request: pytest.FixtureRequest) -> t.Iterator[TropicModel]:
+def tropic_model_port(request: pytest.FixtureRequest) -> t.Iterator[int | None]:
+ """Fixture that starts Tropic01 model and returns the TCP port it's running on.
+ It returns None if the currently tested emulator does not need it."""
worker_id = _get_worker_id(request)
+
+ emulator_wrapper = EmulatorWrapper(
+ request.session.config.getoption("model") or "core"
+ )
+ if not emulator_wrapper.executable_is_tropic_capable():
+ LOG.debug(f"Not starting tropic model (worker {worker_id})")
+ yield None
+ return
+
logfile = get_logfile(f"trezor-tropic-model-{worker_id}.log")
port = get_tropic_model_port(worker_id)
@@ -114,18 +125,18 @@ def tropic_model(request: pytest.FixtureRequest) -> t.Iterator[TropicModel]:
logfile=logfile,
) as tropic_model:
tropic_model.start()
- yield tropic_model
+ yield tropic_model.port
@pytest.fixture
def core_emulator(
- tropic_model: TropicModel, request: pytest.FixtureRequest
+ tropic_model_port: int | None, request: pytest.FixtureRequest
) -> t.Iterator[Emulator]:
"""Fixture returning default core emulator with possibility of screen recording."""
with EmulatorWrapper(
"core",
main_args=_emulator_wrapper_main_args(),
- tropic_model_port=tropic_model.port,
+ tropic_model_port=tropic_model_port,
) as emu:
# Modifying emu.client to add screen recording (when --ui=test is used)
_check_protocol(request, emu.client)
@@ -135,7 +146,7 @@ def core_emulator(
@pytest.fixture(scope="session")
def emulator(
- tropic_model: TropicModel, request: pytest.FixtureRequest
+ tropic_model_port: int | None, request: pytest.FixtureRequest
) -> t.Generator["Emulator", None, None]:
"""Fixture for getting emulator connection in case tests should operate it on their own.
@@ -171,7 +182,7 @@ def emulator(
headless=True,
auto_interact=not interact,
main_args=_emulator_wrapper_main_args(),
- tropic_model_port=tropic_model.port,
+ tropic_model_port=tropic_model_port,
) as emu:
yield emu
diff --git a/tests/emulators.py b/tests/emulators.py
index d1bca6bb..73c9c855 100644
--- a/tests/emulators.py
+++ b/tests/emulators.py
@@ -233,6 +233,10 @@ class EmulatorWrapper:
f"Unrecognized gen - {gen} - only 'core' and 'legacy' supported"
)
+ def executable_is_tropic_capable(self) -> bool:
+ """Try running the binary with --emulator-properties to see if it is Tropic capable."""
+ return self.emulator.properties().get("tropic", False)
+
def __enter__(self) -> Emulator:
self.emulator.start()
return self.emulator
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.