Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-05-06 Thread Bobby Eshleman
On Fri, May 02, 2025 at 12:22:46PM +0200, Paolo Abeni wrote:
> On 4/29/25 1:48 AM, Bobby Eshleman wrote:
> > This commit introduces a new vmtest.sh runner for vsock.
> > 
> > It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
> > H2G, and loopback. The testing tools from tools/testing/vsock/ are
> > reused. Currently, only vsock_test is used.
> > 
> > VMCI and hyperv support is automatically built, though not used.
> > 
> > Only tested on x86.
> > 
> > To run:
> > 
> >   $ tools/testing/selftests/vsock/vmtest.sh
> > 
> > or
> > 
> >   $ make -C tools/testing/selftests TARGETS=vsock run_tests
> > 
> > Results:
> > # linux/tools/testing/selftests/vsock/vmtest.log
> > setup:  Building kernel and tests
> > setup:  Booting up VM
> > setup:  VM booted up
> > test:vm_server_host_client:guest:   Control socket listening on 
> > 0.0.0.0:51000
> > test:vm_server_host_client:guest:   Control socket connection 
> > accepted...
> > [...]
> > test:vm_loopback:guest: 30 - SOCK_STREAM retry failed connect()...ok
> > test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
> > test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
> > 
> > Future work can include vsock_diag_test.
> > 
> > vmtest.sh is loosely based off of tools/testing/selftests/net/pmtu.sh,
> > which was picked out of the bag of tests I knew to work with NIPA.
> > 
> > Because vsock requires a VM to test anything other than loopback, this
> > patch adds vmtest.sh as a kselftest itself. This is different than other
> > systems that have a "vmtest.sh", where it is used as a utility script to
> > spin up a VM to run the selftests as a guest (but isn't hooked into
> > kselftest). This aspect is worth review, as I'm not aware of all of the
> > enviroments where this would run.
> 
> I think this approach is interesting, but I think it will need some
> additional more work, see below...
> 
> [...]
> 
> > diff --git a/tools/testing/selftests/vsock/settings 
> > b/tools/testing/selftests/vsock/settings
> > new file mode 100644
> > index 
> > ..e7b9417537fbc4626153b72e8f295ab4594c844b
> > --- /dev/null
> > +++ b/tools/testing/selftests/vsock/settings
> > @@ -0,0 +1 @@
> > +timeout=0
> 
> We need a reasonable, bounded runtime for nipa integration.
> 
> > diff --git a/tools/testing/selftests/vsock/vmtest.sh 
> > b/tools/testing/selftests/vsock/vmtest.sh
> > new file mode 100755
> > index 
> > ..d70b9446e531d6d20beb24ddeda2cf0a9f7e9a39
> > --- /dev/null
> > +++ b/tools/testing/selftests/vsock/vmtest.sh
> > @@ -0,0 +1,354 @@
> > +#!/bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# Copyright (c) 2025 Meta Platforms, Inc. and affiliates
> > +#
> > +# Dependencies:
> > +#  * virtme-ng
> > +#  * busybox-static (used by virtme-ng)
> > +#  * qemu  (used by virtme-ng)
> 
> You should probably check for such tools presence and bail out with skip
> otherwise.
> 
> > +
> > +SCRIPT_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
> > +KERNEL_CHECKOUT=$(realpath ${SCRIPT_DIR}/../../../..)
> 
> This is not going to work if/when the self-tests are installed in their
> own directory via `make install` in the tools/testing/selftests/
> directory, and that use case is supposed to work.
> 
> At very least you should check for the expected layout and skip otherwise.
> 
> > +QEMU=$(command -v qemu-system-$(uname -m))
> > +VERBOSE=0
> > +SKIP_BUILD=0
> > +VSOCK_TEST=${KERNEL_CHECKOUT}/tools/testing/vsock/vsock_test
> > +
> > +TEST_GUEST_PORT=51000
> > +TEST_HOST_PORT=5
> > +TEST_HOST_PORT_LISTENER=50001
> > +SSH_GUEST_PORT=22
> > +SSH_HOST_PORT=
> > +VSOCK_CID=1234
> > +WAIT_PERIOD=3
> > +WAIT_PERIOD_MAX=20
> > +
> > +QEMU_PIDFILE=/tmp/qemu.pid
> > +
> > +# virtme-ng offers a netdev for ssh when using "--ssh", but we also need a
> > +# control port forwarded for vsock_test.  Because virtme-ng doesn't support
> > +# adding an additional port to forward to the device created from "--ssh" 
> > and
> > +# virtme-init mistakenly sets identical IPs to the ssh device and 
> > additional
> > +# devices, we instead opt out of using --ssh, add the device manually, and 
> > also
> > +# add the kernel cmdline options that virtme-init uses to setup the 
> > interface.
> > +QEMU_OPTS=""
> > +QEMU_OPTS="${QEMU_OPTS} -netdev 
> > user,id=n0,hostfwd=tcp::${TEST_HOST_PORT}-:${TEST_GUEST_PORT}"
> > +QEMU_OPTS="${QEMU_OPTS},hostfwd=tcp::${SSH_HOST_PORT}-:${SSH_GUEST_PORT}"
> > +QEMU_OPTS="${QEMU_OPTS} -device virtio-net-pci,netdev=n0"
> > +QEMU_OPTS="${QEMU_OPTS} -device vhost-vsock-pci,guest-cid=${VSOCK_CID}"
> > +QEMU_OPTS="${QEMU_OPTS} --pidfile ${QEMU_PIDFILE}"
> > +KERNEL_CMDLINE="virtme.dhcp net.ifnames=0 biosdevname=0 virtme.ssh 
> > virtme_ssh_user=$USER"
> > +
> > +LOG=${SCRIPT_DIR}/vmtest.log
> > +
> > +#  NameDescription
> > +avai

Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-05-02 Thread Paolo Abeni
On 4/30/25 3:06 PM, Stefano Garzarella wrote:
> On Mon, Apr 28, 2025 at 04:48:11PM -0700, Bobby Eshleman wrote:
>> This commit introduces a new vmtest.sh runner for vsock.
>>
>> It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
>> H2G, and loopback. The testing tools from tools/testing/vsock/ are
>> reused. Currently, only vsock_test is used.
>>
>> VMCI and hyperv support is automatically built, though not used.
>>
>> Only tested on x86.
>>
>> To run:
>>
>>  $ tools/testing/selftests/vsock/vmtest.sh
> 
> I tried and it's working, but I have a lot of these messages in the
> output:
>  dmesg: read kernel buffer failed: Operation not permitted
> 
> I'm on Fedora 41:
> 
> $ uname -r
> 6.14.4-200.fc41.x86_64

