]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: simplify program detection
authorDaiki Ueno <ueno@gnu.org>
Thu, 24 Sep 2020 09:48:24 +0000 (11:48 +0200)
committerDaiki Ueno <ueno@gnu.org>
Sat, 3 Oct 2020 12:47:29 +0000 (14:47 +0200)
Signed-off-by: Daiki Ueno <ueno@gnu.org>
tests/cert-reencoding.sh
tests/cert-tests/certtool
tests/ocsp-tests/ocsp-must-staple-connection
tests/ocsp-tests/ocsp-tls-connection
tests/scripts/common.sh
tests/slow/test-ciphers-common.sh
tests/slow/test-hash-large.sh

index 22396558a0db9abac0f5a671283896e97468884e..547a37ce10949160ea908b7902c152adda892f78 100755 (executable)
@@ -68,8 +68,8 @@ TLS_SERVER_PORT=$PORT
 eval "${GETPORT}"
 
 # Check for OpenSSL
-OPENSSL=`which openssl`
-if ! test -x "${OPENSSL}"; then
+: ${OPENSSL=openssl}
+if ! ("$OPENSSL" version) > /dev/null 2>&1; then
     echo "You need openssl to run this test."
     exit 77
 fi
index 4b194ac9ca03690b5576e2a960e818b55fabec81..11b8b8f6368344797972598a75785c756fc49668 100755 (executable)
@@ -39,8 +39,8 @@ if ! test -z "${VALGRIND}"; then
        VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND}"
 fi
 
-SETSID=$(which setsid)
-if test -n "${SETSID}";then
+: ${SETSID=setsid}
+if ("$SETSID" --version) >/dev/null 2>&1; then
        ${VALGRIND} "${CERTTOOL}" --generate-privkey --rsa --outfile ${TMPFILE1} --pkcs8 --password ${PASS}
        if test $? != 0;then
                echo "private key generation failed"
index 284864ff39843b4cfa910536b016af4a902285eb..049491add6ed66d2869db43db123c777f03f15ac 100755 (executable)
@@ -69,8 +69,8 @@ OCSP_PORT=$PORT
 SERVER_START_TIMEOUT=10
 
 # Check for OpenSSL
-OPENSSL=`which openssl`
-if ! test -x "${OPENSSL}"; then
+: ${OPENSSL=openssl}
+if ! ("$OPENSSL" version) > /dev/null 2>&1; then
     echo "You need openssl to run this test."
     exit 77
 fi
@@ -316,8 +316,8 @@ eval "${GETPORT}"
 TLS_SERVER_PORT=$PORT
 PORT=${TLS_SERVER_PORT}
 
-TIMEOUT=$(which timeout)
-if test -n "$TIMEOUT";then
+: ${TIMEOUT=timeout}
+if ("$TIMEOUT" --version) >/dev/null 2>&1; then
 ${TIMEOUT} 30 "${SERV}" --echo --disable-client-cert \
          --x509keyfile="${srcdir}/ocsp-tests/certs/server_good.key" \
          --x509certfile="${SERVER_CERT_FILE}" \
index 5431a3e67051882a19279dd6d760735303eebfbf..84eda22b2795e3e59cd544daf9c567eb54d8417c 100755 (executable)
@@ -69,8 +69,8 @@ OCSP_PORT=$PORT
 SERVER_START_TIMEOUT=10
 
 # Check for OpenSSL
-OPENSSL=`which openssl`
-if ! test -x "${OPENSSL}"; then
+: ${OPENSSL=openssl}
+if ! ("$OPENSSL" version) > /dev/null 2>&1; then
     echo "You need openssl to run this test."
     exit 77
 fi
