Files
StarPilot/panda/tests/usbprotocol/test_pandalib.py
T
firestar5683 22a8575199 Vendor dependencies and resources for standalone builds
Keep official openpilot ancestry and dependency licenses. Store resources directly in Git, remove LFS setup requirements, and leave the downloadable big model outside the source tree.
2026-10-03 21:01:18 +00:00

27 lines
733 B
Python
Executable File

#!/usr/bin/env python3
import random
import unittest
from panda import pack_can_buffer, unpack_can_buffer, DLC_TO_LEN
class PandaTestPackUnpack(unittest.TestCase):
def test_panda_lib_pack_unpack(self):
overflow_buf = b''
to_pack = []
for _ in range(10000):
address = random.randint(1, (1 << 29) - 1)
data = bytes([random.getrandbits(8) for _ in range(DLC_TO_LEN[random.randrange(0, len(DLC_TO_LEN))])])
to_pack.append((address, data, 0))
packed = pack_can_buffer(to_pack)
unpacked = []
for dat in packed:
msgs, overflow_buf = unpack_can_buffer(overflow_buf + dat)
unpacked.extend(msgs)
self.assertEqual(unpacked, to_pack)
if __name__ == "__main__":
unittest.main()