This sounds like the test tripping on selinux. I think this problem
should not be handled by the script itself.

[...]
> ERROR: trailing whitespace
> #174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
> +^Ivm_server_host_client^IRun vsock_test in server mode on the VM and in 
> client mode on the host.^I$
> 
> WARNING: line length of 104 exceeds 100 columns
> #174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
> + vm_server_host_client   Run vsock_test in server mode on the VM and in 
> client mode on the host. 
> 
> ERROR: trailing whitespace
> #175: FILE: tools/testing/selftests/vsock/vmtest.sh:48:
> +^Ivm_client_host_server^IRun vsock_test in client mode on the VM and in 
> server mode on the host.^I$
> 
> WARNING: line length of 104 exceeds 100 columns
> #175: FILE: tools/testing/selftests/vsock/vmtest.sh:48:
> + vm_client_host_server   Run vsock_test in client mode on the VM and in 
> server mode on the host. 
> 
> ERROR: trailing whitespace
> #176: FILE: tools/testing/selftests/vsock/vmtest.sh:49:
> +^Ivm_loopback^I^IRun vsock_test using the loopback transport in the VM.^I$
> 
> ERROR: trailing whitespace
> #443: FILE: tools/testing/selftests/vsock/vmtest.sh:316:
> +IFS="^I$
> 
> total: 4 errors, 4 warnings, 0 checks, 382 lines checked
> 
I almost forgot: I think it's better to avoid the special formatting and
replies on review for proper updating of the script's help.

Thanks,

