tests: delay reading of pidfile if found empty

Delay the reading of the PID file if it is found to be empty.
This can happend if swtpm is run by valgrind.

Also, use the passed parameters rather than the global ones to check
the PID file contents against the expected pid. So far this worked
because PID and PID_FILE were variables used by every caller.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2020-01-09 16:36:35 -05:00 committed by Stefan Berger
parent 41cae9e1bd
commit 996ad55fbc

View File

@ -735,8 +735,14 @@ function validate_pidfile()
{
local pid="$1"
local pidfile="$2"
local rpid="$(cat $pidfile)"
if [ "$PID" != "$(cat $PID_FILE)" ]; then
if [ -z "$rpid" ]; then
sleep 0.1
rpid="$(cat $pidfile)"
fi
if [ "$pid" != "$rpid" ]; then
echo "Error: pid file contains unexpected PID value."
echo "expected: $pid"
echo "actual : $(cat $pidfile)"