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(-)
Let's restrict the scope of these variables to avoid possible interferences.
Signed-off-by: Guillaume Nault gnault@redhat.com --- tools/testing/selftests/net/fib_rule_tests.sh | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tools/testing/selftests/net/fib_rule_tests.sh b/tools/testing/selftests/net/fib_rule_tests.sh index 43ea8407a82e..f04f337dd7c6 100755 --- a/tools/testing/selftests/net/fib_rule_tests.sh +++ b/tools/testing/selftests/net/fib_rule_tests.sh @@ -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
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.
Signed-off-by: Guillaume Nault gnault@redhat.com --- tools/testing/selftests/net/fib_rule_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/fib_rule_tests.sh b/tools/testing/selftests/net/fib_rule_tests.sh index f04f337dd7c6..012f9385d68c 100755 --- a/tools/testing/selftests/net/fib_rule_tests.sh +++ b/tools/testing/selftests/net/fib_rule_tests.sh @@ -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 }
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.
Signed-off-by: Guillaume Nault gnault@redhat.com --- tools/testing/selftests/net/fib_rule_tests.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/fib_rule_tests.sh b/tools/testing/selftests/net/fib_rule_tests.sh index 012f9385d68c..6a05e81fc81d 100755 --- a/tools/testing/selftests/net/fib_rule_tests.sh +++ b/tools/testing/selftests/net/fib_rule_tests.sh @@ -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()
Run sysctl in quiet mode. Echoing the modified sysctl doesn't bring any useful information.
Signed-off-by: Guillaume Nault gnault@redhat.com --- tools/testing/selftests/net/fib_rule_tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/fib_rule_tests.sh b/tools/testing/selftests/net/fib_rule_tests.sh index 6a05e81fc81d..3b0489910422 100755 --- a/tools/testing/selftests/net/fib_rule_tests.sh +++ b/tools/testing/selftests/net/fib_rule_tests.sh @@ -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"
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller davem@davemloft.net:
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!
linux-kselftest-mirror@lists.linaro.org