Improve test framework: report stderr/stdout of execute within fork

So that if execute() is used within a forked process and if that process
is terminated prematurely, the log will show what the execute'd command
was doing
This commit is contained in:
Andrew Bettison 2015-05-18 17:17:29 +09:30
parent c560374da5
commit f4df768041

View File

@ -829,6 +829,7 @@ _tfw_execute() {
fi
export TFWSTDOUT="${_tfw_stdout_file:-$_tfw_process_tmp/stdout}"
export TFWSTDERR="${_tfw_stderr_file:-$_tfw_process_tmp/stderr}"
echo "$executed" >"$_tfw_process_tmp/executing"
{
time -p "$_tfw_executable" "$@" >"$TFWSTDOUT" 2>"$TFWSTDERR"
} 2>"$_tfw_process_tmp/times" &
@ -874,6 +875,7 @@ _tfw_execute() {
done
wait $timer_pid
fi
rm -f "$_tfw_process_tmp/executing"
# Deal with core dump.
if $_tfw_opt_core_backtrace && [ -s core ]; then
tfw_core_backtrace "$_tfw_executable" core
@ -2050,6 +2052,15 @@ _tfw_forkwait() {
cat $_tfw_tmp/fork-$forkid/log.xtrace
echo "++++++++++"
fi
if [ -s $_tfw_tmp/fork-$forkid/executing ]; then
local executed="$(cat $_tfw_tmp/fork-$forkid/executing)"
echo "++++++++++ $desc stdout of ($executed) ++++++++++"
cat $_tfw_tmp/fork-$forkid/stdout
echo "++++++++++"
echo "++++++++++ $desc stderr of ($executed) ++++++++++"
cat $_tfw_tmp/fork-$forkid/stderr
echo "++++++++++"
fi
case $status in
0) ;;
143) ;; # terminated with SIGTERM (probably from fork_terminate)