Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{FEC} Added unittests #858

Merged
merged 45 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c0db916
Random refactoring and small bugfixes during FEC works.
Sep 4, 2019
275518d
Added lacking setupCC fix
Sep 4, 2019
73f7a4c
Added changes for packet filter FW and API
Sep 4, 2019
b856a84
Added packetfiler option doc
Sep 4, 2019
4ed2773
Added FEC filter
Sep 4, 2019
7cc342b
Added application support
Sep 5, 2019
353e58a
Added ut
Sep 5, 2019
b784855
Introduced a capability flag for packet filter. Added standard capabi…
Sep 6, 2019
3d8bd2c
Merge branch 'pr-fec-core-packetfilter-api' into pf-fec-docs-packetfi…
Sep 6, 2019
6a2f264
Merge branch 'pf-fec-docs-packetfilter-api' into pf-fec-core-fec
Sep 6, 2019
1dd599d
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 6, 2019
4bca391
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 6, 2019
9d10077
Post-review fixes (docs/comments only)
Sep 6, 2019
7281917
Post-review fixes
Sep 6, 2019
a27b275
Updated from parent
Sep 6, 2019
328d988
Merge branch 'pr-fec-core-packetfilter-api' into pf-fec-docs-packetfi…
Sep 6, 2019
90206c3
Merge branch 'pf-fec-docs-packetfilter-api' into pf-fec-core-fec
Sep 6, 2019
3873f92
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 6, 2019
7e23237
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 6, 2019
6d7d265
Fixed automatic merge mistake
Sep 6, 2019
5b8b403
Post-review fixes.
Sep 9, 2019
7a5b060
Merge branch 'pr-fec-core-packetfilter-api' into pf-fec-docs-packetfi…
Sep 9, 2019
c9bd7f3
Merge branch 'pf-fec-docs-packetfilter-api' into pf-fec-core-fec
Sep 9, 2019
076cb4c
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 9, 2019
590790f
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 9, 2019
12b1417
Made extraSize implemented as static. Check filter extra size against…
Sep 9, 2019
c28d2a1
Merge branch 'pr-fec-core-packetfilter-api' into pf-fec-core-fec
Sep 9, 2019
56c6b45
Fixed according to the changes in the packet filter API.
Sep 9, 2019
37ebad4
Backfixes after testing with apps
Sep 9, 2019
e793db7
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 9, 2019
dfc10c4
Fixed design flaw in virtual factory
Sep 9, 2019
db57706
Backfix (ManagedPtr design flaw)
Sep 9, 2019
48ae77a
Merge branch 'pr-fec-core-packetfilter-api' into pf-fec-docs-packetfi…
Sep 9, 2019
e43be24
Updated from parent
Sep 9, 2019
65264f4
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 9, 2019
a080376
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 9, 2019
9cb12fb
Merge branch 'master' into pf-fec-docs-packetfilter-api
Sep 10, 2019
4e5a99f
Merge branch 'pf-fec-docs-packetfilter-api' into pf-fec-core-fec
Sep 10, 2019
958362f
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 10, 2019
e6b940c
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 10, 2019
4895f5b
Added const where it's due
Sep 10, 2019
1c21e5c
Merge branch 'master' into pf-fec-core-fec
Sep 10, 2019
c8898c9
Merge branch 'pf-fec-core-fec' into pf-fec-apps-support
Sep 10, 2019
f87b64f
Merge branch 'pf-fec-apps-support' into pf-fec-tests-fec
Sep 10, 2019
2d5702b
Merge branch 'master' into pf-fec-tests-fec
ethouris Sep 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/filelist.maf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test_seqno.cpp
test_strict_encription.cpp
test_timer.cpp
test_listen_callback.cpp
test_fec_rebuilding.cpp
271 changes: 271 additions & 0 deletions test/test_fec_rebuilding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
#include <vector>

#include "gtest/gtest.h"
#include "packet.h"
#include "fec.h"
#include "packetfilter.h"
#include "packetfilter_api.h"

using namespace std;

