Skip to contentSkip to conversation

selftests: fib rule: Small internal and test output improvments

PATCH Applied Guillaume Nault 2 participants 6 messages Jan 31, 2022 – Feb 1, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover selftests: fib rule: Small internal and test output improvments

The first half of these patch set improves the code logic and has no user visible effect. The second half improves the script output, to make it clearer and nicer to read.

Guillaume Nault (4):
selftests: fib rule: Make 'getmatch' and 'match' local variables
selftests: fib rule: Drop erroneous TABLE variable
selftests: fib rule: Log test description
selftests: fib rule: Don't echo modified sysctls

 tools/testing/selftests/net/fib_rule_tests.sh | 26 ++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/4 selftests: fib rule: Make 'getmatch' and 'match' local variables

Let's restrict the scope of these variables to avoid possible interferences.

---
 tools/testing/selftests/net/fib_rule_tests.sh | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/net/fib_rule_tests.sh +6 -0
index 43ea8407a82e..f04f337dd7c6 100755
@@ -115,6 +115,9 @@ fib_rule6_test_match_n_redirect()
 
 fib_rule6_test()
 {
+	local getmatch
+	local match
+
 	# setup the fib rule redirect route
 	$IP -6 route add table $RTABLE default via $GW_IP6 dev $DEV onlink
 
@@ -184,6 +187,9 @@ fib_rule4_test_match_n_redirect()
 
 fib_rule4_test()
 {
+	local getmatch
+	local match
+
 	# setup the fib rule redirect route
 	$IP route add table $RTABLE default via $GW_IP4 dev $DEV onlink
 
Signature · 1 line
2.21.3
#2 lore raw

PATCH 2/4 selftests: fib rule: Drop erroneous TABLE variable

In reply to Guillaume Nault

The fib_rule6_del_by_pref() and fib_rule4_del_by_pref() functions use an uninitialised $TABLE variable. They should use $RTABLE instead. This doesn't alter the result of the test, as it just makes the grep command less specific (but since the script always uses the same table number, that doesn't really matter).

Let's fix it anyway and, while there, specify the filtering parameters directly in 'ip -X rule show' to avoid the extra grep command entirely.

---
 tools/testing/selftests/net/fib_rule_tests.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/fib_rule_tests.sh +2 -2
index f04f337dd7c6..012f9385d68c 100755
@@ -96,7 +96,7 @@ fib_rule6_del()
 
 fib_rule6_del_by_pref()
 {
-	pref=$($IP -6 rule show | grep "$1 lookup $TABLE" | cut -d ":" -f 1)
+	pref=$($IP -6 rule show $1 table $RTABLE | cut -d ":" -f 1)
 	$IP -6 rule del pref $pref
 }
 
@@ -168,7 +168,7 @@ fib_rule4_del()
 
 fib_rule4_del_by_pref()
 {
-	pref=$($IP rule show | grep "$1 lookup $TABLE" | cut -d ":" -f 1)
+	pref=$($IP rule show $1 table $RTABLE | cut -d ":" -f 1)
 	$IP rule del pref $pref
 }
 
Signature · 1 line
2.21.3
#3 lore raw

PATCH 3/4 selftests: fib rule: Log test description

In reply to Guillaume Nault

All callers of fib_rule6_test_match_n_redirect() and fib_rule4_test_match_n_redirect() pass a third argument containing a description of the test being run. Instead of ignoring this argument, let's use it for logging instead of printing a truncated version of the command.

---
 tools/testing/selftests/net/fib_rule_tests.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/testing/selftests/net/fib_rule_tests.sh +6 -4
index 012f9385d68c..6a05e81fc81d 100755
@@ -104,13 +104,14 @@ fib_rule6_test_match_n_redirect()
 {
 	local match="$1"
 	local getmatch="$2"
+	local description="$3"
 
 	$IP -6 rule add $match table $RTABLE
 	$IP -6 route get $GW_IP6 $getmatch | grep -q "table $RTABLE"
-	log_test $? 0 "rule6 check: $1"
+	log_test $? 0 "rule6 check: $description"
 
 	fib_rule6_del_by_pref "$match"
-	log_test $? 0 "rule6 del by pref: $match"
+	log_test $? 0 "rule6 del by pref: $description"
 }
 
 fib_rule6_test()
@@ -176,13 +177,14 @@ fib_rule4_test_match_n_redirect()
 {
 	local match="$1"
 	local getmatch="$2"
+	local description="$3"
 
 	$IP rule add $match table $RTABLE
 	$IP route get $GW_IP4 $getmatch | grep -q "table $RTABLE"
-	log_test $? 0 "rule4 check: $1"
+	log_test $? 0 "rule4 check: $description"
 
 	fib_rule4_del_by_pref "$match"
-	log_test $? 0 "rule4 del by pref: $match"
+	log_test $? 0 "rule4 del by pref: $description"
 }
 
 fib_rule4_test()
Signature · 1 line
2.21.3
#4 lore raw

PATCH 4/4 selftests: fib rule: Don't echo modified sysctls

In reply to Guillaume Nault

Run sysctl in quiet mode. Echoing the modified sysctl doesn't bring any useful information.

---
 tools/testing/selftests/net/fib_rule_tests.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/net/fib_rule_tests.sh +3 -3
index 6a05e81fc81d..3b0489910422 100755
@@ -200,11 +200,11 @@ fib_rule4_test()
 
 	# need enable forwarding and disable rp_filter temporarily as all the
 	# addresses are in the same subnet and egress device == ingress device.
-	ip netns exec testns sysctl -w net.ipv4.ip_forward=1
-	ip netns exec testns sysctl -w net.ipv4.conf.$DEV.rp_filter=0
+	ip netns exec testns sysctl -qw net.ipv4.ip_forward=1
+	ip netns exec testns sysctl -qw net.ipv4.conf.$DEV.rp_filter=0
 	match="from $SRC_IP iif $DEV"
 	fib_rule4_test_match_n_redirect "$match" "$match" "iif redirect to table"
-	ip netns exec testns sysctl -w net.ipv4.ip_forward=0
+	ip netns exec testns sysctl -qw net.ipv4.ip_forward=0
 
 	match="tos 0x10"
 	fib_rule4_test_match_n_redirect "$match" "$match" "tos redirect to table"
Signature · 1 line
2.21.3
#5 lore raw
In reply to Guillaume Nault
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 11 lines · On Mon, 31 Jan 2022 16:41:54 +0100 you wrote:

The first half of these patch set improves the code logic and has no user visible effect. The second half improves the script output, to make it clearer and nicer to read.

Guillaume Nault (4):
selftests: fib rule: Make 'getmatch' and 'match' local variables
selftests: fib rule: Drop erroneous TABLE variable
selftests: fib rule: Log test description
selftests: fib rule: Don't echo modified sysctls

[...]

Here is the summary with links:
- [net-next,1/4] selftests: fib rule: Make 'getmatch' and 'match' local variables

    https://git.kernel.org/netdev/net-next/c/8af2ba9a7811
  - [net-next,2/4] selftests: fib rule: Drop erroneous TABLE variable
    https://git.kernel.org/netdev/net-next/c/2e2521136327
  - [net-next,3/4] selftests: fib rule: Log test description
    https://git.kernel.org/netdev/net-next/c/21f25cd43672
  - [net-next,4/4] selftests: fib rule: Don't echo modified sysctls
    https://git.kernel.org/netdev/net-next/c/9f397dd5f155

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html