[lttng-dev] [PATCH urcu] Tests fix: errors in shell scripts

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Nov 7 22:10:17 UTC 2017


Merged into master, thanks!

Mathieu

----- On Jul 26, 2017, at 1:31 PM, Michael Jeanson mjeanson at efficios.com wrote:

> Fix all shellcheck errors in the test scripts, switch to posix
> compatible syntax. Remove duplicated code already included in common.sh.
> Call the tap.sh cleanup code from our exit trap instead of overriding
> it.
> 
> Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
> ---
> tests/benchmark/common.sh         | 38 +++++++++++++++++----------
> tests/benchmark/run-urcu-tests.sh | 55 ++++++++++++++++++---------------------
> tests/benchmark/runhash.sh        | 47 ++++++++++++++++++---------------
> tests/benchmark/runtests-batch.sh | 29 +++------------------
> tests/benchmark/runtests.sh       | 27 +++----------------
> 5 files changed, 84 insertions(+), 112 deletions(-)
> 
> diff --git a/tests/benchmark/common.sh b/tests/benchmark/common.sh
> index 1f5f07f..4dbc567 100755
> --- a/tests/benchmark/common.sh
> +++ b/tests/benchmark/common.sh
> @@ -2,25 +2,35 @@
> # This file is meant to be sourced from other tests scripts.
> #
> 
> -if [ -x "$URCU_TEST_TIME_BIN" ]; then
> -	test_time_bin="$URCU_TEST_TIME_BIN"
> -elif [ -x "/usr/bin/time" ]; then
> -	test_time_bin="/usr/bin/time"
> -else
> -	test_time_bin=""
> -fi
> +cleanup() {
> +	if [ x"$TMPFILE" != "x" ]; then
> +		rm -f "$TMPFILE"
> +	fi
> 
> -function cleanup()
> -{
> -        if [ x"$tmpfile" != x"" ]; then
> -                rm -f $tmpfile
> -        fi
> +	# Call the tap.sh exit cleanup code
> +	_exit
> }
> 
> -function xseq () {
> +xseq() {
> 	i=$1
> 	while [[ "$i" -le "$2" ]]; do
> 		echo "$i"
> -		i=$(expr $i + 1)
> +		i=$(( i + 1 ))
> 	done
> }
> +
> +# Set TEST_TIME_BIN
> +if [ -x "$URCU_TEST_TIME_BIN" ]; then
> +	TEST_TIME_BIN="$URCU_TEST_TIME_BIN"
> +elif [ -x "/usr/bin/time" ]; then
> +	TEST_TIME_BIN="/usr/bin/time"
> +else
> +	TEST_TIME_BIN=""
> +fi
> +export TEST_TIME_BIN
> +
> +# Create a temporary file for tests output
> +TMPFILE=$(mktemp)
> +
> +# Set traps to delete the temporary file on exit
> +trap cleanup EXIT
> diff --git a/tests/benchmark/run-urcu-tests.sh
> b/tests/benchmark/run-urcu-tests.sh
> index 1df988a..751514a 100755
> --- a/tests/benchmark/run-urcu-tests.sh
> +++ b/tests/benchmark/run-urcu-tests.sh
> @@ -3,7 +3,7 @@
> #first parameter: seconds per test
> DURATION=$1
> 
> -if [ "x$DURATION" = "x" ]; then
> +if [ "x${DURATION}" = "x" ]; then
> 	echo "usage: $0 [DURATION]"
> 	exit 1
> fi
> @@ -30,16 +30,13 @@ fi
> # fraction: 15 * 29 =
> # scalabilit NUM_CPUS * 15
> # reader 15 * 23 =
> -NUM_TESTS=$(( 19 + 435 + ( ${NUM_CPUS} * 15 ) + 345 ))
> +NUM_TESTS=$(( 19 + 435 + ( NUM_CPUS * 15 ) + 345 ))
> 
> plan_tests	${NUM_TESTS}
> 
> #run all tests
> diag "Executing URCU tests"
> 
> -tmpfile=
> -trap cleanup SIGINT SIGTERM EXIT
> -tmpfile=$(mktemp)
> 
> #extra options, e.g. for setting affinity on even CPUs :
> #EXTRA_OPTS=$(for a in $(seq 0 2 127); do echo -n "-a ${a} "; done)
> @@ -67,16 +64,16 @@ BATCH_ARRAY="1 2 4 8 16 32 64 128 256 512 1024 2048 4096
> 8192 16384 32768 65536
> 	     131072 262144"
> BATCH_TEST_ARRAY="test_urcu_gc"
> 
> -NR_WRITERS=$((${NUM_CPUS} / 2))
> +NR_WRITERS=$((NUM_CPUS / 2))
> +NR_READERS=$((NUM_CPUS - NR_WRITERS))
> 
> -NR_READERS=$((${NUM_CPUS} - ${NR_WRITERS}))
> for BATCH_SIZE in ${BATCH_ARRAY}; do
> 	for TEST in ${BATCH_TEST_ARRAY}; do
> -		okx $test_time_bin ./${TEST} ${NR_READERS} ${NR_WRITERS} ${DURATION} \
> -			-d 0 -b ${BATCH_SIZE} ${EXTRA_OPTS} 2>${tmpfile}
> -		cat $tmpfile | while read line; do
> -			echo "# $line"
> -		done
> +		okx ${TEST_TIME_BIN} ./"${TEST}" "${NR_READERS}" "${NR_WRITERS}"
> "${DURATION}" \
> +			-d 0 -b "${BATCH_SIZE}" ${EXTRA_OPTS} 2>"${TMPFILE}"
> +		while read line; do
> +			echo "## $line"
> +		done <"${TMPFILE}"
> 	done
> done
> 
> @@ -93,16 +90,16 @@ diag "Executing update fraction test"
> WDELAY_ARRAY="0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
>               65536 131072 262144 524288 1048576 2097152 4194304 8388608
>               16777216 33554432 67108864 134217728"
> -NR_WRITERS=$((${NUM_CPUS} / 2))
> +NR_WRITERS=$((NUM_CPUS / 2))
> +NR_READERS=$((NUM_CPUS - NR_WRITERS))
> 
> -NR_READERS=$((${NUM_CPUS} - ${NR_WRITERS}))
> for WDELAY in ${WDELAY_ARRAY}; do
> 	for TEST in ${TEST_ARRAY}; do
> -		okx $test_time_bin ./${TEST} ${NR_READERS} ${NR_WRITERS} ${DURATION} \
> -			-d ${WDELAY} ${EXTRA_OPTS} 2>$tmpfile
> -		cat $tmpfile | while read line; do
> -			echo "# $line"
> -		done
> +		okx ${TEST_TIME_BIN} ./"${TEST}" "${NR_READERS}" "${NR_WRITERS}"
> "${DURATION}" \
> +			-d "${WDELAY}" ${EXTRA_OPTS} 2>"${TMPFILE}"
> +		while read line; do
> +			echo "## $line"
> +		done <"${TMPFILE}"
> 	done
> done
> 
> @@ -117,11 +114,11 @@ NR_WRITERS=0
> 
> for NR_READERS in $(xseq 1 ${NUM_CPUS}); do
> 	for TEST in ${TEST_ARRAY}; do
> -		okx $test_time_bin ./${TEST} ${NR_READERS} ${NR_WRITERS} ${DURATION} \
> -			${EXTRA_OPTS} 2>$tmpfile
> -		cat $tmpfile | while read line; do
> -			echo "# $line"
> -		done
> +		okx ${TEST_TIME_BIN} ./"${TEST}" "${NR_READERS}" "${NR_WRITERS}"
> "${DURATION}" \
> +			${EXTRA_OPTS} 2>"${TMPFILE}"
> +		while read line; do
> +			echo "## $line"
> +		done <"${TMPFILE}"
> 	done
> done
> 
> @@ -140,10 +137,10 @@ READERCSLEN_ARRAY="0 1 2 4 8 16 32 64 128 256 512 1024
> 2048 4096 8192 16384 3276
> 
> for READERCSLEN in ${READERCSLEN_ARRAY}; do
> 	for TEST in ${TEST_ARRAY}; do
> -		okx $test_time_bin ./${TEST} ${NR_READERS} ${NR_WRITERS} ${DURATION} \
> -			-c ${READERCSLEN} ${EXTRA_OPTS} 2>$tmpfile
> -		cat $tmpfile | while read line; do
> -			echo "# $line"
> -		done
> +		okx ${TEST_TIME_BIN} ./"${TEST}" "${NR_READERS}" "${NR_WRITERS}"
> "${DURATION}" \
> +			-c "${READERCSLEN}" ${EXTRA_OPTS} 2>"${TMPFILE}"
> +		while read line; do
> +			echo "## $line"
> +		done <"${TMPFILE}"
> 	done
> done
> diff --git a/tests/benchmark/runhash.sh b/tests/benchmark/runhash.sh
> index dc894d4..4f693d1 100755
> --- a/tests/benchmark/runhash.sh
> +++ b/tests/benchmark/runhash.sh
> @@ -1,5 +1,13 @@
> #!/bin/bash
> 
> +# 1st parameter: seconds per test
> +DURATION=$1
> +
> +if [ "x${DURATION}" = "x" ]; then
> +	echo "usage: $0 [DURATION]"
> +	exit 1
> +fi
> +
> source ../utils/tap.sh
> 
> NUM_TESTS=17
> @@ -13,9 +21,6 @@ diag "Executing Hash table test"
> #   add/remove/random
> # - validate that "nr_leaked" is always 0 in SUMMARY for all tests
> 
> -# 1st parameter: seconds per test
> -TIME_UNITS=$1
> -
> TESTPROG=./test_urcu_hash
> 
> NUM_CPUS="1"
> @@ -33,7 +38,7 @@ if [[ ${NUM_CPUS} -lt 4 ]]; then
> 	NUM_CPUS=4	# Floor at 4 due to following assumptions.
> fi
> 
> -THREAD_MUL=$(( ${NUM_CPUS} / 4 ))
> +THREAD_MUL=$((NUM_CPUS / 4))
> 
> EXTRA_PARAMS=-v
> 
> @@ -41,19 +46,19 @@ EXTRA_PARAMS=-v
> 
> # rw test, single key, replace and del randomly, 4 threads, auto resize.
> # key range: init, lookup, and update: 0 to 0
> -okx ${TESTPROG} 0 $((4*${THREAD_MUL})) ${TIME_UNITS} -A -s -M 1 -N 1 -O 1
> ${EXTRA_PARAMS}
> +okx ${TESTPROG} 0 $((4*THREAD_MUL)) "${DURATION}" -A -s -M 1 -N 1 -O 1
> ${EXTRA_PARAMS}
> 
> # rw test, single key, add unique and del randomly, 4 threads, auto resize.
> # key range: init, lookup, and update: 0 to 0
> -okx ${TESTPROG} 0 $((4*${THREAD_MUL})) ${TIME_UNITS} -A -u -M 1 -N 1 -O 1
> ${EXTRA_PARAMS}
> +okx ${TESTPROG} 0 $((4*THREAD_MUL)) "${DURATION}" -A -u -M 1 -N 1 -O 1
> ${EXTRA_PARAMS}
> 
> # rw test, single key, replace and del randomly, 2 lookup threads, 2 update
> threads, auto resize.
> # key range: init, lookup, and update: 0 to 0
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -s
> -M 1 -N 1 -O 1 ${EXTRA_PARAMS}
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -s -M 1 -N
> 1 -O 1 ${EXTRA_PARAMS}
> 
> # rw test, single key, add and del randomly, 2 lookup threads, 2 update threads,
> auto resize.
> # key range: init, lookup, and update: 0 to 0
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -M 1
> -N 1 -O 1 ${EXTRA_PARAMS}
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -M 1 -N 1
> -O 1 ${EXTRA_PARAMS}
> 
> 
> # ** test updates vs lookups with default table
> @@ -61,17 +66,17 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A -M 1
> # rw test, 2 lookup, 2 update threads, add and del randomly, auto resize.
> # max 1048576 buckets
> # key range: init, lookup, and update: 0 to 999999
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A
> ${EXTRA_PARAMS}
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A
> ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add_replace and del randomly, auto
> resize.
> # max 1048576 buckets
> # key range: init, lookup, and update: 0 to 999999
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -s
> ${EXTRA_PARAMS}
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -s
> ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add_unique and del randomly, auto resize.
> # max 1048576 buckets
> # key range: init, lookup, and update: 0 to 999999
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -u
> ${EXTRA_PARAMS}
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -u
> ${EXTRA_PARAMS}
> 
> 
> # test memory management backends
> @@ -80,21 +85,21 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A -u ${
> # max buckets: 1048576
> # key range: init, lookup, and update: 0 to 99999999
> # mm backend: "order"
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -m 1
> -n 1048576 -i \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -m 1 -n
> 1048576 -i \
> 	-M 100000000 -N 100000000 -O 100000000 -B order ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add only, auto resize.
> # max buckets: 1048576
> # key range: init, lookup, and update: 0 to 99999999
> # mm backend: "chunk"
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -m 1
> -n 1048576 -i \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -m 1 -n
> 1048576 -i \
> 	-M 100000000 -N 100000000 -O 100000000 -B chunk ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add only, auto resize.
> # max buckets: 1048576
> # key range: init, lookup, and update: 0 to 99999999
> # mm backend: "mmap"
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A -m 1
> -n 1048576 -i \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A -m 1 -n
> 1048576 -i \
> 	-M 100000000 -N 100000000 -O 100000000 -B mmap ${EXTRA_PARAMS}
> 
> 
> @@ -106,7 +111,7 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A -m 1
> # key range: lookup: 1000000 to 1999999
> # NOTE: reader threads in this test should never have a successful
> # lookup. TODO
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-R 1000000 ${EXTRA_PARAMS}
> 
> # ** small key range
> @@ -114,19 +119,19 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A \
> # rw test, 2 lookup, 2 update threads, add and del randomly, auto resize.
> # max 1048576 buckets
> # key range: init, update, and lookups: 0 to 9
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-M 10 -N 10 -O 10 ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add_unique and del randomly, auto resize.
> # max 1048576 buckets
> # key range: init, update, and lookups: 0 to 9
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-M 10 -N 10 -O 10 -u ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add_replace and del randomly, auto
> resize.
> # max 1048576 buckets
> # key range: init, update, and lookups: 0 to 9
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-M 10 -N 10 -O 10 -s ${EXTRA_PARAMS}
> 
> # ** lookup for known keys
> @@ -138,7 +143,7 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A \
> # key range: updates: 10 to 19
> # NOTE: reader threads in this test should always have successful
> # lookups. TODO
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-M 10 -N 10 -O 10 -R 0 -T 0 -S 10 -k 10 -s ${EXTRA_PARAMS}
> 
> # ** Uniqueness test
> @@ -147,12 +152,12 @@ okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL}))
> ${TIME_UNITS} -A \
> # max 1048576 buckets
> # asserts that no duplicates are observed by reader threads
> # standard length hash chains
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-U ${EXTRA_PARAMS}
> 
> # rw test, 2 lookup, 2 update threads, add_unique, add_replace and del randomly,
> auto resize.
> # max 1048576 buckets
> # asserts that no duplicates are observed by reader threads
> # create long hash chains: using modulo 4 on keys as hash
> -okx ${TESTPROG} $((2*${THREAD_MUL})) $((2*${THREAD_MUL})) ${TIME_UNITS} -A \
> +okx ${TESTPROG} $((2*THREAD_MUL)) $((2*THREAD_MUL)) "${DURATION}" -A \
> 	-U -C 4 ${EXTRA_PARAMS}
> diff --git a/tests/benchmark/runtests-batch.sh
> b/tests/benchmark/runtests-batch.sh
> index 0e5577b..f030de6 100755
> --- a/tests/benchmark/runtests-batch.sh
> +++ b/tests/benchmark/runtests-batch.sh
> @@ -1,35 +1,14 @@
> #!/bin/bash
> 
> -source ../utils/tap.sh
> +. ../utils/tap.sh
> +. ./common.sh
> 
> NUM_TESTS=1
> 
> plan_tests	${NUM_TESTS}
> 
> -. ./common.sh
> -
> -function cleanup()
> -{
> -	if [ x"$tmpfile" != x"" ]; then
> -		rm -f $tmpfile
> -	fi
> -}
> -
> -tmpfile=
> -trap cleanup SIGINT SIGTERM EXIT
> -tmpfile=$(mktemp)
> -
> -# Check if time bin is non-empty
> -if [ -n "$test_time_bin" ]; then
> -	time_command="$test_time_bin"
> -else
> -	time_command=""
> -fi
> -
> -tmpfile=$(mktemp)
> -
> #for a in test_urcu_gc test_urcu_gc_mb test_urcu_qsbr_gc; do
> for a in test_urcu_gc; do
> -	okx $time_command -o $tmpfile ./${a} $*
> -	diag "time: $(cat $tmpfile)"
> +	okx "${TEST_TIME_BIN}" ./"${a}" "$@" 2>"${TMPFILE}"
> +	diag "time: $(cat "${TMPFILE}")"
> done
> diff --git a/tests/benchmark/runtests.sh b/tests/benchmark/runtests.sh
> index 781e8f7..dd5d662 100755
> --- a/tests/benchmark/runtests.sh
> +++ b/tests/benchmark/runtests.sh
> @@ -1,35 +1,16 @@
> #!/bin/bash
> 
> -source ../utils/tap.sh
> +. ../utils/tap.sh
> +. ./common.sh
> 
> NUM_TESTS=15
> 
> plan_tests	${NUM_TESTS}
> 
> -. ./common.sh
> -
> -function cleanup()
> -{
> -	if [ x"$tmpfile" != x"" ]; then
> -		rm -f $tmpfile
> -	fi
> -}
> -
> -tmpfile=
> -trap cleanup SIGINT SIGTERM EXIT
> -tmpfile=$(mktemp)
> -
> -# Check if time bin is non-empty
> -if [ -n "$test_time_bin" ]; then
> -	time_command="$test_time_bin"
> -else
> -	time_command=""
> -fi
> -
> for a in test_urcu_gc test_urcu_signal_gc test_urcu_mb_gc test_urcu_qsbr_gc \
> 	test_urcu_lgc test_urcu_signal_lgc test_urcu_mb_lgc test_urcu_qsbr_lgc \
> 	test_urcu test_urcu_signal test_urcu_mb test_urcu_qsbr \
> 	test_rwlock test_perthreadlock test_mutex; do
> -	okx $time_command -o $tmpfile ./${a} $*
> -	diag "time: $(cat $tmpfile)"
> +	okx ${TEST_TIME_BIN} ./"${a}" "$@" 2>"${TMPFILE}"
> +	diag "time: $(cat "${TMPFILE}")"
> done
> --
> 2.7.4

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list