summaryrefslogtreecommitdiff
path: root/cleopatre/plcdrv/arm/utests/src/hal_utests.c
blob: e3f2b37edf41a416bd948e1f3fa7ffc7a63f8ed7 (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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal_utests.c
 * \brief   Unitary tests for HAL layer
 * \ingroup Cleopatre - PlcDrv
 *
 * This file content all the unitary tests for the hal layer,
 * this layer will provide all mechanisms to manage hardware.
 */

#include <check.h>
#include <stdio.h>
#include <string.h>
#include "hal.h"

/** local defines */
#define L2A_RING_BASE_ADDR ((uint32_t)&MBX_ring[A2L_RING_SIZE/4])
#define A2L_RING_BASE_ADDR ((uint32_t)&MBX_ring[0])

/** local variables */
struct halctx *tstctx;

struct init_info info = {
    .ring_base_addr = (uint32_t)&MBX_ring[0],
    .mbx_reg_base_addr = (uint32_t)&MBX_registers[0]
};

/** init test procedure */
START_TEST (test_halmbx_init)
{
    //Check arguments
    fail_if(halmbx_init(NULL) != NULL, "halmbx_init arguments error");

    tstctx = halmbx_init(&info);

    //Check mailbox pointer initialization
    fail_if(tstctx->A2L_ptr != &MBX_ring[0], "A2L ring pointer not initialize");
    fail_if(tstctx->L2A_ptr != &MBX_ring[A2L_RING_SIZE/4], "L2A ring pointer not initialize");
    fail_if(tstctx->A2L_head != &MBX_registers[5], "A2L_tail pointer not initialize");
    fail_if(tstctx->A2L_tail != &MBX_registers[4], "A2L_tail pointer not initialize");
    fail_if(tstctx->L2A_head != &MBX_registers[7], "L2A_head pointer not initialize");
    fail_if(tstctx->L2A_tail != &MBX_registers[6], "L2A_tail pointer not initialize");
    fail_if(tstctx->A2L_it != &MBX_registers[0], "A2L it pointer not initialize");
    fail_if(tstctx->L2A_it != &MBX_registers[2], "L2A it pointer not initialize");
    fail_if(tstctx->L2A_it_mask != &MBX_registers[3], "L2A it mask pointer not initialize");
}
END_TEST

START_TEST (test_set_A2Lt_interrupt)
{
    *tstctx->A2L_it = 0;
    set_A2Lt_interrupt(tstctx);
    fail_if(*tstctx->A2L_it != 0x01, "A2L trigger not set");
    *tstctx->A2L_it = 3;
    set_A2Lt_interrupt(tstctx);
    fail_if(*tstctx->A2L_it != 0x03, "A2L trigger not set");
}
END_TEST

START_TEST (test_set_L2Aa_interrupt)
{
    *tstctx->A2L_it = 0;
    set_L2Aa_interrupt(tstctx);
    fail_if(*tstctx->A2L_it != 0x02, "L2A acknowledge not set");
    *tstctx->A2L_it = 3;
    set_L2Aa_interrupt(tstctx);
    fail_if(*tstctx->A2L_it != 0x03, "L2A acknowledge not set");
}
END_TEST

START_TEST (test_clr_L2At_interrupt)
{
    *tstctx->L2A_it = 1;
    clr_L2At_interrupt(tstctx);
    fail_if(*tstctx->L2A_it != 0x01, "L2A trigger not clr");
    *tstctx->L2A_it = 2;
    clr_L2At_interrupt(tstctx);
    fail_if(*tstctx->L2A_it != 0x01, "L2A trigger not clr");
}
END_TEST

START_TEST (test_clr_A2La_interrupt)
{
    *tstctx->L2A_it = 2;
    clr_A2La_interrupt(tstctx);
    fail_if(*tstctx->L2A_it != 0x02, "A2L acknowledge not clr");
    *tstctx->L2A_it = 1;
    clr_A2La_interrupt(tstctx);
    fail_if(*tstctx->L2A_it != 0x02, "A2L acknowledge not clr");
}
END_TEST

START_TEST (test_A2La_it_enable)
{
    *tstctx->L2A_it_mask = 2;
    A2La_it_enable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x00, "A2L acknowledge not enable");
    *tstctx->L2A_it_mask = 1;
    A2La_it_enable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x01, "A2L acknowledge not enable");
}
END_TEST

