From 46c25abd1cf46d52f94703ef6aeb36e7e0437c1d Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 7 Feb 2018 16:03:48 -0800 Subject: [PATCH] test/encoding: refactor to avoid escaping shell magic Signed-off-by: Patrick Donnelly --- qa/standalone/ceph-helpers.sh | 10 ++++++++-- src/test/encoding/check-generated.sh | 21 ++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/qa/standalone/ceph-helpers.sh b/qa/standalone/ceph-helpers.sh index 119a18530f75..f66eef3631bb 100755 --- a/qa/standalone/ceph-helpers.sh +++ b/qa/standalone/ceph-helpers.sh @@ -1733,13 +1733,19 @@ function test_display_logs() { # function run_in_background() { local pid_variable=$1 - shift; + shift # Execute the command and prepend the output with its pid # We enforce to return the exit status of the command and not the awk one. - ("$@" |& awk '{ a[i++] = $0 }END{for (i = 0; i in a; ++i) { print "'$$': " a[i]} }'; return ${PIPESTATUS[0]}) >&2 & + ("$@" |& sed 's/^/'$$': /'; return "${PIPESTATUS[0]}") >&2 & eval "$pid_variable+=\" $!\"" } +function save_stdout { + local out="$1" + shift + "$@" > "$out" +} + function test_run_in_background() { local pids run_in_background pids sleep 1 diff --git a/src/test/encoding/check-generated.sh b/src/test/encoding/check-generated.sh index d49186cd6d21..55a9195db859 100755 --- a/src/test/encoding/check-generated.sh +++ b/src/test/encoding/check-generated.sh @@ -15,21 +15,16 @@ failed=0 numtests=0 echo "checking ceph-dencoder generated test instances..." echo "numgen type" -for type in `ceph-dencoder list_types`; do +ceph-dencoder list_types | while read type; do num=`ceph-dencoder type $type count_tests` echo "$num $type" for n in `seq 1 1 $num 2>/dev/null`; do - safe_type=$type - # BitVector<2> needs some escaping to avoid bash issues with <> - if [ "$type" = "BitVector<2>" ]; then - safe_type="BitVector\<2\>" - fi pids="" - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n dump_json > $tmp1" - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n encode decode dump_json > $tmp2" - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n copy dump_json > $tmp3" - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n copy_ctor dump_json > $tmp4" + run_in_background pids save_stdout "$tmp1" ceph-dencoder type "$type" select_test "$n" dump_json + run_in_background pids save_stdout "$tmp2" ceph-dencoder type "$type" select_test "$n" encode decode dump_json + run_in_background pids save_stdout "$tmp3" ceph-dencoder type "$type" select_test "$n" copy dump_json + run_in_background pids save_stdout "$tmp4" ceph-dencoder type "$type" select_test "$n" copy_ctor dump_json wait_background pids if [ $? -ne 0 ]; then @@ -43,7 +38,7 @@ for type in `ceph-dencoder list_types`; do # the sorted json output. this is a weaker test, but is better # than nothing. deterministic=0 - if ceph-dencoder type $type is_deterministic; then + if ceph-dencoder type "$type" is_deterministic; then deterministic=1 fi @@ -80,8 +75,8 @@ for type in `ceph-dencoder list_types`; do fi if [ $deterministic -ne 0 ]; then - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n encode export $tmp1" - run_in_background pids bash -c "ceph-dencoder type $safe_type select_test $n encode decode encode export $tmp2" + run_in_background pids ceph-dencoder type "$type" select_test $n encode export "$tmp1" + run_in_background pids ceph-dencoder type "$type" select_test $n encode decode encode export "$tmp2" wait_background pids if ! cmp $tmp1 $tmp2; then -- 2.47.3