Paolo




Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-05-02 Thread Paolo Abeni
On 4/29/25 1:48 AM, Bobby Eshleman wrote:
> This commit introduces a new vmtest.sh runner for vsock.
> 
> It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
> H2G, and loopback. The testing tools from tools/testing/vsock/ are
> reused. Currently, only vsock_test is used.
> 
> VMCI and hyperv support is automatically built, though not used.
> 
> Only tested on x86.
> 
> To run:
> 
>   $ tools/testing/selftests/vsock/vmtest.sh
> 
> or
> 
>   $ make -C tools/testing/selftests TARGETS=vsock run_tests
> 
> Results:
>   # linux/tools/testing/selftests/vsock/vmtest.log
>   setup:  Building kernel and tests
>   setup:  Booting up VM
>   setup:  VM booted up
>   test:vm_server_host_client:guest:   Control socket listening on 
> 0.0.0.0:51000
>   test:vm_server_host_client:guest:   Control socket connection 
> accepted...
>   [...]
>   test:vm_loopback:guest: 30 - SOCK_STREAM retry failed connect()...ok
>   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
>   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
> 
> Future work can include vsock_diag_test.
> 
> vmtest.sh is loosely based off of tools/testing/selftests/net/pmtu.sh,
> which was picked out of the bag of tests I knew to work with NIPA.
> 
> Because vsock requires a VM to test anything other than loopback, this
> patch adds vmtest.sh as a kselftest itself. This is different than other
> systems that have a "vmtest.sh", where it is used as a utility script to
> spin up a VM to run the selftests as a guest (but isn't hooked into
> kselftest). This aspect is worth review, as I'm not aware of all of the
> enviroments where this would run.

I think this approach is interesting, but I think it will need some
additional more work, see below...

[...]

> diff --git a/tools/testing/selftests/vsock/settings 
> b/tools/testing/selftests/vsock/settings
> new file mode 100644
> index 
> ..e7b9417537fbc4626153b72e8f295ab4594c844b
> --- /dev/null
> +++ b/tools/testing/selftests/vsock/settings
> @@ -0,0 +1 @@
> +timeout=0

We need a reasonable, bounded runtime for nipa integration.

> diff --git a/tools/testing/selftests/vsock/vmtest.sh 
> b/tools/testing/selftests/vsock/vmtest.sh
> new file mode 100755
> index 
> ..d70b9446e531d6d20beb24ddeda2cf0a9f7e9a39
> --- /dev/null
> +++ b/tools/testing/selftests/vsock/vmtest.sh
> @@ -0,0 +1,354 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Copyright (c) 2025 Meta Platforms, Inc. and affiliates
> +#
> +# Dependencies:
> +#* virtme-ng
> +#* busybox-static (used by virtme-ng)
> +#* qemu  (used by virtme-ng)

You should probably check for such tools presence and bail out with skip
otherwise.

> +
> +SCRIPT_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
> +KERNEL_CHECKOUT=$(realpath ${SCRIPT_DIR}/../../../..)

This is not going to work if/when the self-tests are installed in their
own directory via `make install` in the tools/testing/selftests/
directory, and that use case is supposed to work.

At very least you should check for the expected layout and skip otherwise.

