Skip to contentSkip to conversation

introduce V= level to manage t_client.sh output verbosity

PATCH Superseded Gert Doering 3 participants 7 messages Sep 17, 2022 – Sep 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 introduce V= level to manage t_client.sh output verbosity

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

default is V=1 now

---
 tests/t_client.sh.in | 89 +++++++++++++++++++++++++++++---------------
 1 file changed, 59 insertions(+), 30 deletions(-)
tests/t_client.sh.in +59 -30
index 76ac9b22..4c217645 100755
@@ -121,17 +121,43 @@ else
     exit 1
 fi
 
+# verbosity, defaults to "1"
+V="${V:-1}"
+
 exit_code=0
 
 # ----------------------------------------------------------
 # helper functions
 # ----------------------------------------------------------
 
+# output progress information
+#  depending on verbosity level, collect & print only on failure
+output_start()
+{
+    outbuf="\n";
+    case $V in
+	0) outbuf="" ;;			# no per-test output at all
+	1) echo -e "$@" ;;		# compact, details only on failure
+	*) echo -e "\n$@\n" ;;		# print all, with a bit formatting
+    esac
+}
+
+output()
+{
+    NO_NL=''; if [ "X$1" = "-n" ] ; then NO_NL=$1 ; shift ; fi
+    case $V in
+	0) ;;				# no per-test output at all
+	1) outbuf="$outbuf\n$@" 	# print details only on failure
+	   test -z "$NO_NL" && outbuf="$outbuf\n"
+           ;;
+	*) echo -e $NO_NL "$@" ;;	# print everything
+    esac
+}
+
 # print failure message, increase FAIL counter
 fail()
 {
-    echo ""
-    echo "FAIL: $@" >&2
+    output "\nFAIL: $@"
     fail_count=$(( $fail_count + 1 ))
 }
 
@@ -236,7 +262,7 @@ run_ping_tests()
 
     for bytes in $sizes_list
     do
-	echo "run IPv$proto ping tests ($want), $bytes byte packets..."
+	output "run IPv$proto ping tests ($want), $bytes byte packets..."
 
 	echo "$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist" >>$LOGDIR/$SUF:fping.out
 	$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist >>$LOGDIR/$SUF:fping.out 2>&1
@@ -287,32 +313,32 @@ do
         up=""
     fi
 
-    echo -e "\n### test run $SUF: '$test_run_title' ###\n"
+    output_start "### test run $SUF: '$test_run_title' ###"
     fail_count=0
 
     if [ -n "$test_prep" ]; then
-        echo -e "running preparation: '$test_prep'"
+        output "running preparation: '$test_prep'"
         eval $test_prep
     fi
 
-    echo "save pre-openvpn ifconfig + route"
+    output "save pre-openvpn ifconfig + route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt
 
-    echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..."
+    output "\nrun pre-openvpn ping tests - targets must not be reachable..."
     run_ping_tests 4 want_fail "$ping4_hosts"
     run_ping_tests 6 want_fail "$ping6_hosts"
     if [ "$fail_count" = 0 ] ; then
-        echo -e "OK.\n"
+        output "OK.\n"
     else
-	echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF".
+	fail "make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF."
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=31
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
     openvpn_conf="$openvpn_conf --writepid $pidfile $up"
-    echo " run openvpn $openvpn_conf"
+    output " run openvpn $openvpn_conf"
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
     umask 022
     $RUN_SUDO "${top_builddir}/src/openvpn/openvpn" $openvpn_conf >>$LOGDIR/$SUF:openvpn.log &
@@ -335,25 +361,25 @@ do
 
     opid=`cat $pidfile`
     if [ -n "$opid" ]; then
-        echo "  OpenVPN running with PID $opid"
+        output "  OpenVPN running with PID $opid"
     else
-        echo "  Could not read OpenVPN PID file" >&2
+        output "  Could not read OpenVPN PID file"
     fi
 
     # If OpenVPN did not start
     if [ $ovpn_init_success -ne 1 -o -z "$opid" ]; then
