All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] testcases/lib: introduce sysctl wrapper
@ 2022-02-22 15:55 Nikita Yushchenko via ltp
  2022-02-22 16:09 ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Nikita Yushchenko via ltp @ 2022-02-22 15:55 UTC (permalink / raw)
  To: Petr Vorel; +Cc: kernel, ltp, Nikita Yushchenko

Linux sysctl utility does not propagate errors returned from proc writes
to it's exit code:

> sysctl -q -w net.ipv4.tcp_congestion_control=dctcp
sysctl: setting key "net.ipv4.tcp_congestion_control": Operation not permitted
> echo $?
0

This causes the tests to not notice issues.

Workaround that by using a wrapper instead of sysctl. The wrapper calls
sysctl with given arguments, and returns non-zero exit status if either
sysctl returned non-zero exist status, or sysctl's stderr was not empty.

Signed-off-by: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com>
---
 testcases/lib/Makefile       |  2 +-
 testcases/lib/sysctl_wrapper | 10 ++++++++++
 testcases/lib/tst_net.sh     |  6 +++---
 3 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 testcases/lib/sysctl_wrapper

diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f2de0c832..ecf4bdc2d 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -6,7 +6,7 @@ top_srcdir		?= ../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-INSTALL_TARGETS		:= *.sh
+INSTALL_TARGETS		:= *.sh sysctl_wrapper
 
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
diff --git a/testcases/lib/sysctl_wrapper b/testcases/lib/sysctl_wrapper
new file mode 100644
index 000000000..59e7fb7c0
--- /dev/null
+++ b/testcases/lib/sysctl_wrapper
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+stderr=$(mktemp)
+err=0
+sysctl $* 2>$stderr || err=1
+test -s $stderr && err=1
+cat $stderr >&2
+rm -f $stderr
+
+exit $err
diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index 047686dc3..c7b835cbf 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -517,7 +517,7 @@ tst_init_iface()
 		ip link set $iface down || return $?
 		ip route flush dev $iface || return $?
 		ip addr flush dev $iface || return $?
-		sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
+		sysctl_wrapper -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
 		ip link set $iface up
 		return $?
 	fi
@@ -529,7 +529,7 @@ tst_init_iface()
 	tst_rhost_run -c "ip link set $iface down" || return $?
 	tst_rhost_run -c "ip route flush dev $iface" || return $?
 	tst_rhost_run -c "ip addr flush dev $iface" || return $?
-	tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
+	tst_rhost_run -c "sysctl_wrapper -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
 	tst_rhost_run -c "ip link set $iface up"
 }
 
@@ -922,7 +922,7 @@ tst_set_sysctl()
 	local rparam=
 	[ "$TST_USE_NETNS" = "yes" ] && rparam="-i -r '-e'"
 
-	tst_net_run $safe -q $rparam "sysctl" "-q -w $name=$value"
+	tst_net_run $safe -q $rparam "sysctl"_wrapper "-q -w $name=$value"
 }
 
 tst_cleanup_rhost()
-- 
2.30.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-02-23 14:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 15:55 [LTP] [PATCH] testcases/lib: introduce sysctl wrapper Nikita Yushchenko via ltp
2022-02-22 16:09 ` Cyril Hrubis
2022-02-22 16:09   ` Nikita Yushchenko via ltp
2022-02-22 17:35     ` Cyril Hrubis
2022-02-22 18:31       ` Petr Vorel
2022-02-23 12:44         ` Cyril Hrubis
2022-02-23 14:47           ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.