> +QEMU=$(command -v qemu-system-$(uname -m))
> +VERBOSE=0
> +SKIP_BUILD=0
> +VSOCK_TEST=${KERNEL_CHECKOUT}/tools/testing/vsock/vsock_test
> +
> +TEST_GUEST_PORT=51000
> +TEST_HOST_PORT=5
> +TEST_HOST_PORT_LISTENER=50001
> +SSH_GUEST_PORT=22
> +SSH_HOST_PORT=
> +VSOCK_CID=1234
> +WAIT_PERIOD=3
> +WAIT_PERIOD_MAX=20
> +
> +QEMU_PIDFILE=/tmp/qemu.pid
> +
> +# virtme-ng offers a netdev for ssh when using "--ssh", but we also need a
> +# control port forwarded for vsock_test.  Because virtme-ng doesn't support
> +# adding an additional port to forward to the device created from "--ssh" and
> +# virtme-init mistakenly sets identical IPs to the ssh device and additional
> +# devices, we instead opt out of using --ssh, add the device manually, and 
> also
> +# add the kernel cmdline options that virtme-init uses to setup the 
> interface.
> +QEMU_OPTS=""
> +QEMU_OPTS="${QEMU_OPTS} -netdev 
> user,id=n0,hostfwd=tcp::${TEST_HOST_PORT}-:${TEST_GUEST_PORT}"
> +QEMU_OPTS="${QEMU_OPTS},hostfwd=tcp::${SSH_HOST_PORT}-:${SSH_GUEST_PORT}"
> +QEMU_OPTS="${QEMU_OPTS} -device virtio-net-pci,netdev=n0"
> +QEMU_OPTS="${QEMU_OPTS} -device vhost-vsock-pci,guest-cid=${VSOCK_CID}"
> +QEMU_OPTS="${QEMU_OPTS} --pidfile ${QEMU_PIDFILE}"
> +KERNEL_CMDLINE="virtme.dhcp net.ifnames=0 biosdevname=0 virtme.ssh 
> virtme_ssh_user=$USER"
> +
> +LOG=${SCRIPT_DIR}/vmtest.log
> +
> +#NameDescription
> +avail_tests="
> + vm_server_host_client   Run vsock_test in server mode on the VM and in 
> client mode on the host. 
> + vm_client_host_server   Run vsock_test in client mode on the VM and in 
> server mode on the host. 
> + vm_loopback Run vsock_test using the loopback transport in 

Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-04-30 Thread Bobby Eshleman
PS. sorry for weird formatting, writing from the gmail web UI instead of mutt.
Tried to limit line lengths manually. Looks weird after hitting "send"... lol.

Best,
Bobby