-        echo "$0:  OpenVPN did not initialize in a reasonable time" >&2
+        output "$0:  OpenVPN did not initialize in a reasonable time"
         if [ -n "$opid" ]; then
            $RUN_SUDO $KILL_EXEC $opid
         fi
         $RUN_SUDO $KILL_EXEC $sudopid
-	echo "tail -5 $SUF:openvpn.log" >&2
-	tail -5 $LOGDIR/$SUF:openvpn.log >&2
-	echo -e "\nFAIL. skip rest of sub-tests for test run $SUF.\n" >&2
+	output "tail -5 $SUF:openvpn.log"
+	output "`tail -5 $LOGDIR/$SUF:openvpn.log`"
+	fail "skip rest of sub-tests for test run $SUF."
 	trap - 0 1 2 3 15
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     # make sure openvpn client is terminated in case shell exits
@@ -361,21 +387,21 @@ do
     trap "$RUN_SUDO $KILL_EXEC $opid ; trap - 0 ; exit 1" 1 2 3 15
 
     # compare whether anything changed in ifconfig/route setup?
-    echo "save ifconfig+route"
+    output "save ifconfig+route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt
 
-    echo -n "compare pre-openvpn ifconfig+route with current values..."
+    output -n "compare pre-openvpn ifconfig+route with current values..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route.txt >/dev/null
     then
 	fail "no differences between ifconfig/route before OpenVPN start and now."
     else
-	echo -e " OK!\n"
+	output " OK!\n"
     fi
 
     # post init script needed?
     if [ -n "$test_postinit" ]; then
-        echo -e "running post-init cmd: '$test_postinit'"
+        output "running post-init cmd: '$test_postinit'"
         eval $test_postinit
     fi
 
@@ -385,9 +411,9 @@ do
 
     run_ping_tests 4 want_ok "$ping4_hosts"
     run_ping_tests 6 want_ok "$ping6_hosts"
-    echo -e "ping tests done.\n"
+    output "ping tests done.\n"
 
-    echo "stopping OpenVPN"
+    output "stopping OpenVPN"
     $RUN_SUDO $KILL_EXEC $opid
     wait $!
     rc=$?
@@ -395,23 +421,26 @@ do
 	fail "OpenVPN return code $rc, expect 0"
     fi
 
-    echo -e "\nsave post-openvpn ifconfig + route..."
+    output "\nsave post-openvpn ifconfig + route..."
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt
 
-    echo -n "compare pre- and post-openvpn ifconfig + route..."
+    output -n "compare pre- and post-openvpn ifconfig + route..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt
     then
-	echo -e " OK.\n"
+	output " OK.\n"
     else
-	cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2
+	output `cat $LOGDIR/$SUF:ifconfig_route_diff.txt`
 	fail "differences between pre- and post-ifconfig/route"
     fi
     if [ "$fail_count" = 0 ] ; then
-        echo -e "test run $SUF: all tests OK.\n"
+        output "test run $SUF: all tests OK.\n"
 	SUMMARY_OK="$SUMMARY_OK $SUF"
     else
-	echo -e "test run $SUF: $fail_count test failures. FAIL.\n";
+	if [ "$V" -gt 0 ] ; then
+	    echo -e "$outbuf"
+	    echo "test run $SUF: $fail_count test failures. FAIL.\n"
+        fi
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
     fi
Signature · 1 line
2.35.1
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 41 lines · Gert Doering

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

default is V=1 now

---
  tests/t_client.sh.in | 89 +++++++++++++++++++++++++++++---------------
  1 file changed, 59 insertions(+), 30 deletions(-)
tests/t_client.sh.in +8 -0
index 76ac9b22..4c217645 100755
@@ -121,17 +121,43 @@ else
      exit 1
  fi
 
+# verbosity, defaults to "1"
+V="${V:-1}"
+
  exit_code=0
 
  # ----------------------------------------------------------
  # helper functions
  # ----------------------------------------------------------
 
