Commit 4c781c43 authored by Kai Vogelgesang's avatar Kai Vogelgesang
Browse files

Update ReceptionTable tests

parent 03073905
Loading
Loading
Loading
Loading
Loading
+77 −34
Original line number Diff line number Diff line
#include "common.h"
#include "prrt/proto/clock.h"
#include <iostream>

extern "C" {
#include "prrt/proto/stores/receptionTable.h"
@@ -6,50 +8,91 @@ extern "C" {

class ReceptionTableTest : public ::testing::Test {
protected:
    virtual void SetUp()
    {
    void SetUp() override {
        lg = PrrtReceptionTable_create();
    }

    virtual void TearDown()
    {
    void TearDown() override {
        PrrtReceptionTable_destroy(lg);
    }

    PrrtReceptionTable *lg;
    PrrtReceptionTable *lg = nullptr;
};
/*
TEST_F(ReceptionTableTest, CreateDestroy)

void print_stats(PrrtLossStatistics &stats) {
    std::cout << "===== stats =====" << std::endl
              << "#pkt " << stats.packetCount << std::endl
              << "#ers " << stats.erasureCount << std::endl
              << "#gap " << stats.gapCount << std::endl
              << "gapl " << stats.gapLength << std::endl
              << "#brs " << stats.burstCount << std::endl
              << "brsl " << stats.burstLength << std::endl;
}

TEST_F(ReceptionTableTest, Print)
{
    PrrtReceptionTable *lg = PrrtReceptionTable_create();
    void *n = NULL;
    ASSERT_NE(n, lg);
    ASSERT_NE(n, lg->bitmap);
    PrrtReceptionTable_destroy(lg);
    PrrtLossStatistics stats;

    stats = PrrtReceptionTable_calculate_statistics(lg, 0, 100);
    print_stats(stats);

    PrrtReceptionTable_mark_received(lg, 0, 9, 10);
    PrrtReceptionTable_mark_received(lg, 1, 19, 20);
    PrrtReceptionTable_mark_received(lg, 2, 29, 30);

    PrrtReceptionTable_mark_received(lg, 4, 39, 40);

    stats = PrrtReceptionTable_calculate_statistics(lg, 0, 100);
    print_stats(stats);
}

TEST_F(ReceptionTableTest, Continuous)
{
    for (prrtSequenceNumber_t i = 0; i < 20; ++i) {
        PrrtReceptionTable_mark_received(lg, i, i, i);
    }

    PrrtLossStatistics stats = PrrtReceptionTable_calculate_statistics(lg, 0, 20);

    ASSERT_EQ(stats.packetCount, 20);
    ASSERT_EQ(stats.erasureCount, 0);
    ASSERT_EQ(stats.gapCount, 0);
    ASSERT_EQ(stats.gapLength, 0);
    ASSERT_EQ(stats.burstCount, 1);
    ASSERT_EQ(stats.burstLength, 20);
}

TEST_F(ReceptionTableTest, CalculateStatistics)
TEST_F(ReceptionTableTest, Gaps)
{
    // mark every even packet
    for (prrtSequenceNumber_t i = 0; i < 21; i += 2) {
        PrrtReceptionTable_mark_received(lg, i, i, i);
    }

    PrrtReceptionTable_mark_received(lg, 0);
    PrrtReceptionTable_mark_received(lg, 1);
    PrrtReceptionTable_mark_received(lg, 2);
    PrrtReceptionTable_mark_received(lg, 3);
    PrrtReceptionTable_mark_received(lg, 4);
    PrrtReceptionTable_mark_received(lg, 5);
    PrrtReceptionTable_mark_received(lg, 6);
    PrrtReceptionTable_mark_received(lg, 9);
    PrrtLossStatistics stats = PrrtReceptionTable_calculate_statistics(lg, 0, 20);

    PrrtLossStatistics stats = PrrtReceptionTable_calculate_statistics(lg);
    ASSERT_EQ(stats.packetCount, 21);
    ASSERT_EQ(stats.erasureCount, 10);
    ASSERT_EQ(stats.gapCount, 10);
    ASSERT_EQ(stats.gapLength, 10);
    ASSERT_EQ(stats.burstCount, 11);
    ASSERT_EQ(stats.burstLength, 11);
}

TEST_F(ReceptionTableTest, Wrap)
{
    auto t_0 = MAX_TIMESTAMP - 10;

    for (prrtTimestamp_t i = 0; i < 20; ++i) {
        PrrtReceptionTable_mark_received(lg, i, t_0 + i, t_0 + i);
    }

    printf("PC: %d, EC: %d, GC: %d, GL: %d, BC: %d, BL: %d\n", stats.packetCount, stats.erasureCount, stats.gapCount,
           stats.gapLength, stats.burstCount, stats.burstLength);
    PrrtLossStatistics stats = PrrtReceptionTable_calculate_statistics(lg, t_0, t_0 + 20u);

    ASSERT_EQ(10, stats.packetCount);
    ASSERT_EQ(2, stats.erasureCount);
    ASSERT_EQ(1, stats.gapCount);
    ASSERT_EQ(2, stats.gapLength);
    ASSERT_EQ(8, stats.burstLength);
    ASSERT_EQ(2, stats.burstCount);
    ASSERT_EQ(stats.packetCount, 20);
    ASSERT_EQ(stats.erasureCount, 0);
    ASSERT_EQ(stats.gapCount, 0);
    ASSERT_EQ(stats.gapLength, 0);
    ASSERT_EQ(stats.burstCount, 1);
    ASSERT_EQ(stats.burstLength, 20);
}
 */
 No newline at end of file