vhost-user-bridge housekeeping and test
v2 cover vhost-user-bridge housekeeping and test
vhost-user-bridge was introduced prior to the first vhost-user daemon in contrib/, and has remained in tests/ ever since. Let's join it with its friends. By moving it into its own subdir of contrib/, it's granted coverage in MAINTAINERS under the vhost section, whereas in tests/ it remains uncovered and somewhat out of place.
Since vhost-user daemons in contrib have sections in the vhost-user-contrib doc, let's add a section for vubr there. The section as proposed doesn't fully cover all of vhost-user-bridge's capabilities; for example, in aef8486ede8b Marc-André added a client mode to vubr that is, for now, left unmentioned in the doc.
To complete the move, changes were made to the tests/ and root meson.build files in addition to the new one in contrib/vhost-user-bridge/.
The second patch was the subject of the first RFC. It introduces a basic functional test of vubr in the same spirit as the testing mentioned for it in vubr's initial commit, 3595e2eb0a23 (I had the wrong commit hash in v1 of the RFC, my apologies). Initially, we used wget in the guest to make an http request to an external host. This proved to be the wrong tack, and I want to thank Marc-André for pointing that out and Thomas for suggesting the alternative methods to eliminate the external host dependency that are now used by the test.
The test is described in its header and commit message, but in short:
the guest serves a file to the host via http, and the host serves a file to the guest via tftp.
I should mention that the guest kernel image has since been modified to add python in the guest to be able to serve http. Also, the buildroot option to enable DHCP on boot is now included. As before, please see:
https://github.com/yodel/vhost-user-bridge-test
for the kernel and initramfs combined image and associated build files.
For the last patch, adding an RX hexdump to complement the existing transmit hexdump proved helpful to me when I was going through vubr's logs, and I think it may be helpful to others. I'm not sure if there's a reason for its omission besides time-constraints or simply being overlooked, so please let me know otherwise?
I think the test patch (two) is probably ready for pulling but am, as always, open to suggestions for improvements/fixes; as for its line in MAINTAINERS, I placed it under vhost after Michael's comment in the RFC (thank you, Michael), but perhaps the suggestion was meant only for vhost-user-bridge.c and not the functional test. Please let me know if the vhost section is the right place for the test or not?
And as before, thank you Cédric for having encouraged me to write the test in the first place, and now for having Cc-ed Marc-André.
Link to RFCv1:
https://lore.kernel.org/qemu-devel/[email protected]/
Changes since RFCv1:
- Remove external host dependency (Marc-André)
- Replace wget to external host with http and tftp between guest and host (Thomas)
- Use hardcoded UUIDs in the guest and a scratch file on the host for data transfer
- Use a Popen context manager to terminate and wait on vubr (this isn't necessary now, because vubr terminates when the connected guest shuts down, but I suppose it could be with future changes to vubr)
- Add line in MAINTAINERS (Michael?)
- New patch to move from tests/ to contrib/vhost-user-bridge/ and add docs section
- New patch to add RX debug logging in vhost-user-bridge.c
Thanks,
Yodel
Yodel Eldar (3):
tests/vhost-user-bridge: Move to contrib/vhost-user-bridge/ tests/functional/x86_64: Add vhost-user-bridge test contrib/vhost-user-bridge: Add UDP receive hexdump
MAINTAINERS | 1 +
contrib/vhost-user-bridge/meson.build | 4 +
.../vhost-user-bridge}/vhost-user-bridge.c | 7 +
.../devices/virtio/vhost-user-contrib.rst | 39 +++++
meson.build | 1 +
.../x86_64/test_vhost_user_bridge.py | 147 ++++++++++++++++++
tests/meson.build | 6 -
7 files changed, 199 insertions(+), 6 deletions(-)
create mode 100644 contrib/vhost-user-bridge/meson.build
rename {tests => contrib/vhost-user-bridge}/vhost-user-bridge.c (98%)
create mode 100755 tests/functional/x86_64/test_vhost_user_bridge.pySignature · 1 line
2.52.0
RFC PATCH v2 1/3 tests/vhost-user-bridge: Move to contrib/vhost-user-bridge/
After the introduction of vhost-user-bridge and libvhost-user, we formed the convention of placing vhost-user daemons in eponymous subdirs of contrib/. Follow this convention.
Create a contrib/vhost-user-bridge/ directory and move vhost-user-bridge into it. Extract its build target definition from tests/meson.build into the new directory, and include its subdir in the root-level meson.build.
Add a section about it in the "vhost-user daemons in contrib" document.
---
contrib/vhost-user-bridge/meson.build | 4 ++
.../vhost-user-bridge}/vhost-user-bridge.c | 0
.../devices/virtio/vhost-user-contrib.rst | 39 +++++++++++++++++++
meson.build | 1 +
tests/meson.build | 6 ---
5 files changed, 44 insertions(+), 6 deletions(-)
create mode 100644 contrib/vhost-user-bridge/meson.build
rename {tests => contrib/vhost-user-bridge}/vhost-user-bridge.c (100%)contrib/vhost-user-bridge/meson.build new file +4 -0
@@ -0,0 +1,4 @@ +if have_tools and have_vhost_user and host_os == 'linux' + executable('vhost-user-bridge', files('vhost-user-bridge.c'), + dependencies: [qemuutil, vhost_user], install: false) +endif
contrib/vhost-user-bridge/vhost-user-bridge.c renamed from tests/vhost-user-bridge.c +0 -0
docs/system/devices/virtio/vhost-user-contrib.rst +39 -0
@@ -85,3 +85,42 @@ vhost-user-scsi - SCSI controller The vhost-user-scsi daemon can proxy iSCSI devices onto a virtualized SCSI controller. + +.. _vhost_user_bridge: + +vhost-user-bridge - Network bridge +================================== + +The vhost-user-bridge daemon serves as a development tool for testing real +internet traffic by providing a networking backend, i.e. server, for the +vhost-user protocol. + +Example +------- +For a single QEMU instance that both runs the user-mode net stack (slirp) and +serves as a vhost-user protocol frontend, i.e. client, simultaneously: + +First, start vhost-user-bridge: + +:: + + $ vhost-user-bridge -u /tmp/vubr.sock \ + -l 127.0.0.1:4444 \ + -r 127.0.0.1:5555 + +Then, invoke QEMU: + +:: + + $ qemu-system-x86_64 \ + -m 4G \ + -object memory-backend-memfd,id=mem0,size=4G,share=on,prealloc=on \ + -numa node,memdev=mem0 \ + -chardev socket,id=char0,path=/tmp/vubr.sock \ + -netdev vhost-user,id=vhost0,chardev=char0,vhostforce=on \ + -device virtio-net-pci,netdev=vhost0 \ + -netdev socket,id=udp0,udp=localhost:4444,localaddr=localhost:5555 \ + -netdev user,id=user0 \ + -netdev hubport,id=hub0,hubid=0,netdev=udp0 \ + -netdev hubport,id=hub1,hubid=0,netdev=user0 \ + ...
meson.build +1 -0
@@ -4546,6 +4546,7 @@ if have_tools subdir('contrib/vhost-user-gpu') subdir('contrib/vhost-user-input') subdir('contrib/vhost-user-scsi') + subdir('contrib/vhost-user-bridge') endif if host_os == 'linux'
tests/meson.build +0 -6
@@ -70,12 +70,6 @@ test_deps = { 'test-qht-par': qht_bench, } -if have_tools and have_vhost_user and host_os == 'linux' - executable('vhost-user-bridge', - sources: files('vhost-user-bridge.c'), - dependencies: [qemuutil, vhost_user]) -endif - subdir('decode') if 'CONFIG_TCG' in config_all_accel
Signature · 1 line
2.52.0
Re: [RFC PATCH v2 1/3] tests/vhost-user-bridge: Move to contrib/vhost-user-bridge/
Quoted 5 lines · Yodel Eldar
After the introduction of vhost-user-bridge and libvhost-user, we formed the convention of placing vhost-user daemons in eponymous subdirs of contrib/. Follow this convention.
Quoted 7 lines
Create a contrib/vhost-user-bridge/ directory and move vhost-user-bridge into it. Extract its build target definition from tests/meson.build into the new directory, and include its subdir in the root-level meson.build.
Add a section about it in the "vhost-user daemons in contrib" document.
Signed-off-by Yodel Eldar <[email protected]>
Quoted 104 lines
--- contrib/vhost-user-bridge/meson.build | 4 ++ .../vhost-user-bridge}/vhost-user-bridge.c | 0 .../devices/virtio/vhost-user-contrib.rst | 39 +++++++++++++++++++ meson.build | 1 + tests/meson.build | 6 --- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 contrib/vhost-user-bridge/meson.build rename {tests => contrib/vhost-user-bridge}/vhost-user-bridge.c (100%)contrib/vhost-user-bridge/meson.build new file +4
-0@@ -0,0 +1,4 @@ +if have_tools and have_vhost_user and host_os == 'linux' + executable('vhost-user-bridge', files('vhost-user-bridge.c'), + dependencies: [qemuutil, vhost_user], install: false) +endifcontrib/vhost-user-bridge/vhost-user-bridge.c renamed from tests/vhost-user-bridge.c +0
-0docs/system/devices/virtio/vhost-user-contrib.rst +39
-0@@ -85,3 +85,42 @@ vhost-user-scsi - SCSI controller The vhost-user-scsi daemon can proxy iSCSI devices onto a virtualized SCSI controller. + +.. _vhost_user_bridge: + +vhost-user-bridge - Network bridge +================================== + +The vhost-user-bridge daemon serves as a development tool for testing real +internet traffic by providing a networking backend, i.e. server, for the +vhost-user protocol. + +Example +------- +For a single QEMU instance that both runs the user-mode net stack (slirp) and +serves as a vhost-user protocol frontend, i.e. client, simultaneously: + +First, start vhost-user-bridge: + +:: + + $ vhost-user-bridge -u /tmp/vubr.sock \ + -l 127.0.0.1:4444 \ + -r 127.0.0.1:5555 + +Then, invoke QEMU: + +:: + + $ qemu-system-x86_64 \ + -m 4G \ + -object memory-backend-memfd,id=mem0,size=4G,share=on,prealloc=on \ + -numa node,memdev=mem0 \ + -chardev socket,id=char0,path=/tmp/vubr.sock \ + -netdev vhost-user,id=vhost0,chardev=char0,vhostforce=on \ + -device virtio-net-pci,netdev=vhost0 \ + -netdev socket,id=udp0,udp=localhost:4444,localaddr=localhost:5555 \ + -netdev user,id=user0 \ + -netdev hubport,id=hub0,hubid=0,netdev=udp0 \ + -netdev hubport,id=hub1,hubid=0,netdev=user0 \ + ...meson.build +1
-0@@ -4546,6 +4546,7 @@ if have_tools subdir('contrib/vhost-user-gpu') subdir('contrib/vhost-user-input') subdir('contrib/vhost-user-scsi') + subdir('contrib/vhost-user-bridge') endif if host_os == 'linux'tests/meson.build +0
-7@@ -70,12 +70,6 @@ test_deps = { 'test-qht-par': qht_bench, } -if have_tools and have_vhost_user and host_os == 'linux' - executable('vhost-user-bridge', - sources: files('vhost-user-bridge.c'), - dependencies: [qemuutil, vhost_user]) -endif - subdir('decode') if 'CONFIG_TCG' in config_all_accel --2.52.0
Signature · 1 line
Marc-André Lureau
RFC PATCH v2 2/3 tests/functional/x86_64: Add vhost-user-bridge test
In reply to Yodel EldarIntroduce a functional test of vhost-user-bridge and enter it into MAINTAINERS under the vhost section.
The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in 3595e2eb0a23.
A file containing a hardcoded UUID is created by the test in a scratch file and exposed to the guest via the tftp parameter of the user netdev. The guest requests the file by invoking tftp, and the test verifies its sha256 hashsum.
Similarly, a file containing another hardcoded UUID is created in the guest. A call to check_http_download() serves the file via http to the host and verifies integrity with its hashsum.
--- MAINTAINERS | 1 + .../x86_64/test_vhost_user_bridge.py | 147 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100755 tests/functional/x86_64/test_vhost_user_bridge.py
MAINTAINERS +1 -0
@@ -2374,32 +2374,33 @@ F: docs/devel/vfio-iommufd.rst vhost M: Michael S. Tsirkin <[email protected]> R: Stefano Garzarella <[email protected]> S: Supported F: hw/*/*vhost* F: docs/interop/vhost-user* F: docs/system/devices/vhost-user* F: contrib/vhost-user-*/ F: backends/*vhost* F: include/system/vhost-user-backend.h F: include/hw/virtio/vhost* F: include/*/vhost* F: subprojects/libvhost-user/ F: block/export/vhost-user* F: util/vhost-user-server.c F: net/vhost* +F: tests/functional/x86_64/test_vhost_user_bridge.py vhost-shadow-virtqueue R: Eugenio Pérez <[email protected]> F: hw/virtio/vhost-shadow-virtqueue.* virtio M: Michael S. Tsirkin <[email protected]> S: Supported F: hw/*/virtio* F: hw/virtio/Makefile.objs F: hw/virtio/trace-events F: qapi/virtio.json F: net/vhost-user.c F: include/hw/virtio/ F: docs/devel/virtio* F: docs/devel/migration/virtio.rst
tests/functional/x86_64/test_vhost_user_bridge.py new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [RFC PATCH v2 2/3] tests/functional/x86_64: Add vhost-user-bridge test
Quoted 25 lines · Yodel Eldar
Introduce a functional test of vhost-user-bridge and enter it into
MAINTAINERSunder the vhost section.The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in
3595e2eb0a23.A file containing a hardcoded UUID is created by the test in a scratch file and exposed to the guest via the tftp parameter of the user netdev. The guest requests the file by invoking tftp, and the test verifies its sha256 hashsum.
Similarly, a file containing another hardcoded UUID is created in the guest. A call to
check_http_download()serves the file via http to the host and verifies integrity with its hashsum.Suggested-by Cédric Le Goater <[email protected]>Suggested-by Marc-André Lureau <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>Suggested-by Thomas Huth <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
...
Quoted 14 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +14
-0+ def test_vhost_user_bridge(self): + prompt = "~ # " + host_uuid_filename = "vubr-test-uuid.txt" + guest_uuid_path = "/tmp/uuid.txt" + kernel_path = self.ASSET_KERNEL_INITRAMFS.fetch() + + vubr_path = self.build_file("contrib", "vhost-user-bridge", + "vhost-user-bridge") + if is_readable_executable_file(vubr_path) is None: + self.skipTest("Could not find a readable and executable " + "vhost-user-bridge") + + vubr_log_path = self.log_file("vhost-user-bridge.log") + self.log.info("For the vhost-user-bridge application log,"
tests/functional/x86_64/test_vhost_user_bridge.py line 114
Quoted 10 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +10
-0+ f" see: {vubr_log_path}") + + sock_dir = self.socket_dir() + ud_socket_path = os.path.join(sock_dir.name, "vubr-test.sock") + + tftpdir = self.scratch_file("tftp") + shutil.rmtree(tftpdir, ignore_errors=True) + os.mkdir(tftpdir) + host_uuid_path = self.scratch_file("tftp", host_uuid_filename) + with open(host_uuid_path, "w") as host_uuid_file:
FYI, I just got another test merged that checks the files with pylint now - you might need to add an encoding="ascii" or encoding="utf-8" to that open() call now to avoid that pylint complains.
tests/functional/x86_64/test_vhost_user_bridge.py line 126
Quoted 12 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +12
-0+ host_uuid_file.write(self.HOST_UUID) + + with Ports() as ports: + lport, rport, hostfwd_port = ports.find_free_ports(3) + + self.configure_vm(ud_socket_path, lport, rport, hostfwd_port, + tftpdir) + + vubr_args = self.assemble_vubr_args(vubr_path, ud_socket_path, + lport, rport) + + with open(vubr_log_path, "w+") as vubr_log, \
dito.
Quoted 11 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +11
-0+ subprocess.Popen(vubr_args, stdin=subprocess.DEVNULL, + stdout=vubr_log, + stderr=subprocess.STDOUT) as vubr_proc: + self.launch_kernel(kernel_path, wait_for=prompt) + + exec_command_and_wait_for_pattern(self, + f"tftp -g -r {host_uuid_filename} 10.0.2.2 ; " + f"sha256sum {host_uuid_filename}", self.HOST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + exec_command_and_wait_for_pattern(self,
tests/functional/x86_64/test_vhost_user_bridge.py line 147
Quoted 10 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +10
-0+ f"echo -n '{self.GUEST_UUID}' > {guest_uuid_path}", prompt) + self.check_http_download(guest_uuid_path, self.GUEST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + self.vm.shutdown() + vubr_proc.terminate() + vubr_proc.wait() + +if __name__ == '__main__': + LinuxKernelTest.main()
With the encoding=... added:
Re: [RFC PATCH v2 2/3] tests/functional/x86_64: Add vhost-user-bridge test
Quoted 98 lines · Thomas Huth
Quoted 25 lines · Yodel Eldar
Introduce a functional test of vhost-user-bridge and enter it into
MAINTAINERSunder the vhost section.The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in
3595e2eb0a23.A file containing a hardcoded UUID is created by the test in a scratch file and exposed to the guest via the tftp parameter of the user netdev. The guest requests the file by invoking tftp, and the test verifies its sha256 hashsum.
Similarly, a file containing another hardcoded UUID is created in the guest. A call to
check_http_download()serves the file via http to the host and verifies integrity with its hashsum.Suggested-by Cédric Le Goater <[email protected]>Suggested-by Marc-André Lureau <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>Suggested-by Thomas Huth <[email protected]>Signed-off-by Yodel Eldar <[email protected]>---
...
Quoted 14 lines
+ def
test_vhost_user_bridge(self):
+ prompt = "~ # "
+host_uuid_filename= "vubr-test-uuid.txt" +guest_uuid_path= "/tmp/uuid.txt"
+kernel_path=self.ASSET_KERNEL_INITRAMFS.fetch()tests/functional/x86_64/test_vhost_user_bridge.py new file +9
-0+ + vubr_path = self.build_file("contrib", "vhost-user-bridge", + "vhost-user-bridge") + if is_readable_executable_file(vubr_path) is None: + self.skipTest("Could not find a readable and executable " + "vhost-user-bridge") + + vubr_log_path = self.log_file("vhost-user-bridge.log") + self.log.info("For the vhost-user-bridge application log,"tests/functional/x86_64/test_vhost_user_bridge.py line 114
Quoted 10 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +10
-0+ f" see: {vubr_log_path}") + + sock_dir = self.socket_dir() + ud_socket_path = os.path.join(sock_dir.name, "vubr-test.sock") + + tftpdir = self.scratch_file("tftp") + shutil.rmtree(tftpdir, ignore_errors=True) + os.mkdir(tftpdir) + host_uuid_path = self.scratch_file("tftp", host_uuid_filename) + with open(host_uuid_path, "w") as host_uuid_file:FYI, I just got another test merged that checks the files with pylint now - you might need to add an encoding="ascii" or encoding="utf-8" to that
open()call now to avoid that pylint complains.Quoted 6 lines
+
host_uuid_file.write(self.HOST_UUID)tests/functional/x86_64/test_vhost_user_bridge.py new file +5
-0+ + with Ports() as ports: + lport, rport, hostfwd_port = ports.find_free_ports(3) + + self.configure_vm(ud_socket_path, lport, rport,Quoted 8 lines
hostfwd_port,
+ tftpdir)
+
+vubr_args= self.assemble_vubr_args(vubr_path,ud_socket_path,
+ lport, rport) +
+ withopen(vubr_log_path, "w+")asvubr_log, \dito.
Quoted 18 lines
+ subprocess.Popen(vubr_args, stdin=subprocess.DEVNULL, + stdout=vubr_log,
+ stderr=subprocess.STDOUT) asvubr_proc:
+self.launch_kernel(kernel_path, wait_for=prompt)+
+ exec_command_and_wait_for_pattern(self,
+ f"tftp -g -r {host_uuid_filename} 10.0.2.2 ; " + f"sha256sum {host_uuid_filename}", self.HOST_UUID_HSUM)
+wait_for_console_pattern(self, prompt)
+
+ exec_command_and_wait_for_pattern(self,
+ f"echo -n '{self.GUEST_UUID}' > {guest_uuid_path}", prompt)
+self.check_http_download(guest_uuid_path, self.GUEST_UUID_HSUM)
+wait_for_console_pattern(self, prompt)tests/functional/x86_64/test_vhost_user_bridge.py line 147
Quoted 7 lines
tests/functional/x86_64/test_vhost_user_bridge.py new file +7
-0+ + self.vm.shutdown() + vubr_proc.terminate() + vubr_proc.wait() + +if __name__ == '__main__': + LinuxKernelTest.main()With the encoding=... added:
Quoted 3 lines
Reviewed-by Thomas Huth <[email protected]>
Thanks for the review and the heads up. That test_linters is a boon to the framework.
Adding the encoding='s and a disable=unbalanced-tuple-unpacking on find_free_ports() for v3.
Thanks,
Yodel
Re: [RFC PATCH v2 2/3] tests/functional/x86_64: Add vhost-user-bridge test
In reply to Yodel EldarQuoted 20 lines · Yodel Eldar
Introduce a functional test of vhost-user-bridge and enter it into
MAINTAINERSunder the vhost section.The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in
3595e2eb0a23.A file containing a hardcoded UUID is created by the test in a scratch file and exposed to the guest via the tftp parameter of the user netdev. The guest requests the file by invoking tftp, and the test verifies its sha256 hashsum.
Similarly, a file containing another hardcoded UUID is created in the guest. A call to
check_http_download()serves the file via http to the host and verifies integrity with its hashsum.
Quoted 5 lines
Suggested-by Cédric Le Goater <[email protected]>Suggested-by Marc-André Lureau <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>Suggested-by Thomas Huth <[email protected]>Signed-off-by Yodel Eldar <[email protected]>
by the way, have you left out adding the test to meson on purpose?
+++ b/tests/functional/x86_64/meson.build @@ -36,4 +36,5 @@ tests_x86_64_system_thorough = [
'vfio_user_client',
'virtio_balloon',
'virtio_gpu',
+ 'vhost_user_bridge',
]
As I dig into the image creation process, I wonder if your approach will stand the test of time.
It seems mkosi is the most promising project to create reproducible bootable images, and that we are moving to UKI instead of separate initramfs.
Of course it's neat that you managed to put together a buildroot script that produces a 14Mb bzImage for the test, but it's also slow to build and perhaps not flexible enough if we generalize this approach to other built images in the future.
Quoted 200 lines
--- MAINTAINERS | 1 + .../x86_64/test_vhost_user_bridge.py | 147 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100755 tests/functional/x86_64/test_vhost_user_bridge.pyMAINTAINERS +1
-0@@ -2374,32 +2374,33 @@ F: docs/devel/vfio-iommufd.rst vhost M: Michael S. Tsirkin <[email protected]> R: Stefano Garzarella <[email protected]> S: Supported F: hw/*/*vhost* F: docs/interop/vhost-user* F: docs/system/devices/vhost-user* F: contrib/vhost-user-*/ F: backends/*vhost* F: include/system/vhost-user-backend.h F: include/hw/virtio/vhost* F: include/*/vhost* F: subprojects/libvhost-user/ F: block/export/vhost-user* F: util/vhost-user-server.c F: net/vhost* +F: tests/functional/x86_64/test_vhost_user_bridge.py vhost-shadow-virtqueue R: Eugenio Pérez <[email protected]> F: hw/virtio/vhost-shadow-virtqueue.* virtio M: Michael S. Tsirkin <[email protected]> S: Supported F: hw/*/virtio* F: hw/virtio/Makefile.objs F: hw/virtio/trace-events F: qapi/virtio.json F: net/vhost-user.c F: include/hw/virtio/ F: docs/devel/virtio* F: docs/devel/migration/virtio.rsttests/functional/x86_64/test_vhost_user_bridge.py new file +147
-1@@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2025 Software Freedom Conservancy, Inc. +# +# Author: Yodel Eldar <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0-or-later +""" +Test vhost-user-bridge (vubr) functionality: + + 1) Run vhost-user-bridge on the host. + 2) Launch a guest VM: + a) Instantiate a unix domain socket to the vubr-created path + b) Instantiate a vhost-user backend on top of that socket + c) Map a virtio-net-pci device to the vhost-user backend + d) Instantiate a UDP socket backend + e) Instantiate a user-mode net backend + i) Forward an ephemeral port to port 8080 in-guest with hostfwd= + ii) Expose a generated scratch file to the guest with tftp= + f) Hub the UDP and user-mode backends. + 3) Invoke tftp in the guest to download exported scratch file from the host. + 4) Serve a file to the host via http server in the guest. +""" + +import os +import shutil +import subprocess +from qemu_test import Asset, LinuxKernelTest, which +from qemu_test import exec_command_and_wait_for_pattern +from qemu_test import is_readable_executable_file +from qemu_test import wait_for_console_pattern +from qemu_test.ports import Ports + +class VhostUserBridge(LinuxKernelTest): + + ASSET_KERNEL_INITRAMFS = Asset( + "https://github.com/yodel/vhost-user-bridge-test/raw/refs/heads/main/bzImage", + "8860d7aa59434f483542cdf25b42eacae0d4d4aa7ec923af9589d1ad4703d42b") + + HOST_UUID = "ba4c2e39-627f-487d-ae3b-93cc5d783eb8" + HOST_UUID_HSUM = \ + "d2932e34bf6c17b33e7325140b691e27c191d9ac4dfa550f68c09506facb09b9" + + GUEST_UUID = "143d2b21-fdf0-4c5e-a9ef-f35ebbac8945" + GUEST_UUID_HSUM = \ + "14b64203f5cf2afe520f8be0fdfe630aafc1e85d1301f55a0d1681e68881f3a2" + + def configure_vm(self, ud_socket_path, lport, rport, hostfwd_port, tftpdir): + self.require_accelerator("kvm") + self.require_netdev("vhost-user") + self.require_netdev("socket") + self.require_netdev("hubport") + self.require_netdev("user") + self.require_device("virtio-net-pci") + self.set_machine("q35") + self.vm.add_args( + "-cpu", "host", + "-accel", "kvm", + "-append", "printk.time=0 console=ttyS0", + "-smp", "2", + "-m", "128M", + "-object", "memory-backend-memfd,id=mem0," + "size=128M,share=on,prealloc=on", + "-numa", "node,memdev=mem0", + "-chardev", f"socket,id=char0,path={ud_socket_path}", + "-netdev", "vhost-user,id=vhost0,chardev=char0,vhostforce=on", + "-device", "virtio-net-pci,netdev=vhost0", + "-netdev", f"socket,id=udp0,udp=localhost:{lport}," + f"localaddr=localhost:{rport}", + "-netdev", "hubport,id=hub0,hubid=0,netdev=udp0", + "-netdev", "user,id=user0," + f"hostfwd=tcp:127.0.0.1:{hostfwd_port}-:8080," + f"tftp={tftpdir}", + "-netdev", "hubport,id=hub1,hubid=0,netdev=user0" + ) + + def assemble_vubr_args(self, vubr_path, ud_socket_path, lport, rport): + vubr_args = [] + + if (stdbuf_path := which("stdbuf")) is None: + self.log.info("Could not find stdbuf: vhost-user-bridge " + "log lines may appear out of order") + else: + vubr_args += [stdbuf_path, "-o0", "-e0"] + + vubr_args += [vubr_path, "-u", f"{ud_socket_path}", + "-l", f"127.0.0.1:{lport}", "-r", f"127.0.0.1:{rport}"] + + return vubr_args + + def test_vhost_user_bridge(self): + prompt = "~ # " + host_uuid_filename = "vubr-test-uuid.txt" + guest_uuid_path = "/tmp/uuid.txt" + kernel_path = self.ASSET_KERNEL_INITRAMFS.fetch() + + vubr_path = self.build_file("contrib", "vhost-user-bridge", + "vhost-user-bridge") + if is_readable_executable_file(vubr_path) is None: + self.skipTest("Could not find a readable and executable " + "vhost-user-bridge") + + vubr_log_path = self.log_file("vhost-user-bridge.log") + self.log.info("For the vhost-user-bridge application log," + f" see: {vubr_log_path}") + + sock_dir = self.socket_dir() + ud_socket_path = os.path.join(sock_dir.name, "vubr-test.sock") + + tftpdir = self.scratch_file("tftp") + shutil.rmtree(tftpdir, ignore_errors=True) + os.mkdir(tftpdir) + host_uuid_path = self.scratch_file("tftp", host_uuid_filename) + with open(host_uuid_path, "w") as host_uuid_file: + host_uuid_file.write(self.HOST_UUID) + + with Ports() as ports: + lport, rport, hostfwd_port = ports.find_free_ports(3) + + self.configure_vm(ud_socket_path, lport, rport, hostfwd_port, + tftpdir) + + vubr_args = self.assemble_vubr_args(vubr_path, ud_socket_path, + lport, rport) + + with open(vubr_log_path, "w+") as vubr_log, \ + subprocess.Popen(vubr_args, stdin=subprocess.DEVNULL, + stdout=vubr_log, + stderr=subprocess.STDOUT) as vubr_proc: + self.launch_kernel(kernel_path, wait_for=prompt) + + exec_command_and_wait_for_pattern(self, + f"tftp -g -r {host_uuid_filename} 10.0.2.2 ; " + f"sha256sum {host_uuid_filename}", self.HOST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + exec_command_and_wait_for_pattern(self, + f"echo -n '{self.GUEST_UUID}' > {guest_uuid_path}", prompt) + self.check_http_download(guest_uuid_path, self.GUEST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + self.vm.shutdown() + vubr_proc.terminate() + vubr_proc.wait() + +if __name__ == '__main__': + LinuxKernelTest.main() --2.52.0
Signature · 1 line
Marc-André Lureau
Re: [RFC PATCH v2 2/3] tests/functional/x86_64: Add vhost-user-bridge test
Quoted 34 lines · Marc-André Lureau
Quoted 20 lines · Yodel Eldar
Introduce a functional test of vhost-user-bridge and enter it into
MAINTAINERSunder the vhost section.The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in
3595e2eb0a23.A file containing a hardcoded UUID is created by the test in a scratch file and exposed to the guest via the tftp parameter of the user netdev. The guest requests the file by invoking tftp, and the test verifies its sha256 hashsum.
Similarly, a file containing another hardcoded UUID is created in the guest. A call to
check_http_download()serves the file via http to the host and verifies integrity with its hashsum.Quoted 5 lines
Suggested-by Cédric Le Goater <[email protected]>Suggested-by Marc-André Lureau <[email protected]>Suggested-by Michael S. Tsirkin <[email protected]>Suggested-by Thomas Huth <[email protected]>Signed-off-by Yodel Eldar <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>by the way, have you left out adding the test to meson on purpose?
+++ b/tests/functional/x86_64/meson.build
Review tests_x86_64_system_thorough = [ · line 40
Quoted 5 lines
(quoted diff) +1
-0@@ -36,4 +36,5 @@ tests_x86_64_system_thorough = [ 'vfio_user_client', 'virtio_balloon', 'virtio_gpu', + 'vhost_user_bridge', ]
Ah, an oversight; thanks for the catch and the review. Fixed in v3.
Quoted 4 lines
As I dig into the image creation process, I wonder if your approach will stand the test of time.
I'd be surprised if it did; although, it's so simple that folks with the most basic of use cases may just end up doing the same on their own.
Quoted 4 lines
It seems mkosi is the most promising project to create reproducible bootable images, and that we are moving to UKI instead of separate initramfs.
This on the other hand looks super robust, and has the weight of the systemd community behind it, so probably the best bet. Thanks for telling me about it; I'll look more closely into it in time.
Quoted 5 lines
Of course it's neat that you managed to put together a buildroot script that produces a 14Mb bzImage for the test, but it's also slow to build and perhaps not flexible enough if we generalize this approach to other built images in the future.
Thank you for the kind words and absolutely valid/sound critique. In truth, I had not really looked into what the state of the art was for image creation; when I'm not running/building inside VMs, I'm doing it in containers, so making the image the way I did was just an extension of my existing workflow (plus buildroot).
Thanks,
Yodel
Quoted 203 lines
Quoted 201 lines
--- MAINTAINERS | 1 + .../x86_64/test_vhost_user_bridge.py | 147 ++++++++++++++++++ 2 files changed, 148 insertions(+)create mode 100755
tests/functional/x86_64/test_vhost_user_bridge.pyMAINTAINERS +1
-0@@ -2374,32 +2374,33 @@ F: docs/devel/vfio-iommufd.rst vhost M: Michael S. Tsirkin <[email protected]> R: Stefano Garzarella <[email protected]> S: Supported F: hw/*/*vhost* F: docs/interop/vhost-user* F: docs/system/devices/vhost-user* F: contrib/vhost-user-*/ F: backends/*vhost* F: include/system/vhost-user-backend.h F: include/hw/virtio/vhost* F: include/*/vhost* F: subprojects/libvhost-user/ F: block/export/vhost-user* F: util/vhost-user-server.c F: net/vhost* +F: tests/functional/x86_64/test_vhost_user_bridge.py vhost-shadow-virtqueue R: Eugenio Pérez <[email protected]> F: hw/virtio/vhost-shadow-virtqueue.* virtio M: Michael S. Tsirkin <[email protected]> S: Supported F: hw/*/virtio* F: hw/virtio/Makefile.objs F: hw/virtio/trace-events F: qapi/virtio.json F: net/vhost-user.c F: include/hw/virtio/ F: docs/devel/virtio* F: docs/devel/migration/virtio.rsttests/functional/x86_64/test_vhost_user_bridge.py new file +147
-1@@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2025 Software Freedom Conservancy, Inc. +# +# Author: Yodel Eldar <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0-or-later +""" +Test vhost-user-bridge (vubr) functionality: + + 1) Run vhost-user-bridge on the host. + 2) Launch a guest VM: + a) Instantiate a unix domain socket to the vubr-created path + b) Instantiate a vhost-user backend on top of that socket + c) Map a virtio-net-pci device to the vhost-user backend + d) Instantiate a UDP socket backend + e) Instantiate a user-mode net backend + i) Forward an ephemeral port to port 8080 in-guest with hostfwd= + ii) Expose a generated scratch file to the guest with tftp= + f) Hub the UDP and user-mode backends. + 3) Invoke tftp in the guest to download exported scratch file from the host. + 4) Serve a file to the host via http server in the guest. +""" + +import os +import shutil +import subprocess +from qemu_test import Asset, LinuxKernelTest, which +from qemu_test import exec_command_and_wait_for_pattern +from qemu_test import is_readable_executable_file +from qemu_test import wait_for_console_pattern +from qemu_test.ports import Ports + +class VhostUserBridge(LinuxKernelTest): + + ASSET_KERNEL_INITRAMFS = Asset( + "https://github.com/yodel/vhost-user-bridge-test/raw/refs/heads/main/bzImage", + "8860d7aa59434f483542cdf25b42eacae0d4d4aa7ec923af9589d1ad4703d42b") + + HOST_UUID = "ba4c2e39-627f-487d-ae3b-93cc5d783eb8" + HOST_UUID_HSUM = \ + "d2932e34bf6c17b33e7325140b691e27c191d9ac4dfa550f68c09506facb09b9" + + GUEST_UUID = "143d2b21-fdf0-4c5e-a9ef-f35ebbac8945" + GUEST_UUID_HSUM = \ + "14b64203f5cf2afe520f8be0fdfe630aafc1e85d1301f55a0d1681e68881f3a2" + + def configure_vm(self, ud_socket_path, lport, rport, hostfwd_port, tftpdir): + self.require_accelerator("kvm") + self.require_netdev("vhost-user") + self.require_netdev("socket") + self.require_netdev("hubport") + self.require_netdev("user") + self.require_device("virtio-net-pci") + self.set_machine("q35") + self.vm.add_args( + "-cpu", "host", + "-accel", "kvm", + "-append", "printk.time=0 console=ttyS0", + "-smp", "2", + "-m", "128M", + "-object", "memory-backend-memfd,id=mem0," + "size=128M,share=on,prealloc=on", + "-numa", "node,memdev=mem0", + "-chardev", f"socket,id=char0,path={ud_socket_path}", + "-netdev", "vhost-user,id=vhost0,chardev=char0,vhostforce=on", + "-device", "virtio-net-pci,netdev=vhost0", + "-netdev", f"socket,id=udp0,udp=localhost:{lport}," + f"localaddr=localhost:{rport}", + "-netdev", "hubport,id=hub0,hubid=0,netdev=udp0", + "-netdev", "user,id=user0," + f"hostfwd=tcp:127.0.0.1:{hostfwd_port}-:8080," + f"tftp={tftpdir}", + "-netdev", "hubport,id=hub1,hubid=0,netdev=user0" + ) + + def assemble_vubr_args(self, vubr_path, ud_socket_path, lport, rport): + vubr_args = [] + + if (stdbuf_path := which("stdbuf")) is None: + self.log.info("Could not find stdbuf: vhost-user-bridge " + "log lines may appear out of order") + else: + vubr_args += [stdbuf_path, "-o0", "-e0"] + + vubr_args += [vubr_path, "-u", f"{ud_socket_path}", + "-l", f"127.0.0.1:{lport}", "-r", f"127.0.0.1:{rport}"] + + return vubr_args + + def test_vhost_user_bridge(self): + prompt = "~ # " + host_uuid_filename = "vubr-test-uuid.txt" + guest_uuid_path = "/tmp/uuid.txt" + kernel_path = self.ASSET_KERNEL_INITRAMFS.fetch() + + vubr_path = self.build_file("contrib", "vhost-user-bridge", + "vhost-user-bridge") + if is_readable_executable_file(vubr_path) is None: + self.skipTest("Could not find a readable and executable " + "vhost-user-bridge") + + vubr_log_path = self.log_file("vhost-user-bridge.log") + self.log.info("For the vhost-user-bridge application log," + f" see: {vubr_log_path}") + + sock_dir = self.socket_dir() + ud_socket_path = os.path.join(sock_dir.name, "vubr-test.sock") + + tftpdir = self.scratch_file("tftp") + shutil.rmtree(tftpdir, ignore_errors=True) + os.mkdir(tftpdir) + host_uuid_path = self.scratch_file("tftp", host_uuid_filename) + with open(host_uuid_path, "w") as host_uuid_file: + host_uuid_file.write(self.HOST_UUID) + + with Ports() as ports: + lport, rport, hostfwd_port = ports.find_free_ports(3) + + self.configure_vm(ud_socket_path, lport, rport, hostfwd_port, + tftpdir) + + vubr_args = self.assemble_vubr_args(vubr_path, ud_socket_path, + lport, rport) + + with open(vubr_log_path, "w+") as vubr_log, \ + subprocess.Popen(vubr_args, stdin=subprocess.DEVNULL, + stdout=vubr_log, + stderr=subprocess.STDOUT) as vubr_proc: + self.launch_kernel(kernel_path, wait_for=prompt) + + exec_command_and_wait_for_pattern(self, + f"tftp -g -r {host_uuid_filename} 10.0.2.2 ; " + f"sha256sum {host_uuid_filename}", self.HOST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + exec_command_and_wait_for_pattern(self, + f"echo -n '{self.GUEST_UUID}' > {guest_uuid_path}", prompt) + self.check_http_download(guest_uuid_path, self.GUEST_UUID_HSUM) + wait_for_console_pattern(self, prompt) + + self.vm.shutdown() + vubr_proc.terminate() + vubr_proc.wait() + +if __name__ == '__main__': + LinuxKernelTest.main() --2.52.0
RFC PATCH v2 3/3 contrib/vhost-user-bridge: Add UDP receive hexdump
In reply to Yodel Eldarvhost-user-bridge debug prints UDP TX hexdumps in its transmit handler, but does not for receives, even though they are beneficial for testing. Add an RX hexdump in the receive callback.
To delineate between transmits and receives, also add a debug print indicating that the program is in the transmit handler.
--- contrib/vhost-user-bridge/vhost-user-bridge.c | 7 +++++++ 1 file changed, 7 insertions(+)
contrib/vhost-user-bridge/vhost-user-bridge.c +7 -0
@@ -179,6 +179,9 @@ vubr_handle_tx(VuDev *dev, int qidx)assert (qidx %2 ); +DPRINT ("\n\n *** IN UDP TRANSMIT HANDLER ***\n\n" ); +DPRINT (" hdrlen = %d\n" , hdrlen); +for (;;) {ssize_t ret;unsigned int out_num;
@@ -333,6 +336,10 @@ vubr_backend_recv_cb(int sock, void *ctx) }; ret =RETRY_ON_EINTR (recvmsg (vubr->backend_udp_sock, &msg,0 )); +if (ret >0 &&VHOST_USER_BRIDGE_DEBUG ) { +iov_hexdump (sg, num, stderr,"RX:" , ret); + } +if (i ==0 ) {iov_restore_front (elem->in_sg, sg, hdrlen); }
Signature · 1 line
2.52.0
Re: [RFC PATCH v2 3/3] contrib/vhost-user-bridge: Add UDP receive hexdump
Quoted 9 lines · Yodel Eldar
vhost-user-bridge debug prints UDP TX hexdumps in its transmit handler, but does not for receives, even though they are beneficial for testing. Add an RX hexdump in the receive callback.
To delineate between transmits and receives, also add a debug print indicating that the program is in the transmit handler.
Signed-off-by Yodel Eldar <[email protected]>
Quoted 33 lines
--- contrib/vhost-user-bridge/vhost-user-bridge.c | 7 +++++++ 1 file changed, 7 insertions(+)contrib/vhost-user-bridge/vhost-user-bridge.c +7
-1@@ -179,6 +179,9 @@ vubr_handle_tx(VuDev *dev, int qidx)assert (qidx %2 ); +DPRINT ("\n\n *** IN UDP TRANSMIT HANDLER ***\n\n" ); +DPRINT (" hdrlen = %d\n" , hdrlen); +for (;;) {ssize_t ret;unsigned int out_num;@@ -333,6 +336,10 @@ vubr_backend_recv_cb(int sock, void *ctx) }; ret =RETRY_ON_EINTR (recvmsg (vubr->backend_udp_sock, &msg,0 )); +if (ret >0 &&VHOST_USER_BRIDGE_DEBUG ) { +iov_hexdump (sg, num, stderr,"RX:" , ret); + } +if (i ==0 ) {iov_restore_front (elem->in_sg, sg, hdrlen); } --2.52.0
Signature · 1 line
Marc-André Lureau