+# output progress information
+#  depending on verbosity level, collect & print only on failure
+output_start()
+{
+    outbuf="\n";

tests/t_client.sh.in else · line 147

Quoted 10 lines
tests/t_client.sh.in +10 -0
+    case $V in
+	0) outbuf="" ;;			# no per-test output at all
+	1) echo -e "$@" ;;		# compact, details only on failure
+	*) echo -e "\n$@\n" ;;		# print all, with a bit formatting
+    esac
+}
+
+output()
+{
+    NO_NL=''; if [ "X$1" = "-n" ] ; then NO_NL=$1 ; shift ; fi

as mentioned on RIC, I think the check should be '[ "X$1" = "X-n" ]'.

Quoted 156 lines
tests/t_client.sh.in +35 -28
+    case $V in
+	0) ;;				# no per-test output at all
+	1) outbuf="$outbuf\n$@" 	# print details only on failure
+	   test -z "$NO_NL" && outbuf="$outbuf\n"
+           ;;
+	*) echo -e $NO_NL "$@" ;;	# print everything
+    esac
+}
+
  # print failure message, increase FAIL counter
  fail()
  {
-    echo ""
-    echo "FAIL: $@" >&2
+    output "\nFAIL: $@"
      fail_count=$(( $fail_count + 1 ))
  }
 
@@ -236,7 +262,7 @@ run_ping_tests()
 
      for bytes in $sizes_list
      do
-	echo "run IPv$proto ping tests ($want), $bytes byte packets..."
+	output "run IPv$proto ping tests ($want), $bytes byte packets..."
 
  	echo "$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist" >>$LOGDIR/$SUF:fping.out
  	$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist >>$LOGDIR/$SUF:fping.out 2>&1
@@ -287,32 +313,32 @@ do
          up=""
      fi
 
-    echo -e "\n### test run $SUF: '$test_run_title' ###\n"
+    output_start "### test run $SUF: '$test_run_title' ###"
      fail_count=0
 
      if [ -n "$test_prep" ]; then
-        echo -e "running preparation: '$test_prep'"
+        output "running preparation: '$test_prep'"
          eval $test_prep
      fi
 
-    echo "save pre-openvpn ifconfig + route"
+    output "save pre-openvpn ifconfig + route"
      get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt
 
-    echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..."
+    output "\nrun pre-openvpn ping tests - targets must not be reachable..."
      run_ping_tests 4 want_fail "$ping4_hosts"
      run_ping_tests 6 want_fail "$ping6_hosts"
      if [ "$fail_count" = 0 ] ; then
-        echo -e "OK.\n"
+        output "OK.\n"
      else
-	echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF".
+	fail "make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF."
  	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
  	exit_code=31
-	continue
+	echo -e "$outbuf" ; continue
      fi
 
      pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
      openvpn_conf="$openvpn_conf --writepid $pidfile $up"
-    echo " run openvpn $openvpn_conf"
+    output " run openvpn $openvpn_conf"
      echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
      umask 022
      $RUN_SUDO "${top_builddir}/src/openvpn/openvpn" $openvpn_conf >>$LOGDIR/$SUF:openvpn.log &
@@ -335,25 +361,25 @@ do
 
      opid=`cat $pidfile`
      if [ -n "$opid" ]; then
-        echo "  OpenVPN running with PID $opid"
+        output "  OpenVPN running with PID $opid"
      else
-        echo "  Could not read OpenVPN PID file" >&2
+        output "  Could not read OpenVPN PID file"
      fi
 
      # If OpenVPN did not start
      if [ $ovpn_init_success -ne 1 -o -z "$opid" ]; then
-        echo "$0:  OpenVPN did not initialize in a reasonable time" >&2
+        output "$0:  OpenVPN did not initialize in a reasonable time"
          if [ -n "$opid" ]; then
             $RUN_SUDO $KILL_EXEC $opid
          fi
          $RUN_SUDO $KILL_EXEC $sudopid
-	echo "tail -5 $SUF:openvpn.log" >&2
-	tail -5 $LOGDIR/$SUF:openvpn.log >&2
-	echo -e "\nFAIL. skip rest of sub-tests for test run $SUF.\n" >&2
+	output "tail -5 $SUF:openvpn.log"
+	output "`tail -5 $LOGDIR/$SUF:openvpn.log`"
+	fail "skip rest of sub-tests for test run $SUF."
  	trap - 0 1 2 3 15
  	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
  	exit_code=30
