diff mbox series

[net] selftests: forwarding: skip if kernel not support setting bridge fdb learning limit

Message ID 20240723082252.2703100-1-liuhangbin@gmail.com (mailing list archive)
State Accepted
Commit 863ff546fb62a8fa75757a30794ab6ec6cc4bab7
Delegated to: Netdev Maintainers
Headers show
Series [net] selftests: forwarding: skip if kernel not support setting bridge fdb learning limit | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 10 this patch: 10
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns
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-07-24--03-00 (tests: 694)

Commit Message

Hangbin Liu July 23, 2024, 8:22 a.m. UTC
If the testing kernel doesn't support setting fdb_max_learned or show
fdb_n_learned, just skip it. Or we will get errors like

./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected

Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 .../forwarding/bridge_fdb_learning_limit.sh    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Nikolay Aleksandrov July 23, 2024, 8:30 a.m. UTC | #1
On 23/07/2024 11:22, Hangbin Liu wrote:
> If the testing kernel doesn't support setting fdb_max_learned or show
> fdb_n_learned, just skip it. Or we will get errors like
> 
> ./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
> ./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected
> 
> Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  .../forwarding/bridge_fdb_learning_limit.sh    | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> index 0760a34b7114..a21b7085da2e 100755
> --- a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> +++ b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> @@ -178,6 +178,22 @@ fdb_del()
>  	check_err $? "Failed to remove a FDB entry of type ${type}"
>  }
>  
> +check_fdb_n_learned_support()
> +{
> +	if ! ip link help bridge 2>&1 | grep -q "fdb_max_learned"; then
> +		echo "SKIP: iproute2 too old, missing bridge max learned support"
> +		exit $ksft_skip
> +	fi
> +
> +	ip link add dev br0 type bridge
> +	local learned=$(fdb_get_n_learned)
> +	ip link del dev br0
> +	if [ "$learned" == "null" ]; then
> +		echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
> +		exit $ksft_skip
> +	fi
> +}
> +
>  check_accounting_one_type()
>  {
>  	local type=$1 is_counted=$2 overrides_learned=$3
> @@ -274,6 +290,8 @@ check_limit()
>  	done
>  }
>  
> +check_fdb_n_learned_support
> +
>  trap cleanup EXIT
>  
>  setup_prepare

Isn't the selftest supposed to be added after the feature was included?

I don't understand why this one is special, we should have the same
issue with all new features.
Paolo Abeni July 23, 2024, 9:24 a.m. UTC | #2
On 7/23/24 10:30, Nikolay Aleksandrov wrote:
> On 23/07/2024 11:22, Hangbin Liu wrote:
>> If the testing kernel doesn't support setting fdb_max_learned or show
>> fdb_n_learned, just skip it. Or we will get errors like
>>
>> ./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
>> ./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected
>>
>> Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
>> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>> ---
>>   .../forwarding/bridge_fdb_learning_limit.sh    | 18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>
>> diff --git a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>> index 0760a34b7114..a21b7085da2e 100755
>> --- a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>> +++ b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>> @@ -178,6 +178,22 @@ fdb_del()
>>   	check_err $? "Failed to remove a FDB entry of type ${type}"
>>   }
>>   
>> +check_fdb_n_learned_support()
>> +{
>> +	if ! ip link help bridge 2>&1 | grep -q "fdb_max_learned"; then
>> +		echo "SKIP: iproute2 too old, missing bridge max learned support"
>> +		exit $ksft_skip
>> +	fi
>> +
>> +	ip link add dev br0 type bridge
>> +	local learned=$(fdb_get_n_learned)
>> +	ip link del dev br0
>> +	if [ "$learned" == "null" ]; then
>> +		echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
>> +		exit $ksft_skip
>> +	fi
>> +}
>> +
>>   check_accounting_one_type()
>>   {
>>   	local type=$1 is_counted=$2 overrides_learned=$3
>> @@ -274,6 +290,8 @@ check_limit()
>>   	done
>>   }
>>   
>> +check_fdb_n_learned_support
>> +
>>   trap cleanup EXIT
>>   
>>   setup_prepare
> 
> Isn't the selftest supposed to be added after the feature was included?
> 
> I don't understand why this one is special, we should have the same
> issue with all new features.

I must admit I was surprised when I learned the fact, but the stable 
team routinely runs up2date upstream self-tests on top of stable/older 
kernels:

https://lore.kernel.org/mptcp/ZAHLYvOPEYghRcJ1@kroah.com/

The expected self-test design is to probe the tested feature and skip if 
not available in the running kernel. The self-test should not break when 
run on an older kernel not offering such feature.

I understand some (most?) of the self-tests do not cope with the above 
perfectly, but we can improve ;).

Thanks,

