summaryrefslogtreecommitdiff
path: root/cesar/cp2/conn/test/src/conn_test.c
blob: 21de707f810f7441dc94473be535bfa851e89672 (plain)
1
2
3
4
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bw.c
 * \brief   bandwidth manager module
 * \ingroup cp2_cco_bw
 *
 * Control the schedule of the becon period
 */
#include "common/std.h"
#include "cp2/cp.h"
#include "cp2/inc/context.h"
#include "cp2/conn/link.h"
#include "cp2/conn/inc/link.h"
#include "cp2/conn/conn.h"
#include "cp2/conn/inc/conn.h"
#include "cp2/conn/conn_mgr.h"
#include "lib/blk.h"
#include "lib/list.h"
#include "lib/test.h"

void
test_case_conn_init(test_t test, cp_t *cp)
{

    test_case_begin(test, "conn init");

    cp_conn_mgr_init(cp);

    test_begin(test, "conn init")
    {
       test_fail_if(!list_empty(&cp->conn_mgr.conns),
                    "the conn list should be empty");
    }
    test_end;
}

void
test_case_conn_uninit(test_t test, cp_t *cp)
{
    test_case_begin(test, "conn uninit");

    cp_conn_mgr_uninit(cp);

    test_begin(test, "conn uninit")
    {
        test_fail_if(!list_empty(&cp->conn_mgr.conns),
                    "the conn list should be empty");

        test_fail_if(!blk_check_memory,
                     "Memory pb in the Conn module");    
    }
    test_end;
}