-	continue
+	echo -e "$outbuf" ; continue
      fi
 
      # make sure openvpn client is terminated in case shell exits
@@ -361,21 +387,21 @@ do
      trap "$RUN_SUDO $KILL_EXEC $opid ; trap - 0 ; exit 1" 1 2 3 15
 
      # compare whether anything changed in ifconfig/route setup?
-    echo "save ifconfig+route"
+    output "save ifconfig+route"
      get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt
 
-    echo -n "compare pre-openvpn ifconfig+route with current values..."
+    output -n "compare pre-openvpn ifconfig+route with current values..."
      if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
  	    $LOGDIR/$SUF:ifconfig_route.txt >/dev/null
      then
  	fail "no differences between ifconfig/route before OpenVPN start and now."
      else
-	echo -e " OK!\n"
+	output " OK!\n"
      fi
 
      # post init script needed?
      if [ -n "$test_postinit" ]; then
-        echo -e "running post-init cmd: '$test_postinit'"
+        output "running post-init cmd: '$test_postinit'"
          eval $test_postinit
      fi
 
@@ -385,9 +411,9 @@ do
 
      run_ping_tests 4 want_ok "$ping4_hosts"
      run_ping_tests 6 want_ok "$ping6_hosts"
-    echo -e "ping tests done.\n"
+    output "ping tests done.\n"
 
-    echo "stopping OpenVPN"
+    output "stopping OpenVPN"
      $RUN_SUDO $KILL_EXEC $opid
      wait $!
      rc=$?
@@ -395,23 +421,26 @@ do
  	fail "OpenVPN return code $rc, expect 0"
      fi
 
-    echo -e "\nsave post-openvpn ifconfig + route..."
+    output "\nsave post-openvpn ifconfig + route..."
      get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt
 
-    echo -n "compare pre- and post-openvpn ifconfig + route..."
+    output -n "compare pre- and post-openvpn ifconfig + route..."
      if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
  	    $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt
      then
-	echo -e " OK.\n"
+	output " OK.\n"
      else
-	cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2

tests/t_client.sh.in do · line 440

Quoted 10 lines
tests/t_client.sh.in +3 -2
+	output `cat $LOGDIR/$SUF:ifconfig_route_diff.txt`
  	fail "differences between pre- and post-ifconfig/route"
      fi
      if [ "$fail_count" = 0 ] ; then
-        echo -e "test run $SUF: all tests OK.\n"
+        output "test run $SUF: all tests OK.\n"
  	SUMMARY_OK="$SUMMARY_OK $SUF"
      else
-	echo -e "test run $SUF: $fail_count test failures. FAIL.\n";
+	if [ "$V" -gt 0 ] ; then

To avoid confusing the poor reader, isn't it better to change this test to '-eq 1' ?

if $V is 0, we don't print.

if $V is greater then 1, we have already printed everything.

'1' is the only missing case, where we buffered the output and waited for a failure.

The rest looks good and makes sense to me.

However, I couldn't test it because I have no working t_client.sh rig.

Cheers,

Quoted 6 lines
tests/t_client.sh.in +3 -0
+	    echo -e "$outbuf"
+	    echo "test run $SUF: $fail_count test failures. FAIL.\n"
+        fi
  	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
  	exit_code=30
      fi
Signature · 1 line
Antonio Quartulli
#2 lore raw

PATCH v2 1/1 introduce V= level to manage t_client.sh output verbosity

In reply to Gert Doering

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

default is V=1 now

v2:
fix erroneous test on "-n"
do not accumulate extra "\n" in outbuf (V=1) fix missing "-e" at "test failures. FAIL." message fix missing "\n" when including "diff" output fix missing "-n" when printing outbuf (= extra newline) (and more newlines being shuffled around)

---
 tests/t_client.sh.in | 91 +++++++++++++++++++++++++++++---------------
 1 file changed, 60 insertions(+), 31 deletions(-)
