From 2b4c4d02a543d21972484fca16c29e64ae4336cb Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 3 May 2021 22:47:48 +0200 Subject: [PATCH] TT#111150 When testing the daemon keep the stdout and stderr on failures To be able to ease diagnosing problems in the functional tests, we should not remove the log files storing stdout and stderr, otherwise debugging issue from a failed or crashing daemon turn to be rather brittle. Change-Id: Id285049da7ad030ef7b041f7e2dde86e97ef6487 --- perl/NGCP/Rtpengine/AutoTest.pm | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/perl/NGCP/Rtpengine/AutoTest.pm b/perl/NGCP/Rtpengine/AutoTest.pm index 423ec0912..2c499c1fa 100644 --- a/perl/NGCP/Rtpengine/AutoTest.pm +++ b/perl/NGCP/Rtpengine/AutoTest.pm @@ -42,8 +42,14 @@ sub autotest_start { ok -x $ENV{RTPE_BIN}, 'RTPE_BIN points to executable'; } - $rtpe_stdout = File::Temp::tempfile() or die; - $rtpe_stderr = File::Temp::tempfile() or die; + $rtpe_stdout = File::Temp->new( + TEMPLATE => 'rtpe-out.XXXXXXXXXX', + TMPDIR => 1, + ) or die; + $rtpe_stderr = File::Temp->new( + TEMPLATE => 'rtpe-err.XXXXXXXXXX', + TMPDIR => 1, + ) or die; SKIP: { skip 'daemon is running externally', 1 if $ENV{RTPE_TEST_NO_LAUNCH}; local $ENV{GLIB_SLICE} = 'debug-blocks'; @@ -248,11 +254,22 @@ sub new_tt { $tt = $tag_iter++ . "-test-totag" . $tag_suffix; } +sub terminate { + my $msg = shift; + + $rtpe_stdout->unlink_on_destroy(0); + $rtpe_stderr->unlink_on_destroy(0); + + print "hint: rtpe stdout output is at $rtpe_stdout\n"; + print "hint: rtpe stderr output is at $rtpe_stderr\n"; + + die "error: $msg\n"; +} END { if ($rtpe_pid) { - kill('INT', $rtpe_pid) or die; + kill('INT', $rtpe_pid) or terminate("cannot interrupt rtpe"); # wait for daemon to terminate my $status = -1; for (1 .. 50) { @@ -261,8 +278,8 @@ END { Time::HiRes::usleep(100000); # 100 ms x 50 = 5 sec } kill('KILL', $rtpe_pid) if $status == 0; - $status == $rtpe_pid or die; - $? == 0 or die; + $status == $rtpe_pid or terminate("cannot wait for process $rtpe_pid: $status: $!"); + $? == 0 or terminate("process exited with $?"); } }