On Wed, Apr 30, 2025 at 7:37 PM Bobby Eshleman  wrote:
>
> On Wed, Apr 30, 2025 at 6:06 AM Stefano Garzarella  
> wrote:
> >
> > On Mon, Apr 28, 2025 at 04:48:11PM -0700, Bobby Eshleman wrote:
> > >This commit introduces a new vmtest.sh runner for vsock.
> > >
> > >It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
> > >H2G, and loopback. The testing tools from tools/testing/vsock/ are
> > >reused. Currently, only vsock_test is used.
> > >
> > >VMCI and hyperv support is automatically built, though not used.
> > >
> > >Only tested on x86.
> > >
> > >To run:
> > >
> > >  $ tools/testing/selftests/vsock/vmtest.sh
> >
> > I tried and it's working, but I have a lot of these messages in the
> > output:
> >  dmesg: read kernel buffer failed: Operation not permitted
> >
> > I'm on Fedora 41:
> >
> > $ uname -r
> > 6.14.4-200.fc41.x86_64
> >
> > >
> > >or
> > >
> > >  $ make -C tools/testing/selftests TARGETS=vsock run_tests
> > >
> > >Results:
> > >   # linux/tools/testing/selftests/vsock/vmtest.log
> > >   setup:  Building kernel and tests
> > >   setup:  Booting up VM
> > >   setup:  VM booted up
> > >   test:vm_server_host_client:guest:   Control socket listening on 
> > > 0.0.0.0:51000
> > >   test:vm_server_host_client:guest:   Control socket connection 
> > > accepted...
> > >   [...]
> > >   test:vm_loopback:guest: 30 - SOCK_STREAM retry failed connect()...ok
> > >   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER 
> > > null-ptr-deref...ok
> > >   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER 
> > > null-ptr-deref...ok
> > >
> > >Future work can include vsock_diag_test.
> > >
> > >vmtest.sh is loosely based off of tools/testing/selftests/net/pmtu.sh,
> > >which was picked out of the bag of tests I knew to work with NIPA.
> > >
> > >Because vsock requires a VM to test anything other than loopback, this
> > >patch adds vmtest.sh as a kselftest itself. This is different than other
> > >systems that have a "vmtest.sh", where it is used as a utility script to
> > >spin up a VM to run the selftests as a guest (but isn't hooked into
> > >kselftest). This aspect is worth review, as I'm not aware of all of the
> > >enviroments where this would run.
> >
> > Yeah, an opinion from net maintainers on this would be great.
> >
> > >
> > >Signed-off-by: Bobby Eshleman 
> > >---
> > >Changes in v3:
> > >- use common conditional syntax for checking variables
> > >- use return value instead of global rc
> > >- fix typo TEST_HOST_LISTENER_PORT -> TEST_HOST_PORT_LISTENER
> > >- use SIGTERM instead of SIGKILL on cleanup
> > >- use peer-cid=1 for loopback
> > >- change sleep delay times into globals
> > >- fix test_vm_loopback logging
> > >- add test selection in arguments
> > >- make QEMU an argument
> > >- check that vng binary is on path
> > >- use QEMU variable
> > >- change  to 
> > >- fix hardcoded file paths
> > >- add comment in commit msg about script that vmtest.sh was based off of
> > >- Add tools/testing/selftest/vsock/Makefile for kselftest
> > >- Link to v2: 
> > >https://lore.kernel.org/r/[email protected]
> > >
> > >Changes in v2:
> > >- add kernel oops and warnings checker
> > >- change testname variable to use FUNCNAME
> > >- fix spacing in test_vm_server_host_client
> > >- add -s skip build option to vmtest.sh
> > >- add test_vm_loopback
> > >- pass port to vm_wait_for_listener
> > >- fix indentation in vmtest.sh
> > >- add vmci and hyperv to config
> > >- changed whitespace from tabs to spaces in help string
> > >- Link to v1: 
> > >https://lore.kernel.org/r/[email protected]
> > >---
> > > MAINTAINERS|   1 +
> > > tools/testing/selftests/vsock/.gitignore   |   1 +
> > > tools/testing/selftests/vsock/Makefile |   9 +
> > > tools/testing/selftests/vsock/config.vsock |  10 +
> > > tools/testing/selftests/vsock/settings |   1 +
> > > tools/testing/selftests/vsock/vmtest.sh| 354 
> > > +
> > > 6 files changed, 376 insertions(+)
> >
> > While applying git warned about trailing spaces, but also checkpatch is
> > warning about them, please can you fix at least the errors (and maybe
> > the misspelling):
> >
> > $ ./scripts/checkpatch.pl --strict -g master..HEAD --codespell
> > WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit
> > description?)
> > #31:
> > test:vm_server_host_client:guest:   Control socket listening on 
> > 0.0.0.0:51000
> >
> > WARNING: 'enviroments' may be misspelled - perhaps 'environments'?
> > #48:
> > enviroments where this would run.
> > ^^^
> >
> > ERROR: trailing whitespace
> > #174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
> > +^Ivm_server_host_client^IRun vsoc

Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-04-30 Thread Bobby Eshleman
On Wed, Apr 30, 2025 at 6:06 AM Stefano Garzarella  wrote:
>
> On Mon, Apr 28, 2025 at 04:48:11PM -0700, Bobby Eshleman wrote:
> >This commit introduces a new vmtest.sh runner for vsock.
> >
> >It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
> >H2G, and loopback. The testing tools from tools/testing/vsock/ are
> >reused. Currently, only vsock_test is used.
> >
> >VMCI and hyperv support is automatically built, though not used.
> >
> >Only tested on x86.
> >
> >To run:
> >
> >  $ tools/testing/selftests/vsock/vmtest.sh
>
> I tried and it's working, but I have a lot of these messages in the
> output:
>  dmesg: read kernel buffer failed: Operation not permitted
>
> I'm on Fedora 41:
>
> $ uname -r
> 6.14.4-200.fc41.x86_64
>
> >
> >or
> >
> >  $ make -C tools/testing/selftests TARGETS=vsock run_tests
> >
> >Results:
> >   # linux/tools/testing/selftests/vsock/vmtest.log
> >   setup:  Building kernel and tests
> >   setup:  Booting up VM
> >   setup:  VM booted up
> >   test:vm_server_host_client:guest:   Control socket listening on 
> > 0.0.0.0:51000
> >   test:vm_server_host_client:guest:   Control socket connection 
> > accepted...
> >   [...]
> >   test:vm_loopback:guest: 30 - SOCK_STREAM retry failed connect()...ok
> >   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
> >   test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
> >
> >Future work can include vsock_diag_test.
> >
> >vmtest.sh is loosely based off of tools/testing/selftests/net/pmtu.sh,
> >which was picked out of the bag of tests I knew to work with NIPA.
> >
> >Because vsock requires a VM to test anything other than loopback, this
> >patch adds vmtest.sh as a kselftest itself. This is different than other
> >systems that have a "vmtest.sh", where it is used as a utility script to
> >spin up a VM to run the selftests as a guest (but isn't hooked into
> >kselftest). This aspect is worth review, as I'm not aware of all of the
> >enviroments where this would run.
>
> Yeah, an opinion from net maintainers on this would be great.
>
> >
> >Signed-off-by: Bobby Eshleman 
> >---
> >Changes in v3:
> >- use common conditional syntax for checking variables
> >- use return value instead of global rc
> >- fix typo TEST_HOST_LISTENER_PORT -> TEST_HOST_PORT_LISTENER
> >- use SIGTERM instead of SIGKILL on cleanup
> >- use peer-cid=1 for loopback
> >- change sleep delay times into globals
> >- fix test_vm_loopback logging
> >- add test selection in arguments
> >- make QEMU an argument
> >- check that vng binary is on path
> >- use QEMU variable
> >- change  to 
> >- fix hardcoded file paths
> >- add comment in commit msg about script that vmtest.sh was based off of
> >- Add tools/testing/selftest/vsock/Makefile for kselftest
> >- Link to v2: 
> >https://lore.kernel.org/r/[email protected]
> >
> >Changes in v2:
> >- add kernel oops and warnings checker
> >- change testname variable to use FUNCNAME
> >- fix spacing in test_vm_server_host_client
> >- add -s skip build option to vmtest.sh
> >- add test_vm_loopback
> >- pass port to vm_wait_for_listener
> >- fix indentation in vmtest.sh
> >- add vmci and hyperv to config
> >- changed whitespace from tabs to spaces in help string
> >- Link to v1: 
> >https://lore.kernel.org/r/[email protected]
> >---
> > MAINTAINERS|   1 +
> > tools/testing/selftests/vsock/.gitignore   |   1 +
> > tools/testing/selftests/vsock/Makefile |   9 +
> > tools/testing/selftests/vsock/config.vsock |  10 +
> > tools/testing/selftests/vsock/settings |   1 +
> > tools/testing/selftests/vsock/vmtest.sh| 354 
> > +
> > 6 files changed, 376 insertions(+)
>
> While applying git warned about trailing spaces, but also checkpatch is
> warning about them, please can you fix at least the errors (and maybe
> the misspelling):
>
> $ ./scripts/checkpatch.pl --strict -g master..HEAD --codespell
> WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit
> description?)
> #31:
> test:vm_server_host_client:guest:   Control socket listening on 
> 0.0.0.0:51000
>
> WARNING: 'enviroments' may be misspelled - perhaps 'environments'?
> #48:
> enviroments where this would run.
> ^^^
>
> ERROR: trailing whitespace
> #174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
> +^Ivm_server_host_client^IRun vsock_test in server mode on the VM and in 
> client mode on the host.^I$
>
> WARNING: line length of 104 exceeds 100 columns
> #174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
> +   vm_server_host_client   Run vsock_test in server mode on the VM and 
> in client mode on the host.
>
> ERROR: trailing whitespace
> #175: FILE: tools/testing/selftests/vsock/vmtest.sh:48:
> +^Ivm_client_host_server^IRun vsock_test in client mode on the VM and in 
> server mode on the host.^I$
>
> WA

