2012-04-10 03:11:15 +00:00
|
|
|
# Common definitions for all test suites in test/*
|
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
testdefs_sh=$(abspath "${BASH_SOURCE[0]}")
|
2012-05-20 04:18:02 +00:00
|
|
|
servald_source_root="${testdefs_sh%/*}"
|
|
|
|
servald_build_root="$servald_source_root"
|
2012-04-10 03:11:15 +00:00
|
|
|
|
|
|
|
# Utility function for setting up a fixture with a DNA server process:
|
2012-05-20 04:18:02 +00:00
|
|
|
# - Ensure that no servald processes are running
|
|
|
|
# - Start a servald server process
|
2012-04-10 03:11:15 +00:00
|
|
|
# - Ensure that it is still running after one second
|
2012-05-20 04:18:02 +00:00
|
|
|
start_servald_server() {
|
|
|
|
check_no_servald_processes
|
2012-04-10 03:11:15 +00:00
|
|
|
# Start DNA server
|
2012-05-20 04:18:02 +00:00
|
|
|
set -- $servald -v verbose -f $hlr_dat -S -n "$@"
|
|
|
|
echo "+ run $*"
|
|
|
|
"$@" >$DNATMP/servald.log 2>&1 &
|
2012-04-10 03:11:15 +00:00
|
|
|
sleep 1
|
2012-05-20 04:18:02 +00:00
|
|
|
local servald_basename="${servald##*/}"
|
|
|
|
if [ -z "$servald_basename" ]; then
|
|
|
|
error "cannot run test: \$servald not set"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
pid=$(ps -u$UID | awk '$4 == "'"$servald_basename"'" {print $1}')
|
2012-04-10 03:11:15 +00:00
|
|
|
if [ -z "$pid" ]; then
|
2012-05-20 04:18:02 +00:00
|
|
|
echo "servald server did not start"
|
|
|
|
tfw_cat --header=servald.log $SERVALINSTANCE_PATH/servald.log
|
2012-04-10 03:11:15 +00:00
|
|
|
fail
|
|
|
|
fi
|
|
|
|
if ! [ -s $SERVALINSTANCE_PATH/serval.pid ] && kill -0 $(cat $SERVALINSTANCE_PATH/serval.pid); then
|
|
|
|
echo "serval.pid was not created"
|
2012-05-20 04:18:02 +00:00
|
|
|
tfw_cat --header=servald.log $SERVALINSTANCE_PATH/servald.log
|
2012-04-10 03:11:15 +00:00
|
|
|
fail
|
|
|
|
fi
|
2012-05-20 04:18:02 +00:00
|
|
|
echo "# Started servald server process, pid=$pid"
|
2012-04-10 03:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function for tearing down DNA fixtures:
|
2012-05-20 04:18:02 +00:00
|
|
|
# - If a servald server process is running, then kill it
|
|
|
|
# - Cat any servald log file into the test log
|
|
|
|
# - Ensure that no servald processes are running
|
|
|
|
stop_servald_server() {
|
|
|
|
if [ -s $SERVALINSTANCE_PATH/servald.pid ]; then
|
|
|
|
local pid=$(cat $SERVALINSTANCE_PATH/servald.pid)
|
2012-04-10 03:11:15 +00:00
|
|
|
if kill $pid; then
|
2012-05-20 04:18:02 +00:00
|
|
|
echo "# Killed servald process pid=$pid"
|
2012-04-10 03:11:15 +00:00
|
|
|
else
|
|
|
|
error "# Dna process pid=$pid was not running"
|
|
|
|
fi
|
|
|
|
fi
|
2012-05-20 04:18:02 +00:00
|
|
|
if [ -s $DNATMP/servald.log ]; then
|
|
|
|
tfw_cat --header=servald.log $DNATMP/servald.log
|
2012-04-10 03:11:15 +00:00
|
|
|
fi
|
2012-05-20 04:18:02 +00:00
|
|
|
check_no_servald_processes
|
2012-04-10 03:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function for creating DNA fixtures:
|
2012-05-20 04:18:02 +00:00
|
|
|
# - Create a temporary directory to contain all servald-related files
|
|
|
|
# - set $servald and $hlr_dat variables
|
2012-04-10 03:11:15 +00:00
|
|
|
# - set SERVALINSTANCE_PATH environment variable
|
2012-04-12 08:06:27 +00:00
|
|
|
# - mkdir $SERVALINSTANCE_PATH unless --no-mkdir option given
|
2012-05-20 04:18:02 +00:00
|
|
|
setup_servald() {
|
|
|
|
servald=$(abspath "$servald_build_root/dna") # The DNA executable under test
|
|
|
|
if ! [ -x "$servald" ]; then
|
|
|
|
error "servald executable not present: $servald"
|
2012-04-10 03:11:15 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2012-05-20 04:18:02 +00:00
|
|
|
export DNATMP=$TFWTMP/servaldtmp
|
2012-04-17 07:24:39 +00:00
|
|
|
[ "$1" = --no-mkdir ] || mkdir $DNATMP
|
2012-04-10 03:11:15 +00:00
|
|
|
export SERVALINSTANCE_PATH=$DNATMP
|
|
|
|
hlr_dat=$SERVALINSTANCE_PATH/hlr.dat
|
2012-04-24 07:45:50 +00:00
|
|
|
unset SERVALD_OUTPUT_DELIMITER
|
2012-04-10 03:11:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
# Utility function for setting up DNA JNI fixtures:
|
|
|
|
# - check that libservald.so is present
|
|
|
|
# - set LD_LIBRARY_PATH so that libservald.so can be found
|
|
|
|
setup_servald_so() {
|
2012-05-20 04:18:02 +00:00
|
|
|
assert [ -r "$servald_build_root/libservald.so" ]
|
|
|
|
export LD_LIBRARY_PATH="$servald_build_root"
|
2012-04-24 07:36:48 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 03:11:15 +00:00
|
|
|
# Utility function for managing DNA fixtures:
|
|
|
|
# - Ensure there are no existing DNA server processes
|
2012-05-20 04:18:02 +00:00
|
|
|
check_no_servald_processes() {
|
|
|
|
local servald_basename="${servald##*/}"
|
|
|
|
if [ -z "$servald_basename" ]; then
|
|
|
|
error "cannot run test: \$servald not set"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
local pids=$(ps -u$UID | awk '$4 == "'"$servald_basename"'" {print $1}')
|
2012-04-10 03:11:15 +00:00
|
|
|
if [ -n "$pids" ]; then
|
2012-05-20 04:18:02 +00:00
|
|
|
error "cannot run test: $servald_basename process already running with pid: $pids"
|
2012-04-10 03:11:15 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2012-05-20 04:18:02 +00:00
|
|
|
echo "# No other $servald_basename processes running for uid=$UID"
|
2012-04-10 03:11:15 +00:00
|
|
|
return 0
|
|
|
|
}
|