From a8403c1de03ab41fd262c65e6b37e6ab430f1b42 Mon Sep 17 00:00:00 2001 From: Jonas Witschel Date: Thu, 27 Dec 2018 23:31:41 +0100 Subject: [PATCH 1/3] test: restrict netstat listing to IPv4 netstat shows both IPv4 and IPv6 bindings for tpm_server, but the tests only connect to the simulator using IPv4. If binding to the desired port only works for the IPv6 interface, we need to retry with a different port instead of erroneously proceeding with the test. Fixes #1227. Signed-off-by: Jonas Witschel --- script/int-log-compiler.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/int-log-compiler.sh b/script/int-log-compiler.sh index 4077fd41c..0e964b77e 100755 --- a/script/int-log-compiler.sh +++ b/script/int-log-compiler.sh @@ -202,9 +202,9 @@ for i in $(seq ${BACKOFF_MAX}); do fi PID=$(cat ${SIM_PID_FILE}) echo "simulator PID: ${PID}"; - netstat -ltpn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_DATA}" + netstat -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_DATA}" ret_data=$? - netstat -ltpn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_CMD}" + netstat -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_CMD}" ret_cmd=$? if [ \( $ret_data -eq 0 \) -a \( $ret_cmd -eq 0 \) ]; then echo "Simulator with PID ${PID} bound to port ${SIM_PORT_DATA} and " \ From 5914160819e065fed2998ba38dcb990105ea8b2c Mon Sep 17 00:00:00 2001 From: Jonas Witschel Date: Thu, 27 Dec 2018 23:53:21 +0100 Subject: [PATCH 2/3] test: replace netstat by ss netstat is deprecated in favour of ss, see the netstat man page. Signed-off-by: Jonas Witschel --- Dockerfile | 2 +- INSTALL.md | 4 ++-- configure.ac | 2 +- script/int-log-compiler.sh | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ad7c809b..d373f2dae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN apt-get update && apt-get install -y \ libssl-dev \ libtool \ m4 \ - net-tools \ + iproute2 \ pkg-config \ wget diff --git a/INSTALL.md b/INSTALL.md index 98ce298c2..1cf00cef9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -22,7 +22,7 @@ The following are dependencies only required when building test suites. * OpenSSL development libraries and header files * Unit test suite (see ./configure option --enable-unit): * cmocka unit test framework, version >= 1.0 -* netstat executable (usually in the net-tools package) +* ss executable (usually in the iproute2 package) * Code coverage analysis: * lcov * uthash development libraries and header files @@ -36,7 +36,7 @@ $ sudo apt -y install \ autoconf-archive \ libcmocka0 \ libcmocka-dev \ - net-tools \ + iproute2 \ build-essential \ git \ pkg-config \ diff --git a/configure.ac b/configure.ac index 14b127590..54a70f97a 100644 --- a/configure.ac +++ b/configure.ac @@ -167,7 +167,7 @@ AC_ARG_ENABLE([integration], [enable_integration=no]) AS_IF([test "x$enable_integration" = "xyes"], [ERROR_IF_NO_PROG([tpm_server]) - ERROR_IF_NO_PROG([netstat]) + ERROR_IF_NO_PROG([ss]) ERROR_IF_NO_PROG([ps]) ERROR_IF_NO_PROG([echo]) ERROR_IF_NO_PROG([kill]) diff --git a/script/int-log-compiler.sh b/script/int-log-compiler.sh index 0e964b77e..a471308ee 100755 --- a/script/int-log-compiler.sh +++ b/script/int-log-compiler.sh @@ -71,8 +71,8 @@ sanity_test () exit 1 fi - if [ -z "$(which netstat)" ]; then - echo "netstat not on PATH; exiting" + if [ -z "$(which ss)" ]; then + echo "ss not on PATH; exiting" exit 1 fi } @@ -202,9 +202,9 @@ for i in $(seq ${BACKOFF_MAX}); do fi PID=$(cat ${SIM_PID_FILE}) echo "simulator PID: ${PID}"; - netstat -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_DATA}" + ss -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_DATA}" ret_data=$? - netstat -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_CMD}" + ss -lt4pn 2> /dev/null | grep "${PID}" | grep -q "${SIM_PORT_CMD}" ret_cmd=$? if [ \( $ret_data -eq 0 \) -a \( $ret_cmd -eq 0 \) ]; then echo "Simulator with PID ${PID} bound to port ${SIM_PORT_DATA} and " \ From 2d1f3acbf16e1d1b2d0e25dfbf6773d5baf31577 Mon Sep 17 00:00:00 2001 From: Jonas Witschel Date: Thu, 27 Dec 2018 23:55:55 +0100 Subject: [PATCH 3/3] test: use stdbuf to disable buffering of daemon log output If the daemon is killed before the buffer is flushed, the log file can be incomplete. Signed-off-by: Jonas Witschel --- configure.ac | 2 +- script/int-log-compiler.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 54a70f97a..c0e3917e6 100644 --- a/configure.ac +++ b/configure.ac @@ -171,7 +171,7 @@ AS_IF([test "x$enable_integration" = "xyes"], ERROR_IF_NO_PROG([ps]) ERROR_IF_NO_PROG([echo]) ERROR_IF_NO_PROG([kill]) - ERROR_IF_NO_PROG([nohup]) + ERROR_IF_NO_PROG([stdbuf]) ERROR_IF_NO_PROG([sleep]) ERROR_IF_NO_PROG([cat]) ERROR_IF_NO_PROG([realpath]) diff --git a/script/int-log-compiler.sh b/script/int-log-compiler.sh index a471308ee..badcb8f95 100755 --- a/script/int-log-compiler.sh +++ b/script/int-log-compiler.sh @@ -102,7 +102,7 @@ daemon_start () local daemon_pid_file="$4" local daemon_env="$5" - env ${daemon_env} nohup ${daemon_bin} ${daemon_opts} > ${daemon_log_file} 2>&1 & + env ${daemon_env} stdbuf -o0 -e0 ${daemon_bin} ${daemon_opts} > ${daemon_log_file} 2>&1 & local ret=$? local pid=$! if [ ${ret} -ne 0 ]; then