Paolo
Nikolay Aleksandrov July 23, 2024, 9:43 a.m. UTC | #3
On 23/07/2024 12:24, Paolo Abeni wrote:
> 
> 
> On 7/23/24 10:30, Nikolay Aleksandrov wrote:
>> On 23/07/2024 11:22, Hangbin Liu wrote:
>>> If the testing kernel doesn't support setting fdb_max_learned or show
>>> fdb_n_learned, just skip it. Or we will get errors like
>>>
>>> ./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
>>> ./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected
>>>
>>> Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
>>> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>>> ---
>>>   .../forwarding/bridge_fdb_learning_limit.sh    | 18 ++++++++++++++++++
>>>   1 file changed, 18 insertions(+)
>>>
>>> diff --git a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>>> index 0760a34b7114..a21b7085da2e 100755
>>> --- a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>>> +++ b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
>>> @@ -178,6 +178,22 @@ fdb_del()
>>>       check_err $? "Failed to remove a FDB entry of type ${type}"
>>>   }
>>>   +check_fdb_n_learned_support()
>>> +{
>>> +    if ! ip link help bridge 2>&1 | grep -q "fdb_max_learned"; then
>>> +        echo "SKIP: iproute2 too old, missing bridge max learned support"
>>> +        exit $ksft_skip
>>> +    fi
>>> +
>>> +    ip link add dev br0 type bridge
>>> +    local learned=$(fdb_get_n_learned)
>>> +    ip link del dev br0
>>> +    if [ "$learned" == "null" ]; then
>>> +        echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
>>> +        exit $ksft_skip
>>> +    fi
>>> +}
>>> +
>>>   check_accounting_one_type()
>>>   {
>>>       local type=$1 is_counted=$2 overrides_learned=$3
>>> @@ -274,6 +290,8 @@ check_limit()
>>>       done
>>>   }
>>>   +check_fdb_n_learned_support
>>> +
>>>   trap cleanup EXIT
>>>     setup_prepare
>>
>> Isn't the selftest supposed to be added after the feature was included?
>>
>> I don't understand why this one is special, we should have the same
>> issue with all new features.
> 
> I must admit I was surprised when I learned the fact, but the stable team routinely runs up2date upstream self-tests on top of stable/older kernels:
> 
> https://lore.kernel.org/mptcp/ZAHLYvOPEYghRcJ1@kroah.com/
> 
> The expected self-test design is to probe the tested feature and skip if not available in the running kernel. The self-test should not break when run on an older kernel not offering such feature.
> 
> I understand some (most?) of the self-tests do not cope with the above perfectly, but we can improve ;).
> 
> Thanks,
> 
> Paolo
> 
> 

Interesting, and unexpected at least for me. :) But okay, I'll keep it in mind
when sending/reviewing patches.

Thanks!

For the patch:
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Johannes Nixdorf July 23, 2024, 11:13 a.m. UTC | #4
On Tue, Jul 23, 2024 at 04:22:52PM +0800, Hangbin Liu wrote:
> If the testing kernel doesn't support setting fdb_max_learned or show
> fdb_n_learned, just skip it. Or we will get errors like
> 
> ./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
> ./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected
> 
> Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  .../forwarding/bridge_fdb_learning_limit.sh    | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> index 0760a34b7114..a21b7085da2e 100755
> --- a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> +++ b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
> @@ -178,6 +178,22 @@ fdb_del()
>  	check_err $? "Failed to remove a FDB entry of type ${type}"
>  }
>  
> +check_fdb_n_learned_support()
> +{
> +	if ! ip link help bridge 2>&1 | grep -q "fdb_max_learned"; then
> +		echo "SKIP: iproute2 too old, missing bridge max learned support"
> +		exit $ksft_skip
> +	fi
> +
> +	ip link add dev br0 type bridge
> +	local learned=$(fdb_get_n_learned)
> +	ip link del dev br0
> +	if [ "$learned" == "null" ]; then
> +		echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
> +		exit $ksft_skip
> +	fi
> +}
> +
>  check_accounting_one_type()
>  {
>  	local type=$1 is_counted=$2 overrides_learned=$3
> @@ -274,6 +290,8 @@ check_limit()
>  	done
>  }
>  
> +check_fdb_n_learned_support
> +
>  trap cleanup EXIT
>  
>  setup_prepare
> -- 
> 2.45.0

Thanks for the fix. I also assumed that it's fine to depend on new
features after trying to find out how those feature tests are usually
done from the surrounding tests and their history.

The code looks right to me, and seems to behave as expected when feeding
it data with and without fdb_n_learned.

Reviewed-by: Johannes Nixdorf <jnixdorf-oss@avm.de>
patchwork-bot+netdevbpf@kernel.org July 24, 2024, noon UTC | #5
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue, 23 Jul 2024 16:22:52 +0800 you wrote:
> If the testing kernel doesn't support setting fdb_max_learned or show
> fdb_n_learned, just skip it. Or we will get errors like
> 
> ./bridge_fdb_learning_limit.sh: line 218: [: null: integer expression expected
> ./bridge_fdb_learning_limit.sh: line 225: [: null: integer expression expected
> 
> Fixes: 6f84090333bb ("selftests: forwarding: bridge_fdb_learning_limit: Add a new selftest")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> 
> [...]

Here is the summary with links:
  - [net] selftests: forwarding: skip if kernel not support setting bridge fdb learning limit
    https://git.kernel.org/netdev/net/c/863ff546fb62

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
index 0760a34b7114..a21b7085da2e 100755
--- a/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
+++ b/tools/testing/selftests/net/forwarding/bridge_fdb_learning_limit.sh
@@ -178,6 +178,22 @@  fdb_del()
 	check_err $? "Failed to remove a FDB entry of type ${type}"
 }
 
+check_fdb_n_learned_support()
+{
+	if ! ip link help bridge 2>&1 | grep -q "fdb_max_learned"; then
+		echo "SKIP: iproute2 too old, missing bridge max learned support"
+		exit $ksft_skip
+	fi
+
+	ip link add dev br0 type bridge
+	local learned=$(fdb_get_n_learned)
+	ip link del dev br0
+	if [ "$learned" == "null" ]; then
+		echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
+		exit $ksft_skip
+	fi
+}
+
 check_accounting_one_type()
 {
 	local type=$1 is_counted=$2 overrides_learned=$3
@@ -274,6 +290,8 @@  check_limit()
 	done
 }
 
+check_fdb_n_learned_support
+
 trap cleanup EXIT
 
 setup_prepare