OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.swp.api/] [openmcapi/] [1.0/] [test/] [func/] [fts_mcapi_pktchan_available.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Copyright (c) 2010, Mentor Graphics Corporation
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
/*
31
*   FILENAME
32
*
33
*       fts_main.c
34
*
35
*
36
*************************************************************************/
37
 
38
#include "fts_defs.h"
39
#include "support_suite/mcapid_support.h"
40
#include "mcapid.h"
41
 
42
extern MCAPI_MUTEX      MCAPID_FTS_Mutex;
43
 
44
/************************************************************************
45
*
46
*   FUNCTION
47
*
48
*       MCAPI_FTS_Tx_2_21_1
49
*
50
*   DESCRIPTION
51
*
52
*       Testing mcapi_pktchan_available - zero packets available.
53
*
54
*           Node 0 – Create endpoint, open send side, wait for connection
55
*
56
*           Node 1 – Create endpoint, get endpoint on Node 0, open receive
57
*                    side, make connection, check for message count on
58
*                    endpoint
59
*
60
*************************************************************************/
61
MCAPI_THREAD_ENTRY(MCAPI_FTS_Tx_2_21_1)
62
{
63
    MCAPID_STRUCT               *mcapi_struct = (MCAPID_STRUCT*)argv;
64
    size_t                      rx_len;
65
    mcapi_status_t              status;
66
    mcapi_endpoint_t            tx_endp;
67
    mcapi_request_t             request;
68
 
69
    /* Don't let any other test run while this test is running. */
70
    MCAPI_Obtain_Mutex(&MCAPID_FTS_Mutex);
71
 
72
    /* Indicate that a remote endpoint should be created. */
73
    mcapi_struct->status =
74
        MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CREATE_ENDP, 1024,
75
                               mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
76
 
77
    if (mcapi_struct->status == MCAPI_SUCCESS)
78
    {
79
        /* Wait for a response. */
80
        mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
81
 
82
        /* If the endpoint was created. */
83
        if (mcapi_struct->status == MCAPI_SUCCESS)
84
        {
85
            /* Indicate that the endpoint should be opened as a sender. */
86
            mcapi_struct->status =
87
                MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_OPEN_TX_SIDE_PKT,
88
                                       1024, mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
89
 
90
            if (mcapi_struct->status == MCAPI_SUCCESS)
91
            {
92
                /* Wait for a response. */
93
                mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
94
 
95
                /* If the send side was opened. */
96
                if (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED)
97
                {
98
                    /* Get the send side endpoint. */
99
                    tx_endp = mcapi_get_endpoint(FUNC_BACKEND_NODE_ID, 1024, &mcapi_struct->status);
100
 
101
                    if (mcapi_struct->status == MCAPI_SUCCESS)
102
                    {
103
                        /* Connect the two endpoints. */
104
                        mcapi_connect_pktchan_i(tx_endp, mcapi_struct->local_endp,
105
                                                &mcapi_struct->request,
106
                                                &mcapi_struct->status);
107
 
108
                        if (mcapi_struct->status == MCAPI_SUCCESS)
109
                        {
110
                            /* Wait for the connection to complete. */
111
                            mcapi_wait(&mcapi_struct->request, &rx_len,
112
                                        &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
113
 
114
                            /* Open the local endpoint as the receiver. */
115
                            mcapi_open_pktchan_recv_i(&mcapi_struct->pkt_rx_handle,
116
                                                      mcapi_struct->local_endp,
117
                                                      &request, &mcapi_struct->status);
118
 
119
                            if (mcapi_struct->status == MCAPI_SUCCESS)
120
                            {
121
                                /* Wait for the open call to return successfully. */
122
                                mcapi_wait(&request, &rx_len,
123
                                           &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
124
 
125
                                /* Check for data on the receive side. */
126
                                if (mcapi_pktchan_available(mcapi_struct->pkt_rx_handle,
127
                                                            &mcapi_struct->status) != 0)
128
                                {
129
                                    mcapi_struct->status = 0;
130
                                }
131
 
132
                                /* Close the receive side. */
133
                                mcapi_packetchan_recv_close_i(mcapi_struct->pkt_rx_handle,
134
                                                              &request, &status);
135
 
136
                                if (status == MCAPI_SUCCESS)
137
                                {
138
                                    /* Wait for the connection to close. */
139
                                    mcapi_wait(&request, &rx_len, &status, MCAPI_FTS_TIMEOUT);
140
                                }
141
                            }
142
                        }
143
                    }
144
 
145
                    /* Tell the other side to close the send side. */
146
                    status =
147
                        MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CLOSE_TX_SIDE_PKT, 1024,
148
                                               mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
149
 
150
                    if (status == MCAPI_SUCCESS)
151
                    {
152
                        /* Wait for the response. */
153
                        status = MCAPID_RX_Mgmt_Response(mcapi_struct);
154
                    }
155
                }
156
            }
157
        }
158
 
159
        /* Tell the other side to delete the endpoint. */
160
        status =
161
            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_DELETE_ENDP, 1024,
162
                                   mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
163
 
164
        if (status == MCAPI_SUCCESS)
165
        {
166
            /* Wait for the response. */
167
            status = MCAPID_RX_Mgmt_Response(mcapi_struct);
168
        }
169
    }
170
 
171
    /* Set the state of the test to completed. */
172
    mcapi_struct->state = 0;
173
 
174
    /* Allow the next test to run. */
175
    MCAPI_Release_Mutex(&MCAPID_FTS_Mutex);
176
 
177
} /* MCAPI_FTS_Tx_2_21_1 */
178
 
179
/************************************************************************
180
*
181
*   FUNCTION
182
*
183
*       MCAPI_FTS_Tx_2_21_2
184
*
185
*   DESCRIPTION
186
*
187
*       Testing mcapi_pktchan_available - one packet available.
188
*
189
*           Node 0 – Create endpoint, open send side, wait for connection,
190
*                    send one packet
191
*
192
*           Node 1 – Create endpoint, get endpoint on Node 0, open receive
193
*                    side, make connection, check for message count on
194
*                    endpoint
195
*
196
*************************************************************************/
197
MCAPI_THREAD_ENTRY(MCAPI_FTS_Tx_2_21_2)
198
{
199
    MCAPID_STRUCT               *mcapi_struct = (MCAPID_STRUCT*)argv;
200
    size_t                      rx_len;
201
    mcapi_status_t              status;
202
    mcapi_endpoint_t            tx_endp, rx_endp;
203
    mcapi_request_t             request;
204
 
205
    /* Don't let any other test run while this test is running. */
206
    MCAPI_Obtain_Mutex(&MCAPID_FTS_Mutex);
207
 
208
    /* An extra endpoint is required for this test. */
209
    rx_endp = mcapi_create_endpoint(MCAPI_PORT_ANY, &mcapi_struct->status);
210
 
211
    if (mcapi_struct->status == MCAPI_SUCCESS)
212
    {
213
        /* Indicate that a remote endpoint should be created. */
214
        mcapi_struct->status =
215
            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CREATE_ENDP, 1024,
216
                                   mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
217
 
218
        if (mcapi_struct->status == MCAPI_SUCCESS)
219
        {
220
            /* Wait for a response. */
221
            mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
222
 
223
            /* If the endpoint was created. */
224
            if (mcapi_struct->status == MCAPI_SUCCESS)
225
            {
226
                /* Indicate that the endpoint should be opened as a sender. */
227
                mcapi_struct->status =
228
                    MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_OPEN_TX_SIDE_PKT,
229
                                           1024, mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
230
 
231
                if (mcapi_struct->status == MCAPI_SUCCESS)
232
                {
233
                    /* Wait for a response. */
234
                    mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
235
 
236
                    /* If the send side was opened. */
237
                    if (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED)
238
                    {
239
                        /* Get the send side endpoint. */
240
                        tx_endp = mcapi_get_endpoint(FUNC_BACKEND_NODE_ID, 1024, &mcapi_struct->status);
241
 
242
                        if (mcapi_struct->status == MCAPI_SUCCESS)
243
                        {
244
                            /* Connect the two endpoints. */
245
                            mcapi_connect_pktchan_i(tx_endp, rx_endp,
246
                                                    &mcapi_struct->request,
247
                                                    &mcapi_struct->status);
248
 
249
                            if (mcapi_struct->status == MCAPI_SUCCESS)
250
                            {
251
                                /* Wait for the connection to complete. */
252
                                mcapi_wait(&mcapi_struct->request, &rx_len,
253
                                            &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
254
 
255
                                /* Open the local endpoint as the receiver. */
256
                                mcapi_open_pktchan_recv_i(&mcapi_struct->pkt_rx_handle,
257
                                                          rx_endp, &request,
258
                                                          &mcapi_struct->status);
259
 
260
                                if (mcapi_struct->status == MCAPI_SUCCESS)
261
                                {
262
                                    /* Wait for the open call to return successfully. */
263
                                    mcapi_wait(&request, &rx_len,
264
                                               &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
265
 
266
                                    /* Tell the other side to send a packet. */
267
                                    mcapi_struct->status =
268
                                        MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_TX_PKT, 1024,
269
                                                               mcapi_struct->local_endp, 0,
270
                                                               MCAPI_DEFAULT_PRIO);
271
 
272
                                    if (mcapi_struct->status == MCAPI_SUCCESS)
273
                                    {
274
                                        /* Wait for data to be received on the local endpoint. */
275
                                        while (mcapi_pktchan_available(mcapi_struct->pkt_rx_handle,
276
                                               &mcapi_struct->status) != 1)
277
                                        {
278
                                            MCAPID_Sleep(250);
279
                                        }
280
                                    }
281
 
282
                                    /* Close the receive side. */
283
                                    mcapi_packetchan_recv_close_i(mcapi_struct->pkt_rx_handle,
284
                                                                  &request, &status);
285
 
286
                                    if (status == MCAPI_SUCCESS)
287
                                    {
288
                                        /* Wait for the connection to close. */
289
                                        mcapi_wait(&request, &rx_len, &status, MCAPI_FTS_TIMEOUT);
290
                                    }
291
                                }
292
                            }
293
                        }
294
 
295
                        /* Tell the other side to close the send side. */
296
                        status =
297
                            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CLOSE_TX_SIDE_PKT, 1024,
298
                                                   mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
299
 
300
                        if (status == MCAPI_SUCCESS)
301
                        {
302
                            /* Wait for the response. */
303
                            status = MCAPID_RX_Mgmt_Response(mcapi_struct);
304
                        }
305
                    }
306
                }
307
            }
308
 
309
            /* Tell the other side to delete the endpoint. */
310
            status =
311
                MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_DELETE_ENDP, 1024,
312
                                       mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
313
 
314
            if (status == MCAPI_SUCCESS)
315
            {
316
                /* Wait for the response. */
317
                status = MCAPID_RX_Mgmt_Response(mcapi_struct);
318
            }
319
        }
320
 
321
        /* Delete the extra endpoint. */
322
        mcapi_delete_endpoint(rx_endp, &status);
323
    }
324
 
325
    /* Set the state of the test to completed. */
326
    mcapi_struct->state = 0;
327
 
328
    /* Allow the next test to run. */
329
    MCAPI_Release_Mutex(&MCAPID_FTS_Mutex);
330
 
331
} /* MCAPI_FTS_Tx_2_21_2 */
332
 
333
/************************************************************************
334
*
335
*   FUNCTION
336
*
337
*       MCAPI_FTS_Tx_2_21_3
338
*
339
*   DESCRIPTION
340
*
341
*       Testing mcapi_pktchan_available - two packets available.
342
*
343
*           Node 0 – Create endpoint, open send side, wait for connection,
344
*                    send two packets
345
*
346
*           Node 1 – Create endpoint, get endpoint on Node 0, open receive
347
*                    side, make connection, check for message count on
348
*                    endpoint
349
*
350
*************************************************************************/
351
MCAPI_THREAD_ENTRY(MCAPI_FTS_Tx_2_21_3)
352
{
353
    MCAPID_STRUCT               *mcapi_struct = (MCAPID_STRUCT*)argv;
354
    size_t                      rx_len;
355
    mcapi_status_t              status;
356
    mcapi_endpoint_t            tx_endp, rx_endp;
357
    mcapi_request_t             request;
358
 
359
    /* Don't let any other test run while this test is running. */
360
    MCAPI_Obtain_Mutex(&MCAPID_FTS_Mutex);
361
 
362
    /* An extra endpoint is required for this test. */
363
    rx_endp = mcapi_create_endpoint(MCAPI_PORT_ANY, &mcapi_struct->status);
364
 
365
    if (mcapi_struct->status == MCAPI_SUCCESS)
366
    {
367
        /* Indicate that a remote endpoint should be created. */
368
        mcapi_struct->status =
369
            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CREATE_ENDP, 1024,
370
                                   mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
371
 
372
        if (mcapi_struct->status == MCAPI_SUCCESS)
373
        {
374
            /* Wait for a response. */
375
            mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
376
 
377
            /* If the endpoint was created. */
378
            if (mcapi_struct->status == MCAPI_SUCCESS)
379
            {
380
                /* Indicate that the endpoint should be opened as a sender. */
381
                mcapi_struct->status =
382
                    MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_OPEN_TX_SIDE_PKT,
383
                                           1024, mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
384
 
385
                if (mcapi_struct->status == MCAPI_SUCCESS)
386
                {
387
                    /* Wait for a response. */
388
                    mcapi_struct->status = MCAPID_RX_Mgmt_Response(mcapi_struct);
389
 
390
                    /* If the send side was opened. */
391
                    if (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED)
392
                    {
393
                        /* Get the send side endpoint. */
394
                        tx_endp = mcapi_get_endpoint(FUNC_BACKEND_NODE_ID, 1024, &mcapi_struct->status);
395
 
396
                        if (mcapi_struct->status == MCAPI_SUCCESS)
397
                        {
398
                            /* Connect the two endpoints. */
399
                            mcapi_connect_pktchan_i(tx_endp, rx_endp,
400
                                                    &mcapi_struct->request,
401
                                                    &mcapi_struct->status);
402
 
403
                            if (mcapi_struct->status == MCAPI_SUCCESS)
404
                            {
405
                                /* Wait for the connection to complete. */
406
                                mcapi_wait(&mcapi_struct->request, &rx_len,
407
                                            &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
408
 
409
                                /* Open the local endpoint as the receiver. */
410
                                mcapi_open_pktchan_recv_i(&mcapi_struct->pkt_rx_handle,
411
                                                          rx_endp, &request,
412
                                                          &mcapi_struct->status);
413
 
414
                                if (mcapi_struct->status == MCAPI_SUCCESS)
415
                                {
416
                                    /* Wait for the open call to return successfully. */
417
                                    mcapi_wait(&request, &rx_len,
418
                                               &mcapi_struct->status, MCAPI_FTS_TIMEOUT);
419
 
420
                                    /* Tell the other side to send a packet. */
421
                                    mcapi_struct->status =
422
                                        MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_TX_PKT, 1024,
423
                                                               mcapi_struct->local_endp, 0,
424
                                                               MCAPI_DEFAULT_PRIO);
425
 
426
                                    if (mcapi_struct->status == MCAPI_SUCCESS)
427
                                    {
428
                                        /* Tell the other side to send another packet. */
429
                                        mcapi_struct->status =
430
                                            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_TX_PKT, 1024,
431
                                                                   mcapi_struct->local_endp, 0,
432
                                                                   MCAPI_DEFAULT_PRIO);
433
 
434
                                        if (mcapi_struct->status == MCAPI_SUCCESS)
435
                                        {
436
                                            /* Wait for data to be received on the local endpoint. */
437
                                            while (mcapi_pktchan_available(mcapi_struct->pkt_rx_handle,
438
                                                   &mcapi_struct->status) != 2)
439
                                            {
440
                                                MCAPID_Sleep(250);
441
                                            }
442
                                        }
443
                                    }
444
 
445
                                    /* Close the receive side. */
446
                                    mcapi_packetchan_recv_close_i(mcapi_struct->pkt_rx_handle,
447
                                                                  &request, &status);
448
 
449
                                    if (status == MCAPI_SUCCESS)
450
                                    {
451
                                        /* Wait for the connection to close. */
452
                                        mcapi_wait(&request, &rx_len, &status, MCAPI_FTS_TIMEOUT);
453
                                    }
454
                                }
455
                            }
456
                        }
457
 
458
                        /* Tell the other side to close the send side. */
459
                        status =
460
                            MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_CLOSE_TX_SIDE_PKT, 1024,
461
                                                   mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
462
 
463
                        if (status == MCAPI_SUCCESS)
464
                        {
465
                            /* Wait for the response. */
466
                            status = MCAPID_RX_Mgmt_Response(mcapi_struct);
467
                        }
468
                    }
469
                }
470
            }
471
 
472
            /* Tell the other side to delete the endpoint. */
473
            status =
474
                MCAPID_TX_Mgmt_Message(mcapi_struct, MCAPID_MGMT_DELETE_ENDP, 1024,
475
                                       mcapi_struct->local_endp, 0, MCAPI_DEFAULT_PRIO);
476
 
477
            if (status == MCAPI_SUCCESS)
478
            {
479
                /* Wait for the response. */
480
                status = MCAPID_RX_Mgmt_Response(mcapi_struct);
481
            }
482
        }
483
 
484
        /* Delete the extra endpoint. */
485
        mcapi_delete_endpoint(rx_endp, &status);
486
    }
487
 
488
    /* Set the state of the test to completed. */
489
    mcapi_struct->state = 0;
490
 
491
    /* Allow the next test to run. */
492
    MCAPI_Release_Mutex(&MCAPID_FTS_Mutex);
493
 
494
} /* MCAPI_FTS_Tx_2_21_3 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.