fix(tsp_control): split load_script() by line when total length exceeds threshold - #581
fix(tsp_control): split load_script() by line when total length exceeds threshold#581bestcal wants to merge 3 commits into
Conversation
|
|
03f6138 to
1e50789
Compare
|
pre-commit.ci autofix |
…ds threshold Fixes tektronix#500 The TSP load_script() method previously sent the entire script command (including loadscript/endscript wrapper) in a single write() call. Devices enforce a maximum write length; scripts longer than ~1000 chars would silently fail or error out. This change introduces a hybrid strategy: - If total script command length >= 1000, send it line-by-line: loadscript <name>, each line of the body, then endscript. - Otherwise, keep the original single-write behavior for backward compatibility with simulation/backplane tests. A regression test is added that asserts: - A 45-line long script is split into multiple write() calls - A short script uses a single write() call
cc98674 to
f52fac7
Compare
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
| # script_body argument is overwritten by file contents | ||
| script_body = Path(file_path).read_text(encoding="utf-8").strip() | ||
|
|
||
| tsp_max_write_length = 1000 # TSP devices require a write_termination within 1000 chars |
There was a problem hiding this comment.
I would recommend making this a private, class constant. Then subclasses can overwrite it if needed.
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pytest-order>=1.4.0", |
There was a problem hiding this comment.
This shouldn't be necessary, please remove this
- Move tsp_max_write_length to a private class constant _TSP_MAX_WRITE_LENGTH so subclasses can override it if needed. - Remove the unnecessary [dependency-groups] section from pyproject.toml.
| assert written_calls[1] == "loadscript longscript" | ||
| # Every call should be ≤ 1000 characters | ||
| for idx, call in enumerate(written_calls): | ||
| assert len(call) <= 1000, ( |
There was a problem hiding this comment.
This should access the private variable from the device driver
|
Closing this PR based on a lack of interaction and updates. |
Fixes #500
Problem
The
load_script()method inTSPControlpreviously assembled the entireTSP script command—including the
loadscript <name>, body, andendscriptwrapper—into a single string, then sent it via one
write()call.Real TSP devices enforce a maximum write length (commonly 1024 chars). When
the total command exceeds this, the script silently fails or raises a device
error. Issue #500 reports exactly this failure with long user scripts.
Solution
Introduce a hybrid split strategy based on a
TSP_MAX_WRITE_LENGTH = 1000threshold:
len(script_command) >= 1000loadscript name, then each line of the body viaself.write(line), finallyendscriptlen(script_command) < 1000Key implementation details:
device-specific limits and protocol overhead.
(they are idempotent for TSP).
Testing
A new regression test
test_load_script_split_long_linesis added intests/test_smu.pythat asserts:load_script()splits into multiplewrite()calls, each ≤ 1000 chars.print("hello"), ~40 chars assembled):load_script()still uses a singlewrite()call, matching existingsimulator expectations.
Full test run (
pytest tests/test_smu.py -k "test_smu or test_load_script_split_long_lines") passes 5/5:Checklist