START_TEST (test_L2At_it_enable)
{
    *tstctx->L2A_it_mask = 1;
    L2At_it_enable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x00, "L2A trigger not enable");
    *tstctx->L2A_it_mask = 2;
    L2At_it_enable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x02, "L2A trigger not enable");
}
END_TEST

START_TEST (test_A2La_it_disable)
{
    *tstctx->L2A_it_mask = 0;
    A2La_it_disable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x02, "A2L acknowledge not disable");
    *tstctx->L2A_it_mask = 3;
    A2La_it_disable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x03, "A2L acknowledge not disable");
}
END_TEST

START_TEST (test_L2At_it_disable)
{
    *tstctx->L2A_it_mask = 0;
    L2At_it_disable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x01, "L2A trigger not disable");
    *tstctx->L2A_it_mask = 3;
    L2At_it_disable(tstctx);
    fail_if(*tstctx->L2A_it_mask != 0x03, "L2A trigger not disable");
}
END_TEST

START_TEST (test_halmbx_L2Amail_not_empty_queue)
{
    //The ring size for the test is 0x100
    *tstctx->L2A_tail = 0x5;
    *tstctx->L2A_head = 0x5;
    fail_if(halmbx_L2Amail_not_empty_queue(tstctx) != 0, "Error checking L2A not empty queue");
    *tstctx->L2A_tail = 0xA;
    *tstctx->L2A_head = 0x7;
    fail_if(halmbx_L2Amail_not_empty_queue(tstctx) == 0, "Error checking L2A not empty queue");
    *tstctx->L2A_tail = 0x0;
    *tstctx->L2A_head = 0xFE;
    fail_if(halmbx_L2Amail_not_empty_queue(tstctx) == 0, "Error checking L2A not empty queue");
}
END_TEST

START_TEST (test_halmbx_A2Lmail_status_queue)
{
    //The ring size for the test is 0x100
    *tstctx->A2L_tail = 0x05;
    *tstctx->A2L_head = 0x05;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != NOT_FULL, "Error checking A2L status queue");
    *tstctx->A2L_tail = 0x54;
    *tstctx->A2L_head = 0x04;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != NOT_FULL, "Error checking A2L status queue");
    *tstctx->A2L_tail = 0x20;
    *tstctx->A2L_head = 0xF0;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != NOT_FULL, "Error checking A2L status queue");
    *tstctx->A2L_tail = 0x1C;
    *tstctx->A2L_head = 0x18;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != FULL, "Error checking A2L status queue");
    *tstctx->A2L_tail = 0x04;
    *tstctx->A2L_head = 0xFC;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != FULL, "Error checking A2L status queue");
    *tstctx->A2L_tail = 0x14;
    *tstctx->A2L_head = 0x08;
    fail_if(halmbx_A2Lmail_status_queue(tstctx) != NEARLY_FULL, "Error checking A2L status queue");
}
END_TEST

START_TEST (test_halmbx_L2Amail_status_queue)
{
    //The ring size for the test is 0x100
    *tstctx->L2A_tail = 0x05;
    *tstctx->L2A_head = 0x05;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != NOT_FULL, "Error checking L2A status queue");
    *tstctx->L2A_tail = 0x54;
    *tstctx->L2A_head = 0x04;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != NOT_FULL, "Error checking L2A status queue");
    *tstctx->L2A_tail = 0x20;
    *tstctx->L2A_head = 0xF0;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != NOT_FULL, "Error checking L2A status queue");
    *tstctx->L2A_tail = 0x1C;
    *tstctx->L2A_head = 0x18;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != FULL, "Error checking L2A status queue");
    *tstctx->L2A_tail = 0x04;
    *tstctx->L2A_head = 0xFC;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != FULL, "Error checking L2A status queue");
    *tstctx->L2A_tail = 0x14;
    *tstctx->L2A_head = 0x08;
    fail_if(halmbx_L2Amail_status_queue(tstctx) != NEARLY_FULL, "Error checking L2A status queue");
}
END_TEST

