Skip to content

examples/vsock: add a vsock test client and server - #4045

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
CV-Bowen:up/P85-examples-vsock
Nov 14, 2026
Merged

xiaoxiang781216 merged 3 commits into
apache:masterfrom
CV-Bowen:up/P85-examples-vsock

Conversation

@CV-Bowen

Copy link
Copy Markdown
Contributor

Summary

There is no tool in nuttx-apps to exercise AF_VSOCK sockets. Add
examples/vsock:

vsock [-c <cid>] [-t data|conn] [-p <port>] [-i <size>] [-n <count>]
  • examples/vsock: add a vsock test client and server
    • -t data: the server echoes what it receives; the client (-c)
      sends -n buffers of -i bytes and checks the echo. Also builds
      on Linux against <linux/vm_sockets.h> to test against a Linux
      peer.
  • examples/vsock: add a connection stress test
    • -t conn: open and close -n connections in a row.
  • examples/vsock: accept a cid given as a name

Impact

New example, CONFIG_EXAMPLES_VSOCK, default n. No other change.

Testing

Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205

qemu-armv8a:rpserver + qemu-armv8a:rpproxy with apache/nuttx#21818
(vsock over the rptun ivshmem resource table). Overlay on both:
CONFIG_NET, CONFIG_NET_SOCKOPTS, CONFIG_NET_VSOCK,
CONFIG_EXAMPLES_VSOCK; rpproxy adds CONFIG_DRIVERS_VHOST +
CONFIG_NET_VSOCK_VHOST, rpserver adds CONFIG_DRIVERS_VIRTIO +
CONFIG_NET_VSOCK_VIRTIO. Builds with 0 warnings.

proxy>  vsock -t data -p 28065 -i 1024 -n 64 &
server> vsock -c prox -t data -p 28065 -i 1024 -n 64
proxy>  vsock -t conn -p 28066 &
server> vsock -c 2020569712 -t conn -p 28066 -n 32
output
proxy> Vsock server test, port=28065, size=1024, cid=4294967295

Vsock client test, port=28065, size=1024, count=64, cid=2020569712

Connect, s=3

Send finish, sendlen=65536

Close

server> Accept peer_fd=4

Close

proxy> Vsock client conn test: port=28066, cid=4294967295

Vsock server conn test: port=28066, count=32, cid=2020569712

Connection attempts: 32 (Success: 32, Failed: 0)

checkpatch passes.

@CV-Bowen
CV-Bowen force-pushed the up/P85-examples-vsock branch from d3b0d13 to ae1552d Compare November 13, 2026 09:02
Add "vsock", a test for AF_VSOCK sockets. "-t data" runs a server that
echoes what it receives, or a client (with "-c <cid>") that sends
"-n" buffers of "-i" bytes to port "-p" and checks the echo. The same
source also builds on Linux against <linux/vm_sockets.h>, so a Linux
peer can be tested against NuttX.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
"-t conn" opens and closes "-n" connections in a row, on the server
accepting and closing each one, to exercise the vsock connection
setup and teardown paths.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
A NuttX vsock cid set from a cpu name holds the first four bytes of
the name. Let "-c" take either a number or such a name, e.g.
"-c prox".

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
@CV-Bowen
CV-Bowen force-pushed the up/P85-examples-vsock branch from ae1552d to 98d17e6 Compare November 13, 2026 13:28
@xiaoxiang781216
xiaoxiang781216 merged commit 40c9f52 into apache:master Nov 14, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants