Skip to content

Commit 69a5209

Browse files
authored
Enable SocketCAN interface tests in GitHub CI (#1484)
* Update CI to set up vcan and run SocketCAN tests * Add test to document PyPy raw CAN socket implementation status * Update test for restarting of SocketCAN SendTask Previously, it was not permitted to restart an already started period send task for SocketCAN. This behavior was changed in PR #1440. This commit adjusts the test to reflect this change. * Update PyPy raw CAN socket test failure into warning
1 parent ef803a5 commit 69a5209

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

.github/workflows/ci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ jobs:
3838
run: |
3939
python -m pip install --upgrade pip
4040
pip install tox
41+
- name: Setup SocketCAN
42+
if: ${{ matrix.os == 'ubuntu-latest' }}
43+
run: |
44+
sudo apt-get -y install linux-modules-extra-$(uname -r)
45+
sudo ./test/open_vcan.sh
4146
- name: Test with pytest via tox
4247
run: |
4348
tox -e gh
44-
49+
env:
50+
# SocketCAN tests currently fail with PyPy because it does not support raw CAN sockets
51+
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3809
52+
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.python-version, 'pypy' ) }}"
4553
- name: Coveralls Parallel
4654
uses: coverallsapp/github-action@master
4755
with:

test/test_cyclic_socketcan.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,8 @@ def test_start_already_started_task(self):
256256
task_a = self._send_bus.send_periodic(messages_a, self.PERIOD)
257257
time.sleep(0.1)
258258

259-
# Try to start it again, task_id is not incremented in this case
260-
with self.assertRaises(can.CanOperationError) as ctx:
261-
task_a.start()
262-
self.assertEqual(
263-
"A periodic task for task ID 1 is already in progress by the SocketCAN Linux layer",
264-
str(ctx.exception),
265-
)
266-
259+
# Task restarting is permitted as of #1440
260+
task_a.start()
267261
task_a.stop()
268262

269263
def test_create_same_id(self):

test/test_socketcan.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
import ctypes
77
import struct
88
import unittest
9+
import warnings
910
from unittest.mock import patch
11+
import can
1012

13+
from can.interfaces.socketcan.constants import (
14+
CAN_BCM_TX_DELETE,
15+
CAN_BCM_TX_SETUP,
16+
SETTIMER,
17+
STARTTIMER,
18+
TX_COUNTEVT,
19+
)
1120
from can.interfaces.socketcan.socketcan import (
1221
bcm_header_factory,
1322
build_bcm_header,
@@ -16,13 +25,7 @@
1625
build_bcm_update_header,
1726
BcmMsgHead,
1827
)
19-
from can.interfaces.socketcan.constants import (
20-
CAN_BCM_TX_DELETE,
21-
CAN_BCM_TX_SETUP,
22-
SETTIMER,
23-
STARTTIMER,
24-
TX_COUNTEVT,
25-
)
28+
from .config import IS_LINUX, IS_PYPY
2629

2730

2831
class SocketCANTest(unittest.TestCase):
@@ -353,6 +356,24 @@ def test_build_bcm_update_header(self):
353356
self.assertEqual(can_id, result.can_id)
354357
self.assertEqual(1, result.nframes)
355358

359+
@unittest.skipUnless(IS_LINUX and IS_PYPY, "Only test when run on Linux with PyPy")
360+
def test_pypy_socketcan_support(self):
361+
"""Wait for PyPy raw CAN socket support
362+
363+
This test shall document raw CAN socket support under PyPy. Once this test fails, it is likely that PyPy
364+
either implemented raw CAN socket support or at least changed the error that is thrown.
365+
https://foss.heptapod.net/pypy/pypy/-/issues/3809
366+
https://github.com/hardbyte/python-can/issues/1479
367+
"""
368+
try:
369+
can.Bus(interface="socketcan", channel="vcan0", bitrate=500000)
370+
except OSError as e:
371+
if "unknown address family" not in str(e):
372+
warnings.warn(
373+
"Please check if PyPy has implemented raw CAN socket support! "
374+
"See: https://foss.heptapod.net/pypy/pypy/-/issues/3809"
375+
)
376+
356377

357378
if __name__ == "__main__":
358379
unittest.main()

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ passenv =
2626
GITHUB_*
2727
COVERALLS_*
2828
PY_COLORS
29+
TEST_SOCKETCAN
2930

3031
[testenv:travis]
3132
passenv =

0 commit comments

Comments
 (0)