[ovs-dev] [PATCH] tests: Kill the daemons at cleanup only if pidfile exists.

Jakub Sitnicki jkbs at redhat.com
Fri Dec 22 15:12:52 UTC 2017


Remembering the PIDs of started daemon processes and killing them during
cleanup can interfere with other tests.

When the tests are running in parallel (i.e., -jX was passed in
TESTSUITEFLAGS), PIDs of daemons that have terminated before the cleanup
are subject to reuse by processes, or threads, spawned in another test.

This means that, while executing its 'cleanup' script, one test can
accidentally send a SIGTERM to a process running as a part of another
test and influence its outcome.

Retrieve the PID of the process we intend to kill at the last possible
moment to narrow down the window of opportunity for interfering.

This approach has a downside that if the daemon's pidfile has
disappeared but the process has not terminated, we will not clean it up
at the end of the test.

Signed-off-by: Jakub Sitnicki <jkbs at redhat.com>
---
 tests/ofproto-macros.at | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index 64cba44..ec5c892 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -55,8 +55,8 @@ m4_define([PARSE_LISTENING_PORT],
 
 start_daemon () {
     "$@" -vconsole:off --detach --no-chdir --pidfile --log-file
-    pid=`cat "$OVS_RUNDIR"/$1.pid`
-    on_exit "kill $pid"
+    pidfile="$OVS_RUNDIR"/$1.pid
+    on_exit "test -e \"$pidfile\" && kill \`cat \"$pidfile\"\`"
 }
 
 # sim_add SANDBOX
-- 
2.9.5



More information about the dev mailing list