#!/usr/bin/perl use strict; use warnings; use NGCP::Rtpengine::Test; use Test::More; use File::Temp; use IPC::Open3; use Time::HiRes; use POSIX ":sys_wait_h"; like $ENV{LD_PRELOAD}, qr/tests-preload/, 'LD_PRELOAD present'; is $ENV{RTPE_PRELOAD_TEST_ACTIVE}, '1', 'preload library is active'; ok -x $ENV{RTPE_BIN}, 'RTPE_BIN points to executable'; my $rtpe_stdout = File::Temp::tempfile() or die; my $rtpe_stderr = File::Temp::tempfile() or die; my $rtpe_pid = open3(undef, $rtpe_stdout, $rtpe_stderr, $ENV{RTPE_BIN}, qw(-t -1 -i 203.0.113.1 -i 2001:db8:4321::1 -n 2223 -c 12345 -f -L 7 -E -u 2222)); ok $rtpe_pid, 'daemon launched in background'; # keep trying to connect to the control socket while daemon is starting up my $c; for (1 .. 300) { $c = NGCP::Rtpengine->new($ENV{RTPENGINE_HOST} // 'localhost', $ENV{RTPENGINE_PORT} // 2223); last if $c->{socket}; Time::HiRes::usleep(100000); # 100 ms x 300 = 30 sec } 1; $c->{socket} or die; my ($cid, $ft, $tt, $r); sub new_call { undef($r); $cid = rand(); $ft = rand(); $tt = rand(); return; } sub crlf { my ($s) = @_; $s =~ s/\r\n/\n/gs; return $s; } sub sdp_split { my ($s) = @_; return split(/--------*\n/, $s); } sub offer_answer { my ($cmd, $name, $req, $sdps) = @_; my ($sdp_in, $exp_sdp_out) = sdp_split($sdps); $req->{command} = $cmd; $req->{'call-id'} = $cid; $req->{'from-tag'} = $ft; $req->{sdp} = $sdp_in; my $resp = $c->req($req); is $resp->{result}, 'ok', "$name - $cmd status"; my $regexp = "^\Q$exp_sdp_out\E\$"; $regexp =~ s/PORT/(\\d{1,5})/gs; $regexp =~ s/ICEBASE/([0-9a-zA-Z]{16})/gs; $regexp =~ s/ICEUFRAG/([0-9a-zA-Z]{8})/gs; $regexp =~ s/ICEPWD/([0-9a-zA-Z]{26})/gs; like crlf($resp->{sdp}), qr/$regexp/s, "$name - output $cmd SDP"; return; } sub offer { return offer_answer('offer', @_); } sub answer { my ($name, $req, $sdps) = @_; $req->{'to-tag'} = $tt; return offer_answer('answer', $name, $req, $sdps); } $r = $c->req({command => 'ping'}); ok $r->{result} eq 'pong', 'ping works, daemon operational'; # SDP in/out tests, various ICE options new_call; offer('plain SDP, no ICE', { ICE => 'remove' }, < 'remove' }, < 'remove' }, < 'remove' }, < 'force' }, < 'force' }, < 'force' }, < 'force' }, < 'remove' }, <