[PATCH can-next v3 0/9] selftests: can: add J1939 socket and transport tests
From: Oleksij Rempel
Date: Wed Nov 11 2026 - 10:34:12 EST
net/can/j1939 has had no in-tree selftests. This series adds a kselftest
suite for the J1939 socket layer and the TP/ETP transport, run on vcan with
a CAN_RAW socket as an independent on-the-wire peer.
The timer checks are relaxed by default, for slow CI machines;
J1939_STRICT_TIMING selects tight bounds. Not covered yet: the ETP abort
and timeout paths.
This series changes no kernel code. Known bugs in the stack affect these
tests or limit what they can cover. The fixes belong in the stack and are
not part of this series:
- The stack updates a session from the loopback echo of its own CTS, RTS
and DT frames, and a CAN_RAW peer can see that echo before the stack
does. A peer frame that follows quickly can then cancel the session and
fail a TP or ETP test (patches 7 and 8). I have not seen this in QEMU
runs.
- If the last J1939 socket closes while an address-claim timer is still
pending, the kernel keeps a reference to the interface, and deleting it
hangs (patch 5). The tests keep a socket open until the timer has run.
- On success, setsockopt() for SO_J1939_PROMISC and SO_J1939_ERRQUEUE
returns the value passed in instead of 0. The tests accept any value
>= 0 (patches 4 and 9).
- The stack ignores a Connection Abort received on a kernel TX session,
so no test covers it.
- An ETP CTS can ask for more packets than remain in the message. The
stack lowers the count to what remains. It does not abort with reason
15 (ECTS requested packets exceeds message size), so no test can reach
that abort.
I used Claude Code (mainly Claude Opus 5.5) to write most of the test
code, the commit messages, the Q&As and the changelogs, and to review
them. I have read, edited and run all of it myself, on vcan under QEMU.
v1: https://lore.kernel.org/all/20261014154435.3577983-1-o.rempel@xxxxxxxxxxxxxx/
v2: https://lore.kernel.org/all/20261104-j1939-selftests-v2-0-cf797c83317b@xxxxxxxxxxxxxx/
---
Oleksij Rempel (9):
selftests: can: install net/lib.sh with the CAN tests
selftests: can: add J1939 test helper header and library
selftests: can: add J1939 base functional tests
selftests: can: add J1939 socket option and metadata tests
selftests: can: add J1939 addressing and concurrency tests
selftests: can: add J1939 wire-format tests against CAN_RAW
selftests: can: add J1939 TP/ETP multi-frame tests against CAN_RAW
selftests: can: cover J1939 transport abort and timeout paths
selftests: can: check SO_J1939_PROMISC receive effect
tools/testing/selftests/net/can/.gitignore | 5 +
tools/testing/selftests/net/can/Makefile | 21 +-
tools/testing/selftests/net/can/config | 2 +
tools/testing/selftests/net/can/j1939_helpers.c | 524 ++++++++++++
tools/testing/selftests/net/can/j1939_helpers.h | 374 ++++++++
tools/testing/selftests/net/can/j1939_lib.sh | 92 ++
tools/testing/selftests/net/can/j1939_tests.h | 71 ++
tools/testing/selftests/net/can/test_j1939_addr.c | 736 ++++++++++++++++
tools/testing/selftests/net/can/test_j1939_addr.sh | 4 +
tools/testing/selftests/net/can/test_j1939_base.c | 236 +++++
tools/testing/selftests/net/can/test_j1939_base.sh | 4 +
tools/testing/selftests/net/can/test_j1939_multi.c | 950 +++++++++++++++++++++
.../testing/selftests/net/can/test_j1939_multi.sh | 4 +
tools/testing/selftests/net/can/test_j1939_opts.c | 434 ++++++++++
tools/testing/selftests/net/can/test_j1939_opts.sh | 4 +
tools/testing/selftests/net/can/test_j1939_wire.c | 196 +++++
tools/testing/selftests/net/can/test_j1939_wire.sh | 4 +
17 files changed, 3659 insertions(+), 2 deletions(-)
---
base-commit: 6584acd42820478910a771efb28a355a707e9cb0
change-id: 20261104-j1939-selftests-12fc860698c0
Best regards,
--
Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>