[Devel] [PATCH vz10 07/12] selftests: net: skip test_blackhole_dev if kernel module is unavailable

Konstantin Khorenko khorenko at virtuozzo.com
Fri Dec 19 18:02:03 MSK 2025


On 12/19/25 04:12, Pavel Tikhomirov wrote:
> 
> 
> On 12/17/25 05:04, Aleksei Oladko wrote:
>> The test_blackhole_dev.sh kselftest relies on the test_blackhole_dev
>> kernel module to be present and loadable. If the module in not built
>> or not available on the system, modprobe fails and the test is
>> reported as a failure.
>>
>> Add an explicit check for the availability of the test_blackhole_dev
>> module and skip the test when the module is missing.
>>
>> https://virtuozzo.atlassian.net/browse/VSTOR-120995
>>
>> Signed-off-by: Aleksei Oladko <aleksey.oladko at virtuozzo.com>
>> ---
>>   tools/testing/selftests/net/test_blackhole_dev.sh | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/tools/testing/selftests/net/test_blackhole_dev.sh b/tools/testing/selftests/net/test_blackhole_dev.sh
>> index 3119b80e711f..8a5c3c0d4dc7 100755
>> --- a/tools/testing/selftests/net/test_blackhole_dev.sh
>> +++ b/tools/testing/selftests/net/test_blackhole_dev.sh
>> @@ -2,6 +2,9 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   # Runs blackhole-dev test using blackhole-dev kernel module
>>   
>> +ksft_skip=4
> 
> Can we instead of redefining ksft_skip use `source lib.sh` ?

Yes, most of tests use "sources lib.sh" style.

Just don't forget to use bash in this case.

   The shebang change is required because:
   1. lib.sh uses bash-specific features:
     • ${BASH_SOURCE[0]} — bash-specific variable
     • [[ ... ]] — bash-specific syntax (sh uses [ ... ])
   2. source is a bash alias for .; it doesn't exist in sh.
   3. If the script runs via #!/bin/sh, lib.sh won't load due to these bash-specific constructs.

   Alternatives:
   • Keep #!/bin/sh and define ksft_skip=4 directly (as in the original patch)
   • But then we don't use the centralized definition from lib.sh

   Conclusion: If we use source lib.sh, we need #!/bin/bash. All scripts that use source lib.sh have 
#!/bin/bash in their shebang.


> 
>> +modinfo test_blackhole_dev || exit $ksft_skip
>> +
>>   if /sbin/modprobe -q test_blackhole_dev ; then
>>   	/sbin/modprobe -q -r test_blackhole_dev;
>>   	echo "test_blackhole_dev: ok";
> 



More information about the Devel mailing list