Skip to contentSkip to conversation

selftests: net: add tests for the QRTR socket family

RFC New Murali Krishna 1 participant 1 message Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 selftests: net: add tests for the QRTR socket family

net/qrtr has no test coverage in tools/testing/selftests, although the behaviour it exposes to userspace is well defined and testable without Qualcomm hardware: the local node always exists, and CONFIG_QRTR_TUN lets a test act as a QRTR endpoint.

Add tools/testing/selftests/net/qrtr with two programs.

qrtr_sock covers the AF_QIPCRTR socket contract: the ephemeral port range and the CAP_NET_ADMIN boundary documented above qrtr_port_assign(), the bind() rule that an address must name the socket's own node, rebinding (which moves the port and releases the old one), EADDRINUSE on a taken port, auto-bind on send, and local datagram delivery including the source address reported to the receiver.

qrtr_endpoint covers frame validation in qrtr_endpoint_post() by writing crafted frames to /dev/qrtr-tun: length alignment, unknown protocol versions, headers truncated below the v1 and v2 minimums, a zero or over-long declared payload size, a size that disagrees with the frame length, control types whose payload is too small to hold a struct qrtr_ctrl_pkt, control types addressed to an ordinary port, and the legacy 16-bit control port number. Each frame is malformed in exactly one way so a failure names the check that regressed.

Both programs skip cleanly when CONFIG_QRTR is not available, and qrtr_endpoint also skips when /dev/qrtr-tun cannot be opened, so the suite is harmless on non-Qualcomm configurations.

Assisted-by LLM

---
This is an RFC rather than a submission: net/qrtr has no selftests at all, and I could not tell from Documentation/process/maintainer-netdev.rst whether a test-only series is wanted on its own, since it describes selftests as travelling with a code change. If the shape is wrong, or you would rather tests arrived only alongside functional patches, please say so and I will drop it.

Questions I would most like answered: whether the split between the socket-contract tests and the frame-validation tests makes sense, and which behaviours are worth covering next.

Testing: built and run on x86_64 against net-next (a4c450594). qrtr_sock passes 12/12 as an ordinary user; qrtr_endpoint passes 12/12 as root with qrtr-tun loaded. Both skip cleanly when CONFIG_QRTR or /dev/qrtr-tun is unavailable, and the suite builds with no warnings under -Wall -Wextra. I have no Qualcomm hardware, so only the tun endpoint and the local node are covered; the SMD and MHI transports are untested.

checkpatch --strict reports four things I believe are expected, and I have left them alone:

- three "Prefer __packed over __attribute__((packed))" warnings. __packed is a kernel-internal macro that is not available to a userspace selftest, and existing selftests use __attribute__((packed)) in the same way.
- an unrecognized-email-address error for 'LLM', and a non-standard signature warning for the Assisted-by trailer. checkpatch does not know that tag, although Documentation/process/coding-assistants.rst asks for it and specifies it as the word LLM followed by optional tool names, with no address.

The tests were written with the help of an LLM coding assistant, from a prompt asking for selftests covering the AF_QIPCRTR socket contract and qrtr_endpoint_post() frame validation; hence the Assisted-by tag. I have read and run every test and can explain what each one checks. Writing them corrected two assumptions I had got wrong: that bind() treats sq_node == 0 as "any node", and that rebinding an already bound socket fails.

 MAINTAINERS                                   |   1 +
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/net/qrtr/.gitignore   |   3 +
 tools/testing/selftests/net/qrtr/Makefile     |  11 +
 tools/testing/selftests/net/qrtr/config       |   2 +
 .../selftests/net/qrtr/qrtr_endpoint.c        | 275 ++++++++++++++++
 tools/testing/selftests/net/qrtr/qrtr_sock.c  | 298 ++++++++++++++++++
 7 files changed, 591 insertions(+)
 create mode 100644 tools/testing/selftests/net/qrtr/.gitignore
 create mode 100644 tools/testing/selftests/net/qrtr/Makefile
 create mode 100644 tools/testing/selftests/net/qrtr/config
 create mode 100644 tools/testing/selftests/net/qrtr/qrtr_endpoint.c
 create mode 100644 tools/testing/selftests/net/qrtr/qrtr_sock.c
MAINTAINERS +1 -0
index 97308edec..cce309b30 100644
@@ -23174,6 +23174,7 @@ S:	Maintained
 F:	include/trace/events/qrtr.h
 F:	include/uapi/linux/qrtr.h
 F:	net/qrtr/
+F:	tools/testing/selftests/net/qrtr/
 
 QUALCOMM IPCC MAILBOX DRIVER
 M:	Manivannan Sadhasivam <[email protected]>
tools/testing/selftests/Makefile +1 -0
index c55d7792b..3d0916b60 100644
@@ -97,6 +97,7 @@ TARGETS += net/openvswitch
 TARGETS += net/ovpn
 TARGETS += net/packetdrill
 TARGETS += net/ppp
+TARGETS += net/qrtr
 TARGETS += net/rds
 TARGETS += net/tcp_ao
 TARGETS += nfsd
tools/testing/selftests/net/qrtr/.gitignore new file +3 -0
new file mode 100644
index 000000000..cc2ea8a2b
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+qrtr_endpoint
+qrtr_sock
tools/testing/selftests/net/qrtr/Makefile new file +11 -0
new file mode 100644
index 000000000..0e22f4047
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+top_srcdir := ../../../../..
+
+CFLAGS += $(KHDR_INCLUDES) -Wall -Wextra -Wno-unused-parameter
+
+TEST_GEN_PROGS := \
+	qrtr_endpoint \
+	qrtr_sock \
+# end of TEST_GEN_PROGS
+
+include ../../lib.mk
tools/testing/selftests/net/qrtr/config new file +2 -0
new file mode 100644
index 000000000..0bdb8a4c5
@@ -0,0 +1,2 @@
+CONFIG_QRTR=m
+CONFIG_QRTR_TUN=m
tools/testing/selftests/net/qrtr/qrtr_endpoint.c new file +275 -0

275 lines not on this page · raw message

tools/testing/selftests/net/qrtr/qrtr_sock.c new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
2.43.0