Skip to content

Commit

Permalink
[tests] Added a couple of tests on RCV loss list.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Sep 27, 2022
1 parent 90af35a commit 43a7c32
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 14 deletions.
18 changes: 10 additions & 8 deletions srtcore/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ srt::CRcvLossList::~CRcvLossList()
delete[] m_caSeq;
}

void srt::CRcvLossList::insert(int32_t seqno1, int32_t seqno2)
int srt::CRcvLossList::insert(int32_t seqno1, int32_t seqno2)
{
// Data to be inserted must be larger than all those in the list
if (m_iLargestSeq != SRT_SEQNO_NONE && CSeqNo::seqcmp(seqno1, m_iLargestSeq) <= 0)
Expand All @@ -522,7 +522,7 @@ void srt::CRcvLossList::insert(int32_t seqno1, int32_t seqno2)
log << "RCV-LOSS/insert: (" << seqno1 << "," << seqno2
<< ") to be inserted is too small: m_iLargestSeq=" << m_iLargestSeq << ", m_iLength=" << m_iLength
<< ", m_iHead=" << m_iHead << ", m_iTail=" << m_iTail << " -- REJECTING");
return;
return 0;
}
}
m_iLargestSeq = seqno2;
Expand All @@ -538,19 +538,19 @@ void srt::CRcvLossList::insert(int32_t seqno1, int32_t seqno2)

m_caSeq[m_iHead].inext = -1;
m_caSeq[m_iHead].iprior = -1;
m_iLength += CSeqNo::seqlen(seqno1, seqno2);

return;
const int n = CSeqNo::seqlen(seqno1, seqno2);
m_iLength += n;
return n;
}

// otherwise searching for the position where the node should be
int offset = CSeqNo::seqoff(m_caSeq[m_iHead].seqstart, seqno1);
const int offset = CSeqNo::seqoff(m_caSeq[m_iHead].seqstart, seqno1);
if (offset < 0)
{
LOGC(qrlog.Error,
log << "RCV-LOSS/insert: IPE: new LOSS %(" << seqno1 << "-" << seqno2 << ") PREDATES HEAD %"
<< m_caSeq[m_iHead].seqstart << " -- REJECTING");
return;
return -1;
}

int loc = (m_iHead + offset) % m_iSize;
Expand All @@ -575,7 +575,9 @@ void srt::CRcvLossList::insert(int32_t seqno1, int32_t seqno2)
m_iTail = loc;
}

m_iLength += CSeqNo::seqlen(seqno1, seqno2);
const int n = CSeqNo::seqlen(seqno1, seqno2);
m_iLength += n;
return n;
}

bool srt::CRcvLossList::remove(int32_t seqno)
Expand Down
4 changes: 2 additions & 2 deletions srtcore/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class CRcvLossList
/// Insert a series of loss seq. no. between "seqno1" and "seqno2" into the receiver's loss list.
/// @param [in] seqno1 sequence number starts.
/// @param [in] seqno2 seqeunce number ends.

void insert(int32_t seqno1, int32_t seqno2);
/// @return length of the loss record inserted (seqlen(seqno1, seqno2)), -1 on error.
int insert(int32_t seqno1, int32_t seqno2);

/// Remove a loss seq. no. from the receiver's loss list.
/// @param [in] seqno sequence number.
Expand Down
4 changes: 2 additions & 2 deletions test/filelist.maf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ test_epoll.cpp
test_fec_rebuilding.cpp
test_file_transmission.cpp
test_ipv6.cpp
test_list.cpp
test_listen_callback.cpp
test_losslist_rcv.cpp
test_losslist_snd.cpp
test_muxer.cpp
test_seqno.cpp
test_socket_options.cpp
Expand All @@ -28,4 +29,3 @@ test_reuseaddr.cpp
# Tests for bonding only - put here!

SOURCES - ENABLE_BONDING

71 changes: 71 additions & 0 deletions test/test_losslist_rcv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <iostream>
#include "gtest/gtest.h"
#include "common.h"
#include "list.h"

using namespace std;
using namespace srt;

class CRcvLossListTest
: public ::testing::Test
{
protected:
void SetUp() override
{
m_lossList = new CRcvLossList(CRcvLossListTest::SIZE);
}

void TearDown() override
{
delete m_lossList;
}

void CheckEmptyArray()
{
EXPECT_EQ(m_lossList->getLossLength(), 0);
EXPECT_EQ(m_lossList->getFirstLostSeq(), SRT_SEQNO_NONE);
}

void CleanUpList()
{
//while (m_lossList->popLostSeq() != -1);
}

CRcvLossList* m_lossList;

public:
const int SIZE = 256;
};

/// Check the state of the freshly created list.
/// Capacity, loss length and pop().
TEST_F(CRcvLossListTest, Create)
{
CheckEmptyArray();
}

///////////////////////////////////////////////////////////////////////////////
///
/// The first group of tests checks insert and pop()
///
///////////////////////////////////////////////////////////////////////////////

/// Insert and remove one element from the list.
TEST_F(CRcvLossListTest, InsertRemoveOneElem)
{
EXPECT_EQ(m_lossList->insert(1, 1), 1);

EXPECT_EQ(m_lossList->getLossLength(), 1);
EXPECT_TRUE(m_lossList->remove(1, 1));
CheckEmptyArray();
}


/// Insert and pop one element from the list.
TEST_F(CRcvLossListTest, InsertTwoElemsEdge)
{
EXPECT_EQ(m_lossList->insert(CSeqNo::m_iMaxSeqNo, 1), 3);
EXPECT_EQ(m_lossList->getLossLength(), 3);
EXPECT_TRUE(m_lossList->remove(CSeqNo::m_iMaxSeqNo, 1));
CheckEmptyArray();
}
4 changes: 2 additions & 2 deletions test/test_list.cpp → test/test_losslist_snd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class CSndLossListTest
void CheckEmptyArray()
{
EXPECT_EQ(m_lossList->getLossLength(), 0);
EXPECT_EQ(m_lossList->popLostSeq(), -1);
EXPECT_EQ(m_lossList->popLostSeq(), SRT_SEQNO_NONE);
}

void CleanUpList()
{
while (m_lossList->popLostSeq() != -1);
while (m_lossList->popLostSeq() != SRT_SEQNO_NONE);
}

CSndLossList* m_lossList;
Expand Down

0 comments on commit 43a7c32

Please sign in to comment.