Skip to contentSkip to conversation

t_net.sh: make bash dep explicit and run only if SITNL is compiled

PATCH In review Antonio Quartulli 2 participants 4 messages Jun 15, 2019 – Jun 16, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 t_net.sh: make bash dep explicit and run only if SITNL is compiled

From: Antonio Quartulli <[email protected]...>

The t_net script currently has #!/bin/sh but it implicitly assume to be using bash.
This is fine on most distros, but some do not have sh pointing to bash by default, thus breaking the script.
Explicitly use bash to avoid failures.

On the other hand, run this unit-test only if SITNL was enabled at compile time. This test was designed with SITNL in mind and it is not yet ready for other backends.

Running only when SITNL is enabled implies running on Linux only therefore we are guaranteed that bash will always work.

While at it, also add a comment as of why the t_client.rc file is sourced.

---
 configure.ac                         | 3 +++
 tests/Makefile.am                    | 7 ++++---
 tests/t_net.sh                       | 3 ++-
 tests/unit_tests/openvpn/Makefile.am | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)
configure.ac +3 -0
index 2d78098e..8c95e310 100644
@@ -1226,11 +1226,14 @@ else
 	enable_plugin_down_root="no"
 fi
 
+AM_CONDITIONAL([HAVE_SITNL], [false])
+
 if test "${enable_iproute2}" = "yes"; then
 	test -z "${IPROUTE}" && AC_MSG_ERROR([ip utility is required but missing])
 	AC_DEFINE([ENABLE_IPROUTE], [1], [enable iproute2 support])
 else if test "${have_sitnl}" = "yes"; then
 	AC_DEFINE([ENABLE_SITNL], [1], [enable sitnl support])
+	AM_CONDITIONAL([HAVE_SITNL], [true])
 else if test "${WIN32}" != "yes" -a "${have_sitnl}" != "yes"; then
 	test -z "${ROUTE}" && AC_MSG_ERROR([route utility is required but missing])
 	test -z "${IFCONFIG}" && AC_MSG_ERROR([ifconfig utility is required but missing])
tests/Makefile.am +4 -3
index 67acf7e3..801192ed 100644
@@ -14,9 +14,10 @@ MAINTAINERCLEANFILES = \
 
 SUBDIRS = unit_tests
 
-test_scripts = t_net.sh
-test_scripts += t_client.sh
-test_scripts += t_lpback.sh t_cltsrv.sh
+test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
+if HAVE_SITNL
+test_scripts += t_net.sh
+endif
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
 TESTS = $(test_scripts)
tests/t_net.sh +2 -1
index 0be5bb42..1940ec92 100755
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
 
 IFACE="dummy0"
 UNIT_TEST="./unit_tests/openvpn/networking_testdriver"
@@ -74,6 +74,7 @@ run_test()
 
 ## execution starts here
 
+# t_client.rc required only for RUN_SUDO definition
 if [ -r "${top_builddir}"/t_client.rc ]; then
     . "${top_builddir}"/t_client.rc
 elif [ -r "${srcdir}"/t_client.rc ]; then
tests/unit_tests/openvpn/Makefile.am +1 -1
index c6da91a8..e61c57c4 100644
@@ -14,7 +14,7 @@ endif
 TESTS = $(test_binaries)
 check_PROGRAMS = $(test_binaries)
 
-if TARGET_LINUX
+if HAVE_SITNL
 check_PROGRAMS += networking_testdriver
 endif
 
Signature · 1 line
2.22.0
#1 lore raw

PATCH 2/2 t_net.sh: properly perform sudo check and print test steps

From: Antonio Quartulli <[email protected]...>

The current script is performing a tes ton the "kill" command, but this is not useful to the t_net.sh script as it never really executes it.

Rather test that "sudo <unit-test-binary>" really works.

<unit-test-binary> has to be added to the sudoers file if this test has to be performend unattanded. The path is:
./unit_tests/openvpn/networking_testdriver

On to pof that, print a simple OK for every test that is succesful.

---
 tests/t_net.sh                             | 12 +++++-------
 tests/unit_tests/openvpn/test_networking.c |  6 ++++++
 2 files changed, 11 insertions(+), 7 deletions(-)
tests/t_net.sh +5 -7
index 1940ec92..70e8517d 100755
@@ -125,14 +125,12 @@ else
         echo "      must be set correctly in 't_client.rc'. SKIP." >&2
         exit 77
     else
-        # We have to use sudo. Make sure that we (hopefully) do not have
-        # to ask the users password during the test. This is done to
-        # prevent timing issues, e.g. when the waits for openvpn to start
-	    if $RUN_SUDO $KILL_EXEC -0 $$
+        # check that we can run the unit-test binary with sudo
+	    if $RUN_SUDO $UNIT_TEST test
         then
-	        echo "$0: $RUN_SUDO $KILL_EXEC -0 succeeded, good."
+	        echo "$0: $RUN_SUDO $UNIT_TEST succeeded, good."
         else
-	        echo "$0: $RUN_SUDO $KILL_EXEC -0 failed, cannot go on. SKIP." >&2
+	        echo "$0: $RUN_SUDO $UNIT_TEST failed, cannot go on. SKIP." >&2
 	        exit 77
         fi
     fi
@@ -172,7 +170,7 @@ for i in $(seq 0 $MAX_TEST); do
             exit 1
         fi
     done
-
+    echo "Test $i: OK"
 done
 
 # remove interface for good
tests/unit_tests/openvpn/test_networking.c +6 -0
index 66035011..6c50da92 100644
@@ -185,6 +185,12 @@ main(int argc, char *argv[])
         return -1;
     }
 
+    /* the t_net script can use this command to perform a dry-run test */
+    if (strcmp(argv[1], "test") == 0)
+    {
+        return 0;
+    }
+
     if (argc > 3)
     {
         iface = argv[2];
Signature · 1 line
2.22.0
Acked-by on v1 2/2
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: t_net.sh: properly perform sudo check and print test steps

"because it makes sense" :-) - for added point, the declarations of KILL_EXEC= and CC= could also be removed. And the comment about Solaris... dead code...

Your patch has been applied to the master branch.

commit 6f89dac0ed8b84bc581ceda710c506be2287f2b5

Author: Antonio Quartulli
Date:   Sun Jun 16 01:02:13 2019 +0200
     t_net.sh: properly perform sudo check and print test steps

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

--
kind regards,

Gert Doering

Acked-by on v1 1/2
#3 lore raw
In reply to Antonio Quartulli

Does what it says and fixes "make check" errors on platforms that either have a non-bash in /bin/sh, or are not compiled with SITNL. (As a side note, the claim "this is fine on most distros" is one of the aspects that annoys me very much as a sysadmin - it is *never* fine to call /bin/sh and assume you can get any sort of functionality that is more than POSIX sh that way. Even if it works on your Linux system and that of your friend, it is still not *fine*, it will just cause annoyance for other people)

Your patch has been applied to the master branch.

commit af7d6d78ad5db7d538d908df42e03a8d1baa1708

Author: Antonio Quartulli
Date:   Sun Jun 16 01:02:12 2019 +0200
     t_net.sh: make bash dep explicit and run only if SITNL is compiled

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

--
kind regards,

Gert Doering