]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: rework port locking
authorDaiki Ueno <ueno@gnu.org>
Sun, 5 Sep 2021 15:28:43 +0000 (17:28 +0200)
committerDaiki Ueno <ueno@gnu.org>
Tue, 7 Sep 2021 07:53:15 +0000 (09:53 +0200)
This makes the locking logic per port, not per entire make process.
It also makes use of absolute paths for locking directory, so that
tlsfuzzer tests can use it.

Signed-off-by: Daiki Ueno <ueno@gnu.org>
tests/scripts/common.sh
tests/suite/Makefile.am

index 30afae3460424f66daff6a71cbe71996830bd537..0198bfadcc7c30676974cf1061ef7cc5a4b0ae7b 100644 (file)
@@ -54,10 +54,27 @@ have_port_finder() {
        exit 77
 }
 
+reserve_port() {
+       local PORT=$1
+       mkdir "$abs_top_builddir/tests/port.lock.d.$PORT" > /dev/null 2>&1 || return 1
+       echo "reserved port $PORT"
+       trap "unreserve_port $PORT" 0 1 15 2
+}
+
+unreserve_port() {
+       local PORT=$1
+       echo "unreserved port $PORT"
+       rmdir "$abs_top_builddir/tests/port.lock.d.$PORT" > /dev/null 2>&1 || :
+}
+
 check_if_port_in_use() {
        local PORT=$1
+       reserve_port $PORT
        have_port_finder
-       $PFCMD -an|grep "[\:\.]$PORT" >/dev/null 2>&1
+       if ! $PFCMD -an|grep "[\:\.]$PORT" >/dev/null 2>&1; then
+               return 1
+       fi
+       unreserve_port $PORT
 }
 
 check_if_port_listening() {
@@ -66,27 +83,8 @@ check_if_port_listening() {
        $PFCMD -anl|grep "[\:\.]$PORT"|grep LISTEN >/dev/null 2>&1
 }
 
-trap "rmdir \"$top_builddir/tests/port.lock.d\" > /dev/null 2>&1 || :" 1 15 2
-
-obtain_port_lock()
-{
-    local i
-    for i in 1 2 3 4 5 6; do
-        if mkdir "$top_builddir/tests/port.lock.d" > /dev/null 2>&1; then
-            return
-        fi
-        echo "try $i: obtaining port lock"
-       sleep 2
-    done
-    return 1
-}
-
 # Find a port number not currently in use.
 GETPORT='
-    obtain_port_lock()
-    if $? -ne 0; then
-        echo "failed to obtain port lock: continuing anyway"
-    fi
     rc=0
     unset myrandom
     while test $rc = 0; do
@@ -200,7 +198,6 @@ wait_server() {
                kill $PID
                exit 1
        fi
-       rmdir "$top_builddir/tests/port.lock.d" > /dev/null 2>&1 || :
 }
 
 wait_udp_server() {
index c91f00c0ff6ccf463595df4b89df08d0fcf0a7a9..2bfb3cd5fd4ab5e332276ccd235847e6fb90678d 100644 (file)
@@ -58,14 +58,15 @@ scripts_to_test = chain.sh \
        tls-fuzzer/tls-fuzzer-nolimit.sh tls-fuzzer/tls-fuzzer-nolimit-tls13.sh \
        multi-ticket-reception.sh
 
-TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) \
-       LC_ALL="C"                      \
-       PYTHON="$(PYTHON)"              \
-       VALGRIND="$(VALGRIND)"          \
-       top_builddir="$(top_builddir)"  \
-       srcdir="$(srcdir)"              \
-       ASAN_OPTIONS="detect_leaks=0"   \
-       GNUTLS_TEST_SUITE_RUN=1         \
+TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT)                                   \
+       LC_ALL="C"                                                      \
+       PYTHON="$(PYTHON)"                                              \
+       VALGRIND="$(VALGRIND)"                                          \
+       top_builddir="$(top_builddir)"                                  \
+       abs_top_builddir="$(abs_top_builddir)"                          \
+       srcdir="$(srcdir)"                                              \
+       ASAN_OPTIONS="detect_leaks=0"                                   \
+       GNUTLS_TEST_SUITE_RUN=1                                         \
        GNUTLS_SYSTEM_PRIORITY_FILE=$(abs_top_srcdir)/tests/system.prio \
        OPENSSL_ia32cap=0x00000000