START_TEST (test_halmbx_copy_to_ring)
{
    uint32_t msg[] = {0x12345678, 0xFEDCBA98};
    uint32_t *res;

    //Check arguments
    fail_if(halmbx_copy_to_ring(NULL,NULL,5) == 0, "Error with no context");
    fail_if(halmbx_copy_to_ring(tstctx,NULL,MAX_MSG_SIZE+5) == 0, "Error with a too big size");
    fail_if(halmbx_copy_to_ring(tstctx,NULL,0) == 0, "Error without size");
    fail_if(halmbx_copy_to_ring(tstctx,NULL,3) == 0, "Error with size not align");
    fail_if(halmbx_copy_to_ring(tstctx,NULL,4) == 0, "Error without pointer");
    fail_if(halmbx_copy_to_ring(tstctx,(uint32_t*)0x67546421,4) == 0, "Error with pointer not align");

    //Check function
    *tstctx->A2L_tail = 0x4;
    *tstctx->A2L_head = 0x4;
    fail_if(halmbx_copy_to_ring(tstctx,(uint32_t*)msg, sizeof(msg)) != 0, "Error during copy");
    res = (uint32_t*)(A2L_RING_BASE_ADDR + *tstctx->A2L_tail);
    fail_if(*res++ != msg[0], "Error with copy");
    fail_if(*res != msg[1], "Error with copy");

    *tstctx->A2L_tail = 0xFC;
    *tstctx->A2L_head = 0xFC;
    fail_if(halmbx_copy_to_ring(tstctx,(uint32_t*)msg, sizeof(msg)) != 0, "Error before copy");
    res = (uint32_t*)(A2L_RING_BASE_ADDR + *tstctx->A2L_tail);
    fail_if(*res != msg[0], "Error with rollover copy"); //offset=FC to FF
    res = (uint32_t*)A2L_RING_BASE_ADDR;
    fail_if(*res != msg[1], "Error with rollover copy"); //offset=0 to 3
}
END_TEST

START_TEST (test_halmbx_copy_from_ring)
{
    uint32_t msg_origin[] = {0x87654321, 0x89ABCDEF};
    uint32_t msg[2];
    uint32_t *res;

    //Check arguments
    fail_if(halmbx_copy_to_ring(NULL,NULL,5) == 0, "Error with no context");
    fail_if(halmbx_copy_from_ring(tstctx,NULL,MAX_MSG_SIZE+5) == 0, "Error with a too big size");
    fail_if(halmbx_copy_from_ring(tstctx,NULL,0) == 0, "Error without size");
    fail_if(halmbx_copy_from_ring(tstctx,NULL,3) == 0, "Error with size not align");
    fail_if(halmbx_copy_from_ring(tstctx,NULL,4) == 0, "Error without pointer");
    fail_if(halmbx_copy_from_ring(tstctx,(uint32_t*)0x67546421,4) == 0, "Error with pointer not align");

    //Check function
    *tstctx->L2A_tail = 0x4;
    *tstctx->L2A_head = 0x4;
    res = (uint32_t*)(L2A_RING_BASE_ADDR + *tstctx->L2A_head);
    *res = msg_origin[0];
    *(res+1) = msg_origin[1];
    fail_if(halmbx_copy_from_ring(tstctx,(uint32_t*)msg, sizeof(msg_origin)) != 0, "Error before copy");
    fail_if(msg[0] != msg[0], "Error with copy");
    fail_if(msg[1] != msg[1], "Error with copy");

    memset((char*)tstctx->L2A_head, 0, 4);
    *tstctx->L2A_tail = 0xFC;
    *tstctx->L2A_head = 0xFC;
    res = (uint32_t*)(L2A_RING_BASE_ADDR + *tstctx->L2A_head); //offset=FC to FF
    *res = msg_origin[0];
    res = (uint32_t*)L2A_RING_BASE_ADDR; //offset=0 to 3
    *(res+1) = msg_origin[1];
    fail_if(halmbx_copy_from_ring(tstctx,(uint32_t*)msg, sizeof(msg_origin)) != 0, "Error before copy");
    fail_if(msg[0] != msg[0], "Error with rollover copy");
    fail_if(msg[1] != msg[1], "Error with rollover copy");
}
END_TEST

