Statistics
| Branch: | Tag: | Revision:

sssimulator / Test / stats_test.c @ f1158e5c

History | View | Annotate | Download (5.11 KB)

1
/*
2
 * This is SSSim: the Simple & Stupid Simulator
3
 *
4
 *  Copyright (c) 2015 Luca Baldesi
5
 *
6
 *  This is free software; see gpl-3.0.txt
7
 */
8

    
9
#include <assert.h>
10
#include <stdio.h>
11
#include <math.h>
12
#include <string.h>
13
#include <malloc.h>
14

    
15
#include <core.h>
16
#include <stats.h>
17

    
18
int PO_DELAY;    // playout delay
19
float convergence_precision = 0.1;
20
float netload = 1;
21

    
22
void windowed_big_chunk_stats_converge_test()
23
{
24
        int res;
25
        struct chunk chunks[22];
26
        struct peer peers[10];
27
        struct stats * stat = NULL;
28
        uint32_t window = 10;
29

    
30
        memset(chunks, 0, 21*sizeof(struct chunk));
31
        memset(peers, 0, 10*sizeof(struct peer));
32

    
33
        for (res = 0; res < 10; res++)
34
                peers[res].latest_not_needed = 200;
35
        for (res = 10; res < 21; res++)
36
        {
37
                chunks[res].avg_delay = 5;
38
                chunks[res].received = 10;
39
        }
40
        chunks[21].avg_delay = 3;
41
        chunks[21].received = 3;
42
        res = chunk_stats_converge(&stat, chunks, 22, peers, 10, 0, window);
43
        //chunk_stats_print(stat, PLAIN_STATS);
44
        assert(res == 0);
45
        assert(stat != NULL);
46
        assert(stat->avg_delay > 0.49);
47
        assert(stat->avg_delay < 0.51);
48
        assert(stat->loss == 0);
49

    
50
        free(stat);
51
        fprintf(stderr,"%s successfully passed!\n",__func__);
52
}
53

    
54
void windowed_chunk_stats_converge_test()
55
{
56
        int res;
57
        struct chunk chunks[10];
58
        struct peer peers[10];
59
        struct stats * stat = NULL;
60
        uint32_t window = 2;
61

    
62
        memset(chunks, 0, 10*sizeof(struct chunk));
63
        memset(peers, 0, 10*sizeof(struct peer));
64

    
65
        chunks[0].avg_delay = 9;
66
        chunks[0].received = 10;
67
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
68
        assert(res == 0);
69
        assert(stat != NULL);
70
        assert(stat->avg_delay < 0);
71
        assert(stat->loss == -1);
72

    
73

    
74
        chunks[1].avg_delay = 5;
75
        chunks[1].received = 10;
76
        for (res = 0; res < 10; res++)
77
                peers[res].latest_not_needed = 1;
78
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
79
        assert(res == 0);
80
        assert(stat->avg_delay > 0.69);
81
        assert(stat->avg_delay < 0.71);
82

    
83
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
84
        assert(stat->avg_delay > 0.69);
85
        assert(stat->avg_delay < 0.71);
86
        assert(res == 0);
87

    
88
        chunks[2].avg_delay = 3;
89
        chunks[2].received = 10;
90
        for (res = 0; res < 10; res++)
91
                peers[res].latest_not_needed = 2;
92
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
93
        assert(res == 0);
94
        //chunk_stats_print(stat, PLAIN_STATS);
95
        assert(stat->avg_delay > 0.69);
96
        assert(stat->avg_delay < 0.71);
97

    
98
        chunks[3].avg_delay = 8;
99
        chunks[3].received = 10;
100
        for (res = 0; res < 10; res++)
101
                peers[res].latest_not_needed = 3;
102
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
103
        //chunk_stats_print(stat, PLAIN_STATS);
104
        assert(res == 0);
105
        assert(stat->avg_delay > 0.54);
106
        assert(stat->avg_delay < 0.56);
107

    
108
        for (res = 0; res < 10; res++)
109
                peers[res].latest_not_needed = 1000;
110
        for (res = 4; res < 10; res++)
111
        {
112
                chunks[res].avg_delay = 5.5;
113
                chunks[res].received = 10;
114
        }
115
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, window);
116
        assert(res == 1);
117
        assert(stat->avg_delay > 0.54);
118
        assert(stat->avg_delay < 0.56);
119

    
120

    
121
        free(stat);
122
        stat = NULL;
123
        for (res = 0; res < 10; res++)
124
                peers[res].latest_not_needed = 2;
125
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 3);
126
        assert(res == 0);
127
        assert(stat->avg_delay > 0.56);
128
        assert(stat->avg_delay < 0.57);
129

    
130

    
131
        for (res = 0; res < 10; res++)
132
                peers[res].latest_not_needed = 9;
133
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 3);
134
        //chunk_stats_print(stat, PLAIN_STATS);
135
        assert(stat->avg_delay > 0.54);
136
        assert(stat->avg_delay < 0.56);
137

    
138
        free(stat);
139
        fprintf(stderr,"%s successfully passed!\n",__func__);
140
}
141

    
142
void windowless_chunk_stats_converge_test()
143
{
144
        int res;
145
        struct chunk chunks[10];
146
        struct peer peers[10];
147
        struct stats * stat = NULL;
148

    
149
        memset(chunks, 0, 10*sizeof(struct chunk));
150
        memset(peers, 0, 10*sizeof(struct peer));
151

    
152
        chunks[0].avg_delay = 9;
153
        chunks[0].received = 10;
154
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 0);
155
        assert(res == 0);
156
        assert(stat != NULL);
157
        assert(stat->avg_delay > 0.89);
158
        assert(stat->avg_delay < 0.91);
159
        assert(stat->loss == 0);
160

    
161

    
162
        chunks[1].avg_delay = 5;
163
        chunks[1].received = 10;
164
        for (res = 0; res < 10; res++)
165
                peers[res].latest_not_needed = 1;
166
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 0);
167
        assert(res == 0);
168
        assert(stat->avg_delay > 0.69);
169
        assert(stat->avg_delay < 0.71);
170

    
171
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 0);
172
        assert(res == 0);
173

    
174
        chunks[2].avg_delay = 7;
175
        chunks[2].received = 10;
176
        for (res = 0; res < 10; res++)
177
                peers[res].latest_not_needed = 2;
178
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 0);
179
        assert(res == 1);
180
        assert(stat->avg_delay > 0.69);
181
        assert(stat->avg_delay < 0.71);
182

    
183
        for (res = 0; res < 10; res++)
184
                peers[res].latest_not_needed = 1000;
185
        for (res = 3; res < 10; res++)
186
        {
187
                chunks[res].avg_delay = 10;
188
                chunks[res].received = 10;
189
        }
190
        res = chunk_stats_converge(&stat, chunks, 10, peers, 10, 0, 0);
191
        assert(res == 0);
192
        assert(stat->avg_delay > 0.9);
193
        assert(stat->avg_delay < 0.92);
194

    
195
        free(stat);
196
        fprintf(stderr,"%s successfully passed!\n",__func__);
197
}
198

    
199
int main(char ** argc,int argv)
200
{
201
        windowless_chunk_stats_converge_test();
202
        windowed_chunk_stats_converge_test();
203
        windowed_big_chunk_stats_converge_test();
204
        return 0;
205
}