diff mbox series

[05/11] selftests: net/fcnal: kill_procs via spin instead of sleep

Message ID ff71285715d47b8c9b6bedb3b50700a26bc81f41.1633520807.git.cdleonard@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series selftests: Improve nettest and net/fcnal-test.sh | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Leonard Crestez Oct. 6, 2021, 11:47 a.m. UTC
Sleeping for one second after a kill is not necessary and adds up quite
quickly. Replace with a fast loop spinning until pidof returns nothing.

Signed-off-by: Leonard Crestez <cdleonard@gmail.com>
---
 tools/testing/selftests/net/fcnal-test.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

David Ahern Oct. 6, 2021, 2:45 p.m. UTC | #1
On 10/6/21 5:47 AM, Leonard Crestez wrote:
> Sleeping for one second after a kill is not necessary and adds up quite
> quickly. Replace with a fast loop spinning until pidof returns nothing.
> 
> Signed-off-by: Leonard Crestez <cdleonard@gmail.com>
> ---
>  tools/testing/selftests/net/fcnal-test.sh | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
> index 0bd60cd3bc06..b7fda51deb3f 100755
> --- a/tools/testing/selftests/net/fcnal-test.sh
> +++ b/tools/testing/selftests/net/fcnal-test.sh
> @@ -176,12 +176,19 @@ show_hint()
>  	fi
>  }
>  
>  kill_procs()
>  {
> -	killall nettest ping ping6 >/dev/null 2>&1
> -	sleep 1
> +	local pids
> +	while true; do
> +		pids=$(pidof nettest ping ping6)
> +		if [[ -z $pids ]]; then
> +			break
> +		fi
> +		kill $pids
> +		sleep 0.01
> +	done
>  }
>  
>  do_run_cmd()
>  {
>  	local cmd="$*"
> 

ideally the script keeps track of processes it launches and only kills
those. The original killall was just a stop gap until the process
tracking was added.
Leonard Crestez Oct. 6, 2021, 9:16 p.m. UTC | #2
On 06.10.2021 17:45, David Ahern wrote:
> On 10/6/21 5:47 AM, Leonard Crestez wrote:
>> Sleeping for one second after a kill is not necessary and adds up quite
>> quickly. Replace with a fast loop spinning until pidof returns nothing.
>>
>> Signed-off-by: Leonard Crestez <cdleonard@gmail.com>
>> ---
>>   tools/testing/selftests/net/fcnal-test.sh | 11 +++++++++--
>>   1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
>> index 0bd60cd3bc06..b7fda51deb3f 100755
>> --- a/tools/testing/selftests/net/fcnal-test.sh
>> +++ b/tools/testing/selftests/net/fcnal-test.sh
>> @@ -176,12 +176,19 @@ show_hint()
>>   	fi
>>   }
>>   
>>   kill_procs()
>>   {
>> -	killall nettest ping ping6 >/dev/null 2>&1
>> -	sleep 1
>> +	local pids
>> +	while true; do
>> +		pids=$(pidof nettest ping ping6)
>> +		if [[ -z $pids ]]; then
>> +			break
>> +		fi
>> +		kill $pids
>> +		sleep 0.01
>> +	done
>>   }
>>   
>>   do_run_cmd()
>>   {
>>   	local cmd="$*"
>>
> 
> ideally the script keeps track of processes it launches and only kills
> those. The original killall was just a stop gap until the process
> tracking was added.

That's harder to do. This is much faster and not in any way worse than 
killall + sleep.

Some sort of a wrapper would have to added for each process running the 
background, for each run_ping_bg.

If nettest forks by itself then $! won't work, maybe some sort of 
--pid-file switch would be required?

--
Regards,
Leonard
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/fcnal-test.sh b/tools/testing/selftests/net/fcnal-test.sh
index 0bd60cd3bc06..b7fda51deb3f 100755
--- a/tools/testing/selftests/net/fcnal-test.sh
+++ b/tools/testing/selftests/net/fcnal-test.sh
@@ -176,12 +176,19 @@  show_hint()
 	fi
 }
 
 kill_procs()
 {
-	killall nettest ping ping6 >/dev/null 2>&1
-	sleep 1
+	local pids
+	while true; do
+		pids=$(pidof nettest ping ping6)
+		if [[ -z $pids ]]; then
+			break
+		fi
+		kill $pids
+		sleep 0.01
+	done
 }
 
 do_run_cmd()
 {
 	local cmd="$*"