tests/t_client.sh.in +60 -31
index 76ac9b22..a3581905 100755
@@ -121,17 +121,43 @@ else
     exit 1
 fi
 
+# verbosity, defaults to "1"
+V="${V:-1}"
+
 exit_code=0
 
 # ----------------------------------------------------------
 # helper functions
 # ----------------------------------------------------------
 
+# output progress information
+#  depending on verbosity level, collect & print only on failure
+output_start()
+{
+    case $V in
+	0) outbuf="" ;;			# no per-test output at all
+	1) echo -e "$@"			# compact, details only on failure
+           outbuf="\n" ;;
+	*) echo -e "\n$@\n" ;;		# print all, with a bit formatting
+    esac
+}
+
+output()
+{
+    NO_NL=''; if [ "X$1" = "X-n" ] ; then NO_NL=$1 ; shift ; fi
+    case $V in
+	0) ;;				# no per-test output at all
+	1) outbuf="$outbuf$@" 		# print details only on failure
+	   test -z "$NO_NL" && outbuf="$outbuf\n"
+           ;;
+	*) echo -e $NO_NL "$@" ;;	# print everything
+    esac
+}
+
 # print failure message, increase FAIL counter
 fail()
 {
-    echo ""
-    echo "FAIL: $@" >&2
+    output "FAIL: $@\n"
     fail_count=$(( $fail_count + 1 ))
 }
 
@@ -236,7 +262,7 @@ run_ping_tests()
 
     for bytes in $sizes_list
     do
-	echo "run IPv$proto ping tests ($want), $bytes byte packets..."
+	output "run IPv$proto ping tests ($want), $bytes byte packets..."
 
 	echo "$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist" >>$LOGDIR/$SUF:fping.out
 	$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist >>$LOGDIR/$SUF:fping.out 2>&1
@@ -287,32 +313,32 @@ do
         up=""
     fi
 
-    echo -e "\n### test run $SUF: '$test_run_title' ###\n"
+    output_start "### test run $SUF: '$test_run_title' ###"
     fail_count=0
 
     if [ -n "$test_prep" ]; then
-        echo -e "running preparation: '$test_prep'"
+        output "running preparation: '$test_prep'"
         eval $test_prep
     fi
 
-    echo "save pre-openvpn ifconfig + route"
+    output "save pre-openvpn ifconfig + route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt
 
-    echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..."
+    output "\nrun pre-openvpn ping tests - targets must not be reachable..."
     run_ping_tests 4 want_fail "$ping4_hosts"
     run_ping_tests 6 want_fail "$ping6_hosts"
     if [ "$fail_count" = 0 ] ; then
-        echo -e "OK.\n"
+        output "OK.\n"
     else
-	echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF".
+	fail "make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF."
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=31
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
     openvpn_conf="$openvpn_conf --writepid $pidfile $up"
-    echo " run openvpn $openvpn_conf"
+    output " run openvpn $openvpn_conf"
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
     umask 022
     $RUN_SUDO "${top_builddir}/src/openvpn/openvpn" $openvpn_conf >>$LOGDIR/$SUF:openvpn.log &
@@ -335,25 +361,25 @@ do
 
     opid=`cat $pidfile`
     if [ -n "$opid" ]; then
-        echo "  OpenVPN running with PID $opid"
+        output "  OpenVPN running with PID $opid"
     else
-        echo "  Could not read OpenVPN PID file" >&2
+        output "  Could not read OpenVPN PID file"
     fi
 
     # If OpenVPN did not start
     if [ $ovpn_init_success -ne 1 -o -z "$opid" ]; then
-        echo "$0:  OpenVPN did not initialize in a reasonable time" >&2
+        output "$0:  OpenVPN did not initialize in a reasonable time"
         if [ -n "$opid" ]; then
            $RUN_SUDO $KILL_EXEC $opid
         fi
         $RUN_SUDO $KILL_EXEC $sudopid
