summaryrefslogtreecommitdiff
path: root/cleopatre/plcdrv/arm/utests/inc/mailbox_utests.h
blob: b69fb9f5997a52a0be9643eecd219752cf773670 (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
#ifndef mailbox_utests_h
#define mailbox_utests_h
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    processing_utests.h
 * \brief   interfaces for unitary tests of processing layer
 * \ingroup Cleopatre - PlcDrv
 *
 * this file content interfaces and exported macros, variables... For the
 * unitary tests of mailbox layer
 */

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "common.h"

/****************************************************/
/*****            SPECIFICS DEFINES             *****/
/****************************************************/
#define SEND_DONE_ADDRESS 0x12345678
#define INTERFACE_ADDRESS 0x87654321
#define DATADATA_ADDRESS  0x73895622
#define DATAMME_ADDRESS   0x57826189

/****************************************************/
/*****           SPECIFICS VARIABLES            *****/
/****************************************************/
static int nbtests_A2L_status_queue = 0;
static int nbtests_L2A_status_queue = 0;
uint32_t mbx_send_result[2];
uint32_t mbx_buffer_add_result[2];
uint32_t mbx_rx_ptr_result;

/****************************************************/
/*****              LOWER STUB                  *****/
/****************************************************/
struct halctx {
    uint32_t num_tst;
};
struct halctx glbctx;
static inline void A2La_it_disable(struct halctx *ctx){}
static inline void L2At_it_disable(struct halctx *ctx){}
static inline void A2La_it_enable(struct halctx *ctx){}
static inline void L2At_it_enable(struct halctx *ctx){}
static inline struct halctx * halmbx_init(struct init_info *info)
{
    if((!info) || ((uint32_t)info == (uint32_t)0x55555555))
        return NULL;
    else
    {
        glbctx.num_tst=0;
        return &glbctx;
    }
}
static inline int halmbx_uninit(struct halctx *ctx){return 0;}
static inline int halmbx_L2Amail_not_empty_queue(struct halctx *ctx)
{
    if(ctx->num_tst == 0)
    {   //return empty
        return 0;
    }
    else if(ctx->num_tst == 5)
    {   //return empty to break RX loop for SEND_DONE
        return 0;
    }
    else if(ctx->num_tst == 8)
    {   //return empty to break RX loop for INTERFACE
        return 0;
    }
    else if(ctx->num_tst == 11)
    {   //return empty to break RX loop for DATA
        return 0;
    }
    else if(ctx->num_tst == 14)
    {   //return empty to break RX loop for MME
        return 0;
    }
    else
    {
        //return not_empty
        return 1;
    }
}
static inline int halmbx_A2Lmail_status_queue(struct halctx *ctx)
{
    //The first  time you use this function it will return NEARLY_FULL
    //The second time you use this function it will return FULL
    //The other times you use this function it will return NOT_FULL
    nbtests_A2L_status_queue++;
    switch(nbtests_A2L_status_queue)
    {
    case 1:
        return NEARLY_FULL;
    case 2:
        return FULL;
    default:
        return NOT_FULL;
    }
}
static inline int halmbx_L2Amail_status_queue(struct halctx *ctx)
{
    //The first  time you use this function it will return NEARLY_FULL
    //The second time you use this function it will return FULL
    //The other times you use this function it will return NOT_FULL
    nbtests_L2A_status_queue++;
    switch(nbtests_L2A_status_queue)
    {
    case 1:
        return NEARLY_FULL;
    case 2:
        return FULL;
    default:
        return NOT_FULL;
    }
}
static inline int halmbx_copy_to_ring(struct halctx *ctx, uint32_t *message, int size)
{
    if((uint32_t)message == (uint32_t)0x55555555)
        return -1;
    else
        return 0;
}
static inline int halmbx_copy_from_ring(struct halctx *ctx, uint32_t *message, int size)
{
    if(ctx->num_tst == 1)
    {   //return error
        return -1;
    }
    else if((ctx->num_tst == 3)||(ctx->num_tst == 4))
    {
        //SEND DONE test
        //return a send_done message
        *message = 0x00000102;
        *(message+1) = SEND_DONE_ADDRESS;
        //return OK
        return 0;
    }
    else if((ctx->num_tst == 6)||(ctx->num_tst == 7))
    {
        //INTERFACE test
        //return a interface message
        *message = 0x00070203;
        *(message+1) = INTERFACE_ADDRESS;
        //return OK
        return 0;
    }
    else if((ctx->num_tst == 9)||(ctx->num_tst == 10))
    {
        //MME test
        //return a mme message
        *message = 0x00009100;
        *(message+1) = DATAMME_ADDRESS;
        //return OK
        return 0;
    }
    else if((ctx->num_tst == 12)||(ctx->num_tst == 13))
    {
        //DATA test
        //return a data message
        *message = 0x00008100;
        *(message+1) = DATADATA_ADDRESS;
        //return OK
        return 0;
    }
    else
    {
        //return OK
        return 0;
    }
}
static inline int halmbx_A2Lmail_update(struct halctx *ctx, int size)
{
    if(size)
        return 0;
    else
        return -1;
}
static inline int halmbx_L2Amail_update(struct halctx *ctx, int size)
{
    if(ctx->num_tst == 2)
    {   //return error
        return -1;
    }
    else
    {
        //return OK
        return 0;
    }
}

/****************************************************/
/*****              UPPER STUB                  *****/
/****************************************************/
static inline int processing_buffer_free(void *pointer)
{
    if(glbctx.num_tst == 3)
    {   //return error
        return -1;
    }
    else if(glbctx.num_tst == 4)
    {   //return ok
        //we are in OK SEND_DONE process and we need to break RX loop
        glbctx.num_tst++;
        mbx_rx_ptr_result = (uint32_t)pointer;
        return 0;
    }
    else
    {
        //return OK
        return 0;
    }
}
static inline int processing_receive(void *pointer, int length, enum buffer_type type)
{
    if((glbctx.num_tst == 6) || (glbctx.num_tst == 9) || (glbctx.num_tst == 12))
    {   //return error
        return -1;
    }
    else if(glbctx.num_tst == 7)
    {   //return ok
        //we are in OK INTERFACE process and we need to break RX loop
        glbctx.num_tst++;
        mbx_rx_ptr_result = (uint32_t)pointer;
        return 0;
    }
    else if(glbctx.num_tst == 10)
    {   //return ok
        //we are in OK DATA process and we need to break RX loop
        glbctx.num_tst++;
        mbx_rx_ptr_result = (uint32_t)pointer;
        return 0;
    }
    else if(glbctx.num_tst == 13)
    {   //return ok
        //we are in OK MME process and we need to break RX loop
        glbctx.num_tst++;
        mbx_rx_ptr_result = (uint32_t)pointer;
        return 0;
    }
    else
    {
        //return OK
        return 0;
    }
}

/****************************************************/
/*****              LINUX STUB                  *****/
/****************************************************/
#define printk(...)

/****************************************************/
/*****        STATIC FUNCTION PROTOTYPES        *****/
/****************************************************/
/** 
 * Give the message to hardware
 *
 * \param  msg  message pointer.
 * \param  size  size of message.
 * \return  error code or status queue.
 */
int internal_mailbox_send(uint32_t *msg, int size);

#endif /* mailbox_utests_h */