summaryrefslogtreecommitdiff
path: root/cesar/cl/test/src/cl_mme_recv.c
blob: 9a03afff2c8ada78aa3f1f871a2d4a2b4f0e7650 (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cl/test/src/cl_mme_recv.c
 * \brief   <brief>
 * \ingroup cl/test/src/
 * 
 */

#include "common/std.h"
#include "lib/test.h"
#include "lib/trace.h"

#include "mac/common/store.h"
#include "mac/common/ntb.h"
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar.h"

#include "cl/cl.h"
#include "cl/cl_mactotei.h"

#include "cl/inc/trace.h"

#include "hal/phy/phy.h"

bool test_mme_recv;
bool test_mme_send_done_to_cp;
cl_t *cl;

void cl_send_mme_to_cp (void *user, mfs_rx_t *mfs, u8 *buffer, uint length,
        cl_mme_recv_t *mme_recv, bool encryption)
{
    test_mme_send_done_to_cp = true;
    
    cl_mme_recv_done (cl, mme_recv);
}

void hle_mme_send_done (void *test, u8 *buffer)
{
    test_mme_recv = true;
}

int main (void)
{
    test_t test;
    mac_store_t *mac_store;
    sar_t *sar;
    pbproc_t *pbproc;
    mac_config_t *mac_config;
    phy_t *phy;
    mfs_rx_t *mfs;
    bool added;
    u8 buffer[2048];

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

    mac_store = mac_store_init ();
    mac_config = blk_alloc ();
    phy = blk_alloc ();
    mac_ntb_init(phy, mac_config);
    pbproc = pbproc_init (mac_config, mac_store);
    sar = sar_init (mac_store, pbproc, NULL);
    mac_config->tei = 10;
    cl = cl_init (mac_store, sar, mac_config);

    mfs = mac_store_mfs_add_rx (mac_store, false, false, 1, 1, &added);
    dbg_assert (added);

    cl_mme_recv_init (cl, cl_send_mme_to_cp, NULL);

    // send a data to the CP
    test_mme_send_done_to_cp = false;
    cl_mme_sar_recv (cl, buffer, 1204, mfs, false);

    test_begin(test, "Send done to CP from SAR")
    {
        test_fail_if (test_mme_send_done_to_cp == false, "data not send");
    }
    test_end;

    mac_store_mfs_remove (mac_store, (mfs_t *) mfs);
    blk_release (mfs);

    test_mme_send_done_to_cp = false;
    test_mme_recv = false;
    cl_mme_ul_init_send_done(cl, hle_mme_send_done, NULL);
    cl_mme_ul_send (cl, buffer, 1024);

    test_begin(test, "Send done to CP from HLE")
    {
        test_fail_if (test_mme_send_done_to_cp == false, "data not send");
        test_fail_if (test_mme_recv == false, "Hle not informed");
    }
    test_end;

    added = mac_store_sta_remove (mac_store, 1);
    dbg_check (added);
    mac_store_uninit (mac_store);
    blk_release (mac_config);
    blk_release (phy);
    pbproc_uninit (pbproc);
    sar_uninit (sar);

    cl_trace_print (cl);
    cl_uninit(cl);

    test_begin (test, "memory check")
    {
        test_fail_if (blk_check_memory == false, "momery not correctly freed");
    }
    test_end;

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