-	echo "tail -5 $SUF:openvpn.log" >&2
-	tail -5 $LOGDIR/$SUF:openvpn.log >&2
-	echo -e "\nFAIL. skip rest of sub-tests for test run $SUF.\n" >&2
+	output "tail -5 $SUF:openvpn.log"
+	output "`tail -5 $LOGDIR/$SUF:openvpn.log`"
+	fail "skip rest of sub-tests for test run $SUF."
 	trap - 0 1 2 3 15
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     # make sure openvpn client is terminated in case shell exits
@@ -361,21 +387,21 @@ do
     trap "$RUN_SUDO $KILL_EXEC $opid ; trap - 0 ; exit 1" 1 2 3 15
 
     # compare whether anything changed in ifconfig/route setup?
-    echo "save ifconfig+route"
+    output "save ifconfig+route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt
 
-    echo -n "compare pre-openvpn ifconfig+route with current values..."
+    output -n "compare pre-openvpn ifconfig+route with current values..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route.txt >/dev/null
     then
 	fail "no differences between ifconfig/route before OpenVPN start and now."
     else
-	echo -e " OK!\n"
+	output " OK!\n"
     fi
 
     # post init script needed?
     if [ -n "$test_postinit" ]; then
-        echo -e "running post-init cmd: '$test_postinit'"
+        output "running post-init cmd: '$test_postinit'"
         eval $test_postinit
     fi
 
@@ -385,9 +411,9 @@ do
 
     run_ping_tests 4 want_ok "$ping4_hosts"
     run_ping_tests 6 want_ok "$ping6_hosts"
-    echo -e "ping tests done.\n"
+    output "ping tests done.\n"
 
-    echo "stopping OpenVPN"
+    output "stopping OpenVPN"
     $RUN_SUDO $KILL_EXEC $opid
     wait $!
     rc=$?
@@ -395,23 +421,26 @@ do
 	fail "OpenVPN return code $rc, expect 0"
     fi
 
-    echo -e "\nsave post-openvpn ifconfig + route..."
+    output "\nsave post-openvpn ifconfig + route..."
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt
 
-    echo -n "compare pre- and post-openvpn ifconfig + route..."
+    output -n "compare pre- and post-openvpn ifconfig + route..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt
     then
-	echo -e " OK.\n"
+	output " OK.\n"
     else
-	cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2
-	fail "differences between pre- and post-ifconfig/route"
+	output "\n" `cat $LOGDIR/$SUF:ifconfig_route_diff.txt` "\n"
+	fail "differences between pre- and post-ifconfig/route."
     fi
     if [ "$fail_count" = 0 ] ; then
-        echo -e "test run $SUF: all tests OK.\n"
+        output "test run $SUF: all tests OK.\n"
 	SUMMARY_OK="$SUMMARY_OK $SUF"
     else
-	echo -e "test run $SUF: $fail_count test failures. FAIL.\n";
+	if [ "$V" -gt 0 ] ; then
+	    echo -e -n "$outbuf"
+	    echo -e "test run $SUF: $fail_count test failures. FAIL.\n"
+        fi
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
     fi
Signature · 1 line
2.35.1
#3 lore raw

PATCH v3 1/1 introduce V= level to manage t_client.sh output verbosity

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

default is V=1 now

v2:
fix erroneous test on "-n"
do not accumulate extra "\n" in outbuf (V=1) fix missing "-e" at "test failures. FAIL." message fix missing "\n" when including "diff" output fix missing "-n" when printing outbuf (= extra newline) (and more newlines being shuffled around)

v3:
fix quoting on inclusion of "ifconfig/route diff", with newlines...

---
 tests/t_client.sh.in | 91 +++++++++++++++++++++++++++++---------------
 1 file changed, 60 insertions(+), 31 deletions(-)
tests/t_client.sh.in +60 -31
index 76ac9b22..d90fe638 100755
@@ -121,17 +121,43 @@ else
     exit 1
 fi
 
+# verbosity, defaults to "1"
+V="${V:-1}"
+
 exit_code=0
 
 # ----------------------------------------------------------
 # helper functions
 # ----------------------------------------------------------
 