class TestFECRebuilding: public testing::Test
{
protected:
FECFilterBuiltin* fec = nullptr;
vector<SrtPacket> provided;
vector<unique_ptr<CPacket>> source;
int sockid = 54321;
int isn = 123456;
size_t plsize = 1316;

TestFECRebuilding()
{
// Required to make ParseCorrectorConfig work
PacketFilter::globalInit();
}

void SetUp() override
{
int timestamp = 10;

SrtFilterInitializer init = {
sockid,
isn - 1, // It's passed in this form to PacketFilter constructor, it should increase it
isn - 1, // XXX Probably this better be changed.
plsize
};


// Make configuration row-only with size 7
string conf = "fec,rows:1,cols:7";

provided.clear();

fec = new FECFilterBuiltin(init, provided, conf);

int32_t seq = isn;

for (int i = 0; i < 7; ++i)
{
source.emplace_back(new CPacket);
CPacket& p = *source.back();

p.allocate(SRT_LIVE_MAX_PLSIZE);

uint32_t* hdr = p.getHeader();

// Fill in the values
hdr[SRT_PH_SEQNO] = seq;
hdr[SRT_PH_MSGNO] = 1 | MSGNO_PACKET_BOUNDARY::wrap(PB_SOLO);
hdr[SRT_PH_ID] = sockid;
hdr[SRT_PH_TIMESTAMP] = timestamp;

// Fill in the contents.
// Randomly chose the size

int minsize = 732;
int divergence = plsize - minsize - 1;
size_t length = minsize + rand() % divergence;

p.setLength(length);
for (size_t b = 0; b < length; ++b)
{
p.data()[b] = rand() % 255;
}

timestamp += 10;
seq = CSeqNo::incseq(seq);
}
}

void TearDown() override
{
delete fec;
}
};


TEST_F(TestFECRebuilding, Prepare)
{
// Stuff in prepared packets into the source fec.
int32_t seq;
for (int i = 0; i < 7; ++i)
{
CPacket& p = *source[i].get();

// Feed it simultaneously into the sender FEC
fec->feedSource(p);
seq = p.getSeqNo();
}

SrtPacket fec_ctl(SRT_LIVE_MAX_PLSIZE);

// Use the sequence number of the last packet, as usual.
bool have_fec_ctl = fec->packControlPacket(fec_ctl, seq);

EXPECT_EQ(have_fec_ctl, true);
}

TEST_F(TestFECRebuilding, NoRebuild)
{
// Stuff in prepared packets into the source fec.
int32_t seq;
for (int i = 0; i < 7; ++i)
{
CPacket& p = *source[i].get();

// Feed it simultaneously into the sender FEC
fec->feedSource(p);
seq = p.getSeqNo();
}

SrtPacket fec_ctl(SRT_LIVE_MAX_PLSIZE);

// Use the sequence number of the last packet, as usual.
bool have_fec_ctl = fec->packControlPacket(fec_ctl, seq);

ASSERT_EQ(have_fec_ctl, true);
// By having all packets and FEC CTL packet, now stuff in
// these packets into the receiver

FECFilterBuiltin::loss_seqs_t loss; // required as return, ignore

for (int i = 0; i < 7; ++i)
{
// SKIP packet 4 to simulate loss
if (i == 4 || i == 6)
continue;

// Stuff in the packet into the FEC filter
bool want_passthru = fec->receive(*source[i], loss);
EXPECT_EQ(want_passthru, true);
}

// Prepare a real packet basing on the SrtPacket.

// XXX Consider packing this into a callable function as this
// is a code directly copied from PacketFilter::packControlPacket.

unique_ptr<CPacket> fecpkt ( new CPacket );

uint32_t* chdr = fecpkt->getHeader();
memcpy(chdr, fec_ctl.hdr, SRT_PH__SIZE * sizeof(*chdr));

// The buffer can be assigned.
fecpkt->m_pcData = fec_ctl.buffer;
fecpkt->setLength(fec_ctl.length);

// This sets only the Packet Boundary flags, while all other things:
// - Order
// - Rexmit
// - Crypto
// - Message Number
// will be set to 0/false
fecpkt->m_iMsgNo = MSGNO_PACKET_BOUNDARY::wrap(PB_SOLO);

// ... and then fix only the Crypto flags
fecpkt->setMsgCryptoFlags(EncryptionKeySpec(0));

// And now receive the FEC control packet

bool want_passthru_fec = fec->receive(*fecpkt, loss);
EXPECT_EQ(want_passthru_fec, false); // Confirm that it's been eaten up
EXPECT_EQ(provided.size(), 0); // Confirm that nothing was rebuilt

/*
// XXX With such a short sequence, losses will not be reported.
// You need at least one packet past the row, even in 1-row config.
// Probably a better way for loss collection should be devised.

ASSERT_EQ(loss.size(), 2);
EXPECT_EQ(loss[0].first, isn + 4);
EXPECT_EQ(loss[1].first, isn + 6);
*/
}

