summaryrefslogtreecommitdiff
path: root/cesar/hle/test/src/hle_add_buffer.c
blob: 031dea429015d13ace761f9e98b872a274a4c370 (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
/* Cesar project {{{;
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    test/hle_recv.c
 * \brief   unit test to test the hle when it sends a data to the CL.
 * \ingroup hle
 *
 * « long description »
 */
#include "common/std.h"

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "lib/test.h"
#include "lib/blk.h"
#include "lib/trace.h"
#include "lib/bitstream.h"

#include "cl/cl.h"

#include "hle/hle.h"
#include "lib/test.h"

#include "hle/inc/trace.h"

#include "mac/common/ntb.h"

void
interface_buffer_work_add (void *user_data, u8 *buffer)
{
}

void
interface_mme_recv (void *user_data, u8 *buffer)
{
}

int main (void)
{
    test_t test;
    bitstream_t bitstream;

    hle_t *hle;
    cl_t *cl;

    uint msgs [10];
    u8 *buff_packet[2];
    uint data;
    uint phy;
    mac_config_t mac_config;

    mac_ntb_init ((phy_t *) &phy, &mac_config);

    buff_packet[0] = malloc (2048 * sizeof(u8));
    buff_packet[1] = malloc (2048 * sizeof(u8));

    test_init (test, 0, NULL);
    trace_init();
    // The function cl_init has been overided.
    cl = cl_init (NULL, NULL);
    hle = hle_init (cl);


    /** Data allocation */
    bitstream_init (&bitstream, msgs, 32, BITSTREAM_WRITE);

    data = HLE_MSG_TYPE_BUFFER_ADD;
    bitstream_access (&bitstream, &data, 8);

    data = 1;
    bitstream_access (&bitstream, &data, 4);

    data = 1;
    bitstream_access (&bitstream, &data, 3);
    bitstream_finalise (&bitstream);

    memcpy (&msgs[1], &buff_packet[0], sizeof(uint));

    memcpy (&msgs[2], &msgs[0], sizeof(uint));
    memcpy (&msgs[3], &buff_packet[1], sizeof(uint));

    hle_ipmbox_recv (hle, msgs, 4);

    /** MME allocation */
    buff_packet[0] = malloc (2048 * sizeof(u8));
    buff_packet[1] = malloc (2048 * sizeof(u8));

    bitstream_init (&bitstream, msgs, 32, BITSTREAM_WRITE);

    data = HLE_MSG_TYPE_BUFFER_ADD;
    bitstream_access (&bitstream, &data, 8);

    data = 1;
    bitstream_access (&bitstream, &data, 4);

    data = 0;
    bitstream_access (&bitstream, &data, 3);
    bitstream_finalise (&bitstream);


    memcpy (&msgs[1], &buff_packet[0], sizeof(uint));
    memcpy (&msgs[2], &msgs[0], sizeof(uint));
    memcpy (&msgs[3], &buff_packet[1], sizeof(uint));

    hle_ipmbox_recv (hle, msgs, 4);

    /** INTERFACE allocation */
    hle_init_interface_cb (hle, interface_buffer_work_add,
                           interface_mme_recv, NULL);

    buff_packet[0] = malloc (2048 * sizeof(u8));
    buff_packet[1] = malloc (2048 * sizeof(u8));

    bitstream_init (&bitstream, msgs, 32, BITSTREAM_WRITE);

    data = HLE_MSG_TYPE_BUFFER_ADD;
    bitstream_access (&bitstream, &data, 8);

    data = 1;
    bitstream_access (&bitstream, &data, 4);


    data = 2;
    bitstream_access (&bitstream, &data, 3);
    bitstream_finalise (&bitstream);

    memcpy (&msgs[1], &buff_packet[0], sizeof(uint));
    memcpy (&msgs[2], &msgs[0], sizeof(uint));
    memcpy (&msgs[3], &buff_packet[1], sizeof(uint));

    hle_ipmbox_recv (hle, msgs, 4);

    hle_trace_print (hle);

    hle_uninit (hle);
    cl_uninit (cl);

    test_begin (test, "Memory test")
    {
        test_fail_if (blk_check_memory() == false, "Memory not freed");
    }
    test_end;

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

u32
phy_date (phy_t *phy)
{
    return 0;
}