Re: [PATCH net-next v3] selftests/vsock: add initial vmtest.sh for vsock

2025-04-30 Thread Stefano Garzarella

On Mon, Apr 28, 2025 at 04:48:11PM -0700, Bobby Eshleman wrote:

This commit introduces a new vmtest.sh runner for vsock.

It uses virtme-ng/qemu to run tests in a VM. The tests validate G2H,
H2G, and loopback. The testing tools from tools/testing/vsock/ are
reused. Currently, only vsock_test is used.

VMCI and hyperv support is automatically built, though not used.

Only tested on x86.

To run:

 $ tools/testing/selftests/vsock/vmtest.sh


I tried and it's working, but I have a lot of these messages in the
output:
dmesg: read kernel buffer failed: Operation not permitted

I'm on Fedora 41:

$ uname -r
6.14.4-200.fc41.x86_64



or

 $ make -C tools/testing/selftests TARGETS=vsock run_tests

Results:
# linux/tools/testing/selftests/vsock/vmtest.log
setup:  Building kernel and tests
setup:  Booting up VM
setup:  VM booted up
test:vm_server_host_client:guest:   Control socket listening on 
0.0.0.0:51000
test:vm_server_host_client:guest:   Control socket connection 
accepted...
[...]
test:vm_loopback:guest: 30 - SOCK_STREAM retry failed connect()...ok
test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok
test:vm_loopback:guest: 31 - SOCK_STREAM SO_LINGER null-ptr-deref...ok