TEST_F(TestFECRebuilding, Rebuild)
{
// Stuff in prepared packets into the source fec->
int32_t seq;
for (int i = 0; i < 7; ++i)
{
CPacket& p = *source[i].get();

// Feed it simultaneously into the sender FEC
fec->feedSource(p);
seq = p.getSeqNo();
}

SrtPacket fec_ctl(SRT_LIVE_MAX_PLSIZE);

// Use the sequence number of the last packet, as usual.
bool have_fec_ctl = fec->packControlPacket(fec_ctl, seq);

ASSERT_EQ(have_fec_ctl, true);
// By having all packets and FEC CTL packet, now stuff in
// these packets into the receiver

FECFilterBuiltin::loss_seqs_t loss; // required as return, ignore

for (int i = 0; i < 7; ++i)
{
// SKIP packet 4 to simulate loss
if (i == 4)
continue;

// Stuff in the packet into the FEC filter
bool want_passthru = fec->receive(*source[i], loss);
EXPECT_EQ(want_passthru, true);
}

// Prepare a real packet basing on the SrtPacket.

// XXX Consider packing this into a callable function as this
// is a code directly copied from PacketFilter::packControlPacket.

unique_ptr<CPacket> fecpkt ( new CPacket );

uint32_t* chdr = fecpkt->getHeader();
memcpy(chdr, fec_ctl.hdr, SRT_PH__SIZE * sizeof(*chdr));

// The buffer can be assigned.
fecpkt->m_pcData = fec_ctl.buffer;
fecpkt->setLength(fec_ctl.length);

// This sets only the Packet Boundary flags, while all other things:
// - Order
// - Rexmit
// - Crypto
// - Message Number
// will be set to 0/false
fecpkt->m_iMsgNo = MSGNO_PACKET_BOUNDARY::wrap(PB_SOLO);

// ... and then fix only the Crypto flags
fecpkt->setMsgCryptoFlags(EncryptionKeySpec(0));

// And now receive the FEC control packet

bool want_passthru_fec = fec->receive(*fecpkt, loss);
EXPECT_EQ(want_passthru_fec, false); // Confirm that it's been eaten up

EXPECT_EQ(loss.size(), 0);
ASSERT_EQ(provided.size(), 1);

SrtPacket& rebuilt = provided[0];
CPacket& skipped = *source[4];

// Set artificially the SN_REXMIT flag in the skipped source packet
// because the rebuilt packet shall have REXMIT flag set.
skipped.m_iMsgNo |= MSGNO_REXMIT::wrap(true);

// Compare the header
EXPECT_EQ(skipped.getHeader()[SRT_PH_SEQNO], rebuilt.hdr[SRT_PH_SEQNO]);
EXPECT_EQ(skipped.getHeader()[SRT_PH_MSGNO], rebuilt.hdr[SRT_PH_MSGNO]);
EXPECT_EQ(skipped.getHeader()[SRT_PH_ID], rebuilt.hdr[SRT_PH_ID]);
EXPECT_EQ(skipped.getHeader()[SRT_PH_TIMESTAMP], rebuilt.hdr[SRT_PH_TIMESTAMP]);

// Compare sizes and contents
ASSERT_EQ(skipped.size(), rebuilt.size());

EXPECT_EQ(memcmp(skipped.data(), rebuilt.data(), rebuilt.size()), 0);
}