lossGatherer_tests.cpp 3.64 KB
Newer Older
1
2
3
#include <gtest/gtest.h>

extern "C" {
4
#include "prrt/proto/stores/lossGatherer.h"
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
}

class LossGathererTest : public ::testing::Test {
protected:
    virtual void SetUp()
    {
        lg = LossGatherer_create();
    }

    virtual void TearDown()
    {
        LossGatherer_destroy(lg);
    }

    LossGatherer *lg;
};

TEST_F(LossGathererTest, CreateDestroy)
{
    LossGatherer *lg = LossGatherer_create();
    void *n = NULL;
    ASSERT_NE(n, lg);
    ASSERT_NE(n, lg->bitmap);
    LossGatherer_destroy(lg);
}

TEST_F(LossGathererTest, CheckLoss)
{
    ASSERT_FALSE(LossGatherer_check_loss(lg, 0));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 1));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 2));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 3));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 4));

    LossGatherer_mark_loss(lg, 2);
    LossGatherer_mark_loss(lg, 3);

    ASSERT_FALSE(LossGatherer_check_loss(lg, 0));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 1));
    ASSERT_TRUE(LossGatherer_check_loss(lg, 2));
    ASSERT_TRUE(LossGatherer_check_loss(lg, 3));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 4));
}

TEST_F(LossGathererTest, CalculateStatistics)
{
    LossGatherer_mark_loss(lg, 8);
    LossGatherer_mark_loss(lg, 9);
    LossStatistics stats = LossGatherer_calculate_statistics(lg, 0, 10);

    printf("PC: %d, EC: %d, GC: %d, GL: %d, BC: %d, BL: %d\n", stats.packetCount, stats.errorCount, stats.gapCount,
           stats.gapLength, stats.burstCount, stats.burstLength);

    ASSERT_EQ(10, stats.packetCount);
    ASSERT_EQ(2, stats.errorCount);
    ASSERT_EQ(1, stats.gapCount);
    ASSERT_EQ(2, stats.gapLength);
    ASSERT_EQ(8, stats.burstLength);
    ASSERT_EQ(1, stats.burstCount);

    LossGatherer_mark_loss(lg, 0);
    LossGatherer_mark_loss(lg, 1);

    ASSERT_TRUE(LossGatherer_check_loss(lg, 0));
    ASSERT_TRUE(LossGatherer_check_loss(lg, 1));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 2));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 3));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 7));
    ASSERT_TRUE(LossGatherer_check_loss(lg, 8));
    ASSERT_TRUE(LossGatherer_check_loss(lg, 9));
    ASSERT_FALSE(LossGatherer_check_loss(lg, 10));
    printf("PLR: %f, ABL: %f, AGL: %f\n", LossStatistics_get_packet_loss_rate(stats),
           LossStatistics_get_avg_burst_length(stats), LossStatistics_get_avg_gap_length(stats));

    stats = LossGatherer_calculate_statistics(lg, 0, 20);

    printf("PC: %d, EC: %d, GC: %d, GL: %d, BC: %d, BL: %d\n", stats.packetCount, stats.errorCount, stats.gapCount,
           stats.gapLength, stats.burstCount, stats.burstLength);

    ASSERT_EQ(20, stats.packetCount);
    ASSERT_EQ(4, stats.errorCount);
    ASSERT_EQ(2, stats.gapCount);
    ASSERT_EQ(4, stats.gapLength);
    ASSERT_EQ(16, stats.burstLength);
    ASSERT_EQ(2, stats.burstCount);
    printf("PLR: %f, ABL: %f, AGL: %f\n", LossStatistics_get_packet_loss_rate(stats),
           LossStatistics_get_avg_burst_length(stats), LossStatistics_get_avg_gap_length(stats));

    LossGatherer_mark_loss(lg, 2);
    LossGatherer_mark_loss(lg, 3);

    stats = LossGatherer_calculate_statistics(lg, 0, 20);

    printf("PC: %d, EC: %d, GC: %d, GL: %d, BC: %d, BL: %d\n", stats.packetCount, stats.errorCount, stats.gapCount,
           stats.gapLength, stats.burstCount, stats.burstLength);
    ASSERT_EQ(20, stats.packetCount);
    ASSERT_EQ(6, stats.errorCount);
    ASSERT_EQ(2, stats.gapCount);
    ASSERT_EQ(6, stats.gapLength);
    ASSERT_EQ(14, stats.burstLength);
    ASSERT_EQ(2, stats.burstCount);
    printf("PLR: %f, ABL: %f, AGL: %f\n", LossStatistics_get_packet_loss_rate(stats),
           LossStatistics_get_avg_burst_length(stats), LossStatistics_get_avg_gap_length(stats));
108
}