test/sip: Nuke it

These tests were never run on the CI and are not even in the build of Meson.

Change-Id: I0109633de2fd03b8589734d92c039b34d5b729bc
This commit is contained in:
Olivier Dion
2022-08-12 14:37:43 -04:00
committed by Sébastien Blin
parent 5eb4d10da7
commit e16ded663a
11 changed files with 1 additions and 1155 deletions

View File

@ -655,7 +655,6 @@ AC_CONFIG_FILES([Makefile \
src/Makefile \
ringtones/Makefile \
test/Makefile\
test/sip/Makefile
test/unitTest/Makefile \
man/Makefile \
doc/Makefile \

View File

@ -1,5 +1,5 @@
SUBDIRS = unitTest
SUBDIRS += sip
if ENABLE_FUZZING
SUBDIRS += fuzzing
endif

2
test/sip/.gitignore vendored
View File

@ -1,2 +0,0 @@
#test binaries
sip

View File

@ -1,10 +0,0 @@
# Rules for the test code (use `make check` to execute)
include $(top_srcdir)/globals.mk
AM_CXXFLAGS += -I$(top_srcdir)/src
AM_LDFLAGS += $(CPPUNIT_LIBS) $(top_builddir)/src/libring.la
check_PROGRAMS = ut_sip
ut_sip_SOURCES = sip.cpp test_SIP.h test_SIP.cpp
TESTS = $(check_PROGRAMS)

View File

@ -1,60 +0,0 @@
/*
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/CompilerOutputter.h>
#include "jami.h"
#include <stdexcept>
void init_daemon()
{
DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG | DRing::DRING_FLAG_CONSOLE_LOG));
DRing::start("test/unitTest/jami-sample.yml");
}
int main()
{
init_daemon();
CppUnit::TextUi::TestRunner runner;
// Register all tests
auto& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
// Use a compiler error format outputter for results and output into stderr
runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr ));
bool ret;
try {
// Run tests
ret = !runner.run("", false);
} catch (const std::exception& e) {
std::cerr << "Exception catched during tests: " << e.what() << '\n';
ret = 1;
}
DRing::fini();
return ret;
}

View File

@ -1,156 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp default 'uas' scenario. -->
<!-- -->
<scenario name="UAS responder put on hold then hungup">
<!-- This scenario implies a second call made by the uac which implies -->
<!-- This call to be put on hold automatically -->
<recv request="INVITE" crlf="true">
</recv>
<send>
<![CDATA[
SIP/2.0 180 Ringing
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK"
optional="true"
rtd="true"
crlf="true">
</recv>
<!-- Here process a second invite with updated sdp, this call is placed on HOLD -->
<!-- TODO: parse in sdp: Media Attribute (a): sendonly -->
<recv request="INVITE" crlf="true">
</recv>
<send>
<![CDATA[
SIP/2.0 100 Trying
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK"
optional="true"
rtd="true"
crlf="true">
</recv>
<!-- expect to be hung up immediately -->
<recv request="BYE">
</recv>
<send>
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<!-- Keep the call open for a while in case the 200 is lost to be -->
<!-- able to retransmit it if we receive the BYE again. -->
<timewait milliseconds="4000"/>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario>

View File

@ -1,160 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp default 'uac' scenario. -->
<!-- -->
<scenario name="Two simultaneous outgoing call Sipstone UAC">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<send retrans="500">
<![CDATA[
INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv response="100" optional="true">
</recv>
<recv response="180" optional="true">
</recv>
<recv response="183" optional="true">
</recv>
<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv response="200" rtd="true">
</recv>
<!-- Packet lost can be simulated in any send/recv message by -->
<!-- by adding the 'lost = "10"'. Value can be [1-100] percent. -->
<send>
<![CDATA[
ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>
<!-- Here is where the call is put on hold -->
<recv request="INVITE" crlf="true">
</recv>
<send>
<![CDATA[
SIP/2.0 100 Trying
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[pid]SIPpTag01[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK"
rtd="true"
crlf="true">
</recv>
<!-- The 'crlf' option inserts a blank line in the statistics report. -->
<send retrans="500">
<![CDATA[
BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 BYE
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>
<recv response="200" crlf="true">
</recv>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario>

View File

@ -1,187 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="UAS HOLD/OFFHOLD">
<!-- Receive a new call -->
<recv request="INVITE" crlf="true">
<action>
<ereg regexp="sendrecv" search_in="body" check_it="true" assign_to="1"/>
<log message="Media is [$1]"/>
</action>
</recv>
<send>
<![CDATA[
SIP/2.0 180 Ringing
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK" optional="true" rtd="true" crlf="true">
</recv>
<!-- This call is now on HOLD: sendonly tell to PBX to send music on hold-->
<recv request="INVITE" crlf="true">
<action>
<ereg regexp="sendonly" search_in="body" check_it="true" assign_to="2"/>
<log message="Media is [$2]"/>
</action>
</recv>
<send>
<![CDATA[
SIP/2.0 180 Ringing
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK" optional="true" rtd="true" crlf="true">
</recv>
<!-- OFFHOLD this call -->
<recv request="INVITE" crlf="true">
<action>
<ereg regexp="sendrecv" search_in="body" check_it="true" assign_to="3"/>
<log message="Media is [$3]"/>
</action>
</recv>
<send>
<![CDATA[
SIP/2.0 180 Ringing
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<send retrans="500">
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv request="ACK" optional="true" rtd="true" crlf="true">
</recv>
<!-- Hangup this call -->
<recv request="BYE">
</recv>
<send>
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0
]]>
</send>
<pause milliseconds="4000"/>
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario>

View File

@ -1,121 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp default 'uac' scenario. -->
<!-- -->
<scenario name="Basic Sipstone UAC">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. --
<send retrans="500">
<![CDATA[
INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv response="100"
optional="true">
</recv>
<recv response="180" optional="true">
</recv>
<recv response="183" optional="true">
</recv>
<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv response="200" rtd="true">
<action>
<ereg regexp="a=rtpmap:0 PCMU/8000" search_in="body" check_it="true" assign_to="1" />
<log message="Custom header is [$1]"/>
</action>
</recv>
<!-- Packet lost can be simulated in any send/recv message by -->
<!-- by adding the 'lost = "10"'. Value can be [1-100] percent. -->
<send>
<![CDATA[
ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>
<!-- This delay can be customized by the -d command-line option -->
<!-- or by adding a 'milliseconds = "value"' option here. -->
<pause/>
<!-- The 'crlf' option inserts a blank line in the statistics report. -->
<send retrans="500">
<![CDATA[
BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 BYE
Contact: sip:sipp@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test
Content-Length: 0
]]>
</send>
<recv response="200" crlf="true">
</recv>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
</scenario>

View File

@ -1,339 +0,0 @@
/*
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
* Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <pthread.h>
#include <string>
#include <thread>
#include "test_SIP.h"
#include "call_const.h"
using namespace jami;
using namespace std::literals;
static pthread_mutex_t count_mutex;
static pthread_cond_t count_nb_thread;
static int counter = 0;
CPPUNIT_TEST_SUITE_REGISTRATION(test_SIP);
/*
return an error if all call are not successful
*/
void*
sippThreadWithCount(void* str)
{
// number of time we use the mutex. Lock the utilisation of counter
pthread_mutex_lock(&count_mutex);
counter++;
pthread_mutex_unlock(&count_mutex);
// display what is send on the parameter of the method
std::string* command = (std::string*) (str);
std::cout << "test_SIP: " << command << std::endl;
// Set up the sipp instance in this thread in order to catch return value
// 0: All calls were successful
// 1: At least one call failed
// 97: exit on internal command. Calls may have been processed
// 99: Normal exit without calls processed
// -1: Fatal error
// -2: Fatal error binding a socket
int i = system(command->c_str()); // c_str() retrieve the *char of the string
CPPUNIT_ASSERT(i);
pthread_mutex_lock(&count_mutex);
counter--;
// ???
if (counter == 0)
pthread_cond_signal(&count_nb_thread);
pthread_mutex_unlock(&count_mutex);
pthread_exit(NULL);
}
RAIIThread
sippThread(const std::string& command)
{
return std::thread([command] {
std::cout << "test_SIP: " << command << std::endl;
// Set up the sipp instance in this thread in order to catch return value
// 0: All calls were successful
// 1: At least one call failed
// 97: exit on internal command. Calls may have been processed
// 99: Normal exit without calls processed
// -1: Fatal error
// -2: Fatal error binding a socket
auto ret = system(command.c_str());
std::cout << "test_SIP: Command executed by system returned: " << ret << std::endl;
});
}
void
test_SIP::setUp()
{
std::cout << "setup test SIP" << std::endl;
pthread_mutex_lock(&count_mutex);
counter = 0;
pthread_mutex_unlock(&count_mutex);
running_ = true;
eventLoop_ = RAIIThread(std::thread([this] {
while (running_) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}));
}
void
test_SIP::tearDown()
{
running_ = false;
eventLoop_.join();
// in order to stop any currently running threads
std::cout << "test_SIP: Clean all remaining sipp instances" << std::endl;
int ret = system("killall sipp");
if (ret)
std::cout << "test_SIP: Error from system call, killall sipp"
<< ", ret=" << ret << '\n';
Manager::instance().callFactory.clear();
}
void
test_SIP::testSimpleOutgoingIpCall()
{
std::cout << ">>>> test simple outgoing IP call <<<< " << '\n';
CPPUNIT_ASSERT(Manager::instance().callFactory.empty());
// start a user agent server waiting for a call
auto t = sippThread("sipp -sn uas -i 127.0.0.1 -p 5068 -m 1 -bg");
std::string testaccount("IP2IP");
std::string testcallnumber("sip:test@127.0.0.1:5068");
std::string testcallid; // returned by outgoingCall()
CPPUNIT_ASSERT(!Manager::instance().hasCurrentCall());
// start a new call sending INVITE message to sipp instance
testcallid = DRing::placeCallWithMedia(testaccount, testcallnumber, {});
// wait for receiving 180 and 200 message from peer
std::this_thread::sleep_for(std::chrono::seconds(1)); // should be enough
auto call = Manager::instance().getCallFromCallID(testcallid);
CPPUNIT_ASSERT(call);
// check call state
auto state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::CURRENT);
// hangup call
std::cout << ">>>> hangup the call " << '\n';
Manager::instance().hangupCall(testaccount, testcallid);
state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::OVER);
// Call must not not be available (except for thus how already own a pointer like us)
CPPUNIT_ASSERT(not Manager::instance().getCallFromCallID(testcallid));
}
void
test_SIP::testSimpleIncomingIpCall()
{
std::cout << ">>>> test simple incoming IP call <<<< " << '\n';
CPPUNIT_ASSERT(Manager::instance().callFactory.empty());
// command to be executed by the thread, user agent client which initiate a call and hangup
sippThread("sipp -sn uac 127.0.0.1 -i 127.0.0.1 -p 5062 -m 1 -bg");
// sleep a while to make sure that sipp insdtance is initialized and jami received
// the incoming invite.
std::this_thread::sleep_for(std::chrono::seconds(1));
// Answer this call
const auto& calls = Manager::instance().callFactory.getAllCalls();
const auto call = *calls.cbegin();
CPPUNIT_ASSERT(Manager::instance().answerCall("", call->getCallId()));
// hangup this call
Manager::instance().hangupCall("", call->getCallId());
auto state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::OVER);
}
void
test_SIP::testMultipleIncomingIpCall()
{
std::cout << ">>>> test multiple incoming IP call <<<< " << '\n';
CPPUNIT_ASSERT(Manager::instance().callFactory.empty());
// this value change the number of outgoing call we do
int numberOfCall = 5;
for (int i = 0; i < numberOfCall; i++) {
// start a user agent server waiting for a call
sippThread("sipp -sf sippxml/test_2.xml 127.0.0.1 -i 127.0.0.1 -p 506"
+ std::to_string(i + 1) + " -m 1 -bg");
// sleep a while to make sure that sipp insdtance is initialized and jami received
// the incoming invite.
std::this_thread::sleep_for(std::chrono::seconds(3));
const auto& calls = Manager::instance().callFactory.getAllCalls();
const auto call = *calls.cbegin();
auto state = call->getStateStr();
std::cout << ">>>> current call (call number: " + std::to_string(i) + ") state:" << state
<< '\n';
CPPUNIT_ASSERT(state
== DRing::Call::StateEvent::INCOMING); // TODO this state is sometime HOLD
// Answer this call
CPPUNIT_ASSERT(Manager::instance().answerCall("", call->getCallId()));
state = call->getStateStr();
std::cout << ">>>> current call (call number: " + std::to_string(i) + ") state:" << state
<< '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::CURRENT);
Manager::instance().onHoldCall("", call->getCallId());
state = call->getStateStr();
std::cout << ">>>> current call (call number: " + std::to_string(i) + ") state:" << state
<< '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::HOLD);
}
}
void
test_SIP::testMultipleOutgoingIpCall()
{
std::cout << ">>>> test multiple outgoing IP call <<<< " << '\n';
CPPUNIT_ASSERT(Manager::instance().callFactory.empty());
// this value change the number of outgoing call we do
int numberOfCall = 5;
// setup of the calls
std::string callNumber("sip:test@127.0.0.1:5061");
std::string testaccount("IP2IP");
std::string callID[numberOfCall];
for (int i = 0; i < numberOfCall; i++) {
// start a user agent server waiting for a call
sippThread("sipp -sn uas -i 127.0.0.1 -p 5061 -m " + std::to_string(numberOfCall) + " -bg");
callID[i] = DRing::placeCallWithMedia(testaccount, callNumber, {});
auto newCall = Manager::instance().getCallFromCallID(callID[i]);
CPPUNIT_ASSERT(newCall);
// wait for receiving 180 and 200 message from peer
std::this_thread::sleep_for(std::chrono::seconds(1)); // should be enough
auto state = newCall->getStateStr();
std::cout << ">>>> current call (call number: " + std::to_string(i) + ") state:" << state
<< '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::CURRENT);
// test the changement of calls states after doing a new call
if (i) {
for (int j = 0; j < i; j++) {
auto oldCall = Manager::instance().getCallFromCallID(callID[j]);
CPPUNIT_ASSERT(oldCall);
auto oldState = oldCall->getStateStr();
std::cout << ">>>> old call (call number: " + std::to_string(j) + ") state:"
<< oldState << '\n';
CPPUNIT_ASSERT(oldState == DRing::Call::StateEvent::HOLD);
}
}
}
// hangup all calls
for (int i = 0; i < numberOfCall; i++) {
auto call = Manager::instance().getCallFromCallID(callID[i]);
Manager::instance().hangupCall(testaccount, callID[i]);
auto state = call->getStateStr();
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::OVER);
}
}
void
test_SIP::testHoldIpCall()
{
std::cout << ">>>> test hold IP call <<<< " << '\n';
CPPUNIT_ASSERT(Manager::instance().callFactory.empty());
auto testAccount = "IP2IP";
auto testCallNumber = "sip:test@127.0.0.1:5062";
auto callThread = sippThread("sipp -sf sippxml/test_3.xml -i 127.0.0.1 -p 5062 -m 1 -bg");
auto testCallId = DRing::placeCallWithMedia(testAccount, testCallNumber, {});
auto call = Manager::instance().getCallFromCallID(testCallId);
std::this_thread::sleep_for(std::chrono::seconds(2));
auto state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::CURRENT);
Manager::instance().onHoldCall(testAccount, testCallId);
state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::HOLD);
Manager::instance().offHoldCall(testAccount, testCallId);
state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::CURRENT);
Manager::instance().hangupCall(testAccount, testCallId);
state = call->getStateStr();
std::cout << ">>>> call state is now " << state << '\n';
CPPUNIT_ASSERT(state == DRing::Call::StateEvent::OVER);
}
void
test_SIP::testSIPURI()
{
std::cout << ">>>> test SIPURI <<<< " << '\n';
auto foo = sip_utils::stripSipUriPrefix("<sip:17771234567@callcentric.com>"sv);
CPPUNIT_ASSERT_EQUAL("17771234567"sv, foo);
}

