Skip to content

Enable SocketCAN interface tests in GitHub CI #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- name: Setup SocketCAN
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get -y install linux-modules-extra-$(uname -r)
sudo ./test/open_vcan.sh
- name: Test with pytest via tox
run: |
tox -e gh

env:
# SocketCAN tests currently fail with PyPy because it does not support raw CAN sockets
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3809
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.python-version, 'pypy' ) }}"
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
Expand Down
10 changes: 2 additions & 8 deletions test/test_cyclic_socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,8 @@ def test_start_already_started_task(self):
task_a = self._send_bus.send_periodic(messages_a, self.PERIOD)
time.sleep(0.1)

# Try to start it again, task_id is not incremented in this case
with self.assertRaises(can.CanOperationError) as ctx:
task_a.start()
self.assertEqual(
"A periodic task for task ID 1 is already in progress by the SocketCAN Linux layer",
str(ctx.exception),
)

# Task restarting is permitted as of #1440
task_a.start()
task_a.stop()

def test_create_same_id(self):
Expand Down
35 changes: 28 additions & 7 deletions test/test_socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
import ctypes
import struct
import unittest
import warnings
from unittest.mock import patch
import can

from can.interfaces.socketcan.constants import (
CAN_BCM_TX_DELETE,
CAN_BCM_TX_SETUP,
SETTIMER,
STARTTIMER,
TX_COUNTEVT,
)
from can.interfaces.socketcan.socketcan import (
bcm_header_factory,
build_bcm_header,
Expand All @@ -16,13 +25,7 @@
build_bcm_update_header,
BcmMsgHead,
)
from can.interfaces.socketcan.constants import (
CAN_BCM_TX_DELETE,
CAN_BCM_TX_SETUP,
SETTIMER,
STARTTIMER,
TX_COUNTEVT,
)
from .config import IS_LINUX, IS_PYPY


class SocketCANTest(unittest.TestCase):
Expand Down Expand Up @@ -353,6 +356,24 @@ def test_build_bcm_update_header(self):
self.assertEqual(can_id, result.can_id)
self.assertEqual(1, result.nframes)

@unittest.skipUnless(IS_LINUX and IS_PYPY, "Only test when run on Linux with PyPy")
def test_pypy_socketcan_support(self):
"""Wait for PyPy raw CAN socket support

This test shall document raw CAN socket support under PyPy. Once this test fails, it is likely that PyPy
either implemented raw CAN socket support or at least changed the error that is thrown.
https://foss.heptapod.net/pypy/pypy/-/issues/3809
https://github.com/hardbyte/python-can/issues/1479
"""
try:
can.Bus(interface="socketcan", channel="vcan0", bitrate=500000)
except OSError as e:
if "unknown address family" not in str(e):
warnings.warn(
"Please check if PyPy has implemented raw CAN socket support! "
"See: https://foss.heptapod.net/pypy/pypy/-/issues/3809"
)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ passenv =
GITHUB_*
COVERALLS_*
PY_COLORS
TEST_SOCKETCAN

[testenv:travis]
passenv =
Expand Down