Remove some more bashisms and weird shell issues 04/243004/1
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 2 Sep 2020 07:02:54 +0000 (09:02 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 2 Sep 2020 10:45:13 +0000 (12:45 +0200)
Change-Id: Icc8b3e13caf5961cef0938b68718fb39565dacb4

tests/dlog_test.in

index b1c185f..1e32ea2 100644 (file)
@@ -253,7 +253,7 @@ if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
        dlogctl -s 100 && ok || fail
 
        LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
-       [ $(cat "$RUNTIME_FILTERS_DIR/05-logctl.conf" | grep -cE 'limiter\|\*\|\*=100') -eq 1 ] && ok || fail
+       [ "$(grep -cE 'limiter\|\*\|\*=100' $RUNTIME_FILTERS_DIR/05-logctl.conf)" -eq 1 ] && ok || fail
 
        # -g correctness
        LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
@@ -264,7 +264,7 @@ if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
        dlogctl -c -t '*' -p '*' && ok || fail
 
        LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
-       [ $(cat "$RUNTIME_FILTERS_DIR/05-logctl.conf" | grep -cE 'limiter\|\*\|\*=100') -eq 0 ] && ok || fail
+       [ "$(grep -cE 'limiter\|\*\|\*=100' $RUNTIME_FILTERS_DIR/05-logctl.conf)" -eq 0 ] && ok || fail
        dlogctl -c
 
        LOG_DETAILS="testing if the whole dynamic config directory is respected"
@@ -358,7 +358,7 @@ if [ "$quick" -ne 1 ]; then
        sleep 1
        kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
        UTIL_PID=-1
-       [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_continuous1_file` -eq 10 ]] && ok || fail
+       [ "$WAS_ALIVE" -eq 1 ] && [ "$(wc -l < $TESTDIR/dlog_continuous1_file)" -eq 10 ] && ok || fail
 
        LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
        dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
@@ -368,7 +368,7 @@ if [ "$quick" -ne 1 ]; then
        sleep 1
        kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
        UTIL_PID=-1
-       [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_continuous2_file` -eq 11 ]] && ok || fail
+       [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < $TESTDIR/dlog_continuous2_file)" -eq 11 ] && ok || fail
 
        LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
        dlogutil -mb main -f $TESTDIR/dlog_monitor1_file &
@@ -376,7 +376,7 @@ if [ "$quick" -ne 1 ]; then
        sleep 1
        kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
        UTIL_PID=-1
-       [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_monitor1_file` -eq 0 ]] && ok || fail
+       [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < $TESTDIR/dlog_monitor1_file)" -eq 0 ] && ok || fail
 
        LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
        dlogutil -mb main -f $TESTDIR/dlog_monitor2_file &
@@ -386,7 +386,7 @@ if [ "$quick" -ne 1 ]; then
        sleep 1
        kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
        UTIL_PID=-1
-       [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_monitor2_file` -eq 1 ]] && ok || fail
+       [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < $TESTDIR/dlog_monitor2_file)" -eq 1 ] && ok || fail
 fi
 
 LOG_DETAILS="testing if writing entries to rotating files works (-r/-n)"
@@ -472,19 +472,19 @@ regex_timezone="[\+-]{1}[0-9]{4}"
 for PARAM in always auto none never; do
        for PRIO in info error; do
                for OUTPUT in pipe tty; do
-                       if [[ "$PARAM" == "always" ]]; then
+                       if [ "$PARAM" = "always" ]; then
                                COLOR_EXPECTED=1
-                       elif [[ "$PARAM" == "never" ]]; then
+                       elif [ "$PARAM" = "never" ]; then
                                COLOR_EXPECTED=0
-                       elif [[ "$OUTPUT" == "tty" ]]; then
+                       elif [ "$OUTPUT" = "tty" ]; then
                                COLOR_EXPECTED=1
                        else
                                COLOR_EXPECTED=0
                        fi
 
-                       if [[ "$PRIO" == "info" ]]; then
+                       if [ "$PRIO" = "info" ]; then
                                REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
