Repository navigation
Closed
Labels
Description
Describe the bug
it seems that python-can fails the test-suite on big-endian machines.
See https://ci.debian.net/data/autopkgtest/testing/s390x/p/python-can/24833388/log.gz (see below for an excerpt)
To Reproduce
run the test-suite on a big-endian architecture.
Expected behavior
big-endian is supported.
Additional context
| OS and version | Debian/GNU Linux/unstable (as of 2022-08-15) |
| Python version | 3.10 |
| python-can version | 4.0.0 |
| python-can interface/s (if applicable) | n.n. |
| Architecture | s390x |
Traceback and logs
_______ SocketCANTest.test_build_bcm_header_sizeof_long_8_alignof_long_8 _______
self = <test.test_socketcan.SocketCANTest testMethod=test_build_bcm_header_sizeof_long_8_alignof_long_8>
@unittest.skipIf(
not (
ctypes.sizeof(ctypes.c_long) == 8 and ctypes.alignment(ctypes.c_long) == 8
),
"Should only run on platforms where sizeof(long) == 8 and alignof(long) == 8",
)
def test_build_bcm_header_sizeof_long_8_alignof_long_8(self):
expected_result = (
b"\x02\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x01\x04\x00\x00\x01\x00\x00\x00"
)
> self.assertEqual(
expected_result,
build_bcm_header(
opcode=CAN_BCM_TX_DELETE,
flags=0,
count=0,
ival1_seconds=0,
ival1_usec=0,
ival2_seconds=0,
ival2_usec=0,
can_id=0x401,
nframes=1,
),
)
E AssertionError: b'\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00[176 chars]\x00' != b'\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00[176 chars]\x01'
test_socketcan.py:290: AssertionError
Activity
zariiii9003 commentedon Aug 16, 2022
@hartkopp can you take a look?
Is the functionality broken or is it just a brittle test design due to the expected result here?
python-can/test/test_socketcan.py
Line 279 in 2da28c1
hartkopp commentedon Aug 17, 2022
Sure!
Just take the two examples
opcode=CAN_BCM_TX_DELETEwhereopcodeis an uint32 value and CAN_BCM_TX_DELETE = 2can_id=0x401wherecan_idis an uint32 valueThe results are checked with a byte field ("expected_result"):
opcode=CAN_BCM_TX_DELETEresults in b"\x02\x00\x00\x00\x00\x00\x00\x00" (first line)can_id=0x401results in b"\x01\x04\x00\x00\x01\x00\x00\x00" (last line)... which is a correct representation of unit32 values in little endian.
Using these little endian byte fields for testing on a big endian system is supposed to fail.
When testing on a big endian system is needed we would need to provide separate big endian bytefields or provide another implementation for these tests. A quick fix could be to skip those tests on big endian systems as long as there is no solution.
umlaeute commentedon Aug 17, 2022
something like this?
zariiii9003 commentedon Aug 17, 2022
I'd prefer to make the expected result dependent on the system byte order:
umlaeute commentedon Aug 17, 2022
well, that was the "quick fix".
a somewhat nicer fix would be to convert the buffer to native byte ordering first:
(i haven't actually tested this in real life)
umlaeute commentedon Aug 17, 2022
and the same should probably be applied to
test_build_bcm_header_sizeof_long_4_alignof_long_4.so it's probably worth using a helper-function:
and then:
try to fix hardbyte#1376
Fix #1376 (#1412)
Revert "Fix hardbyte#1376 (hardbyte#1412)"