+# output progress information
+#  depending on verbosity level, collect & print only on failure
+output_start()
+{
+    case $V in
+	0) outbuf="" ;;			# no per-test output at all
+	1) echo -e "$@"			# compact, details only on failure
+           outbuf="\n" ;;
+	*) echo -e "\n$@\n" ;;		# print all, with a bit formatting
+    esac
+}
+
+output()
+{
+    NO_NL=''; if [ "X$1" = "X-n" ] ; then NO_NL=$1 ; shift ; fi
+    case $V in
+	0) ;;				# no per-test output at all
+	1) outbuf="$outbuf$@" 		# print details only on failure
+	   test -z "$NO_NL" && outbuf="$outbuf\n"
+           ;;
+	*) echo -e $NO_NL "$@" ;;	# print everything
+    esac
+}
+
 # print failure message, increase FAIL counter
 fail()
 {
-    echo ""
-    echo "FAIL: $@" >&2
+    output "FAIL: $@\n"
     fail_count=$(( $fail_count + 1 ))
 }
 
@@ -236,7 +262,7 @@ run_ping_tests()
 
     for bytes in $sizes_list
     do
-	echo "run IPv$proto ping tests ($want), $bytes byte packets..."
+	output "run IPv$proto ping tests ($want), $bytes byte packets..."
 
 	echo "$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist" >>$LOGDIR/$SUF:fping.out
 	$cmd -b $bytes -C 20 -p 250 -q $FPING_EXTRA_ARGS $targetlist >>$LOGDIR/$SUF:fping.out 2>&1
@@ -287,32 +313,32 @@ do
         up=""
     fi
 
-    echo -e "\n### test run $SUF: '$test_run_title' ###\n"
+    output_start "### test run $SUF: '$test_run_title' ###"
     fail_count=0
 
     if [ -n "$test_prep" ]; then
-        echo -e "running preparation: '$test_prep'"
+        output "running preparation: '$test_prep'"
         eval $test_prep
     fi
 
-    echo "save pre-openvpn ifconfig + route"
+    output "save pre-openvpn ifconfig + route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt
 
-    echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..."
+    output "\nrun pre-openvpn ping tests - targets must not be reachable..."
     run_ping_tests 4 want_fail "$ping4_hosts"
     run_ping_tests 6 want_fail "$ping6_hosts"
     if [ "$fail_count" = 0 ] ; then
-        echo -e "OK.\n"
+        output "OK.\n"
     else
-	echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF".
+	fail "make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF."
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=31
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
     openvpn_conf="$openvpn_conf --writepid $pidfile $up"
-    echo " run openvpn $openvpn_conf"
+    output " run openvpn $openvpn_conf"
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
     umask 022
     $RUN_SUDO "${top_builddir}/src/openvpn/openvpn" $openvpn_conf >>$LOGDIR/$SUF:openvpn.log &
@@ -335,25 +361,25 @@ do
 
     opid=`cat $pidfile`
     if [ -n "$opid" ]; then
-        echo "  OpenVPN running with PID $opid"
+        output "  OpenVPN running with PID $opid"
     else
-        echo "  Could not read OpenVPN PID file" >&2
+        output "  Could not read OpenVPN PID file"
     fi
 
     # If OpenVPN did not start
     if [ $ovpn_init_success -ne 1 -o -z "$opid" ]; then
-        echo "$0:  OpenVPN did not initialize in a reasonable time" >&2
+        output "$0:  OpenVPN did not initialize in a reasonable time"
         if [ -n "$opid" ]; then
            $RUN_SUDO $KILL_EXEC $opid
         fi
         $RUN_SUDO $KILL_EXEC $sudopid
-	echo "tail -5 $SUF:openvpn.log" >&2
-	tail -5 $LOGDIR/$SUF:openvpn.log >&2
-	echo -e "\nFAIL. skip rest of sub-tests for test run $SUF.\n" >&2
+	output "tail -5 $SUF:openvpn.log"
+	output "`tail -5 $LOGDIR/$SUF:openvpn.log`"
+	fail "skip rest of sub-tests for test run $SUF."
 	trap - 0 1 2 3 15
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
-	continue
+	echo -e "$outbuf" ; continue
     fi
 
     # make sure openvpn client is terminated in case shell exits
