-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
117 lines (81 loc) · 3.06 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import contextlib
import json
import traceback
from time import monotonic
import pytest
@pytest.fixture(scope="function")
def barebox(strategy):
try:
strategy.transition("barebox")
except Exception as e:
traceback.print_exc()
pytest.exit(f"Transition into barebox failed: {e}", returncode=3)
return strategy.barebox
@pytest.fixture(scope="function")
def shell(strategy):
try:
strategy.transition("shell")
except Exception as e:
traceback.print_exc()
pytest.exit(f"Transition into shell failed: {e}", returncode=3)
return strategy.shell
@pytest.fixture
def default_bootstate(strategy):
"""Set default state values as setup/teardown"""
strategy.transition("barebox")
strategy.barebox.run_check("bootchooser -a default -p default")
yield
strategy.transition("barebox")
strategy.barebox.run_check("bootchooser -a default -p default")
@pytest.fixture
def booted_slot(shell):
"""Returns booted slot."""
def _booted_slot():
[stdout] = shell.run_check("rauc status --output-format=json", timeout=60)
rauc_status = json.loads(stdout)
assert "booted" in rauc_status, 'No "booted" key in rauc status json found'
return rauc_status["booted"]
yield _booted_slot
@pytest.fixture
def set_bootstate_in_bootloader(strategy, default_bootstate):
"""Sets the given bootchooser parameters."""
def _set_bootstate(system0_prio, system0_attempts, system1_prio, system1_attempts):
strategy.transition("barebox")
barebox = strategy.barebox
barebox.run_check(f"state.bootstate.system0.priority={system0_prio}")
barebox.run_check(f"state.bootstate.system0.remaining_attempts={system0_attempts}")
barebox.run_check(f"state.bootstate.system1.priority={system1_prio}")
barebox.run_check(f"state.bootstate.system1.remaining_attempts={system1_attempts}")
barebox.run_check("state -s")
yield _set_bootstate
@pytest.fixture
def rauc_bundle(target, strategy, env, shell):
"""Makes the RAUC bundle target-accessible at the returned location."""
bundle = env.config.get_image_path("rauc_bundle")
def _rauc_bundle():
target.activate(strategy.httpprovider)
return strategy.httpprovider.stage(bundle)
yield _rauc_bundle
@pytest.fixture
def eet(strategy):
eet = strategy.eet
yield eet
if eet:
eet.link("")
@pytest.fixture(scope="function")
def log_duration(record_property):
"""
Allows to log the duration of a context as a property of the executed test.
This can be used to measure the duration of specific commands and write the result to the junitXML.
Use this fixture as a context manager:
> with log_duration("property-name"):
> time.sleep(1)
"""
@contextlib.contextmanager
def duration_logger(name: str):
start = monotonic()
yield
record_property(name, monotonic() - start)
return duration_logger
def pytest_configure(config):
config.addinivalue_line("markers", "slow: These tests run especially slow.")