Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
132 lines (98 loc) · 4.16 KB
/
Copy pathconftest.py
File metadata and controls
132 lines (98 loc) · 4.16 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# SPDX-License-Identifier: GPL-2.0-only
import pytest
import os
import argparse
from labgrid.exceptions import NoDriverFoundError
from scripts import qemu_interactive
from test.py import helper
def transition_to_barebox(request, strategy):
try:
strategy.transition('barebox')
except Exception as e:
# If a normal strategy transition fails, there's no point in
# continuing the test. Let's print stderr and exit.
capmanager = request.config.pluginmanager.getplugin("capturemanager")
with capmanager.global_and_fixture_disabled():
_, stderr = capmanager.read_global_capture()
pytest.exit(f"{type(e).__name__}(\"{e}\"). Standard error:\n{stderr}",
returncode=3)
@pytest.fixture(scope='function')
def barebox(request, strategy, target):
transition_to_barebox(request, strategy)
return target.get_driver('BareboxDriver')
@pytest.fixture(scope='function')
def shell(strategy, target):
strategy.transition('shell')
return target.get_driver('ShellDriver')
@pytest.fixture(scope="session", autouse=True)
def boot_log(request, strategy, target):
"""Error level and worse messages logged during the target's first boot.
Tests are free to reboot the target - test_fit chainloads barebox into
itself, for example - which discards the log of the boot we actually
want to look at, so snapshot it before the first test runs.
None if the log could not be read at all, e.g. because the target has
no dmesg command.
"""
transition_to_barebox(request, strategy)
command = target.get_driver("BareboxDriver")
stdout, _, returncode = command.run("dmesg -l emerg,alert,crit,err")
if returncode != 0:
return None
return stdout
@pytest.fixture(scope="session")
def barebox_config(request, strategy, target):
transition_to_barebox(request, strategy)
command = target.get_driver("BareboxDriver")
return helper.get_config(command)
lg_env = lg_builddir = None
def pytest_configure(config):
removed_mode = getattr(config.option, 'qemu_interactive_removed', None)
if removed_mode is not None:
pytest.exit(qemu_interactive.replacement_message(removed_mode),
returncode=2)
global lg_env
global lg_builddir
lg_builddir = qemu_interactive.resolve_lg_builddir()
lg_env = config.option.lg_env
if lg_env is None:
lg_env = os.environ.get('LG_ENV')
if lg_env is None:
if lg_env := qemu_interactive.guess_lg_env(lg_builddir):
os.environ['LG_ENV'] = lg_env
def pytest_report_header(config):
report = []
if lg_builddir is not None:
report += [f"Build diectory: {lg_builddir}"]
if lg_env is not None:
report += [f"Labgrid Environment: {lg_env}"]
return "\n".join(report)
def pytest_addoption(parser):
parser.addoption('--interactive', action='store_const',
const='--interactive', dest='qemu_interactive_removed',
help=argparse.SUPPRESS)
parser.addoption('--dry-run', action='store_const',
const='--dry-run', dest='qemu_interactive_removed',
help=argparse.SUPPRESS)
parser.addoption('--dump-dtb', action='store_const',
const='--dump-dtb', dest='qemu_interactive_removed',
help=argparse.SUPPRESS)
group = parser.getgroup('barebox-qemu', 'barebox QEMU options')
qemu_interactive.register_shared_options(group)
def _pytest_exit(message, returncode=1):
pytest.exit(message, returncode=returncode)
@pytest.fixture(scope="session")
def strategy(request, target, pytestconfig): # noqa: max-complexity=30
try:
strategy = target.get_driver("Strategy")
except NoDriverFoundError as e:
pytest.exit(e)
qemu_interactive.apply_shared_options(
strategy, target, pytestconfig.option, interactive=False,
fail=_pytest_exit)
return strategy
@pytest.fixture(scope="session")
def testfs(strategy, env):
if "testfs" not in env.get_target_features():
pytest.skip("testfs not supported on this platform")
path = os.path.join(os.environ["LG_BUILDDIR"], "testfs")
return path