selftests: can: cover CAN XL VCID getsockopt
Subsystems (3)
PATCH 1/1 selftests: can: cover CAN XL VCID getsockopt
CAN_RAW_XL_VCID_OPTS returns the configured VCID options through getsockopt(). When the supplied buffer is too small, it returns ERANGE and updates optlen with the required size. Neither behavior is covered by the CAN selftests.
Add two tests to a separate test_raw_sockopt executable. Set nonzero, distinct VCID values and compare each returned field and the option length. Pass a buffer length one byte below the structure size and check the error and required length.
Use an unbound CAN_RAW socket so the tests need neither a CAN interface nor vcan setup. Skip when CAN_RAW or the VCID option is unavailable. Register the executable with kselftest and request CONFIG_CAN_RAW.
OpenAI Codex assisted with the implementation and commit message.
---
Tested with GCC 13.3.0 (-Werror). On Ubuntu 7.0.0-43-generic in QEMU, both tests pass as root and as uid 65534 with only the loopback interface. Both tests skip with CAN modules absent and on WSL 6.6 without the VCID option. No vcan interface is created.
OpenAI Codex generated the implementation and commit message from a request for these two cases and ran the build and runtime checks.
tools/testing/selftests/net/can/.gitignore | 1 + tools/testing/selftests/net/can/Makefile | 2 + tools/testing/selftests/net/can/config | 1 + .../selftests/net/can/test_raw_sockopt.c | 80 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 tools/testing/selftests/net/can/test_raw_sockopt.c
tools/testing/selftests/net/can/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only test_raw_filter +test_raw_sockopt
tools/testing/selftests/net/can/Makefile +2 -0
@@ -6,6 +6,8 @@ CFLAGS += -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include $(KHDR_INC TEST_PROGS := test_raw_filter.sh +TEST_GEN_PROGS := test_raw_sockopt + TEST_GEN_FILES := test_raw_filter include ../../lib.mk
tools/testing/selftests/net/can/config +1 -0
@@ -1,3 +1,4 @@ CONFIG_CAN=m +CONFIG_CAN_RAW=m CONFIG_CAN_DEV=m CONFIG_CAN_VCAN=m
tools/testing/selftests/net/can/test_raw_sockopt.c new file +80 -0
80 lines not on this page · raw message
base-commit: 573af801552999954caa8347e4490b04cf4763f0
Signature · 1 line
2.47.1.windows.1