diff mbox series

[net-next,2/2] selftests: net: tests net.core.{r,w}mem_{default,max} sysctls in a netns

Message ID 20240528121139.38035-3-teknoraver@meta.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: visibility of memory limits in netns | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 908 this patch: 908
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 906 this patch: 906
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 913 this patch: 913
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Matteo Croce <technoboy85@gmail.com>' != 'Signed-off-by: Matteo Croce <teknoraver@meta.com>' WARNING: Missing or malformed SPDX-License-Identifier tag in line 2 WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-30--06-00 (tests: 1042)

Commit Message

Matteo Croce May 28, 2024, 12:11 p.m. UTC
Add a selftest which checks that the sysctl is present in a netns,
that the value is read from the init one, and that it's readonly.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
---
 tools/testing/selftests/net/Makefile        |  1 +
 tools/testing/selftests/net/netns-sysctl.sh | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100755 tools/testing/selftests/net/netns-sysctl.sh

Comments

Breno Leitao May 30, 2024, 12:10 p.m. UTC | #1
On Tue, May 28, 2024 at 02:11:39PM +0200, Matteo Croce wrote:
> Add a selftest which checks that the sysctl is present in a netns,
> that the value is read from the init one, and that it's readonly.
> 
> Signed-off-by: Matteo Croce <teknoraver@meta.com>
> ---
>  tools/testing/selftests/net/Makefile        |  1 +
>  tools/testing/selftests/net/netns-sysctl.sh | 15 +++++++++++++++
>  2 files changed, 16 insertions(+)
>  create mode 100755 tools/testing/selftests/net/netns-sysctl.sh
> 
> diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> index bd01e4a0be2c..6da63d1831c1 100644
> --- a/tools/testing/selftests/net/Makefile
> +++ b/tools/testing/selftests/net/Makefile
> @@ -53,6 +53,7 @@ TEST_PROGS += bind_bhash.sh
>  TEST_PROGS += ip_local_port_range.sh
>  TEST_PROGS += rps_default_mask.sh
>  TEST_PROGS += big_tcp.sh
> +TEST_PROGS += netns-sysctl.sh
>  TEST_PROGS_EXTENDED := toeplitz_client.sh toeplitz.sh
>  TEST_GEN_FILES =  socket nettest
>  TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
> diff --git a/tools/testing/selftests/net/netns-sysctl.sh b/tools/testing/selftests/net/netns-sysctl.sh
> new file mode 100755
> index 000000000000..b948ba67b13a
> --- /dev/null
> +++ b/tools/testing/selftests/net/netns-sysctl.sh
> @@ -0,0 +1,15 @@
> +#!/bin/bash -e

Don't you need to add the SPDX license header?
Paolo Abeni May 30, 2024, 1:58 p.m. UTC | #2
On Thu, 2024-05-30 at 05:10 -0700, Breno Leitao wrote:
> On Tue, May 28, 2024 at 02:11:39PM +0200, Matteo Croce wrote:
> > Add a selftest which checks that the sysctl is present in a netns,
> > that the value is read from the init one, and that it's readonly.
> > 
> > Signed-off-by: Matteo Croce <teknoraver@meta.com>
> > ---
> >  tools/testing/selftests/net/Makefile        |  1 +
> >  tools/testing/selftests/net/netns-sysctl.sh | 15 +++++++++++++++
> >  2 files changed, 16 insertions(+)
> >  create mode 100755 tools/testing/selftests/net/netns-sysctl.sh
> > 
> > diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> > index bd01e4a0be2c..6da63d1831c1 100644
> > --- a/tools/testing/selftests/net/Makefile
> > +++ b/tools/testing/selftests/net/Makefile
> > @@ -53,6 +53,7 @@ TEST_PROGS += bind_bhash.sh
> >  TEST_PROGS += ip_local_port_range.sh
> >  TEST_PROGS += rps_default_mask.sh
> >  TEST_PROGS += big_tcp.sh
> > +TEST_PROGS += netns-sysctl.sh
> >  TEST_PROGS_EXTENDED := toeplitz_client.sh toeplitz.sh
> >  TEST_GEN_FILES =  socket nettest
> >  TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
> > diff --git a/tools/testing/selftests/net/netns-sysctl.sh b/tools/testing/selftests/net/netns-sysctl.sh
> > new file mode 100755
> > index 000000000000..b948ba67b13a
> > --- /dev/null
> > +++ b/tools/testing/selftests/net/netns-sysctl.sh
> > @@ -0,0 +1,15 @@
> > +#!/bin/bash -e
> 
> Don't you need to add the SPDX license header?

Yes, please!

Additionally, please handle explicitly the sysctl-related I/O errors so
that the script could output a human readable message in case of
failure.

Thanks!

Paolo
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index bd01e4a0be2c..6da63d1831c1 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -53,6 +53,7 @@  TEST_PROGS += bind_bhash.sh
 TEST_PROGS += ip_local_port_range.sh
 TEST_PROGS += rps_default_mask.sh
 TEST_PROGS += big_tcp.sh
+TEST_PROGS += netns-sysctl.sh
 TEST_PROGS_EXTENDED := toeplitz_client.sh toeplitz.sh
 TEST_GEN_FILES =  socket nettest
 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
diff --git a/tools/testing/selftests/net/netns-sysctl.sh b/tools/testing/selftests/net/netns-sysctl.sh
new file mode 100755
index 000000000000..b948ba67b13a
--- /dev/null
+++ b/tools/testing/selftests/net/netns-sysctl.sh
@@ -0,0 +1,15 @@ 
+#!/bin/bash -e
+
+for sc in {r,w}mem_{default,max}; do
+	# change the value in the host netns
+	sysctl -qw "net.core.$sc=300000"
+
+	# check that the value is read from the init netns
+	[ "$(unshare -n sysctl -n "net.core.$sc")" -eq 300000 ]
+
+	# check that this isn't writeable in a netns
+	! unshare -n [ -w "/proc/sys/net/core/$sc" ]
+	! unshare -n sysctl -w "net.core.$sc=100000"
+done
+
+echo 'Test passed OK'