ntfc 0.0.3__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ntfc-0.0.3/src/ntfc.egg-info → ntfc-0.0.4}/PKG-INFO +2 -2
- {ntfc-0.0.3 → ntfc-0.0.4}/README.md +1 -1
- {ntfc-0.0.3 → ntfc-0.0.4}/pyproject.toml +1 -1
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/builder.py +90 -1
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/cli/main.py +1 -1
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/command_builder.py +5 -1
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/core.py +24 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/coreconfig.py +10 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/common.py +27 -7
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/getdev.py +4 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/host.py +43 -2
- ntfc-0.0.4/src/ntfc/device/netconsole.py +260 -0
- ntfc-0.0.4/src/ntfc/device/netdev.py +138 -0
- ntfc-0.0.4/src/ntfc/device/renode.py +210 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/serial.py +62 -25
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/elf/elf_parser.py +22 -7
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/collector.py +20 -4
- {ntfc-0.0.3 → ntfc-0.0.4/src/ntfc.egg-info}/PKG-INFO +2 -2
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc.egg-info/SOURCES.txt +3 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_builder.py +70 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_command_builder.py +24 -2
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_core.py +35 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_coreconfig.py +20 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/LICENSE +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/setup.cfg +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/__init__.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/__main__.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/cli/clitypes.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/cli/environment.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/commands/cmd_build.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/commands/cmd_collect.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/commands/cmd_test.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/cores.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/config.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/base.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/fastboot_handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/gdb_handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/local_file_handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/manager.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/syslog_handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/coredump/ymodem_handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/gdb/controller.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/gdb/plugin/autobp.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/gdb/plugin/gdbprefix.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/gdb/plugin/init.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/debug/getdebug.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/cmds.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/getos.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/heartbeat.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/linux.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/nuttx.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/oscommon.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/qemu.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/sim.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/device/state.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/envconfig.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/ext_commands.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/elf/app_bindir.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/fastboot/controller.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/performance/perf_data_process.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/performance/sqllite_lib.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/lib/ymodem/controller.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log/handler.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log/logger.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log/manager.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log/report.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log/templates/module_report.html +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/log.yaml +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/multi.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/parallel.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/parsers/base.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/parsers/cmocka.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/parsers/custom.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/parsers/gtest.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/plugins_loader.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/product.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/productconfig.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/products.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/collected.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/collecteditem.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/configure.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/coredump_plugin.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/formatters.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/gtest_plugin.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/mypytest.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/parsers.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/runner.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/pytest/signal_plugin.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/testfilter.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc/type_defs.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc.egg-info/dependency_links.txt +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc.egg-info/entry_points.txt +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc.egg-info/requires.txt +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/src/ntfc.egg-info/top_level.txt +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_cores.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_envconfig.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_filtertest.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_heartbeat.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_multi.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_parallel.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_product.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_productconfig.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_products.py +0 -0
- {ntfc-0.0.3 → ntfc-0.0.4}/tests/test_vtfc.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ntfc
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: NTFC for NuttX
|
|
5
5
|
Keywords: ntfc
|
|
6
6
|
Classifier: Topic :: Software Development :: Embedded Systems
|
|
@@ -81,7 +81,7 @@ versions of Python.
|
|
|
81
81
|
|
|
82
82
|
## Features
|
|
83
83
|
|
|
84
|
-
- NuttX simulator, QEMU and devices with serial port are supported
|
|
84
|
+
- NuttX simulator, QEMU, Renode and devices with serial port are supported
|
|
85
85
|
|
|
86
86
|
- Run the command from NSH and compare with the expected output
|
|
87
87
|
|
|
@@ -51,7 +51,7 @@ versions of Python.
|
|
|
51
51
|
|
|
52
52
|
## Features
|
|
53
53
|
|
|
54
|
-
- NuttX simulator, QEMU and devices with serial port are supported
|
|
54
|
+
- NuttX simulator, QEMU, Renode and devices with serial port are supported
|
|
55
55
|
|
|
56
56
|
- Run the command from NSH and compare with the expected output
|
|
57
57
|
|
|
@@ -47,6 +47,7 @@ class NuttXBuilder:
|
|
|
47
47
|
_KCONFIG_DISABLED_RE = re.compile(
|
|
48
48
|
r"^#\s+(CONFIG_[A-Za-z0-9_]+)\s+is not set"
|
|
49
49
|
)
|
|
50
|
+
_KCONFIG_VALUE_RE = re.compile(r"^(CONFIG_[A-Za-z0-9_]+)=(.*)$")
|
|
50
51
|
|
|
51
52
|
def __init__(self, config: Dict[str, Any], rebuild: bool = True):
|
|
52
53
|
"""Initialize NuttX builder."""
|
|
@@ -173,7 +174,10 @@ class NuttXBuilder:
|
|
|
173
174
|
self, tool: str, conf_path: str, key: str, value: Any
|
|
174
175
|
) -> List[str]:
|
|
175
176
|
"""Build one ``kconfig-tweak`` command for a Kconfig override."""
|
|
176
|
-
|
|
177
|
+
# Kconfig symbols are case-sensitive (e.g. CONFIG_NET_IPv6) and
|
|
178
|
+
# kconfig-tweak upper-cases them unless asked not to
|
|
179
|
+
|
|
180
|
+
cmd = [tool, "--file", conf_path, "--keep-case"]
|
|
177
181
|
if value is False or value == "n":
|
|
178
182
|
cmd.extend(["--disable", key])
|
|
179
183
|
elif value is True or value == "y":
|
|
@@ -242,6 +246,85 @@ class NuttXBuilder:
|
|
|
242
246
|
|
|
243
247
|
return f'{key}="{value}"\n'
|
|
244
248
|
|
|
249
|
+
def _read_kconfig_values(self, conf_path: str) -> Dict[str, str]:
|
|
250
|
+
"""Read symbol values from a ``.config`` file.
|
|
251
|
+
|
|
252
|
+
:param conf_path: path to ``.config``
|
|
253
|
+
:return: map of symbol to value; ``n`` for "is not set" symbols
|
|
254
|
+
"""
|
|
255
|
+
values: Dict[str, str] = {}
|
|
256
|
+
with open(conf_path, "r", encoding="utf-8") as f:
|
|
257
|
+
for line in f:
|
|
258
|
+
line = line.rstrip("\n")
|
|
259
|
+
disabled = self._KCONFIG_DISABLED_RE.match(line)
|
|
260
|
+
if disabled:
|
|
261
|
+
values[disabled.group(1)] = "n"
|
|
262
|
+
continue
|
|
263
|
+
match = self._KCONFIG_VALUE_RE.match(line)
|
|
264
|
+
if match:
|
|
265
|
+
values[match.group(1)] = match.group(2)
|
|
266
|
+
|
|
267
|
+
return values
|
|
268
|
+
|
|
269
|
+
@staticmethod
|
|
270
|
+
def _kconfig_values_equal(requested: str, actual: str) -> bool:
|
|
271
|
+
"""Compare two Kconfig values, numbers by value.
|
|
272
|
+
|
|
273
|
+
:param requested: value as written by the override
|
|
274
|
+
:param actual: value found in ``.config``
|
|
275
|
+
:return: True if the values are the same
|
|
276
|
+
"""
|
|
277
|
+
if requested == actual:
|
|
278
|
+
return True
|
|
279
|
+
|
|
280
|
+
try:
|
|
281
|
+
return int(requested, 0) == int(actual, 0)
|
|
282
|
+
except ValueError:
|
|
283
|
+
return False
|
|
284
|
+
|
|
285
|
+
def _check_kconfig_overrides(
|
|
286
|
+
self, conf_path: str, overrides: Dict[str, Any]
|
|
287
|
+
) -> None:
|
|
288
|
+
"""Check that every Kconfig override is in the final ``.config``.
|
|
289
|
+
|
|
290
|
+
Kconfig drops or resets an override silently: an unknown symbol,
|
|
291
|
+
unmet dependencies or an invalid value. Building anyway would test
|
|
292
|
+
a configuration nobody asked for.
|
|
293
|
+
|
|
294
|
+
:param conf_path: path to ``.config`` after ``olddefconfig``
|
|
295
|
+
:param overrides: requested Kconfig overrides
|
|
296
|
+
:raises AssertionError: if any override is not applied
|
|
297
|
+
"""
|
|
298
|
+
values = self._read_kconfig_values(conf_path)
|
|
299
|
+
failed: List[str] = []
|
|
300
|
+
|
|
301
|
+
for key, value in overrides.items():
|
|
302
|
+
line = self._format_kconfig_line(key, value).rstrip("\n")
|
|
303
|
+
match = self._KCONFIG_VALUE_RE.match(line)
|
|
304
|
+
requested = match.group(2) if match else "n"
|
|
305
|
+
actual = values.get(key)
|
|
306
|
+
|
|
307
|
+
if actual is None and requested == "n":
|
|
308
|
+
continue
|
|
309
|
+
|
|
310
|
+
if actual is None:
|
|
311
|
+
failed.append(
|
|
312
|
+
f"{key}: requested {requested}, not in .config "
|
|
313
|
+
"(unknown symbol or unmet dependencies)"
|
|
314
|
+
)
|
|
315
|
+
elif not self._kconfig_values_equal(requested, actual):
|
|
316
|
+
failed.append(
|
|
317
|
+
f"{key}: requested {requested}, got {actual} "
|
|
318
|
+
"(unmet dependencies or invalid value)"
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
if failed:
|
|
322
|
+
for item in failed:
|
|
323
|
+
logger.error(f"Kconfig override not applied: {item}")
|
|
324
|
+
raise AssertionError(
|
|
325
|
+
"'kv' Kconfig overrides not applied: " + "; ".join(failed)
|
|
326
|
+
)
|
|
327
|
+
|
|
245
328
|
def _apply_kconfig_overrides(
|
|
246
329
|
self, conf_path: str, overrides: Dict[str, Any], cfg_cwd: str = ""
|
|
247
330
|
) -> None:
|
|
@@ -462,6 +545,12 @@ class NuttXBuilder:
|
|
|
462
545
|
# that enable new applications take effect
|
|
463
546
|
configure()
|
|
464
547
|
|
|
548
|
+
# fail instead of building a configuration that
|
|
549
|
+
# silently lost some overrides
|
|
550
|
+
self._check_kconfig_overrides(
|
|
551
|
+
nuttx_conf_path, kv_overrides
|
|
552
|
+
)
|
|
553
|
+
|
|
465
554
|
# build
|
|
466
555
|
self._run_build(build_path, env=build_env)
|
|
467
556
|
|
|
@@ -57,7 +57,7 @@ from ntfc.pytest.mypytest import MyPytest
|
|
|
57
57
|
)
|
|
58
58
|
@pass_environment
|
|
59
59
|
def main(ctx: Environment, debug: bool, verbose: bool) -> bool:
|
|
60
|
-
"""
|
|
60
|
+
"""NTFC - NuttX Testing Framework for Community."""
|
|
61
61
|
print("-" * 80)
|
|
62
62
|
print(f"NTFC PID: {os.getpid()}", file=sys.stderr)
|
|
63
63
|
print("-" * 80)
|
|
@@ -198,7 +198,11 @@ class CommandBuilder:
|
|
|
198
198
|
items = expects if regexp else [re.escape(e) for e in expects]
|
|
199
199
|
|
|
200
200
|
if match_all:
|
|
201
|
-
|
|
201
|
+
# Anchor the lookaheads so the engine evaluates them once from
|
|
202
|
+
# the start of the buffer. Unanchored, re.search retries them
|
|
203
|
+
# at every position and each scans to the end: quadratic in
|
|
204
|
+
# the buffer size, tens of seconds on a 100 KB console dump.
|
|
205
|
+
return "^" + "".join(f"(?=.*{item})" for item in items)
|
|
202
206
|
return rf"({'|'.join(items)})"
|
|
203
207
|
|
|
204
208
|
def _default_prompt_pattern(self, cmd: str, flag: str = "") -> str:
|
|
@@ -127,6 +127,28 @@ class ProductCore:
|
|
|
127
127
|
matched = matched.decode("utf-8", errors="ignore")
|
|
128
128
|
return self._device.no_cmd in matched
|
|
129
129
|
|
|
130
|
+
def _check_line_max(self, cmd: bytes) -> None:
|
|
131
|
+
"""Refuse a command the target shell cannot buffer in one line.
|
|
132
|
+
|
|
133
|
+
NSH reads at most ``CONFIG_LINE_MAX - 1`` characters per line and
|
|
134
|
+
executes the overflow as a second command, which fails in
|
|
135
|
+
confusing ways. The limit is only known when the Kconfig of the
|
|
136
|
+
image is available.
|
|
137
|
+
|
|
138
|
+
:param cmd: Encoded command including its line terminator.
|
|
139
|
+
:raises ValueError: Command does not fit the target line buffer.
|
|
140
|
+
"""
|
|
141
|
+
limit = self._conf.kv_check("CONFIG_LINE_MAX")
|
|
142
|
+
if not limit:
|
|
143
|
+
return
|
|
144
|
+
length = len(cmd.rstrip(b"\r\n"))
|
|
145
|
+
if length >= int(limit):
|
|
146
|
+
raise ValueError(
|
|
147
|
+
f"command is {length} characters, the target buffers at "
|
|
148
|
+
f"most {int(limit) - 1} (CONFIG_LINE_MAX={limit}): "
|
|
149
|
+
f"{cmd.decode(errors='replace').strip()!r}"
|
|
150
|
+
)
|
|
151
|
+
|
|
130
152
|
def sendCommand( # noqa: N802
|
|
131
153
|
self,
|
|
132
154
|
cmd: str,
|
|
@@ -162,6 +184,7 @@ class ProductCore:
|
|
|
162
184
|
encoded = self._builder.build(
|
|
163
185
|
cmd, expects, args, flag, match_all, regexp, fail_pattern
|
|
164
186
|
)
|
|
187
|
+
self._check_line_max(encoded.cmd)
|
|
165
188
|
|
|
166
189
|
logger.debug(
|
|
167
190
|
f"Sending command: {encoded.cmd.decode()}, expecting: "
|
|
@@ -204,6 +227,7 @@ class ProductCore:
|
|
|
204
227
|
:return: CmdReturn : command return data
|
|
205
228
|
"""
|
|
206
229
|
encoded = self._builder.build_raw(cmd, pattern, args, fail_pattern)
|
|
230
|
+
self._check_line_max(encoded.cmd)
|
|
207
231
|
|
|
208
232
|
logger.debug(
|
|
209
233
|
f"Sending command: {encoded.cmd.decode()}, expecting pattern: "
|
|
@@ -200,6 +200,16 @@ class CoreConfig:
|
|
|
200
200
|
"""Return whether commands are sent in one transport write."""
|
|
201
201
|
return bool(self._config.get("line_buffered", False))
|
|
202
202
|
|
|
203
|
+
@property
|
|
204
|
+
def netconsole(self) -> Optional[Dict[str, Any]]:
|
|
205
|
+
"""Return the netdev console section, or None to use the pty."""
|
|
206
|
+
cfg = self._config.get("netconsole", None)
|
|
207
|
+
if cfg is None:
|
|
208
|
+
return None
|
|
209
|
+
if not isinstance(cfg, dict):
|
|
210
|
+
raise TypeError("netconsole must be a mapping")
|
|
211
|
+
return cfg
|
|
212
|
+
|
|
203
213
|
def kv_check(self, cfg: str) -> Any:
|
|
204
214
|
"""Check Kconfig option and return its value.
|
|
205
215
|
|
|
@@ -52,6 +52,7 @@ class DeviceCommon(ABC):
|
|
|
52
52
|
|
|
53
53
|
_BUSY_LOOP_TIMEOUT = 180 # 180 sec with no data read from target
|
|
54
54
|
_OUTPUT_TAIL_MAX = 4 * 1024 * 1024
|
|
55
|
+
_FLOOD_DETECT_TIME = 10 # sec of uninterrupted output after a timeout
|
|
55
56
|
|
|
56
57
|
def __init__(self, conf: "CoreConfig", echo: bool = True):
|
|
57
58
|
"""Initialize common device."""
|
|
@@ -101,6 +102,15 @@ class DeviceCommon(ABC):
|
|
|
101
102
|
if len(self._output_tail_buf) > self._OUTPUT_TAIL_MAX:
|
|
102
103
|
del self._output_tail_buf[: -self._OUTPUT_TAIL_MAX]
|
|
103
104
|
|
|
105
|
+
def _idle_at_prompt(self) -> bool:
|
|
106
|
+
"""Return True when the last output ended with the shell prompt.
|
|
107
|
+
|
|
108
|
+
A target that printed its prompt is waiting for input, not stuck,
|
|
109
|
+
so silence after it is a command timeout rather than a busy loop.
|
|
110
|
+
"""
|
|
111
|
+
tail = _ANSI_ESCAPE_RE.sub(b"", bytes(self._output_tail_buf[-256:]))
|
|
112
|
+
return tail.rstrip().endswith(self._dev.prompt.strip())
|
|
113
|
+
|
|
104
114
|
def output_tail(self) -> str:
|
|
105
115
|
"""Return the most recent raw device output.
|
|
106
116
|
|
|
@@ -194,10 +204,12 @@ class DeviceCommon(ABC):
|
|
|
194
204
|
break
|
|
195
205
|
|
|
196
206
|
# check for busy loop
|
|
197
|
-
# trigger an error if there was no data to read for a long time
|
|
207
|
+
# trigger an error if there was no data to read for a long time,
|
|
208
|
+
# unless the target is simply waiting at its prompt
|
|
198
209
|
if not chunk:
|
|
199
|
-
if (
|
|
210
|
+
if (
|
|
200
211
|
not self._state_mgr.is_busy_loop()
|
|
212
|
+
and not self._idle_at_prompt()
|
|
201
213
|
and self._state_mgr.check_busy_loop_timeout()
|
|
202
214
|
):
|
|
203
215
|
self._log_device_event("fault detected: busyloop")
|
|
@@ -306,15 +318,23 @@ class DeviceCommon(ABC):
|
|
|
306
318
|
break
|
|
307
319
|
|
|
308
320
|
# check for output flood condition.
|
|
309
|
-
#
|
|
310
|
-
#
|
|
321
|
+
# A slow command can still be printing when the timeout expires,
|
|
322
|
+
# so keep reading until the device goes quiet. Only a device that
|
|
323
|
+
# never stops printing is flooding (stuck in some command).
|
|
311
324
|
if ret == CmdStatus.TIMEOUT:
|
|
312
|
-
|
|
313
|
-
|
|
325
|
+
flood_end = time.time() + self._FLOOD_DETECT_TIME
|
|
326
|
+
flood = True
|
|
327
|
+
while time.time() < flood_end:
|
|
328
|
+
chunk = self._read_all(self._read_all_sleep)
|
|
329
|
+
self._console_log(chunk)
|
|
330
|
+
if not chunk:
|
|
331
|
+
flood = False
|
|
332
|
+
break
|
|
333
|
+
|
|
334
|
+
if flood:
|
|
314
335
|
if not self._state_mgr.is_unhealthy():
|
|
315
336
|
self._log_device_event("fault detected: flood")
|
|
316
337
|
self._state_mgr.set_unhealthy("Flood detected")
|
|
317
|
-
self._console_log(chunk)
|
|
318
338
|
|
|
319
339
|
return CmdReturn(ret, _match, output.decode("utf-8", errors="replace"))
|
|
320
340
|
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
|
|
23
23
|
from typing import TYPE_CHECKING, Callable, Dict
|
|
24
24
|
|
|
25
|
+
from .netdev import DeviceNetdev
|
|
25
26
|
from .qemu import DeviceQemu
|
|
27
|
+
from .renode import DeviceRenode
|
|
26
28
|
from .serial import DeviceSerial
|
|
27
29
|
from .sim import DeviceSim
|
|
28
30
|
|
|
@@ -36,6 +38,8 @@ _DEVICE_FACTORIES: Dict[str, Callable[["CoreConfig"], "DeviceCommon"]] = {
|
|
|
36
38
|
"sim": DeviceSim,
|
|
37
39
|
"qemu": DeviceQemu,
|
|
38
40
|
"serial": DeviceSerial,
|
|
41
|
+
"renode": DeviceRenode,
|
|
42
|
+
"netdev": DeviceNetdev,
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
###############################################################################
|
|
@@ -31,6 +31,7 @@ import psutil # type: ignore
|
|
|
31
31
|
from ntfc.log.logger import logger
|
|
32
32
|
|
|
33
33
|
from .common import DeviceCommon
|
|
34
|
+
from .netconsole import get_netconsole
|
|
34
35
|
|
|
35
36
|
if TYPE_CHECKING:
|
|
36
37
|
from ntfc.coreconfig import CoreConfig
|
|
@@ -55,6 +56,8 @@ class DeviceHost(DeviceCommon):
|
|
|
55
56
|
self._child = None
|
|
56
57
|
self._cwd = conf.exec_cwd
|
|
57
58
|
self._cmd: Optional[List[str]] = None
|
|
59
|
+
# console over a network transport instead of the child pty
|
|
60
|
+
self._netcon = get_netconsole(conf.netconsole)
|
|
58
61
|
|
|
59
62
|
@property
|
|
60
63
|
def pid(self) -> Optional[int]:
|
|
@@ -81,6 +84,9 @@ class DeviceHost(DeviceCommon):
|
|
|
81
84
|
if not self._child.isalive():
|
|
82
85
|
return False
|
|
83
86
|
|
|
87
|
+
if self._netcon and not self._netcon.is_open:
|
|
88
|
+
return False
|
|
89
|
+
|
|
84
90
|
return True
|
|
85
91
|
|
|
86
92
|
def _dev_reopen(self) -> pexpect.spawn:
|
|
@@ -102,6 +108,10 @@ class DeviceHost(DeviceCommon):
|
|
|
102
108
|
if data[-1] != ord("\n"):
|
|
103
109
|
data += self.NEWLINE_PAD
|
|
104
110
|
|
|
111
|
+
if self._netcon:
|
|
112
|
+
self._netcon.write(data)
|
|
113
|
+
return
|
|
114
|
+
|
|
105
115
|
if self._conf.line_buffered:
|
|
106
116
|
self._child.send(data)
|
|
107
117
|
return
|
|
@@ -116,6 +126,11 @@ class DeviceHost(DeviceCommon):
|
|
|
116
126
|
return
|
|
117
127
|
|
|
118
128
|
assert self._child
|
|
129
|
+
|
|
130
|
+
if self._netcon:
|
|
131
|
+
self._netcon.write(bytes([ord(c.upper()) & 0x1F]))
|
|
132
|
+
return
|
|
133
|
+
|
|
119
134
|
self._child.sendcontrol(c)
|
|
120
135
|
|
|
121
136
|
def _read(self) -> bytes: # pragma: no cover
|
|
@@ -125,10 +140,18 @@ class DeviceHost(DeviceCommon):
|
|
|
125
140
|
|
|
126
141
|
try:
|
|
127
142
|
assert self._child
|
|
128
|
-
|
|
143
|
+
data = self._child.read_nonblocking(size=5120, timeout=0)
|
|
129
144
|
|
|
130
145
|
except (pexpect.TIMEOUT, pexpect.EOF):
|
|
131
|
-
|
|
146
|
+
data = b""
|
|
147
|
+
|
|
148
|
+
if self._netcon:
|
|
149
|
+
# the child pty is not the console: keep its output in the log
|
|
150
|
+
if data:
|
|
151
|
+
logger.debug(f"{self.name}: {data!r}")
|
|
152
|
+
return self._netcon.read()
|
|
153
|
+
|
|
154
|
+
return data
|
|
132
155
|
|
|
133
156
|
def _kill_process_group(self, process: pexpect.spawn) -> None:
|
|
134
157
|
"""Kill process group."""
|
|
@@ -165,6 +188,10 @@ class DeviceHost(DeviceCommon):
|
|
|
165
188
|
# we need command to reopen file in the case of crash
|
|
166
189
|
self._cmd = cmd
|
|
167
190
|
|
|
191
|
+
if self._netcon:
|
|
192
|
+
# listen before the target boots, it sends its console at once
|
|
193
|
+
self._netcon.start()
|
|
194
|
+
|
|
168
195
|
logger.info(f"spawn cmd: {''.join(cmd)}")
|
|
169
196
|
child = pexpect.spawn(
|
|
170
197
|
"".join(cmd), timeout=10, maxread=20000, cwd=self._cwd
|
|
@@ -181,15 +208,26 @@ class DeviceHost(DeviceCommon):
|
|
|
181
208
|
|
|
182
209
|
time.sleep(uptime)
|
|
183
210
|
|
|
211
|
+
self._post_spawn()
|
|
212
|
+
|
|
184
213
|
ret = self._wait_for_boot(self._conf.boot_timeout)
|
|
185
214
|
if ret is False: # pragma: no cover
|
|
186
215
|
raise TimeoutError("device boot timeout")
|
|
187
216
|
|
|
188
217
|
return self._child
|
|
189
218
|
|
|
219
|
+
def _post_spawn(self) -> None:
|
|
220
|
+
"""Run after the child is spawned and before the boot wait.
|
|
221
|
+
|
|
222
|
+
Transports that do not talk to the child's pty (e.g. a socket
|
|
223
|
+
opened by the emulator) attach here. Runs on every reopen.
|
|
224
|
+
"""
|
|
225
|
+
|
|
190
226
|
def _stop_impl(self) -> None:
|
|
191
227
|
"""Stop host device and kill the underlying process."""
|
|
192
228
|
if not self._child:
|
|
229
|
+
if self._netcon:
|
|
230
|
+
self._netcon.stop()
|
|
193
231
|
return
|
|
194
232
|
|
|
195
233
|
if self._child.isalive(): # pragma: no cover
|
|
@@ -203,6 +241,9 @@ class DeviceHost(DeviceCommon):
|
|
|
203
241
|
|
|
204
242
|
self._child = None
|
|
205
243
|
|
|
244
|
+
if self._netcon:
|
|
245
|
+
self._netcon.stop()
|
|
246
|
+
|
|
206
247
|
logger.info("host device closed")
|
|
207
248
|
|
|
208
249
|
@property
|