Re: [PATCH net-next v2] selftests: net: add tests for the QRTR socket family
From: Hangbin Liu
Date: Wed Dec 02 2026 - 04:18:25 EST
Hi Murali,
On Tue, Dec 01, 2026 at 04:14:15PM +0530, Murali Krishna wrote:
> 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 rejection test malforms the
> frame in exactly one way, so a failure names the check that regressed.
>
> A rejection on its own is weak evidence, though, because
> qrtr_endpoint_post() reports every failed validation check as -EINVAL
> through a single error path: a frame can be refused for a reason the
> test did not intend. control_type_to_normal_port therefore binds a
> socket to the destination port, so that qrtr_port_lookup() cannot be
> what fails, and data_to_normal_port shows a DATA frame to that same
> port being accepted.
>
> Header fields are written with htole32()/htole16().
> qrtr_endpoint_post() takes the protocol version from the first byte of
> the frame and decodes the remaining fields with le32_to_cpu() and
> le16_to_cpu(), so frames built in host byte order would be rejected at
> the version check on a big-endian host.
>
> 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.
>
> 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. Both C files and this changelog
> were drafted that way, then reviewed, corrected and run by hand.
> Writing them corrected two assumptions about the interface: that bind()
> treats sq_node == 0 as "any node", and that rebinding an already bound
> socket fails.
The commit description is too long, maybe shorter it?
>
> Signed-off-by: Murali Krishna <muralikrishna2444b@xxxxxxxxx>
> ---
...
> diff --git a/tools/testing/selftests/net/qrtr/config b/tools/testing/selftests/net/qrtr/config
> new file mode 100644
> index 000000000..0bdb8a4c5
> --- /dev/null
> +++ b/tools/testing/selftests/net/qrtr/config
> @@ -0,0 +1,2 @@
> +CONFIG_QRTR=m
> +CONFIG_QRTR_TUN=m
We build qrtr-tun as a module. If the user hasn't loaded it, the test skips with:
no /dev/qrtr-tun: modprobe qrtr-tun, or CONFIG_QRTR_TUN=n
Should we try loading it inside the test script?
Thanks
Hangbin