]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/ipc/examples/ex05_bios_multicore_echo_negative_test/ipc_neg_testsetup.c
J7AHP: OSAL: Osal bringup
[processor-sdk/pdk.git] / packages / ti / drv / ipc / examples / ex05_bios_multicore_echo_negative_test / ipc_neg_testsetup.c
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2020
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
7  *  are met:
8  *
9  *    Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *    Neither the name of Texas Instruments Incorporated nor the names of
18  *    its contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
34 /**
35  *  \file ipc_neg_testsetup.c
36  *
37  *  \brief IPC  example code
38  *
39  */
41 /* ========================================================================== */
42 /*                             Include Files                                  */
43 /* ========================================================================== */
45 #include <stdio.h>
46 #include <stdint.h>
47 #include <string.h>
49 #include <ti/drv/ipc/examples/common/src/ipc_setup.h>
50 #include <ti/drv/ipc/ipc.h>
51 #include <ti/drv/ipc/ipcver.h>
52 #include <ti/drv/ipc/examples/ex05_bios_multicore_echo_negative_test/ipc_neg_setup.h>
54 #include <ti/osal/osal.h>
55 #include <ti/drv/uart/UART.h>
56 #include <ti/drv/uart/UART_stdio.h>
58 #define MSGSIZE  256U
59 #define SERVICE  "ti.ipc4.ping-pong"
60 #define FAKE_SERVICE "negative-test"
61 #define ENDPT1   13U
62 #define ENDPT2   14U
63 #define NUMMSGS  10000 /* number of message sent per task */
64 //#define NUMMSGS  1000000   /* number of message sent per task */
66 extern uint8_t  *pCntrlBuf;
67 extern uint8_t  *pTaskBuf;
68 extern uint8_t  *pSendTaskBuf;
69 extern uint8_t  *pRecvTaskBuf;
70 extern uint8_t  *pTimeoutBuf;
71 extern uint8_t  *pSysVqBuf;
73 extern uint32_t  selfProcId;
74 extern uint32_t *pRemoteProcArray;
75 extern uint32_t  gNumRemoteProc;
77 uint32_t rpmsgNegDataSize = RPMSG_DATA_SIZE;
79 /* ========================================================================== */
80 /*                           Macros & Typedefs                                */
81 /* ========================================================================== */
83 #define RP_MSG_TEST_BUF_SIZE     (512 + 2)
84 /* ========================================================================== */
85 /*                         Structure Declarations                             */
86 /* ========================================================================== */
88 /* None */
90 /* ========================================================================== */
91 /*                          Function Declarations                             */
92 /* ========================================================================== */
95 /* ========================================================================== */
96 /*                            Global Variables                                */
97 /* ========================================================================== */
98 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
99 static uint32_t        RecvEndPt = 0;
100 #endif
102 static uint32_t gTotalTests = 0;
103 static uint32_t gTotalTestsPassed = 0;
104 static uint32_t gTotalTestsFailed = 0;
106 typedef enum Ipc_NegTestId_e {
107     TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF,
108     TEST_VIRTIO_INIT_PARAM_NULL,
109     TEST_RPMSG_INIT_PARAM_NULL,
110     TEST_RPMSG_CREATE_NULL_ENDPNT,
111     TEST_RPMSG_SND_NULL_DATA,
112     TEST_RPMSG_SND_UNPAIR_CORE,
113     TEST_RPMSG_RCV_HNDL_NULL,
114     TEST_RPMSG_SND_HNDL_NULL,
115     TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO,
116     TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO,
117     TEST_RPMSG_PARAM_BUF_NULL,
118     TEST_RPMSG_PARAM_BUF_SIZE_ZERO,
119     TEST_RPMSG_PARAM_STKBUF_NULL,
120     TEST_RPMSG_PARAM_STK_SIZE_ZERO,
121     TEST_RPMSG_RCV_TIMEOUT,
122     TEST_RPMSG_REMOTE_END_TIMEOUT,
123     TEST_END
124 } Ipc_NegTestId;
126 typedef struct Ipc_NegTestParams_s
128     uint32_t  testId;
129     char     *testName;
130 } Ipc_TestParams;
132 Ipc_TestParams negTestCases[] =
134     { TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, "test_rpmsg_pkt_large_than_vring_buf" },
135     { TEST_VIRTIO_INIT_PARAM_NULL, "test_virtio_init_param_null" },
136     { TEST_RPMSG_INIT_PARAM_NULL, "test_rpmsg_init_param_null" },
137     { TEST_RPMSG_CREATE_NULL_ENDPNT, "test_rpmsg_create_null_endpnt" },
138     { TEST_RPMSG_SND_NULL_DATA, "test_rpmsg_snd_null_data" },
139     { TEST_RPMSG_SND_UNPAIR_CORE, "test_rpmsg_snd_unpair_core" },
140     { TEST_RPMSG_RCV_HNDL_NULL, "test_rpmsg_rcv_hndl_null" },
141     { TEST_RPMSG_SND_HNDL_NULL, "test_rpmsg_snd_hndl_null" },
142     { TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, "test_virtio_param_vqbuf_size_zero" },
143     { TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, "test_virtio_param_vringbuf_size_zero" },
144     { TEST_RPMSG_PARAM_BUF_NULL, "test_rpmsg_param_buf_null" },
145     { TEST_RPMSG_PARAM_BUF_SIZE_ZERO, "test_rpmsg_param_buf_size_zero" },
146     { TEST_RPMSG_PARAM_STKBUF_NULL, "test_rpmsg_param_stkbuf_null" },
147     { TEST_RPMSG_PARAM_STK_SIZE_ZERO, "test_rpmsg_param_stk_size_zero" },
148     { TEST_RPMSG_RCV_TIMEOUT, "test_rpmsg_rcv_timeout" },
149     { TEST_RPMSG_REMOTE_END_TIMEOUT, "test_rpmsg_remote_end_timeout" },
150     { TEST_END, NULL },
151 };
153 //#define DEBUG_PRINT
155 bool g_neg_exitRespTsk = 0;
157 void rpmsg_neg_exit_responseTask()
159     g_neg_exitRespTsk = 1;
162 void Ipc_reportResult(uint32_t id, int32_t result)
164     gTotalTests++;
165     if (result == IPC_SOK)
166     {
167         App_printf("[%s] [%s] : [TEST_PASS]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
168         UART_printf("[%s] [%s] : [TEST_PASS]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
169         gTotalTestsPassed++;
170     }
171     else
172     {
173         App_printf("[%s] [%s] : [TEST_FAIL]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
174         UART_printf("[%s] [%s] : [TEST_FAIL]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
175         gTotalTestsFailed++;
176     }
179 /*
180  * This "Task" waits for a "ping" message from any processor
181  * then replies with a "pong" message.
182  */
183 int32_t rpmsg_neg_responderFxn(uint32_t testId)
185     RPMessage_Handle    handle;
186     RPMessage_Handle    handleTimeout;
187     RPMessage_Params    params;
188     uint32_t        myEndPt = 0;
189     uint32_t        myTimeoutEndPt = 0;
190     uint32_t        remoteEndPt;
191     uint32_t        remoteProcId;
192     uint16_t        len;
193     int32_t         status = 0;
194     void            *buf;
195     void            *buf2;
197     uint32_t            bufSize = rpmsgNegDataSize;
198     char                str[MSGSIZE];
199     char                test_buf[RP_MSG_TEST_BUF_SIZE + 1];
202     buf = pRecvTaskBuf;
203     if (buf == NULL)
204     {
205         App_printf("RecvTask: buffer allocation failed\n");
206         return IPC_EFAIL;
207     }
209     /* Testing TEST_RPMSG_REMOTE_END_TIMEOUT */
210     {
211         status = RPMessage_getRemoteEndPt(IPC_MCU1_0, FAKE_SERVICE, &remoteProcId,
212                 &remoteEndPt, 1000);
213         if (status != IPC_SOK)
214         {
215             Ipc_reportResult(TEST_RPMSG_REMOTE_END_TIMEOUT, IPC_SOK);
216         }
217         else
218         {
219             Ipc_reportResult(TEST_RPMSG_REMOTE_END_TIMEOUT, IPC_EFAIL);
220             return IPC_EFAIL;
221         }
222     }
224     RPMessageParams_init(&params);
225     params.requestedEndpt = ENDPT1;
226     params.buf = buf;
227     params.bufSize = bufSize;
229     /* Testing TEST_RPMSG_CREATE_NULL_ENDPNT */
230     {
231         App_printf("RPMessage_create NULL Endpt\n");
232         handle = RPMessage_create(&params, NULL);
233         if (!handle)
234         {
235             Ipc_reportResult(TEST_RPMSG_CREATE_NULL_ENDPNT, IPC_SOK);
236         }
237         else
238         {
239             Ipc_reportResult(TEST_RPMSG_CREATE_NULL_ENDPNT, IPC_EFAIL);
240             return IPC_EFAIL;
241         }
242     }
244     handle = RPMessage_create(&params, &myEndPt);
245     if (!handle)
246     {
247         App_printf("RecvTask: Failed to create endpoint\n");
248         return IPC_EFAIL;
249     }
250     buf2 = pTimeoutBuf;
251     params.requestedEndpt = ENDPT2;
252     params.buf = buf2;
253     params.bufSize = bufSize;
254     handleTimeout = RPMessage_create(&params, &myTimeoutEndPt);
255     if (!handleTimeout)
256     {
257         App_printf("RecvTask: Failed to create timeout endpoint\n");
258         RPMessage_delete(&handle);
259         return IPC_EFAIL;
260     }
262 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
263     RecvEndPt = myEndPt;
264 #endif
266 #if defined (BUILD_MPU1_0)
267     remoteProcId = IPC_MCU1_0;
268 #else
269     remoteProcId = IPC_MPU1_0;
270 #endif
272     /* Testing TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF */
273     {
274         /* Send data to remote endPt: */
275         memset(test_buf, 0, RP_MSG_TEST_BUF_SIZE);
277         len = snprintf(test_buf, RP_MSG_TEST_BUF_SIZE, "ping %d", 0);
279         if(len > RP_MSG_TEST_BUF_SIZE)
280         {
281             App_printf("SendTask%d: snprintf failed, len %d\n", remoteProcId, len);
282             len = RP_MSG_TEST_BUF_SIZE;
283         }
285         len = RP_MSG_TEST_BUF_SIZE;
286         test_buf[len++] = '\0';
288         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, (Ptr)test_buf, len);
289         if (status != IPC_SOK)
290         {
291             Ipc_reportResult(TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, IPC_SOK);
292         }
293         else
294         {
295             Ipc_reportResult(TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, IPC_EFAIL);
296             return IPC_EFAIL;
297         }
298     }
300     /* Testing TEST_RPMSG_SND_NULL_DATA */
301     {
302         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, NULL, len);
304         if (status != IPC_SOK)
305         {
306             Ipc_reportResult(TEST_RPMSG_SND_NULL_DATA, IPC_SOK);
307         }
308         else
309         {
310             Ipc_reportResult(TEST_RPMSG_SND_NULL_DATA, IPC_EFAIL);
311             return IPC_EFAIL;
312         }
313     }
315     /* Testing TEST_RPMSG_SND_UNPAIR_CORE */
316     {
317 #ifdef BUILD_C66X_1
318         remoteProcId = IPC_C66X_1; // todo: what should dstProc be??
319 #endif
320         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, (Ptr)buf, len);
322         if (status != IPC_SOK)
323         {
324             Ipc_reportResult(TEST_RPMSG_SND_UNPAIR_CORE, IPC_SOK);
325         }
326         else
327         {
328             Ipc_reportResult(TEST_RPMSG_SND_UNPAIR_CORE, IPC_EFAIL);
329             return IPC_EFAIL;
330         }
331     }
333     /* Testing TEST_RPMSG_SND_HNDL_NULL */
334     {
335         status = RPMessage_send(NULL, remoteProcId, ENDPT1, myEndPt, (Ptr)buf, len);
336         if (status != IPC_SOK)
337         {
338             Ipc_reportResult(TEST_RPMSG_SND_HNDL_NULL, IPC_SOK);
339         }
340         else
341         {
342             Ipc_reportResult(TEST_RPMSG_SND_HNDL_NULL, IPC_EFAIL);
343             return IPC_EFAIL;
344         }
345     }
347     /* Testing TEST_RPMSG_RCV_HNDL_NULL */
348     {
349         status = RPMessage_recv(NULL, (Ptr)str, &len, &remoteEndPt, &remoteProcId,
350                     IPC_RPMESSAGE_TIMEOUT_FOREVER);
351         if (status != IPC_SOK)
352         {
353             Ipc_reportResult(TEST_RPMSG_RCV_HNDL_NULL, IPC_SOK);
354         }
355         else
356         {
357             Ipc_reportResult(TEST_RPMSG_RCV_HNDL_NULL, IPC_EFAIL);
358             return IPC_EFAIL;
359         }
360     }
362     /* Testing TEST_RPMSG_RCV_TIMEOUT */
363     {
364         App_printf("[%s] calling RPMessage_recv with timeout 100...\n", Ipc_mpGetSelfName());
365         status = RPMessage_recv(handleTimeout, (Ptr)str, &len, &remoteEndPt, &remoteProcId, 100);
367         if (status != IPC_ETIMEOUT)
368         {
369             Ipc_reportResult(TEST_RPMSG_RCV_TIMEOUT, IPC_EFAIL);
370             return IPC_EFAIL;
371         }
372         else
373         {
374             Ipc_reportResult(TEST_RPMSG_RCV_TIMEOUT, IPC_SOK);
375         }
376     }
378     return IPC_SOK;
381 int32_t ipc_neg_test(uint32_t testId)
383     uint32_t          numProc = gNumRemoteProc;
384     Ipc_VirtIoParams  vqParam;
385     uint32_t          index = 0;
386     int32_t           status;
388     /* Step1 : Initialize the multiproc */
389     Ipc_mpSetConfig(selfProcId, numProc, pRemoteProcArray);
391     App_printf("IPC_echo_test (core : %s) .....\r\n%s\r\n",
392             Ipc_mpGetSelfName(), IPC_DRV_VERSION_STR);
394     Ipc_init(NULL);
396     /* Step2 : Initialize Virtio */
397     vqParam.vqObjBaseAddr = (void*)pSysVqBuf;
398     vqParam.vqBufSize     = numProc * Ipc_getVqObjMemoryRequiredPerCore();
399     vqParam.vringBaseAddr = (void*)VRING_BASE_ADDRESS;
400     vqParam.vringBufSize  = IPC_VRING_BUFFER_SIZE;
401     vqParam.timeoutCnt    = 100;  /* Wait for counts */
403     /* Testing TEST_VIRTIO_INIT_PARAM_NULL */
404     {
405         status = Ipc_initVirtIO( NULL );
406         if(status != IPC_SOK)
407         {
408             Ipc_reportResult(TEST_VIRTIO_INIT_PARAM_NULL, IPC_SOK);
409         }
410         else
411         {
412             Ipc_reportResult(TEST_VIRTIO_INIT_PARAM_NULL, IPC_EFAIL);
413             return IPC_EFAIL;
414         }
415     }
417     /* Testing TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO */
418     {
419         vqParam.vqBufSize     = 0;
421         status = Ipc_initVirtIO(&vqParam);
422         if(status != IPC_SOK)
423         {
424             Ipc_reportResult(TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, IPC_SOK);
425         }
426         else
427         {
428             Ipc_reportResult(TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, IPC_EFAIL);
429             return IPC_EFAIL;
430         }
431     }
433     /* Testing TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO */
434     {
435         vqParam.vqBufSize     = numProc * Ipc_getVqObjMemoryRequiredPerCore();
436         vqParam.vringBufSize  = 0;
438         status = Ipc_initVirtIO(&vqParam);
439         if(status != IPC_SOK)
440         {
441             Ipc_reportResult(TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, IPC_SOK);
442         }
443         else
444         {
445             Ipc_reportResult(TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, IPC_EFAIL);
446             return IPC_EFAIL;
447         }
448     }
451     App_printf("Ipc_initVirtIO\n");
452     vqParam.vringBufSize  = IPC_VRING_BUFFER_SIZE;
453     status = Ipc_initVirtIO(&vqParam);
454     if (status != IPC_SOK)
455     {
456         App_printf("[%s] Ipc_initVirtIO failed\n");
457         return IPC_EFAIL;
458     }
460     /* Step 3: Initialize RPMessage */
461     RPMessage_Params cntrlParam;
463     /* Initialize the param */
464     RPMessageParams_init(&cntrlParam);
466     /* Set memory for HeapMemory for control task */
467     cntrlParam.buf         = pCntrlBuf;
468     cntrlParam.bufSize     = rpmsgNegDataSize;
469     cntrlParam.stackBuffer = &pTaskBuf[index * IPC_TASK_STACKSIZE];
470     cntrlParam.stackSize   = IPC_TASK_STACKSIZE;
472     /* Testing TEST_RPMSG_INIT_PARAM_NULL */
473     {
474         status = RPMessage_init(NULL);
475         if(status != IPC_SOK)
476         {
477             Ipc_reportResult(TEST_RPMSG_INIT_PARAM_NULL, IPC_SOK);
478         }
479         else
480         {
481             Ipc_reportResult(TEST_RPMSG_INIT_PARAM_NULL, IPC_EFAIL);
482             return IPC_EFAIL;
483         }
484     }
486     /* Testing TEST_RPMSG_PARAM_BUF_NULL */
487     {
488         cntrlParam.buf =  NULL;
490         status = RPMessage_init(&cntrlParam);
491         if(status != IPC_SOK)
492         {
493             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_NULL, IPC_SOK);
494         }
495         else
496         {
497             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_NULL, IPC_EFAIL);
498             return IPC_EFAIL;
499         }
500     }
502     /* Testing TEST_RPMSG_PARAM_BUF_SIZE_ZERO */
503     {
504         cntrlParam.buf = pCntrlBuf;
505         cntrlParam.bufSize = 0;
507         status = RPMessage_init(&cntrlParam);
508         if(status != IPC_SOK)
509         {
510             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_SIZE_ZERO, IPC_SOK);
511         }
512         else
513         {
514             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_SIZE_ZERO, IPC_EFAIL);
515             return IPC_EFAIL;
516         }
517     }
518 #ifndef IPC_EXCLUDE_CTRL_TASKS
519     /* Testing TEST_RPMSG_PARAM_STKBUF_NULL */
520     {
521         cntrlParam.bufSize     = rpmsgNegDataSize;
522         cntrlParam.stackBuffer = NULL;
524         status = RPMessage_init(&cntrlParam);
525         if(status != IPC_SOK)
526         {
527             Ipc_reportResult(TEST_RPMSG_PARAM_STKBUF_NULL, IPC_SOK);
528         }
529         else
530         {
531             Ipc_reportResult(TEST_RPMSG_PARAM_STKBUF_NULL, IPC_EFAIL);
532             return IPC_EFAIL;
533         }
534     }
535     /* Testing TEST_RPMSG_PARAM_STK_SIZE_ZERO */
536     {
537         cntrlParam.stackBuffer = &pTaskBuf[index * IPC_TASK_STACKSIZE];
538         cntrlParam.stackSize = 0;
540         status = RPMessage_init(&cntrlParam);
541         if(status != IPC_SOK)
542         {
543             Ipc_reportResult(TEST_RPMSG_PARAM_STK_SIZE_ZERO, IPC_SOK);
544         }
545         else
546         {
547             Ipc_reportResult(TEST_RPMSG_PARAM_STK_SIZE_ZERO, IPC_EFAIL);
548             return IPC_EFAIL;
549         }
550     }
551 #endif /* IPC_EXCLUDE_CTRL_TASKS */
553     App_printf("RPMessage_init\n");
554     cntrlParam.stackSize   = IPC_TASK_STACKSIZE;
555     status = RPMessage_init(&cntrlParam);
556     if (status != IPC_SOK)
557     {
558         App_printf("[%s] RPMessage_init failed\n", Ipc_mpGetSelfName());
559         return IPC_EFAIL;
560     }
562     return rpmsg_neg_responderFxn(testId);
565 int32_t Ipc_echo_neg_test(void)
567     uint32_t i = 0;
569     ipc_neg_test(i);
571     UART_printf("Tests finished\n");
572     UART_printf("Total tests: %d Passed: %d Failed %d\n", gTotalTests, gTotalTestsPassed, gTotalTestsFailed);
573     if (gTotalTests == gTotalTestsPassed)
574     {
575         UART_printf("All tests have passed.\n\n\n");
576     }
577     return 0;