Add verbose mode and advanced argument parsing to the test script 27/243627/2
authorMateusz Majewski <m.majewski2@samsung.com>
Tue, 8 Sep 2020 13:35:52 +0000 (15:35 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 9 Sep 2020 07:50:53 +0000 (09:50 +0200)
Change-Id: I8aa0e4cd21e0acaabdad6b82817d63d6087466fc

tests/dlog_test.in

index 1e3fe1c..a281ed5 100644 (file)
@@ -84,22 +84,41 @@ ok() {
        LOG_DETAILS=
 }
 
-# supress stderr messages from subcommands
-exec 2> /dev/null
-
-USAGE_MESSAGE="usage: $0 pipe|logger|pipe_quick|logger_quick"
+USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger"
 
-if [ "$#" -ne 1 ]; then
+OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
+if [ "$?" -eq 1 ]; then
        echo "$USAGE_MESSAGE"
        exit 1
 fi
+eval set -- "$OPTS"
 
+verbose=0
+quick=0
+while true; do
+       case "$1" in
+               --verbose)
+                       verbose=1
+                       ;;
+               --quick)
+                       quick=1
+                       ;;
+               --)
+                       shift
+                       break
+                       ;;
+               *)
+                       echo "This should never happen :)"
+                       exit 1
+                       ;;
+       esac
+       shift
+done
 if [ "$1" = "pipe" ]; then
        type="pipe"
-       quick=0
 elif [ "$1" = "logger" ]; then
        type="logger"
-       quick=0
+# We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to.
 elif [ "$1" = "pipe_quick" ]; then
        type="pipe"
        quick=1
@@ -111,6 +130,11 @@ else
        exit 1
 fi
 
+# supress stderr messages from subcommands
+if [ "$verbose" -eq 0 ]; then
+       exec 2> /dev/null
+fi
+
 NEEDS_TO_QUIT=0
 capsh --print | grep Current | grep cap_syslog > /dev/null || { echo "*** ERROR: cap_syslog missing"; NEEDS_TO_QUIT=1; }
 mount | grep ' / ' | grep rw > /dev/null || { echo "*** ERROR: root not mounted read-write"; NEEDS_TO_QUIT=1; }
@@ -942,7 +966,7 @@ echo "$FAILS / $TOTAL tests failed"
 if [ "$quick" -eq 1 ]; then
        echo "WARNING: quick mode!"
        echo "About 20% slowest running tests are disabled. Some functionality might be untested."
-       echo "Rerun with '$type' instead of '${type}_quick' to run all tests."
+       echo "Rerun without '--quick' to run all tests."
 fi
 
 [ "$FAILS" -eq 0 ]