mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 23:54:08 +00:00
Improve test framework: do not use $BASHPID
Also do not allow -j and --verbose to be given together
This commit is contained in:
parent
3c09a1ec7d
commit
c8a538337d
@ -150,6 +150,9 @@ runTests() {
|
||||
shift
|
||||
done
|
||||
_tfw_shopt_restore
|
||||
if $_tfw_verbose && [ $njobs -ne 1 ]; then
|
||||
_tfw_fatal "--verbose is incompatible with --jobs=$njobs"
|
||||
fi
|
||||
# Create an empty results directory.
|
||||
_tfw_results_dir="$_tfw_tmpdir/results"
|
||||
mkdir "$_tfw_results_dir" || return $?
|
||||
@ -183,23 +186,25 @@ runTests() {
|
||||
$_tfw_stop_on_failure && [ $_tfw_failcount -ne 0 ] && break
|
||||
# Start the next test in a child process.
|
||||
_tfw_echo_intro $testPosition $testNumber $testName
|
||||
[ $njobs -ne 1 ] && echo
|
||||
if $_tfw_verbose || [ $njobs -ne 1 ]; then
|
||||
echo
|
||||
fi
|
||||
echo "$testPosition $testNumber $testName" >"$_tfw_results_dir/$testName"
|
||||
(
|
||||
_tfw_unique=$BASHPID
|
||||
echo "$testPosition $testNumber $testName" >"$_tfw_results_dir/$_tfw_unique"
|
||||
_tfw_tmp=/tmp/_tfw-$_tfw_unique
|
||||
_tfw_test_name="$testName"
|
||||
_tfw_unique=$testNumber
|
||||
_tfw_tmp=/tmp/_tfw-$_tfw_suite_name-$_tfw_test_name
|
||||
trap '_tfw_status=$?; rm -rf "$_tfw_tmp"; exit $_tfw_status' EXIT SIGHUP SIGINT SIGTERM
|
||||
local start_time=$(_tfw_timestamp)
|
||||
local finish_time=unknown
|
||||
(
|
||||
_tfw_test_name="$testName"
|
||||
trap '_tfw_status=$?; _tfw_teardown; exit $_tfw_status' EXIT SIGHUP SIGINT SIGTERM
|
||||
_tfw_result=ERROR
|
||||
mkdir $_tfw_tmp || exit 255
|
||||
_tfw_setup
|
||||
_tfw_result=FAIL
|
||||
_tfw_phase=testcase
|
||||
echo "# call test_$_tfw_test_name()"
|
||||
tfw_log "# CALL test_$_tfw_test_name()"
|
||||
$_tfw_trace && set -x
|
||||
test_$_tfw_test_name
|
||||
_tfw_result=PASS
|
||||
@ -214,11 +219,11 @@ runTests() {
|
||||
finish_time=$(_tfw_timestamp)
|
||||
local result=FATAL
|
||||
case $stat in
|
||||
254) result=ERROR;;
|
||||
254) result=ERROR;;
|
||||
1) result=FAIL;;
|
||||
0) result=PASS;;
|
||||
0) result=PASS;;
|
||||
esac
|
||||
echo "$testPosition $testNumber $testName $result" >"$_tfw_results_dir/$_tfw_unique"
|
||||
echo "$testPosition $testNumber $testName $result" >"$_tfw_results_dir/$testName"
|
||||
{
|
||||
echo "Name: $testName"
|
||||
echo "Result: $result"
|
||||
@ -239,6 +244,7 @@ runTests() {
|
||||
exit 0
|
||||
) &
|
||||
_tfw_running_pids+=($!)
|
||||
ln -s "$_tfw_results_dir/$testName" "$_tfw_results_dir/pid-$!"
|
||||
done
|
||||
# Wait for all child processes to finish.
|
||||
while [ ${#_tfw_running_pids[*]} -ne 0 ]; do
|
||||
@ -271,8 +277,8 @@ _tfw_harvest_processes() {
|
||||
for pid in ${_tfw_running_pids[*]}; do
|
||||
if kill -0 $pid 2>/dev/null; then
|
||||
surviving_pids+=($pid)
|
||||
elif [ -s "$_tfw_results_dir/$pid" ]; then
|
||||
set -- $(<"$_tfw_results_dir/$pid")
|
||||
elif [ -s "$_tfw_results_dir/pid-$pid" ]; then
|
||||
set -- $(<"$_tfw_results_dir/pid-$pid")
|
||||
local testPosition="$1"
|
||||
local testNumber="$2"
|
||||
local testName="$3"
|
||||
@ -293,11 +299,11 @@ _tfw_harvest_processes() {
|
||||
;;
|
||||
esac
|
||||
local lines
|
||||
if [ $njobs -eq 1 ]; then
|
||||
if ! $_tfw_verbose && [ $njobs -eq 1 ]; then
|
||||
echo -n " "
|
||||
_tfw_echo_result "$result"
|
||||
echo
|
||||
elif lines=$($_tfw_tput lines); then
|
||||
elif ! $_tfw_verbose && lines=$($_tfw_tput lines); then
|
||||
local travel=$(($_tfw_test_number_watermark - $testPosition + 1))
|
||||
if [ $travel -gt 0 -a $travel -lt $lines ] && $_tfw_tput cuu $travel ; then
|
||||
_tfw_echo_intro $testPosition $testNumber $testName
|
||||
@ -673,9 +679,12 @@ _tfw_setup() {
|
||||
_tfw_stdout=5
|
||||
_tfw_stderr=5
|
||||
if $_tfw_verbose; then
|
||||
# These tail processes will die when the test case's subshell exits.
|
||||
tail --pid=$BASHPID --follow $_tfw_tmp/log.stdout >&$_tfw_stdout 2>/dev/null &
|
||||
tail --pid=$BASHPID --follow $_tfw_tmp/log.stderr >&$_tfw_stderr 2>/dev/null &
|
||||
# Find the PID of the current subshell process. Cannot use $BASHPID
|
||||
# because MacOS only has Bash-3.2, and $BASHPID was introduced in Bash-4.
|
||||
local mypid=$($BASH -c 'echo $PPID')
|
||||
# These tail processes will die when the current subshell exits.
|
||||
tail --pid=$mypid --follow $_tfw_tmp/log.stdout >&$_tfw_stdout 2>/dev/null &
|
||||
tail --pid=$mypid --follow $_tfw_tmp/log.stderr >&$_tfw_stderr 2>/dev/null &
|
||||
fi
|
||||
export TFWUNIQUE=$_tfw_unique
|
||||
export TFWVAR=$_tfw_tmp/var
|
||||
|
Loading…
x
Reference in New Issue
Block a user