[vxi-11] read function bug corrections - #612
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #612 +/- ##
==========================================
+ Coverage 41.73% 43.69% +1.95%
==========================================
Files 29 30 +1
Lines 5247 5369 +122
Branches 521 528 +7
==========================================
+ Hits 2190 2346 +156
+ Misses 3030 2991 -39
- Partials 27 32 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
About the tests, if it's worth something: test code: import pyvisa
def testcase(provider, size: int):
if provider == '@py':
print(f"******* provider = 'pyvisa-py', data size = {size} *******")
else:
print(f"******* provider = 'NI-VISA', data size = {size} *******")
rm = pyvisa.ResourceManager(provider)
inst = rm.open_resource('TCPIP::192.168.7.116::inst5::INSTR')
inst.timeout = 3000
data_size = size - 2 # add the space for CR/LF
myquery = f"longrd? {data_size}" # this is query to a custom device that can return any length of data, up to 2^32-1 bytes. The data_size does not take into account the CR/LF
# Measure the exact response length (large chunk_size rules out the bug)
inst.chunk_size = 10 * 1024 * 1024
inst.write(myquery)
L = len(inst.read_raw())
for chunk_size in range(L-9, L+11):
# do a series of number of bytes less and more
inst.chunk_size = chunk_size
inst.write(myquery)
try:
inst.read_raw() # -> fails, reproducibly, initially
except Exception as e:
print(f'read_raw() with chunk_size {inst.chunk_size} failed: {e}')
continue
print(f'read_raw() with chunk_size {inst.chunk_size} succeeded')
if __name__ == '__main__':
testcase('@py', 10)
testcase('@py', 2000)
testcase('', 10)
testcase('', 2000)Without repair: With repair: |
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
Thanks the change looks good. I want to audit other transports before merging in case similar issues exist there too. It may take me a couple of weeks.
|
I actually ran into this same bug when running some conformance tests against VPP-4.3. I have been putting LLMs to work (perhaps controversial!) trying to smoke out weird conformance/compatibility bugs between pyvisa/pyvisa-py, a Rust server implementation of HiSLIP/VXI-11 I am playing with, and some of the virtual Keysight instruments. The same bug does exist in the HISLIP transport I believe - I was going to send along a patch for that unless this PR gets to it first. |
|
@MatthieuDartiailh are you OK if I add more VXI-11 compliance patches in this PR? I have identified and patched the following:
.. visible in https://github.com/hb020/pyvisa-py/tree/pr-612-extra |
|
Tjose sounds fine to add here yes. |
for more information, see https://pre-commit.ci
|
merged into this PR |
|
DONE: Will test this more thoroughly on real HW later today. Is OK. TODO: I might also try to set up a hislip and socket test setup. I do not have USBTMC nor VICP testbeds. TODO: I'll add any repairs on those 2 backends (hislip/socket) here, and adapt CHANGES once done. |
|
@MatthieuDartiailh can we do the hislip stuff in another PR? I found a quite large load of problems in hislip, and having 3 branches open in 3 different PRs on the same source code files is not helping testing.... |
|
Yes since this PR now address multiple VXI-11 not just the original one it is fine to keep focused on this transport. I will do my best to review it in a timely manner. |
|
Adapted the changes list. |
| timeout = self._io_timeout # this is derived from from self.timeout | ||
| # See if a timeout was set. This is derived from self.timeout, but slightly | ||
| # convoluted because the unit test scripts may not have set this correctly. |
There was a problem hiding this comment.
Can you clarify this comment ?
There was a problem hiding this comment.
OK like it is now?
# Get the timeout as cleaned up by the upper layers
timeout = self._io_timeout
# See if a timeout was really set.
# if self.timeout is None, the given timeout was VI_TMO_INFINITE
# This lookup method is also slightly convoluted because the unit test scripts
# may not have set this correctly.
finite_timeout = getattr(self, "timeout", None) is not NoneThere was a problem hiding this comment.
I dislike the idea of making the code weirder because the existing test is poorly written. Could this be improved ?
There was a problem hiding this comment.
I'll drill this down, and adapt the test scripts if needed.
Co-authored-by: Matthieu Dartiailh <marul@laposte.net>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
by the way, found no chunk size problems with hislip so far (apart from lack of events, and richness of end of message type support) Sockets looks like it has the same problem, but also NI-Visa chokes on it. |
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
I have one last concern regarding the handling of infinite timeout.
| remaining_timeout = timeout - elapsed_ms | ||
| if finite_timeout and remaining_timeout <= 0: | ||
| return bytes(read_data), StatusCode.error_timeout | ||
| chunk_timeout = max(10, remaining_timeout) |
There was a problem hiding this comment.
If there is no finite timeout this looks wrong since it will cause useless churn on the read function.
There was a problem hiding this comment.
understand, will look into this
| if remaining_timeout <= 0: | ||
| return bytes(read_data), StatusCode.error_timeout | ||
| else: | ||
| remaining_timeout = 2**32 - 1 # VI_TMO_INFINITE |
There was a problem hiding this comment.
Import it and use it rather than redefining it
Why
inst.chunk_sizevalues in relation to the content size, a read falls in timeout. This is corrected.success,success_termination_character_read,success_max_count_read, all while taking into accountVI_ATTR_SUPPRESS_END_ENTasks
black . && isort -c . && flake8with no errors. -> Is this still valid? It seems outdated.