Skip to content

Commit baeda51

Browse files
committed
SWPROT-9959: Make ZLF file rotation opt-in on ZlfFileWriter
Disable rotation by default so zniffer only write ZLF data; enable it explicitly for Hardware devices PTI capture.
1 parent 8d5b7f9 commit baeda51

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Release v0.5.1
5252

5353
- ``hw_clusters`` accepts ``clusters.json`` with ``schema_version`` 1 (metadata keys such as ``$schema``, plus a ``clusters`` object with per-cluster ``devices`` arrays). The legacy top-level ``name -> [wpk, ...]`` map remains supported. Serial and board fields are validated on load (see ``clusters_json.load_clusters_json``).
5454
- Z-Wave sample-app CLI communication uses TCP on port 4901 instead of Telnet (``_CliTcpSocket``, ``run_cmd``). CLI parsers accept an optional ``[I] `` log prefix. ``DevZwaveCli`` adds ``press()`` and ``em1_lock_rtt()``; WPK admin Telnet reconnects on pipe or connection reset.
55-
- Traces and RTT logs are stored under a per-device subdirectory (``N_FriendlyName``). Zniffer and Railtest skip automatic capture folders. ``ZlfFileWriter`` supports size-based rotation with optional gzip and helpers to list rotated files.
55+
- Traces and RTT logs are stored under a per-device subdirectory (``N_FriendlyName``). Zniffer and Railtest skip automatic capture folders. ``ZlfFileWriter`` supports optional size-based rotation (enabled for PTI capture via ``max_size_bytes``); standalone tools use the writer without rotation by default.
5656
- Root ``config.json``, ``conftest.py``, ``pytest.ini``, and ``setup_dev_environment.py`` support local runs. Dev Container, Conan remotes, artifact fetch scripts, ``pick_hw_cluster.py``, and VS Code tasks are included for development setup.
5757
- Pytest options ``--pti`` and ``--rtt`` enable PTI and RTT capture per test (disabled by default in ``SessionContext``).
5858
- SOC devices support ``wpk_serial_speed="auto"``: baud rate is read from WPK admin TCP port 4902 (``serial vcom``). NCP device types reject ``"auto"``.

z_wave_ts_silabs/devices.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .processes import CommanderCli
1717
from .definitions import AppName, ZwaveAppProductType, ZwaveRegion, ZpalRadioRegion
1818
from .pcap import PcapFileWriter
19-
from .zlf import ZlfFileWriter
19+
from .zlf import PTI_ZLF_MAX_SIZE_BYTES, ZlfFileWriter
2020

2121

2222
@dataclass
@@ -330,7 +330,10 @@ def _pti_logger_thread(self, logger_name: str):
330330
# Redirect DCH output from port 4905; store zniffer (zlf) and pcap in device folder.
331331
device_dir = self._ctxt.current_test_logdir / logger_name
332332
device_dir.mkdir(parents=True, exist_ok=True)
333-
zlf_file = ZlfFileWriter(device_dir / "trace.zlf")
333+
zlf_file = ZlfFileWriter(
334+
device_dir / "trace.zlf",
335+
max_size_bytes=PTI_ZLF_MAX_SIZE_BYTES,
336+
)
334337
pcap_file = PcapFileWriter(device_dir / "trace.pcap")
335338
dch_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
336339
dch_socket.connect((self.ip, self.dch_port))

z_wave_ts_silabs/zlf.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
_ZLF_DATACHUNK_HEADER_SIZE: int = 5
2424
_ZLF_API_TYPE_ZNIFFER: int = 0xF5 # 0xF5 is for PTI
2525

26-
# Default max ZLF file size before rotation (50 MiB). Set to None to disable rotation.
27-
DEFAULT_ZLF_MAX_SIZE_BYTES: int | None = 50 * 1024 * 1024
26+
# Suggested max size when enabling rotation on long-running captures (50 MiB).
27+
PTI_ZLF_MAX_SIZE_BYTES: int = 50 * 1024 * 1024
2828

2929
# Minimum size to consider a file as valid ZLF (at least the header)
3030
_MIN_VALID_ZLF_SIZE = _ZLF_HEADER_SIZE
@@ -193,10 +193,16 @@ def __init__(
193193
self,
194194
file_path: Path,
195195
*,
196-
max_size_bytes: int | None = DEFAULT_ZLF_MAX_SIZE_BYTES,
196+
max_size_bytes: int | None = None,
197197
keep_count: int = 0,
198198
compress_rotated: bool = True,
199199
) -> None:
200+
"""
201+
Write Zniffer-compatible ZLF files.
202+
203+
Rotation is opt-in: pass max_size_bytes (e.g. PTI_ZLF_MAX_SIZE_BYTES) for
204+
long-running captures. Short-lived tools and converters can omit it.
205+
"""
200206
self.file_path = file_path
201207
self._max_size_bytes = max_size_bytes
202208
self._keep_count = keep_count
@@ -228,7 +234,7 @@ def _rotate_if_needed(self) -> None:
228234
self._create()
229235

230236
def write_datachunk(self, dch_packet: bytes) -> None:
231-
"""Dumps frame to ZLF file. Rotates when file size exceeds max_size_bytes (default 50 MiB).
237+
"""Dumps frame to ZLF file. Rotates when max_size_bytes was set and the file exceeds it.
232238
:param dch_packet: DCH packet directly from WSTK/WPK/TB
233239
"""
234240
self._rotate_if_needed()

z_wave_ts_silabs/zwave_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def read_until(self, match: bytes, timeout: float = 1.0) -> bytes:
7272
return buffer
7373

7474

75-
def run_cmd(sock: _CliTcpSocket, command: str, read_timeout: float = 0.3) -> str:
75+
def run_cmd(sock: _CliTcpSocket, command: str, read_timeout: float = 1.0) -> str:
7676
"""Execute a command on an open CLI socket and return the response.
7777
7878
Drains any pending data, sends the command, then reads until the prompt ("> ").
@@ -175,7 +175,7 @@ def _run_cmd(self, command: str) -> str:
175175
if self._cli_socket is None:
176176
return ""
177177
try:
178-
response = run_cmd(self._cli_socket, command, read_timeout=0.3)
178+
response = run_cmd(self._cli_socket, command, read_timeout=1.0)
179179
if command not in response or "> " not in response:
180180
self.logger.warning(f"Command response not properly synchronized: {response}")
181181
extra = self._cli_socket.drain_buffer().decode("ascii", errors="ignore")

0 commit comments

Comments
 (0)