mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-30 09:11:07 +00:00
feat(tests): allow for coverage report even when emulator is controlled by the tests
Allowing tests to specify the profiling wrapper over the emulator it is starting. [no changelog]
This commit is contained in:
parent
315b6f9b06
commit
41e07769e2
@ -57,12 +57,12 @@ core device test:
|
||||
needs:
|
||||
- core unix frozen debug build
|
||||
variables:
|
||||
TREZOR_PROFILING: 1
|
||||
TREZOR_PROFILING: 1 # so that we get coverage data
|
||||
MULTICORE: 4 # more could interfere with other jobs
|
||||
script:
|
||||
- $NIX_SHELL --run "poetry run make -C core test_emu_ui_multicore | ts -s"
|
||||
after_script:
|
||||
- mv core/src/.coverage core/.coverage.test_emu
|
||||
- mv core/src/.coverage.* core # there will be more coverage files (one per core)
|
||||
- mv tests/ui_tests/reports/test/ test_ui_report
|
||||
- $NIX_SHELL --run "poetry run python ci/prepare_ui_artifacts.py | ts -s"
|
||||
- diff -u tests/ui_tests/fixtures.json tests/ui_tests/fixtures.suggestion.json
|
||||
|
@ -17,6 +17,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Generator
|
||||
|
||||
import pytest
|
||||
@ -37,6 +38,10 @@ if TYPE_CHECKING:
|
||||
from _pytest.config.argparsing import Parser
|
||||
from _pytest.terminal import TerminalReporter
|
||||
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
# So that we see details of failed asserts from this module
|
||||
pytest.register_assert_rewrite("tests.common")
|
||||
|
||||
@ -83,8 +88,23 @@ def emulator(request: pytest.FixtureRequest) -> Generator["Emulator", None, None
|
||||
# 1. normal link, 2. debug link and 3. webauthn fake interface
|
||||
return 20000 + int(worker_id[2:]) * 3
|
||||
|
||||
# So that we can generate coverage reports
|
||||
profiling = os.environ.get("TREZOR_PROFILING") == "1"
|
||||
if profiling:
|
||||
core_dir = HERE.parent / "core"
|
||||
profiling_wrapper = core_dir / "prof" / "prof.py"
|
||||
main_args = [str(profiling_wrapper)]
|
||||
# So that the coverage reports have the correct paths
|
||||
os.environ["TREZOR_SRC"] = str(core_dir / "src")
|
||||
else:
|
||||
main_args = ["-m", "main"]
|
||||
|
||||
with EmulatorWrapper(
|
||||
model, port=_get_port(), headless=True, auto_interact=not interact
|
||||
model,
|
||||
port=_get_port(),
|
||||
headless=True,
|
||||
auto_interact=not interact,
|
||||
main_args=main_args,
|
||||
) as emu:
|
||||
yield emu
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
import tempfile
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import Dict, List, Optional, Sequence, Tuple
|
||||
|
||||
from trezorlib._internal.emulator import CoreEmulator, Emulator, LegacyEmulator
|
||||
|
||||
@ -75,6 +75,7 @@ class EmulatorWrapper:
|
||||
port: Optional[int] = None,
|
||||
headless: bool = True,
|
||||
auto_interact: bool = True,
|
||||
main_args: Sequence[str] = ("-m", "main"),
|
||||
) -> None:
|
||||
if tag is not None:
|
||||
executable = filename_from_tag(gen, tag)
|
||||
@ -107,6 +108,7 @@ class EmulatorWrapper:
|
||||
port=port,
|
||||
headless=headless,
|
||||
auto_interact=auto_interact,
|
||||
main_args=main_args,
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
|
Loading…
Reference in New Issue
Block a user