Skip to content

Commit

Permalink
tests: Add tests for serializing CAN frames
Browse files Browse the repository at this point in the history
More cases are welcome. :)
  • Loading branch information
rumpelsepp committed Jan 23, 2025
1 parent 1505cf2 commit 6bcd57b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/pytest/test_can_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: AISEC Pentesting Team
#
# SPDX-License-Identifier: Apache-2.0

import sys

assert sys.platform.startswith("linux"), "unsupported platform"

from gallia.transports.can import CANMessage


def test_can_message_serialization() -> None:
input_data = [
b"\x00\x07\x00\x00\x04\x00\x00\x00s\x02>\x00\x00\x00\x00\x00",
]
output_data = [CANMessage(arbitration_id=0x700, dlc=4, data=bytes([0x73, 0x02, 0x3E, 0x00]))]

for i in range(len(input_data)):
frame = CANMessage.unpack(input_data[i])
assert frame == output_data[i]

0 comments on commit 6bcd57b

Please sign in to comment.