Skip to content

tests fail on bigendian #1624

@umlaeute

Description

@umlaeute

Describe the bug

Running the test-suite on a BingEndian architecture (like s390x), fails in two places:

  • test_bit_timing.py::test_btr_persistence FAILED
  • test_pcan.py::TestPCANBus::test_detect_available_configs FAILED
90s =================================== FAILURES ===================================
 90s _____________________________ test_btr_persistence _____________________________
 90s 
 90s     def test_btr_persistence():
 90s         f_clock = 8_000_000
 90s         for btr0btr1 in PCAN_BITRATES.values():
 90s             btr1, btr0 = struct.unpack("BB", btr0btr1)
 90s     
 90s >           t = can.BitTiming.from_registers(f_clock, btr0, btr1)
 90s 
 90s test_bit_timing.py:180: 
 90s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 90s /usr/lib/python3/dist-packages/can/bit_timing.py:183: in from_registers
 90s     return cls(
 90s /usr/lib/python3/dist-packages/can/bit_timing.py:70: in __init__
 90s     self._validate()
 90s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 90s 
 90s self = can.BitTiming(f_clock=8000000, brp=21, tseg1=1, tseg2=1, sjw=1, nof_samples=1)
 90s 
 90s     def _validate(self) -> None:
 90s         if not 8 <= self.nbt <= 25:
 90s >           raise ValueError(f"nominal bit time (={self.nbt}) must be in [8...25].")
 90s E           ValueError: nominal bit time (=3) must be in [8...25].
 90s 
 90s /usr/lib/python3/dist-packages/can/bit_timing.py:74: ValueError
 90s __________________ TestPCANBus.test_detect_available_configs ___________________
 90s 
 90s self = <test.test_pcan.TestPCANBus testMethod=test_detect_available_configs>
 90s 
 90s     def test_detect_available_configs(self) -> None:
 90s         if platform.system() == "Darwin":
 90s             self.mock_pcan.GetValue = Mock(
 90s                 return_value=(PCAN_ERROR_OK, PCAN_CHANNEL_AVAILABLE)
 90s             )
 90s             configs = PcanBus._detect_available_configs()
 90s             self.assertEqual(len(configs), 50)
 90s         else:
 90s             value = (TPCANChannelInformation * 1).from_buffer_copy(
 90s                 b"Q\x00\x05\x00\x01\x00\x00\x00PCAN-USB FD\x00\x00\x00\x00"
 90s                 b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 90s                 b'\x00\x00\x00\x00\x00\x00\x003"\x11\x00\x01\x00\x00\x00'
 90s             )
 90s             self.mock_pcan.GetValue = Mock(return_value=(PCAN_ERROR_OK, value))
 90s >           configs = PcanBus._detect_available_configs()
 90s 
 90s test_pcan.py:382: 
 90s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 90s 
 90s     @staticmethod
 90s     def _detect_available_configs():
 90s         channels = []
 90s         try:
 90s             library_handle = PCANBasic()
 90s         except OSError:
 90s             return channels
 90s     
 90s         interfaces = []
 90s     
 90s         if platform.system() != "Darwin":
 90s             res, value = library_handle.GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS)
 90s             if res != PCAN_ERROR_OK:
 90s                 return interfaces
 90s             channel_information: List[TPCANChannelInformation] = list(value)
 90s             for channel in channel_information:
 90s                 # find channel name in PCAN_CHANNEL_NAMES by value
 90s >               channel_name = next(
 90s                     _channel_name
 90s                     for _channel_name, channel_id in PCAN_CHANNEL_NAMES.items()
 90s                     if channel_id.value == channel.channel_handle
 90s                 )
 90s E               StopIteration
 90s 
 90s /usr/lib/python3/dist-packages/can/interfaces/pcan/pcan.py:691: StopIteration
 90s =========================== short test summary info ============================
 90s FAILED test_bit_timing.py::test_btr_persistence - ValueError: nominal bit tim...
 90s FAILED test_pcan.py::TestPCANBus::test_detect_available_configs - StopIteration
 90s ================== 2 failed, 427 passed, 97 skipped in 32.84s ==================

To Reproduce

Run the test-suite on a BigEndian machine

Expected behavior

tests should succeed, regardless of endianness

Additional context

component version
OS and version Debian/trixie
Python version 3.11
python-can version 4.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions