* [PATCH nft 0/2] tests/shell: workaround for bash
@ 2023-11-27 19:15 Thomas Haller
2023-11-27 19:15 ` [PATCH nft 1/2] tests/shell: workaround lack of `wait -p` before bash 5.1 Thomas Haller
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thomas Haller @ 2023-11-27 19:15 UTC (permalink / raw)
To: NetFilter; +Cc: Thomas Haller
RHEL8 has bash 4.4. Make some adjustments so that the test script works
there.
*** BLURB HERE ***
Thomas Haller (2):
tests/shell: workaround lack of `wait -p` before bash 5.1
tests/shell: workaround lack of $SRANDOM before bash 5.1
tests/shell/run-tests.sh | 48 ++++++++++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 7 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH nft 1/2] tests/shell: workaround lack of `wait -p` before bash 5.1 2023-11-27 19:15 [PATCH nft 0/2] tests/shell: workaround for bash Thomas Haller @ 2023-11-27 19:15 ` Thomas Haller 2023-11-27 19:15 ` [PATCH nft 2/2] tests/shell: workaround lack of $SRANDOM " Thomas Haller 2023-11-29 18:55 ` [PATCH nft 0/2] tests/shell: workaround for bash Pablo Neira Ayuso 2 siblings, 0 replies; 4+ messages in thread From: Thomas Haller @ 2023-11-27 19:15 UTC (permalink / raw) To: NetFilter; +Cc: Thomas Haller Before bash 5.1, `wait -p` is not supported. So we cannot know which child process completed. As workaround, explicitly wait for the next PID. That works, but it significantly reduces parallel execution, because a long running job blocks the queue. Signed-off-by: Thomas Haller <thaller@redhat.com> --- tests/shell/run-tests.sh | 47 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh index 3cde97b7ea17..f1345bb14e7c 100755 --- a/tests/shell/run-tests.sh +++ b/tests/shell/run-tests.sh @@ -30,6 +30,23 @@ array_contains() { return 1 } +array_remove_first() { + local _varname="$1" + local _needle="$2" + local _result=() + local _a + + eval "local _input=( \"\${$_varname[@]}\" )" + for _a in "${_input[@]}" ; do + if [ -n "${_needle+x}" -a "$_needle" = "$_a" ] ; then + unset _needle + else + _result+=("$_a") + fi + done + eval "$_varname="'( "${_result[@]}" )' +} + colorize_keywords() { local out_variable="$1" local color="$2" @@ -598,13 +615,14 @@ if [ ! -x "$DIFF" ] ; then DIFF=true fi +JOBS_PIDLIST_ARR=() declare -A JOBS_PIDLIST _NFT_TEST_VALGRIND_VGDB_PREFIX= cleanup_on_exit() { pids_search='' - for pid in "${!JOBS_PIDLIST[@]}" ; do + for pid in "${JOBS_PIDLIST_ARR[@]}" ; do kill -- "-$pid" &>/dev/null pids_search="$pids_search\\|\\<$pid\\>" done @@ -858,17 +876,33 @@ job_start() { return "$rc_got" } +# `wait -p` is only supported since bash 5.1 +WAIT_SUPPORTS_P=1 +[ "${BASH_VERSINFO[0]}" -le 4 -o \( "${BASH_VERSINFO[0]}" -eq 5 -a "${BASH_VERSINFO[1]}" -eq 0 \) ] && WAIT_SUPPORTS_P=0 + job_wait() { local num_jobs="$1" + local JOBCOMPLETED + local rc_got + + while [ "${#JOBS_PIDLIST_ARR[@]}" -gt 0 -a "${#JOBS_PIDLIST_ARR[@]}" -ge "$num_jobs" ] ; do + if [ "$WAIT_SUPPORTS_P" = 1 ] ; then + wait -n -p JOBCOMPLETED + rc_got="$?" + array_remove_first JOBS_PIDLIST_ARR "$JOBCOMPLETED" + else + # Without `wait -p` support, we need to explicitly wait + # for a PID. That reduces parallelism. + JOBCOMPLETED="${JOBS_PIDLIST_ARR[0]}" + JOBS_PIDLIST_ARR=( "${JOBS_PIDLIST_ARR[@]:1}" ) + wait -n "$JOBCOMPLETED" + rc_got="$?" + fi - while [ "$JOBS_N_RUNNING" -gt 0 -a "$JOBS_N_RUNNING" -ge "$num_jobs" ] ; do - wait -n -p JOBCOMPLETED - local rc_got="$?" local testfile2="${JOBS_PIDLIST[$JOBCOMPLETED]}" unset JOBS_PIDLIST[$JOBCOMPLETED] print_test_result "${JOBS_TEMPDIR["$testfile2"]}" "$testfile2" "$rc_got" - ((JOBS_N_RUNNING--)) check_kmemleak done } @@ -878,7 +912,6 @@ if [ "$NFT_TEST_SHUFFLE_TESTS" = y ] ; then fi TESTIDX=0 -JOBS_N_RUNNING=0 for testfile in "${TESTS[@]}" ; do job_wait "$NFT_TEST_JOBS" @@ -897,7 +930,7 @@ for testfile in "${TESTS[@]}" ; do pid=$! eval "$set_old_state" JOBS_PIDLIST[$pid]="$testfile" - ((JOBS_N_RUNNING++)) + JOBS_PIDLIST_ARR+=( "$pid" ) done job_wait 0 -- 2.43.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH nft 2/2] tests/shell: workaround lack of $SRANDOM before bash 5.1 2023-11-27 19:15 [PATCH nft 0/2] tests/shell: workaround for bash Thomas Haller 2023-11-27 19:15 ` [PATCH nft 1/2] tests/shell: workaround lack of `wait -p` before bash 5.1 Thomas Haller @ 2023-11-27 19:15 ` Thomas Haller 2023-11-29 18:55 ` [PATCH nft 0/2] tests/shell: workaround for bash Pablo Neira Ayuso 2 siblings, 0 replies; 4+ messages in thread From: Thomas Haller @ 2023-11-27 19:15 UTC (permalink / raw) To: NetFilter; +Cc: Thomas Haller $SRANDOM is only supported since bash 5.1. Add a fallback to $RANDOM. Signed-off-by: Thomas Haller <thaller@redhat.com> --- tests/shell/run-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh index f1345bb14e7c..e54f8bf3e3ee 100755 --- a/tests/shell/run-tests.sh +++ b/tests/shell/run-tests.sh @@ -314,6 +314,7 @@ DO_LIST_TESTS= if [ -z "$NFT_TEST_RANDOM_SEED" ] ; then # Choose a random value. n="$SRANDOM" + [ -z "$n" ] && n="$RANDOM" else # Parse as number. n="$(strtonum "$NFT_TEST_RANDOM_SEED")" -- 2.43.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nft 0/2] tests/shell: workaround for bash 2023-11-27 19:15 [PATCH nft 0/2] tests/shell: workaround for bash Thomas Haller 2023-11-27 19:15 ` [PATCH nft 1/2] tests/shell: workaround lack of `wait -p` before bash 5.1 Thomas Haller 2023-11-27 19:15 ` [PATCH nft 2/2] tests/shell: workaround lack of $SRANDOM " Thomas Haller @ 2023-11-29 18:55 ` Pablo Neira Ayuso 2 siblings, 0 replies; 4+ messages in thread From: Pablo Neira Ayuso @ 2023-11-29 18:55 UTC (permalink / raw) To: Thomas Haller; +Cc: NetFilter On Mon, Nov 27, 2023 at 08:15:34PM +0100, Thomas Haller wrote: > RHEL8 has bash 4.4. Make some adjustments so that the test script works > there. Applied, thanks. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-29 18:55 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-11-27 19:15 [PATCH nft 0/2] tests/shell: workaround for bash Thomas Haller 2023-11-27 19:15 ` [PATCH nft 1/2] tests/shell: workaround lack of `wait -p` before bash 5.1 Thomas Haller 2023-11-27 19:15 ` [PATCH nft 2/2] tests/shell: workaround lack of $SRANDOM " Thomas Haller 2023-11-29 18:55 ` [PATCH nft 0/2] tests/shell: workaround for bash Pablo Neira Ayuso
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).