index 275988ebd99d31d051356524fb84296ee46bbc83..b9ed7eff990426127892265fa969ebcefbaacb68 100644 (file)
@@ -26,35 +26,43 @@ export TZ="UTC"
 # command in the caller's PFCMD, or exit, indicating an unsupported
 # test.  Prefer ss from iproute2 over the older netstat.
 have_port_finder() {
-       for file in $(which ss 2> /dev/null) /*bin/ss /usr/*bin/ss /usr/local/*bin/ss;do
-               if test -x "$file";then
-                       PFCMD="$file";return 0
-               fi
-       done
+       # Prefer PFCMD if set
+       if test "${PFCMD+set}" = set; then
+               return
+       fi
 
-       if test -z "$PFCMD";then
-       for file in $(which netstat 2> /dev/null) /bin/netstat /usr/bin/netstat /usr/local/bin/netstat;do
-               if test -x "$file";then
-                       PFCMD="$file";return 0
+       if (ss --version) > /dev/null 2>&1; then
+               PFCMD=ss
+               return
+       fi
+
+       # 'ss' might be installed in /sbin
+       for dir in /sbin /usr/sbin /usr/local/sbin; do
+               if ($dir/ss --version) > /dev/null 2>&1; then
+                       PFCMD=$dir/ss
+                       return
                fi
        done
-       fi
 
-       if test -z "$PFCMD";then
-               echo "neither ss nor netstat found"
-               exit 1
+       # We can't assume netstat --version for portability reasons
+       if (type netstat) > /dev/null 2>&1; then
+               PFCMD=netstat
+               return
        fi
+
+       echo "neither ss nor netstat found" 1>&2
+       exit 77
 }
 
 check_if_port_in_use() {
-       local PORT="$1"
-       local PFCMD; have_port_finder
+       local PORT=$1
+       have_port_finder
        $PFCMD -an|grep "[\:\.]$PORT" >/dev/null 2>&1
 }
 
 check_if_port_listening() {
-       local PORT="$1"
-       local PFCMD; have_port_finder
+       local PORT=$1
+       have_port_finder
        $PFCMD -anl|grep "[\:\.]$PORT"|grep LISTEN >/dev/null 2>&1
 }
 
@@ -101,26 +109,20 @@ fail() {
 
 exit_if_non_x86()
 {
-which lscpu >/dev/null 2>&1
-if test $? = 0;then
-        $(which lscpu)|grep Architecture|grep x86
-        if test $? != 0;then
-                echo "non-x86 CPU detected"
-                exit 0
-        fi
-fi
+       if (lscpu --version) >/dev/null 2>&1 && \
+           ! lscpu 2>/dev/null | grep 'Architecture:[  ]*x86' >/dev/null; then
+               echo "non-x86 CPU detected"
+               exit
+       fi
 }
 
 exit_if_non_padlock()
 {
-which lscpu >/dev/null 2>&1
-if test $? = 0;then
-        $(which lscpu)|grep Flags|grep phe
-        if test $? != 0;then
-                echo "non-Via padlock CPU detected"
-                exit 0
-        fi
-fi
+       if (lscpu --version) >/dev/null 2>&1 && \
+          ! lscpu 2>/dev/null | grep 'Flags:[  ]*phe' >/dev/null; then
+               echo "non-Via padlock CPU detected"
+               exit
+       fi
 }
 
 wait_for_port()
index b1a238671af8c8e0aabfdc533319c02c54a8fdb3..e8b38c84ed78382e7d8fa9baacc9a98ecc32d7b8 100644 (file)
@@ -74,8 +74,8 @@ if test $ret != 0; then
 fi
 
 #SHANI
-$(which lscpu)|grep Flags|grep sha_ni >/dev/null
-if test $? = 0;then
+if (lscpu --version) >/dev/null 2>&1 && \
+   lscpu 2>/dev/null | grep 'Flags:[   ]*sha_ni' >/dev/null; then
        GNUTLS_CPUID_OVERRIDE=0x20 ${PROG}
        ret=$?
        if test $ret != 0; then
index 359a15ff722a539ff427ba2cfa044ce7f5ffd6c8..7a052bddcdd0d982b15e71b58dd5c8862378c72a 100755 (executable)
@@ -44,23 +44,19 @@ run_test() {
 #0x1: no optimizations
 #"": default optimizations
 
-SSSE3FLAG=""
-SHANIFLAG=""
-which lscpu >/dev/null 2>&1
-if test $? = 0;then
-        $(which lscpu)|grep Architecture|grep x86 >/dev/null
-        if test $? = 0;then
-                SSSE3FLAG="0x4"
+FLAGS=""
+if (lscpu --version) >/dev/null 2>&1; then
+        if lscpu 2>/dev/null | grep 'Flags:[   ]*ssse3' >/dev/null; then
+                FLAGS="$FLAGS 0x4"
         fi
 
-        $(which lscpu)|grep Flags|grep sha_ni >/dev/null
-        if test $? = 0;then
-                SHANIFLAG="0x20"
+        if lscpu 2>/dev/null | grep 'Flags:[   ]*sha_ni' >/dev/null; then
+                FLAGS="$FLAGS 0x20"
         fi
 fi
 
 WAITPID=""
-for flags in "" "0x1" ${SSSE3FLAG} ${SHANIFLAG};do
+for flags in "" "0x1" ${FLAGS};do
        run_test ${flags} &
        WAITPID="${WAITPID} $!"
 done