START_TEST (test_halmbx_A2Lmail_update)
{
    //Check arguments
    fail_if(halmbx_A2Lmail_update(NULL,5) == 0, "Error with no context");
    fail_if(halmbx_A2Lmail_update(tstctx,0) == 0, "Error without size");

    //Check function
    *tstctx->A2L_tail = 0x4;
    *tstctx->A2L_head = 0x4;
    fail_if(halmbx_A2Lmail_update(tstctx,8) != 0, "Error before update");
    fail_if(*tstctx->A2L_tail != 0xC, "Error with update");
    *tstctx->A2L_tail = 0xFC;
    *tstctx->A2L_head = 0xFC;
    fail_if(halmbx_A2Lmail_update(tstctx,8) != 0, "Error before update");
    fail_if(*tstctx->A2L_tail != 0x4, "Error with rollover update");
}
END_TEST

START_TEST (test_halmbx_L2Amail_update)
{
    //Check arguments
    fail_if(halmbx_A2Lmail_update(NULL,5) == 0, "Error with no context");
    fail_if(halmbx_L2Amail_update(tstctx,0) == 0, "Error without size");

    //Check function
    *tstctx->L2A_tail = 0x4;
    *tstctx->L2A_head = 0x4;
    fail_if(halmbx_L2Amail_update(tstctx,4) != 0, "Error before update");
    fail_if(*tstctx->L2A_head != 0x8, "Error with update");
    *tstctx->L2A_tail = 0xFC;
    *tstctx->L2A_head = 0xFC;
    fail_if(halmbx_L2Amail_update(tstctx,0xC) != 0, "Error before update");
    fail_if(*tstctx->L2A_head != 0x8, "Error with rollover update");
}
END_TEST

extern Suite* processing_suite(void)
{
    Suite *s = suite_create("HAL");
    TCase *tc_core = tcase_create("Core");

    //Test halmbx_init
    tcase_add_test(tc_core, test_halmbx_init);

    //Test set_A2Lt_interrupt
    tcase_add_test(tc_core, test_set_A2Lt_interrupt);
    //Test set_L2Aa_interrupt
    tcase_add_test(tc_core, test_set_L2Aa_interrupt);
    //Test clr_L2At_interrupt
    tcase_add_test(tc_core, test_clr_L2At_interrupt);
    //Test clr_A2La_interrupt
    tcase_add_test(tc_core, test_clr_A2La_interrupt);

    //Test en_A2La_interrupt
    tcase_add_test(tc_core, test_A2La_it_enable);
    //Test en_L2At_interrupt
    tcase_add_test(tc_core, test_L2At_it_enable);
    //Test dis_A2La_interrupt
    tcase_add_test(tc_core, test_A2La_it_disable);
    //Test dis_L2At_interrupt
    tcase_add_test(tc_core, test_L2At_it_disable);

    //Test halmbx_L2Amail_not_empty_queue
    tcase_add_test(tc_core, test_halmbx_L2Amail_not_empty_queue);
    //Test halmbx_A2Lmail_status_queue
    tcase_add_test(tc_core, test_halmbx_A2Lmail_status_queue);
    //Test halmbx_L2Amail_status_queue
    tcase_add_test(tc_core, test_halmbx_L2Amail_status_queue);

    //Test halmbx_copy_to_ring
    tcase_add_test(tc_core, test_halmbx_copy_to_ring);
    //Test halmbx_copy_from_ring
    tcase_add_test(tc_core, test_halmbx_copy_from_ring);
    //Test halmbx_A2Lmail_update
    tcase_add_test(tc_core, test_halmbx_A2Lmail_update);
    //Test halmbx_L2Amail_update
    tcase_add_test(tc_core, test_halmbx_L2Amail_update);

    suite_add_tcase(s, tc_core);
    return s;
}

int main(void)
{
    int number_failed = 0;
    Suite *s;

    //Run Processing tests
    s = processing_suite();

    SRunner *sr = srunner_create(s);
    srunner_set_fork_status (sr, CK_NOFORK);
    srunner_run_all(sr, CK_NORMAL);
    number_failed = srunner_ntests_failed(sr);
    srunner_free(sr);

    return (number_failed == 0) ? 0 : -1;
}