summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c
blob: 9035df19696dbfc0348c44140d5032bf3e3ea48d (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
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    processing_utests.c
 * \brief   Unitary tests for Porcessing layer
 * \ingroup Cleopatre - PlcDrv
 *
 * This file content all the unitary tests for the processing layer,
 * this layer will analyse all frames(TX ans RX) and decided to pass and drop it.
 */

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

/** local defines */
#define ETH_P_HPAV              0x88E1
#define HPAV_MME_VERSION        0x01
#define HPAV_MME_TYPE_FCALL     0xABCD
#define HPAV_MME_FMI            0x2664

/** local variables */
static uint8_t eth_std[] = {
    0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
    0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
    0x34, 0x12,                         //eth type
    0x01,                               //eth raw
    0x88, 0x99,
    0x55, 0x66,
    0x99
};
static uint8_t eth_hpav[] = {
    0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
    0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
    0x88, 0xE1,                         //eth type=HPAV
    0x01,                               //mme version
    0x88, 0x99,                         //mme type=unknown
    0x55, 0x66,                         //mme fmi
    0x99
};
static uint8_t eth_hpav_fcall[] = {
    0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
    0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
    0x88, 0xE1,                         //eth type=HPAV
    0x01,                               //mme version
    0xAB, 0xCD,                         //mme type=fcall
    0x26, 0x64,                         //mme fmi
    0x99
};

/** Test init */
START_TEST (test_processing_init)
{
    struct init_info info;
    fail_if(processing_init(NULL) == 0, "Error checking arguments");
    fail_if(processing_init((struct init_info*)0x55555555) == 0, "Error with mailbox layer error");
    fail_if(processing_init(&info) != 0, "Error checking normal case");
}
END_TEST

/** Test uninit */
START_TEST (test_processing_uninit)
{
}
END_TEST

/** Test get_eth_src_addr */
START_TEST (test_processing_get_eth_src_addr)
{
    uint8_t source[6];
    int i;
    get_eth_src_addr(eth_std, source);
    for(i=0; i<6; i++)
    {
        fail_if(source[i] != eth_std[i+6], "Error with Eth src addr copy");
    }
}
END_TEST

/** Test get_eth_dst_addr */
START_TEST (test_processing_get_eth_dst_addr)
{
    uint8_t dst[6];
    int i;
    get_eth_dst_addr(eth_std, dst);
    for(i=0; i<6; i++)
    {
        fail_if(dst[i] != eth_std[i], "Error with Eth dst addr copy");
    }
}
END_TEST

/** Test get_eth_type */
START_TEST (test_processing_get_eth_type)
{
    fail_if(get_eth_type(eth_hpav) != ETH_P_HPAV, "Error with Eth type search");
}
END_TEST

/** Test get_eth_mme_version */
START_TEST (test_processing_get_eth_mme_version)
{
    fail_if(get_eth_mme_version(eth_hpav) != HPAV_MME_VERSION, "Error with HPAV MME version search");
}
END_TEST

/** Test get_eth_mme_type */
START_TEST (test_processing_get_eth_mme_type)
{
    fail_if(get_eth_mme_type(eth_hpav_fcall) != HPAV_MME_TYPE_FCALL, "Error with HPAV MME type search");
}
END_TEST

/** Test get_eth_mme_fmi */
START_TEST (test_processing_get_eth_mme_fmi)
{
    fail_if(get_eth_mme_fmi(eth_hpav_fcall) != HPAV_MME_FMI, "Error with HPAV MME fmi search");
}
END_TEST

/** Test processing_buffer_add */
START_TEST (test_processing_buffer_add)
{
    fail_if(processing_buffer_add((void*)NULL, DATA) != -1, "Error with prepare_hw procedure");

    fail_if(processing_buffer_add(eth_hpav_fcall, MME) != 0, "Error with sending a known frame");
    fail_if(processing_buffer_add(eth_std, (enum buffer_type)10) != -1, "Error with sending an unknown type frame");
}
END_TEST

/** Test processing_buffer_free */
START_TEST (test_processing_buffer_free)
{
    fail_if(processing_buffer_free((void*)NULL) != -1, "Error with prepare_hw procedure");

    fail_if(processing_buffer_free((void*)0x12345678) != 0, "Error with freeing a known frame");
    fail_if(processing_buffer_free((void*)0x55555555) != -1, "Error with freeing an unknown type frame");
}
END_TEST

/** Test processing_send */
START_TEST (test_processing_send)
{
    fail_if(processing_send(NULL, 124) != -1, "Error with arguments checking");
    fail_if(processing_send((void*)0x12345678, 0) != -1, "Error with arguments checking");
    fail_if(processing_send((void*)0x12345678, 2000) != -1, "Error with arguments checking");

    fail_if(processing_send((void*)eth_std, 100) != -1, "Error with prepare_hw procedure");

    fail_if(processing_send(eth_hpav_fcall, 70) != 3, "Error with sending an Interface frame");
    fail_if(processing_send(eth_hpav, 70) != 2, "Error with sending a Mme frame");
    fail_if(processing_send(eth_std, 70) != 1, "Error with sending a Data frame");
}
END_TEST

/** Test processing_receive */
START_TEST (test_processing_receive)
{
    fail_if(processing_receive(NULL, 124, DATA) != -1, "Error with arguments checking");
    fail_if(processing_receive((void*)0x12345678, 0, DATA) != -1, "Error with arguments checking");
    fail_if(processing_receive((void*)0x12345678, 2000, DATA) != -1, "Error with arguments checking");

    fail_if(processing_receive((void*)0x12345678, 100, DATA) != -1, "Error with prepare_hw procedure");

    fail_if(processing_receive(eth_hpav_fcall, 70, INTERFACE) != 0, "Error with receiving an Interface frame");
    fail_if(processing_receive(eth_hpav, 70, MME) != 0, "Error with receiving a Mme frame");
    fail_if(processing_receive(eth_hpav, 70, DATA) != 0, "Error with receiving a Data frame");
    fail_if(processing_receive(eth_hpav, 70, (enum buffer_type)10) != -1, "Error with receiving a unknown frame");

    fail_if(processing_receive((void*)0x55555555, 70, DATA) != -1, "Error with plcdrv_rx procedure");
}
END_TEST


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

    //Test init
    tcase_add_test(tc_core, test_processing_init);
    //Test uninit
    tcase_add_test(tc_core, test_processing_uninit);
    //Test get_eth_src_addr
    tcase_add_test(tc_core, test_processing_get_eth_src_addr);
    //Test get_eth_dst_addr
    tcase_add_test(tc_core, test_processing_get_eth_dst_addr);
    //Test get_eth_type
    tcase_add_test(tc_core, test_processing_get_eth_type);
    //Test get_eth_mme_version
    tcase_add_test(tc_core, test_processing_get_eth_mme_version);
    //Test get_eth_mme_type
    tcase_add_test(tc_core, test_processing_get_eth_mme_type);
    //Test get_eth_mme_fmi
    tcase_add_test(tc_core, test_processing_get_eth_mme_fmi);
    //Test processing_buffer_add
    tcase_add_test(tc_core, test_processing_buffer_add);
    //Test processing_buffer_add
    tcase_add_test(tc_core, test_processing_buffer_free);
    //Test processing_send
    tcase_add_test(tc_core, test_processing_send);
    //Test processing_receive
    tcase_add_test(tc_core, test_processing_receive);

    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_run_all(sr, CK_NORMAL);
    number_failed = srunner_ntests_failed(sr);
    srunner_free(sr);

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