]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/encoding: refactor to avoid escaping shell magic 19954/head
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 8 Feb 2018 00:03:48 +0000 (16:03 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 8 Feb 2018 02:03:05 +0000 (18:03 -0800)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
qa/standalone/ceph-helpers.sh
src/test/encoding/check-generated.sh

index 119a18530f7529cc4d336126c1f6f37726dec895..f66eef3631bb80f7d71788cc27e9d7b87143b6ed 100755 (executable)
@@ -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
index d49186cd6d212ce83a3e6105ca2d3cc36ae59ff5..55a9195db859c5c2392eeca3fbfefdf28cddd448 100755 (executable)
@@ -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