Future work can include vsock_diag_test.

vmtest.sh is loosely based off of tools/testing/selftests/net/pmtu.sh,
which was picked out of the bag of tests I knew to work with NIPA.

Because vsock requires a VM to test anything other than loopback, this
patch adds vmtest.sh as a kselftest itself. This is different than other
systems that have a "vmtest.sh", where it is used as a utility script to
spin up a VM to run the selftests as a guest (but isn't hooked into
kselftest). This aspect is worth review, as I'm not aware of all of the
enviroments where this would run.


Yeah, an opinion from net maintainers on this would be great.



Signed-off-by: Bobby Eshleman 
---
Changes in v3:
- use common conditional syntax for checking variables
- use return value instead of global rc
- fix typo TEST_HOST_LISTENER_PORT -> TEST_HOST_PORT_LISTENER
- use SIGTERM instead of SIGKILL on cleanup
- use peer-cid=1 for loopback
- change sleep delay times into globals
- fix test_vm_loopback logging
- add test selection in arguments
- make QEMU an argument
- check that vng binary is on path
- use QEMU variable
- change  to 
- fix hardcoded file paths
- add comment in commit msg about script that vmtest.sh was based off of
- Add tools/testing/selftest/vsock/Makefile for kselftest
- Link to v2: 
https://lore.kernel.org/r/[email protected]

Changes in v2:
- add kernel oops and warnings checker
- change testname variable to use FUNCNAME
- fix spacing in test_vm_server_host_client
- add -s skip build option to vmtest.sh
- add test_vm_loopback
- pass port to vm_wait_for_listener
- fix indentation in vmtest.sh
- add vmci and hyperv to config
- changed whitespace from tabs to spaces in help string
- Link to v1: 
https://lore.kernel.org/r/[email protected]
---
MAINTAINERS|   1 +
tools/testing/selftests/vsock/.gitignore   |   1 +
tools/testing/selftests/vsock/Makefile |   9 +
tools/testing/selftests/vsock/config.vsock |  10 +
tools/testing/selftests/vsock/settings |   1 +
tools/testing/selftests/vsock/vmtest.sh| 354 +
6 files changed, 376 insertions(+)


While applying git warned about trailing spaces, but also checkpatch is 
warning about them, please can you fix at least the errors (and maybe 
the misspelling):


$ ./scripts/checkpatch.pl --strict -g master..HEAD --codespell
WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit 
description?)
#31: 
	test:vm_server_host_client:guest:   Control socket listening on 0.0.0.0:51000


WARNING: 'enviroments' may be misspelled - perhaps 'environments'?
#48: 
enviroments where this would run.

^^^

ERROR: trailing whitespace
#174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
+^Ivm_server_host_client^IRun vsock_test in server mode on the VM and in client 
mode on the host.^I$

WARNING: line length of 104 exceeds 100 columns
#174: FILE: tools/testing/selftests/vsock/vmtest.sh:47:
+   vm_server_host_client   Run vsock_test in server mode on the VM and in 
client mode on the host. 

ERROR: trailing whitespace
#175: FILE: tools/testing/selftests/vsock/vmtest.sh:48:
+^Ivm_client_host_server^IRun vsock_test in client mode on the VM and in server 
mode on the host.^I$

WARNING: line length of 104 exceeds 100 columns
#175: FILE: tools/testing/selftests/vsock/vmtest.sh:48:
+   vm_client_host_server   Run vsock_test in client mode on the VM and in 
server mode on the host. 

ERROR: trailing whitespace
#176: FILE: tools/testing/selftests/vsock/vmtest.sh:49:
+^Ivm_loopback^I^IRun vsock_test using the loopback transport in the VM.^I$

ERROR: trailing whitespace