void
test_case_conn_add_conn (test_t test, cp_t *cp)
{

    int i,j;
    cp_conn_t *conn[3];
    cp_conn_t *test_conn[3];

    cp_link_t *rlink[3];   
    cp_link_t *flink[3];

    cp_link_ble_interval_t *tmp_ble;
    cp_link_ble_interval_t *test_ble[3][10];

    list_node_t *actual_node;


    cp_conn_mgr_init(cp);

    test_case_begin(test, "\nadd connection");

    /* init conn*/

    for(i=0;i<3;i++)
    {
        /*init link*/
        rlink[i] = cp_link_init();
        flink[i] = cp_link_init();
        /*add conn*/
        conn[i] = blk_alloc();

        conn[i]->conn_info = blk_alloc();
        conn[i]->conn_info->cid = i+10;

        conn[i]->conn_info->lid_r = 0;
        conn[i]->conn_info->lid_f = 0;
        
        cp_conn_add_conn(cp, conn[i]);

        conn[i]->conn_info->lid_f = cp_conn_get_free_lid(cp);
        conn[i]->conn_info->lid_r = cp_conn_get_free_lid(cp);

        conn[i]->flink = flink[i];
        conn[i]->rlink = rlink[i];

    }

    /* init forward ble*/
    for(j=0;j<3;j++)
    {
        for(i=0;i<10;i++)
        {
            cp_link_push_ble(flink[j],(i+1)*20,
                     ((i+1)*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10));
            cp_link_push_ble(rlink[j],(i+1)*10,
                     (i+1)*(CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10));
        }
    }   
    /*Get back the connection for the tests*/
    actual_node = list_begin(&cp->conn_mgr.conns);

    for(i=0;i<3;i++)
    {
        test_conn[i] = PARENT_OF(cp_conn_t,node,actual_node);
        actual_node = list_next(actual_node);
    }

    /*Get back the ble for the tests*/
    actual_node = list_begin(&cp->conn_mgr.conns);

    for(j = 0;j<3;j++)
    {
        tmp_ble = PARENT_OF(cp_link_ble_interval_t,node,list_begin(&test_conn[j]->flink->ble));

        for(i = 0; i<10; i++)
        {
            test_ble[j][i] = tmp_ble; 
            tmp_ble = PARENT_OF(cp_link_ble_interval_t,node,list_next(&tmp_ble->node));
        }
    }
    
    test_begin(test,"add connection")
    {
        test_fail_if(test_ble[0][0]->ble != 20,
                     "wrong ble init of the conn");
        test_fail_if(test_ble[1][1]->ble != 40,
                     "wrong ble init of the conn");
        test_fail_if(test_ble[2][2]->ble != 60,
                     "wrong ble init of the conn");

        test_fail_if(test_ble[0][2]->et_atu != (3*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");
        test_fail_if(test_ble[1][6]->et_atu != (7*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");
        test_fail_if(test_ble[2][9]->et_atu != (10*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");

        test_fail_if(conn[0]->conn_info->lid_f!=0x01,
                     "lid init pb");
        test_fail_if(conn[1]->conn_info->lid_r!=0x04,
                     "lid init pb");
        test_fail_if(conn[2]->conn_info->lid_f!=0x05,
                     "lid init pb");
    }
    test_end;
}

void
test_case_conn_del_conn(test_t test)
{
       
    cp_t cp;

    int i;
    u8 conn_cid[3];
    cp_conn_t *conn[3] ;

    list_node_t *actual_node;

    test_case_conn_init(test, &cp);

    test_case_begin(test, "\nget connection");

    test_case_conn_add_conn(test, &cp);

    /*Get back the connection for the tests*/
    actual_node = list_begin(&cp.conn_mgr.conns);

    for(i=0;i<3;i++)
    {
        conn[i] = PARENT_OF(cp_conn_t,node,actual_node);
        actual_node = list_next(actual_node);
        cp_conn_del_conn(&cp, conn_cid[i+10]);
    }
    
    test_begin(test,"get connection")
    {
        test_fail_if(list_empty(&cp.conn_mgr.conns)!=true,
                     "their shouldnt be any conn");
    }
    test_end;

    test_case_conn_uninit(test, &cp);

}

void
test_case_conn_get_conn (test_t test)
{
    cp_t cp;

    int i,j;
    cp_conn_t *conn[3] ;

    cp_link_ble_interval_t *tmp_ble;
    cp_link_ble_interval_t *test_ble[3][10];

    list_node_t *actual_node;

    test_case_conn_init(test, &cp);

    test_case_conn_add_conn(test, &cp);

    test_case_begin(test, "\nget connection");

    actual_node = list_begin(&cp.conn_mgr.conns);

    for(i=0;i<3;i++)
    {
        conn[i] = cp_conn_get_conn(&cp,i+10); 
        actual_node = list_next(actual_node);
    }

    for(j = 0;j<3;j++)
    {
        tmp_ble = PARENT_OF(cp_link_ble_interval_t, node,list_begin(&conn[j]->flink->ble));

        for(i = 0; i<10; i++)
        {
            test_ble[j][i] =tmp_ble;
            tmp_ble = PARENT_OF(cp_link_ble_interval_t, node,list_next(&tmp_ble->node));
        }
    }

    test_begin(test,"get connection")
    {
        test_fail_if(conn[0]->conn_info->cid != 10,
                     "wrong cid 0");
        test_fail_if(conn[1]->conn_info->cid != 11,
                     "wrong cid 1");
        test_fail_if(conn[2]->conn_info->cid != 12,
                     "wrong cid 2");

        test_fail_if(test_ble[0][0]->ble != 20,
                     "wrong ble init of the conn");
        test_fail_if(test_ble[1][1]->ble != 40,
                     "wrong ble init of the conn");
        test_fail_if(test_ble[2][2]->ble != 60,
                     "wrong ble init of the conn");

        test_fail_if(test_ble[0][2]->et_atu != (3*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");
        test_fail_if(test_ble[1][6]->et_atu != (7*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");
        test_fail_if(test_ble[2][9]->et_atu != (10*CP_CCO_BW_ALLOC_TIME_BEACON_PERIOD_ATU/10),
                     "wrong init end time of the conn");

    }
    test_end;

    test_case_conn_uninit(test, &cp);
}
int
main (void){
    test_t test;

    test_init(test, 0, NULL);
    
    test_case_conn_del_conn(test);

    test_case_conn_get_conn (test);
    

    test_result (test);
    HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
    return test_nb_failed (test) == 0 ? 0 : 1;

}