-                       elif [[ "$COLOR_EXPECTED" -eq 0 ]]; then
+                       elif [ "$COLOR_EXPECTED" -eq 0 ]; then
                                REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
                        else
                                REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m  \([[:print:]]*\)@~\[0m$/1/g"
@@ -493,25 +493,25 @@ for PARAM in always auto none never; do
                        # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
                        COMMAND="$cmd_prefix $format"
 
-                       if [[ "$PARAM" == "none" ]]; then
+                       if [ "$PARAM" = "none" ]; then
                                LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
                        else
                                COMMAND="$COMMAND --color=$PARAM"
                                LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
                        fi
 
-                       if [[ "$PRIO" == "info" ]]; then
+                       if [ "$PRIO" = "info" ]; then
                                COMMAND="$COMMAND '*:=I'"
                        else
                                COMMAND="$COMMAND '*:=E'"
                        fi
 
-                       if [[ "$OUTPUT" == "tty" ]]; then
+                       if [ "$OUTPUT" = "tty" ]; then
                                # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
                                COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
                        fi
 
-                       # $(eval) is needed since $($COMMAND) may contain $(")
+                       # $(eval) is needed since `$COMMAND` may contain `"`
                        line=$(eval $COMMAND | tr '\033\n' '~@')
                        [[ $(echo "$line" | sed -re "$REGEX") == "1" ]] && ok || fail
                done
@@ -523,49 +523,49 @@ done
 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="tag"
 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="thread"
 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="time"
 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="threadtime"
 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="kerneltime"
 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="recv_realtime"
 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="rwtime"
 REGEX="s/^$regex_time\s{1}\[[0-9[:space:]]{3,}.[0-9[:space:]]{3,}\]\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="long"
 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
@@ -577,24 +577,24 @@ format="brief"
 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="json"
-if [[ "$type" == "pipe" ]]; then
+if [ "$type" = "pipe" ]; then
        REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"recv_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"recv_mono\":[1-9][0-9]+\.[0-9]{9},\"sent_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"sent_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
 else
        REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"sent_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
 fi
 LOG_DETAILS="testing if \"$format\" print format works"
 line=$($cmd_prefix $format)
-[[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+[ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
 
 format="raw"
 LOG_DETAILS="testing if \"$format\" print format works"
 dlogutil -c
 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
 line=$($cmd_prefix $format)
-[[ "$line" == "rawformatTEST" ]] && ok || fail
+[ "$line" = "rawformatTEST" ] && ok || fail
 
 if [ "$quick" -ne 1 ]; then
        LOG_DETAILS="testing if dlogsend -d works"
@@ -609,7 +609,7 @@ fi
 
 if [ "$type" = "pipe" ]; then
        for format in raw brief long; do
-               for i in {1..8} 10 15 20 25 {513..520}; do
+               for i in 1 2 3 4 5 6 7 8 10 15 20 25 513 514 515 516 517 518 519 520; do
                        LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
                        log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
 
@@ -629,7 +629,7 @@ if [ "$type" = "pipe" ]; then
                                        ;;
                        esac
 
-                       [[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
+                       [ "$(echo $line | sed -re $REGEX)" = "1" ] && ok || fail
                done
        done
 fi
@@ -710,7 +710,7 @@ if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
 
        LOG_DETAILS="testing proper SMACK label for dynamic config file location"
        ORIG_FILTERS_DIR=$(cat $ORIGINAL_CONFIG_PATH | grep dynamic_config_path | awk -F "=" '{print $2}')
-       [ `ls -dZ $ORIG_FILTERS_DIR | awk -F " " '{print $1}'` = "System::Shared" ] && ok || fail
+       [ "$(ls -dZ $ORIG_FILTERS_DIR | awk -F ' ' '{print $1}')" = "System::Shared" ] && ok || fail
 
        if [ "$quick" -ne 1 ]; then
                # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
@@ -862,7 +862,7 @@ if [ "$quick" -ne 1 ]; then
        # group, sent about at the same time.
        (
                for i in $(seq 1 $SPAWN_CNT); do
-                       delay=$(( (RANDOM) % 5 ))
+                       delay=$(shuf -i 1-5 -n 1)
                        ( sleep $delay && dlogsend -b main -t DLOG_TESTSUITE $delay ) &
                done
                wait