View File

@ -1,118 +0,0 @@
/*
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
* Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#pragma once
// Cppunit import
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
// Application import
#include "manager.h"
#include "sip/sipvoiplink.h"
#include "sip/sip_utils.h"
#include <atomic>
#include <thread>
class RAIIThread
{
public:
RAIIThread() = default;
RAIIThread(std::thread&& t) : thread_ {std::move(t)} {};
~RAIIThread() {
join();
}
void join() {
if (thread_.joinable())
thread_.join();
}
RAIIThread(RAIIThread&&) = default;
RAIIThread& operator=(RAIIThread&&) = default;
private:
std::thread thread_;
};
/*
* @file Test-sip.h
* @brief Regroups unitary tests related to the SIP module
*/
class test_SIP : public CppUnit::TestFixture
{
public:
//test_SIP() : CppUnit::TestCase("SIP module Tests") {}
/*
* Code factoring - Common resources can be initialized here.
* This method is called by unitcpp before each test
*/
void setUp();
/*
* Code factoring - Common resources can be released here.
* This method is called by unitcpp after each test
*/
void tearDown();
private:
// Create a simple IP call and test his state
void testSimpleOutgoingIpCall(void);
// Receive a new incoming call and test his state
void testSimpleIncomingIpCall(void);
// Test with multiple outgoing calls
void testMultipleOutgoingIpCall(void);
// TODO this test bug, the new calls are sometimes
// put in hold
void testMultipleIncomingIpCall(void);
// Test the hold state
void testHoldIpCall(void);
void testSIPURI(void);
/**
* Use cppunit library macros to add unit test to the factory
*/
CPPUNIT_TEST_SUITE(test_SIP);
CPPUNIT_TEST ( testSIPURI );
/*CPPUNIT_TEST ( testHoldIpCall );
CPPUNIT_TEST ( testSimpleOutgoingIpCall );
CPPUNIT_TEST ( testMultipleOutgoingIpCall );
CPPUNIT_TEST ( testSimpleIncomingIpCall );*/
//CPPUNIT_TEST ( testMultipleIncomingIpCall );
CPPUNIT_TEST_SUITE_END();
RAIIThread eventLoop_;
std::atomic_bool running_;
};