diff options
Diffstat (limited to 'tests/scripts/common.sh')
-rw-r--r-- | tests/scripts/common.sh | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh index 275988ebd9..b9ed7eff99 100644 --- a/tests/scripts/common.sh +++ b/tests/scripts/common.sh @@ -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() |