Skip to content

Commit

Permalink
New unit tests (#1955)
Browse files Browse the repository at this point in the history
* UT inc

* transport stats

* signaling deserialize unknown

* exclude samples

* more metrics coverage

* Sdp lib

* fix skt tst bug

* Improve deserialize and sdp api test

* RB ut improvement

* more uts

* sig api

* signaling api tests

* Stun

* more stun

* rtp

* more signaling

* update encoder stats

* Metrics coverage

* nat behavior ut

* more stun

* serialize

* twcc on callback

* FIR test

* enable ice stats

* more rtcp

* JB test

* metrics

* CleanUp

* Comments

* Remove config
  • Loading branch information
disa6302 authored Mar 28, 2024
1 parent 7cc13a5 commit b8fee3a
Show file tree
Hide file tree
Showing 27 changed files with 787 additions and 93 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ execute_process(
add_definitions(-DSDK_VERSION=\"${GIT_COMMIT_HASH}\")
add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\")
add_definitions(-DDETECTED_GIT_HASH)

if(NOT KVS_STACK_SIZE OR KVS_STACK_SIZE STREQUAL "")
message(STATUS "Setting default stack size to 64*1024")
set(KVS_DEFAULT_STACK_SIZE 65536)
Expand Down Expand Up @@ -387,8 +388,6 @@ file(GLOB WEBRTC_SIGNALING_CLIENT_SOURCE_FILES "src/source/Signaling/*.c")
include_directories(${OPEN_SRC_INCLUDE_DIRS})
include_directories(${OPEN_SRC_INSTALL_PREFIX}/include)
include_directories(${KINESIS_VIDEO_WEBRTC_CLIENT_SRC}/src/include)
# include sdp_config.h
include_directories(src/source/Sdp/kvssdp)

add_library(kvsWebrtcClient ${LINKAGE} ${WEBRTC_CLIENT_SOURCE_FILES} ${DATACHANNEL_SRC})

Expand Down
25 changes: 0 additions & 25 deletions src/source/Ice/IceAgentStateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,6 @@ STATUS stepIceAgentStateMachine(PIceAgent pIceAgent)
return retStatus;
}

STATUS acceptIceAgentMachineState(PIceAgent pIceAgent, UINT64 state)
{
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
BOOL locked = FALSE;

CHK(pIceAgent != NULL, STATUS_NULL_ARG);

MUTEX_LOCK(pIceAgent->lock);
locked = TRUE;

// Step the state machine
CHK_STATUS(acceptStateMachineState(pIceAgent->pStateMachine, state));

CleanUp:
CHK_LOG_ERR(retStatus);

if (locked) {
MUTEX_UNLOCK(pIceAgent->lock);
}

LEAVES();
return retStatus;
}

/*
* This function is supposed to be called from within IceAgentStateMachine callbacks. Assume holding IceAgent->lock
*/
Expand Down
19 changes: 6 additions & 13 deletions src/source/Ice/NatBehaviorDiscovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ STATUS natTestIncomingDataHandler(UINT64 customData, PSocketConnection pSocketCo
STATUS retStatus = STATUS_SUCCESS;
PNatTestData pNatTestData = (PNatTestData) customData;
PStunPacket pStunPacket = NULL;

MUTEX_LOCK(pNatTestData->lock);
if (pNatTestData->bindingResponseCount < DEFAULT_NAT_TEST_MAX_BINDING_REQUEST_COUNT * NAT_BEHAVIOR_DISCOVER_PROCESS_TEST_COUNT) {
CHK_STATUS(deserializeStunPacket(pBuffer, bufferLen, NULL, 0, &pStunPacket));
Expand All @@ -33,13 +32,13 @@ STATUS natTestIncomingDataHandler(UINT64 customData, PSocketConnection pSocketCo
*
*/
STATUS executeNatTest(PStunPacket bindingRequest, PKvsIpAddress pDestAddr, PSocketConnection pSocketConnection, UINT32 testIndex, PNatTestData pData,
PStunPacket* ppTestReponse)
PStunPacket* ppTestResponse)
{
PStunPacket testResponse = NULL;
UINT32 i, j;
STATUS retStatus = STATUS_SUCCESS;

CHK(bindingRequest != NULL && pDestAddr != NULL && pSocketConnection != NULL && pData != NULL && ppTestReponse != NULL, STATUS_NULL_ARG);
CHK(bindingRequest != NULL && pDestAddr != NULL && pSocketConnection != NULL && pData != NULL && ppTestResponse != NULL, STATUS_NULL_ARG);

MEMSET(bindingRequest->header.transactionId, 0x00, STUN_TRANSACTION_ID_LEN);

Expand All @@ -53,7 +52,7 @@ STATUS executeNatTest(PStunPacket bindingRequest, PKvsIpAddress pDestAddr, PSock
/* Send the STUN packet. Retry DEFAULT_NAT_TEST_MAX_BINDING_REQUEST_COUNT many times until a response
* is received */
for (i = 0; testResponse == NULL && i < DEFAULT_NAT_TEST_MAX_BINDING_REQUEST_COUNT; ++i) {
iceUtilsSendStunPacket(bindingRequest, NULL, 0, pDestAddr, pSocketConnection, NULL, FALSE);
CHK_STATUS(iceUtilsSendStunPacket(bindingRequest, NULL, 0, pDestAddr, pSocketConnection, NULL, FALSE));
CVAR_WAIT(pData->cvar, pData->lock, DEFAULT_TEST_NAT_TEST_RESPONSE_WAIT_TIME);
if (pData->bindingResponseCount > 0) {
for (j = 0; j < pData->bindingResponseCount; ++j) {
Expand All @@ -64,11 +63,10 @@ STATUS executeNatTest(PStunPacket bindingRequest, PKvsIpAddress pDestAddr, PSock
}
}
}

CleanUp:

if (ppTestReponse != NULL) {
*ppTestReponse = testResponse;
if (ppTestResponse != NULL) {
*ppTestResponse = testResponse;
}

CHK_LOG_ERR(retStatus);
Expand Down Expand Up @@ -274,11 +272,11 @@ STATUS discoverNatBehavior(PCHAR stunServer, NAT_BEHAVIOR* pNatMappingBehavior,
PKvsIpAddress pSelectedLocalInterface = NULL;
PConnectionListener pConnectionListener = NULL;

MEMSET(&customData, 0x00, SIZEOF(NatTestData));
CHK(stunServer != NULL && pNatMappingBehavior != NULL && pNatFilteringBehavior != NULL, STATUS_NULL_ARG);
CHK(!IS_EMPTY_STRING(stunServer), STATUS_INVALID_ARG);

MEMSET(&iceServerStun, 0x00, SIZEOF(IceServer));
MEMSET(&customData, 0x00, SIZEOF(NatTestData));
cvar = CVAR_CREATE();
lock = MUTEX_CREATE(FALSE);
CHK_STATUS(parseIceServer(&iceServerStun, stunServer, NULL, NULL));
Expand Down Expand Up @@ -334,24 +332,19 @@ STATUS discoverNatBehavior(PCHAR stunServer, NAT_BEHAVIOR* pNatMappingBehavior,
CHK_STATUS(discoverNatFilteringBehavior(&iceServerStun, &customData, pSocketConnection, pNatFilteringBehavior));

CleanUp:

if (locked) {
MUTEX_UNLOCK(lock);
}

if (pConnectionListener != NULL) {
connectionListenerRemoveAllConnection(pConnectionListener);
freeConnectionListener(&pConnectionListener);
}

if (pSocketConnection != NULL) {
freeSocketConnection(&pSocketConnection);
}

for (i = 0; i < customData.bindingResponseCount; ++i) {
freeStunPacket(&customData.bindingResponseList[i]);
}

if (cvar != INVALID_CVAR_VALUE) {
CVAR_FREE(cvar);
}
Expand Down
10 changes: 6 additions & 4 deletions src/source/Ice/SocketConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ STATUS createSocketConnection(KVS_IP_FAMILY_TYPE familyType, KVS_SOCKET_PROTOCOL
CHK_LOG_ERR(retStatus);

if (pBindAddr) {
getIpAddrStr(pBindAddr, ipAddr, ARRAY_SIZE(ipAddr));
DLOGD("create socket with ip: %s:%u. family:%d", ipAddr, (UINT16) getInt16(pBindAddr->port), pBindAddr->family);
if (STATUS_SUCCEEDED(getIpAddrStr(pBindAddr, ipAddr, ARRAY_SIZE(ipAddr)))) {
DLOGD("create socket with ip: %s:%u. family:%d", ipAddr, (UINT16) getInt16(pBindAddr->port), pBindAddr->family);
}
} else {
DLOGD("create socket without the bind address(%d:%d)", familyType, protocol);
}
if (protocol == KVS_SOCKET_PROTOCOL_TCP) {
getIpAddrStr(pPeerIpAddr, ipAddr, ARRAY_SIZE(ipAddr));
DLOGD("tcp socket connected with ip: %s:%u. family:%d", ipAddr, (UINT16) getInt16(pPeerIpAddr->port), pPeerIpAddr->family);
if (STATUS_SUCCEEDED(getIpAddrStr(pPeerIpAddr, ipAddr, ARRAY_SIZE(ipAddr)))) {
DLOGD("tcp socket connected with ip: %s:%u. family:%d", ipAddr, (UINT16) getInt16(pPeerIpAddr->port), pPeerIpAddr->family);
}
}

if (STATUS_FAILED(retStatus) && pSocketConnection != NULL) {
Expand Down
3 changes: 3 additions & 0 deletions src/source/Include_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C" {
// Project include files
////////////////////////////////////////////////////
#include <com/amazonaws/kinesis/video/webrtcclient/Include.h>
#include "kvssdp/sdp_data_types.h"

#ifdef KVS_USE_OPENSSL
#include <openssl/bio.h>
Expand Down Expand Up @@ -171,6 +172,8 @@ STATUS generateJSONSafeString(PCHAR, UINT32);

#define KVS_CONVERT_TIMESCALE(pts, from_timescale, to_timescale) (pts * to_timescale / from_timescale)

STATUS convertSdpErrorCode(SdpResult_t sdpResult);

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 7 additions & 4 deletions src/source/Metrics/Metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ STATUS getIceCandidatePairStats(PRtcPeerConnection pRtcPeerConnection, PRtcIceCa
STATUS retStatus = STATUS_SUCCESS;
BOOL locked = FALSE;
PIceAgent pIceAgent = NULL;
CHK((pRtcPeerConnection != NULL || pRtcIceCandidatePairStats != NULL), STATUS_NULL_ARG);
CHK((pRtcPeerConnection != NULL && pRtcIceCandidatePairStats != NULL), STATUS_NULL_ARG);
pIceAgent = ((PKvsPeerConnection) pRtcPeerConnection)->pIceAgent;
MUTEX_LOCK(pIceAgent->lock);
locked = TRUE;
Expand Down Expand Up @@ -58,8 +58,9 @@ STATUS getIceCandidateStats(PRtcPeerConnection pRtcPeerConnection, BOOL isRemote
{
STATUS retStatus = STATUS_SUCCESS;
BOOL locked = FALSE;
PIceAgent pIceAgent = ((PKvsPeerConnection) pRtcPeerConnection)->pIceAgent;
CHK((pRtcPeerConnection != NULL || pRtcIceCandidateStats != NULL), STATUS_NULL_ARG);
PIceAgent pIceAgent = NULL;
CHK((pRtcPeerConnection != NULL && pRtcIceCandidateStats != NULL), STATUS_NULL_ARG);
pIceAgent = ((PKvsPeerConnection) pRtcPeerConnection)->pIceAgent;
MUTEX_LOCK(pIceAgent->lock);
locked = TRUE;
CHK_WARN(pIceAgent->kvsRtcConfiguration.enableIceStats, STATUS_SUCCESS, "ICE stats not enabled");
Expand Down Expand Up @@ -87,9 +88,11 @@ STATUS getIceServerStats(PRtcPeerConnection pRtcPeerConnection, PRtcIceServerSta
{
STATUS retStatus = STATUS_SUCCESS;
BOOL locked = FALSE;
PIceAgent pIceAgent = ((PKvsPeerConnection) pRtcPeerConnection)->pIceAgent;
PIceAgent pIceAgent = NULL;
CHK((pRtcPeerConnection != NULL && pRtcIceServerStats != NULL), STATUS_NULL_ARG);

pIceAgent = ((PKvsPeerConnection) pRtcPeerConnection)->pIceAgent;

MUTEX_LOCK(pIceAgent->lock);
locked = TRUE;
CHK_WARN(pIceAgent->kvsRtcConfiguration.enableIceStats, STATUS_SUCCESS, "ICE stats not enabled");
Expand Down
5 changes: 0 additions & 5 deletions src/source/PeerConnection/DataChannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#include "../Include_i.h"

STATUS connectLocalDataChannel()
{
return STATUS_SUCCESS;
}

STATUS createDataChannel(PRtcPeerConnection pPeerConnection, PCHAR pDataChannelName, PRtcDataChannelInit pRtcDataChannelInit,
PRtcDataChannel* ppRtcDataChannel)
{
Expand Down
2 changes: 1 addition & 1 deletion src/source/PeerConnection/Rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static STATUS onRtcpFIRPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPe
}

// TODO handle SLI packet https://tools.ietf.org/html/rfc4585#section-6.3.2
static STATUS onRtcpSLIPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPeerConnection)
STATUS onRtcpSLIPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPeerConnection)
{
STATUS retStatus = STATUS_SUCCESS;
UINT32 mediaSSRC;
Expand Down
2 changes: 2 additions & 0 deletions src/source/PeerConnection/Rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ extern "C" {

STATUS onRtcpPacket(PKvsPeerConnection, PBYTE, UINT32);
STATUS onRtcpRembPacket(PRtcpPacket, PKvsPeerConnection);
STATUS onRtcpTwccPacket(PRtcpPacket, PKvsPeerConnection);
STATUS onRtcpPLIPacket(PRtcpPacket, PKvsPeerConnection);
STATUS onRtcpSLIPacket(PRtcpPacket, PKvsPeerConnection);
STATUS parseRtcpTwccPacket(PRtcpPacket, PTwccManager);
STATUS onRtcpTwccPacket(PRtcpPacket, PKvsPeerConnection);

Expand Down
2 changes: 1 addition & 1 deletion src/source/PeerConnection/Rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ STATUS createKvsRtpTransceiver(RTC_RTP_TRANSCEIVER_DIRECTION direction, DOUBLE r
pKvsRtpTransceiver->rollingBufferBitratebps = DEFAULT_EXPECTED_AUDIO_BIT_RATE;
} else {
DLOGW("Rolling buffer duration set to less than 100 Kibps for unknown codec. Setting to default %d bps", DEFAULT_EXPECTED_AUDIO_BIT_RATE);
rollingBufferBitratebps = DEFAULT_EXPECTED_VIDEO_BIT_RATE;
pKvsRtpTransceiver->rollingBufferBitratebps = DEFAULT_EXPECTED_VIDEO_BIT_RATE;
}

} else {
Expand Down
1 change: 0 additions & 1 deletion src/source/Sdp/Deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "kvssdp/sdp_deserializer.h"

// Convert error code from SDP library to STATUS.
extern STATUS convertSdpErrorCode(SdpResult_t sdpResult);

STATUS parseMediaName(PSessionDescription pSessionDescription, PCHAR mediaValue, SIZE_T mediaValueLength)
{
Expand Down
4 changes: 0 additions & 4 deletions src/source/Sdp/Serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "../Include_i.h"
#include "kvssdp/sdp_serializer.h"

// Convert error code from SDP library to STATUS.
extern STATUS convertSdpErrorCode(SdpResult_t sdpResult);

static STATUS serializeVersion(SdpSerializerContext_t* pCtx, UINT64 version)
{
ENTERS();
Expand Down Expand Up @@ -156,7 +153,6 @@ static STATUS serializeMediaConnectionInformation(SdpSerializerContext_t* pCtx,
SdpConnectionInfo_t connInfo;

CHK(pSdpConnectionInformation != NULL, STATUS_NULL_ARG);

if (pSdpConnectionInformation->networkType[0] != '\0') {
/* Append connection info */
CHK(STRCMP(pSdpConnectionInformation->networkType, "IN") == 0, STATUS_INVALID_ARG);
Expand Down
1 change: 1 addition & 0 deletions src/source/Signaling/FileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct {
STATUS deserializeSignalingCacheEntries(PCHAR, UINT64, PSignalingFileCacheEntry, PUINT32, PCHAR);
STATUS signalingCacheLoadFromFile(PCHAR, PCHAR, SIGNALING_CHANNEL_ROLE_TYPE, PSignalingFileCacheEntry, PBOOL, PCHAR);
STATUS signalingCacheSaveToFile(PSignalingFileCacheEntry, PCHAR);
STATUS createFileIfNotExist(PCHAR);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion tst/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ endif()

file(GLOB WEBRTC_CLIENT_TEST_SOURCE_FILES "*.cpp" )

add_executable(webrtc_client_test ${WEBRTC_CLIENT_TEST_SOURCE_FILES} SignalingApiFunctionalityTest.h)
add_executable(webrtc_client_test ${WEBRTC_CLIENT_TEST_SOURCE_FILES})
target_include_directories(webrtc_client_test PRIVATE "../configs")
target_link_libraries(webrtc_client_test
kvsWebrtcClient
kvsWebrtcSignalingClient
Expand Down
26 changes: 26 additions & 0 deletions tst/CryptoApiTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "WebRTCClientTestFixture.h"

namespace com {
namespace amazonaws {
namespace kinesis {
namespace video {
namespace webrtcclient {

class CryptoApiTest : public WebRtcClientTestBase {
};

TEST_F(CryptoApiTest, createRtcCertificateApiTest)
{
PRtcCertificate pRtcCertificate = NULL;
EXPECT_EQ(createRtcCertificate(NULL), STATUS_NULL_ARG);
EXPECT_EQ(createRtcCertificate(&pRtcCertificate), STATUS_SUCCESS);
EXPECT_TRUE(pRtcCertificate != NULL);
EXPECT_EQ(freeRtcCertificate(NULL), STATUS_SUCCESS);
EXPECT_EQ(freeRtcCertificate(pRtcCertificate), STATUS_SUCCESS);
}

} // namespace webrtcclient
} // namespace video
} // namespace kinesis
} // namespace amazonaws
} // namespace com
13 changes: 13 additions & 0 deletions tst/IceApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ namespace webrtcclient {
class IceApiTest : public WebRtcClientTestBase {
};

TEST_F(IceApiTest, failCreateSocketConnection)
{
PSocketConnection pDummySocketConnection = NULL;
KvsIpAddress localhost;

MEMSET(&localhost, 0x00, SIZEOF(KvsIpAddress));

EXPECT_EQ(createSocketConnection(KVS_IP_FAMILY_TYPE_IPV4, KVS_SOCKET_PROTOCOL_NONE, &localhost, NULL, 0, NULL, 0, &pDummySocketConnection), STATUS_INVALID_ARG);

EXPECT_EQ(createSocketConnection(KVS_IP_FAMILY_TYPE_IPV4, KVS_SOCKET_PROTOCOL_TCP, NULL, NULL, 0, NULL, 0, &pDummySocketConnection), STATUS_INVALID_ARG);

}

TEST_F(IceApiTest, ConnectionListenerApiTest)
{
PConnectionListener pConnectionListener = NULL;
Expand Down
9 changes: 9 additions & 0 deletions tst/JitterBufferFunctionalityTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ TEST_F(JitterBufferFunctionalityTest, continousPacketsComeInOrder)
clearJitterBufferForTest();
}

TEST_F(JitterBufferFunctionalityTest, createJitterBufferLatencySetTest)
{
EXPECT_EQ(createJitterBuffer(testFrameReadyFunc, testFrameDroppedFunc, testDepayRtpFunc, 0,
TEST_JITTER_BUFFER_CLOCK_RATE, (UINT64) this, &mJitterBuffer), STATUS_SUCCESS);
EXPECT_EQ(mJitterBuffer->maxLatency, DEFAULT_JITTER_BUFFER_MAX_LATENCY * TEST_JITTER_BUFFER_CLOCK_RATE / HUNDREDS_OF_NANOS_IN_A_SECOND);
EXPECT_EQ(freeJitterBuffer(NULL), STATUS_NULL_ARG);
EXPECT_EQ(freeJitterBuffer(&mJitterBuffer), STATUS_SUCCESS);
}

TEST_F(JitterBufferFunctionalityTest, continousPacketsComeOutOfOrder)
{
UINT32 i;
Expand Down
Loading

0 comments on commit b8fee3a

Please sign in to comment.