@@ -361,21 +387,21 @@ do
     trap "$RUN_SUDO $KILL_EXEC $opid ; trap - 0 ; exit 1" 1 2 3 15
 
     # compare whether anything changed in ifconfig/route setup?
-    echo "save ifconfig+route"
+    output "save ifconfig+route"
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt
 
-    echo -n "compare pre-openvpn ifconfig+route with current values..."
+    output -n "compare pre-openvpn ifconfig+route with current values..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route.txt >/dev/null
     then
 	fail "no differences between ifconfig/route before OpenVPN start and now."
     else
-	echo -e " OK!\n"
+	output " OK!\n"
     fi
 
     # post init script needed?
     if [ -n "$test_postinit" ]; then
-        echo -e "running post-init cmd: '$test_postinit'"
+        output "running post-init cmd: '$test_postinit'"
         eval $test_postinit
     fi
 
@@ -385,9 +411,9 @@ do
 
     run_ping_tests 4 want_ok "$ping4_hosts"
     run_ping_tests 6 want_ok "$ping6_hosts"
-    echo -e "ping tests done.\n"
+    output "ping tests done.\n"
 
-    echo "stopping OpenVPN"
+    output "stopping OpenVPN"
     $RUN_SUDO $KILL_EXEC $opid
     wait $!
     rc=$?
@@ -395,23 +421,26 @@ do
 	fail "OpenVPN return code $rc, expect 0"
     fi
 
-    echo -e "\nsave post-openvpn ifconfig + route..."
+    output "\nsave post-openvpn ifconfig + route..."
     get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt
 
-    echo -n "compare pre- and post-openvpn ifconfig + route..."
+    output -n "compare pre- and post-openvpn ifconfig + route..."
     if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
 	    $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt
     then
-	echo -e " OK.\n"
+	output " OK.\n"
     else
-	cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2
-	fail "differences between pre- and post-ifconfig/route"
+	output "\n\n" "`cat $LOGDIR/$SUF:ifconfig_route_diff.txt`" "\n"
+	fail "differences between pre- and post-ifconfig/route."
     fi
     if [ "$fail_count" = 0 ] ; then
-        echo -e "test run $SUF: all tests OK.\n"
+        output "test run $SUF: all tests OK.\n"
 	SUMMARY_OK="$SUMMARY_OK $SUF"
     else
-	echo -e "test run $SUF: $fail_count test failures. FAIL.\n";
+	if [ "$V" -gt 0 ] ; then
+	    echo -e -n "$outbuf"
+	    echo -e "test run $SUF: $fail_count test failures. FAIL.\n"
+        fi
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
     fi
Signature · 1 line
2.35.1
Acked-by on v3 1/1
#4 lore raw
Quoted 5 lines · Gert Doering

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Quoted 9 lines

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

default is V=1 now

Seems to do what it is supposed to do.

Regards,

Signature · 1 line
  Frank Lichtenheld
#5 lore raw

Hi,

Quoted 13 lines · Frank Lichtenheld
Quoted 12 lines · Gert Doering

If t_client.sh is run interactively, more verbose output is useful to quickly see what it is doing. If run from a CI environment, going through lots of output for successful tests just to find the one that failed is non-useful.

Introduce V=<n> environment variable to control output verbosity

V=0 - do not print any per-test output at all, just overall summary V=1 - print single header line for each successful test
print full output for failing tests
V=99 - print full output, always, as before

Quoted 6 lines
Quoted 2 lines

default is V=1 now

Seems to do what it is supposed to do.

I also second this verdict:

Signature · 1 line
Antonio Quartulli
#6 lore raw
In reply to Gert Doering

Thanks for the review & testing ;-)

Patch has been applied to the master branch.

commit 398f73094a692ba46be7e3205b65d915d2593a64

Author: Gert Doering
Date:   Tue Sep 20 15:23:51 2022 +0200
     introduce V= level to manage t_client.sh output verbosity

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25285.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering