PDK-7626: IPC: Test: Cleanup ex05 test and Make ready for Automation
[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 /* XDCtools Header files */
50 #include <xdc/std.h>
51 #include <xdc/runtime/Error.h>
52 #include <xdc/runtime/System.h>
53 #include <xdc/runtime/Memory.h>
55 /* BIOS Header files */
56 #include <ti/sysbios/BIOS.h>
57 #include <ti/sysbios/knl/Task.h>
59 #include <ti/drv/ipc/ipc.h>
60 #include <ti/drv/ipc/ipcver.h>
61 #include <ti/drv/ipc/examples/common/src/ipc_setup.h>
62 #include <ti/drv/ipc/examples/ex05_bios_multicore_echo_negative_test/ipc_neg_setup.h>
63 #include <ti/osal/osal.h>
64 #include <ti/drv/uart/UART.h>
65 #include <ti/drv/uart/UART_stdio.h>
67 #define MSGSIZE  256U
68 #define SERVICE  "ti.ipc4.ping-pong"
69 #define FAKE_SERVICE "negative-test"
70 #define ENDPT1   13U
71 #define ENDPT2   14U
72 #define NUMMSGS  10000 /* number of message sent per task */
73 //#define NUMMSGS  1000000   /* number of message sent per task */
75 extern uint8_t  *pCntrlBuf;
76 extern uint8_t  *pTaskBuf;
77 extern uint8_t  *pSendTaskBuf;
78 extern uint8_t  *pRecvTaskBuf;
79 extern uint8_t  *pTimeoutBuf;
80 extern uint8_t  *pSysVqBuf;
82 extern uint32_t  selfProcId;
83 extern uint32_t *pRemoteProcArray;
84 extern uint32_t  gNumRemoteProc;
86 uint32_t rpmsgNegDataSize = RPMSG_DATA_SIZE;
88 /* ========================================================================== */
89 /*                           Macros & Typedefs                                */
90 /* ========================================================================== */
92 #define RP_MSG_TEST_BUF_SIZE     (512 + 2)
93 /* ========================================================================== */
94 /*                         Structure Declarations                             */
95 /* ========================================================================== */
97 /* None */
99 /* ========================================================================== */
100 /*                          Function Declarations                             */
101 /* ========================================================================== */
104 /* ========================================================================== */
105 /*                            Global Variables                                */
106 /* ========================================================================== */
107 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
108 static uint32_t        RecvEndPt = 0;
109 #endif
111 static uint32_t gTotalTests = 0;
112 static uint32_t gTotalTestsPassed = 0;
113 static uint32_t gTotalTestsFailed = 0;
115 typedef enum Ipc_NegTestId_e {
116     TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF,
117     TEST_VIRTIO_INIT_PARAM_NULL,
118     TEST_RPMSG_INIT_PARAM_NULL,
119     TEST_RPMSG_CREATE_NULL_ENDPNT,
120     TEST_RPMSG_SND_NULL_DATA,
121     TEST_RPMSG_SND_UNPAIR_CORE,
122     TEST_RPMSG_RCV_HNDL_NULL,
123     TEST_RPMSG_SND_HNDL_NULL,
124     TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO,
125     TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO,
126     TEST_RPMSG_PARAM_BUF_NULL,
127     TEST_RPMSG_PARAM_BUF_SIZE_ZERO,
128     TEST_RPMSG_PARAM_STKBUF_NULL,
129     TEST_RPMSG_PARAM_STK_SIZE_ZERO,
130     TEST_RPMSG_RCV_TIMEOUT,
131     TEST_RPMSG_REMOTE_END_TIMEOUT,
132     TEST_END
133 } Ipc_NegTestId;
135 typedef struct Ipc_NegTestParams_s
137     uint32_t  testId;
138     char     *testName;
139 } Ipc_TestParams;
141 Ipc_TestParams negTestCases[] =
143     { TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, "test_rpmsg_pkt_large_than_vring_buf" },
144     { TEST_VIRTIO_INIT_PARAM_NULL, "test_virtio_init_param_null" },
145     { TEST_RPMSG_INIT_PARAM_NULL, "test_rpmsg_init_param_null" },
146     { TEST_RPMSG_CREATE_NULL_ENDPNT, "test_rpmsg_create_null_endpnt" },
147     { TEST_RPMSG_SND_NULL_DATA, "test_rpmsg_snd_null_data" },
148     { TEST_RPMSG_SND_UNPAIR_CORE, "test_rpmsg_snd_unpair_core" },
149     { TEST_RPMSG_RCV_HNDL_NULL, "test_rpmsg_rcv_hndl_null" },
150     { TEST_RPMSG_SND_HNDL_NULL, "test_rpmsg_snd_hndl_null" },
151     { TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, "test_virtio_param_vqbuf_size_zero" },
152     { TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, "test_virtio_param_vringbuf_size_zero" },
153     { TEST_RPMSG_PARAM_BUF_NULL, "test_rpmsg_param_buf_null" },
154     { TEST_RPMSG_PARAM_BUF_SIZE_ZERO, "test_rpmsg_param_buf_size_zero" },
155     { TEST_RPMSG_PARAM_STKBUF_NULL, "test_rpmsg_param_stkbuf_null" },
156     { TEST_RPMSG_PARAM_STK_SIZE_ZERO, "test_rpmsg_param_stk_size_zero" },
157     { TEST_RPMSG_RCV_TIMEOUT, "test_rpmsg_rcv_timeout" },
158     { TEST_RPMSG_REMOTE_END_TIMEOUT, "test_rpmsg_remote_end_timeout" },
159     { TEST_END, NULL },
160 };
162 //#define DEBUG_PRINT
164 bool g_neg_exitRespTsk = 0;
166 void rpmsg_neg_exit_responseTask()
168     g_neg_exitRespTsk = 1;
171 void Ipc_reportResult(uint32_t id, int32_t result)
173     gTotalTests++;
174     if (result == IPC_SOK)
175     {
176         System_printf("[%s] [%s] : [TEST_PASS]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
177         UART_printf("[%s] [%s] : [TEST_PASS]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
178         gTotalTestsPassed++;
179     }
180     else
181     {
182         System_printf("[%s] [%s] : [TEST_FAIL]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
183         UART_printf("[%s] [%s] : [TEST_FAIL]\n", Ipc_mpGetSelfName(), negTestCases[id].testName);
184         gTotalTestsFailed++;
185     }
188 /*
189  * This "Task" waits for a "ping" message from any processor
190  * then replies with a "pong" message.
191  */
192 int32_t rpmsg_neg_responderFxn(uint32_t testId)
194     RPMessage_Handle    handle;
195     RPMessage_Handle    handleTimeout;
196     RPMessage_Params    params;
197     uint32_t        myEndPt = 0;
198     uint32_t        myTimeoutEndPt = 0;
199     uint32_t        remoteEndPt;
200     uint32_t        remoteProcId;
201     uint16_t        len;
202     int32_t         status = 0;
203     void            *buf;
204     void            *buf2;
206     uint32_t            bufSize = rpmsgNegDataSize;
207     char                str[MSGSIZE];
208     char                test_buf[RP_MSG_TEST_BUF_SIZE + 1];
211     buf = pRecvTaskBuf;
212     if (buf == NULL)
213     {
214         System_printf("RecvTask: buffer allocation failed\n");
215         return IPC_EFAIL;
216     }
218     /* Testing TEST_RPMSG_REMOTE_END_TIMEOUT */
219     {
220         status = RPMessage_getRemoteEndPt(IPC_MCU1_0, FAKE_SERVICE, &remoteProcId,
221                 &remoteEndPt, 1000);
222         if (status != IPC_SOK)
223         {
224             Ipc_reportResult(TEST_RPMSG_REMOTE_END_TIMEOUT, IPC_SOK);
225         }
226         else
227         {
228             Ipc_reportResult(TEST_RPMSG_REMOTE_END_TIMEOUT, IPC_EFAIL);
229             return IPC_EFAIL;
230         }
231     }
233     RPMessageParams_init(&params);
234     params.requestedEndpt = ENDPT1;
235     params.buf = buf;
236     params.bufSize = bufSize;
238     /* Testing TEST_RPMSG_CREATE_NULL_ENDPNT */
239     {
240         System_printf("RPMessage_create NULL Endpt\n");
241         handle = RPMessage_create(&params, NULL);
242         if (!handle)
243         {
244             Ipc_reportResult(TEST_RPMSG_CREATE_NULL_ENDPNT, IPC_SOK);
245         }
246         else
247         {
248             Ipc_reportResult(TEST_RPMSG_CREATE_NULL_ENDPNT, IPC_EFAIL);
249             return IPC_EFAIL;
250         }
251     }
253     handle = RPMessage_create(&params, &myEndPt);
254     if (!handle)
255     {
256         System_printf("RecvTask: Failed to create endpoint\n");
257         return IPC_EFAIL;
258     }
259     buf2 = pTimeoutBuf;
260     params.requestedEndpt = ENDPT2;
261     params.buf = buf2;
262     params.bufSize = bufSize;
263     handleTimeout = RPMessage_create(&params, &myTimeoutEndPt);
264     if (!handleTimeout)
265     {
266         System_printf("RecvTask: Failed to create timeout endpoint\n");
267         RPMessage_delete(&handle);
268         return IPC_EFAIL;
269     }
271 #if !defined(BUILD_MPU1_0) && defined(A72_LINUX_OS) && defined(A72_LINUX_OS_IPC_ATTACH)
272     RecvEndPt = myEndPt;
273 #endif
275 #if defined (BUILD_MPU1_0)
276     remoteProcId = IPC_MCU1_0;
277 #else
278     remoteProcId = IPC_MPU1_0;
279 #endif
281     /* Testing TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF */
282     {
283         /* Send data to remote endPt: */
284         memset(test_buf, 0, RP_MSG_TEST_BUF_SIZE);
286         len = snprintf(test_buf, RP_MSG_TEST_BUF_SIZE, "ping %d", 0);
288         if(len > RP_MSG_TEST_BUF_SIZE)
289         {
290             System_printf("SendTask%d: snprintf failed, len %d\n", remoteProcId, len);
291             len = RP_MSG_TEST_BUF_SIZE;
292         }
294         len = RP_MSG_TEST_BUF_SIZE;
295         test_buf[len++] = '\0';
297         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, (Ptr)test_buf, len);
298         if (status != IPC_SOK)
299         {
300             Ipc_reportResult(TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, IPC_SOK);
301         }
302         else
303         {
304             Ipc_reportResult(TEST_RPMSG_PKT_LARGE_THAN_VRING_BUF, IPC_EFAIL);
305             return IPC_EFAIL;
306         }
307     }
309     /* Testing TEST_RPMSG_SND_NULL_DATA */
310     {
311         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, NULL, len);
313         if (status != IPC_SOK)
314         {
315             Ipc_reportResult(TEST_RPMSG_SND_NULL_DATA, IPC_SOK);
316         }
317         else
318         {
319             Ipc_reportResult(TEST_RPMSG_SND_NULL_DATA, IPC_EFAIL);
320             return IPC_EFAIL;
321         }
322     }
324     /* Testing TEST_RPMSG_SND_UNPAIR_CORE */
325     {
326 #ifdef BUILD_C66X_1
327         remoteProcId = IPC_C66X_1; // todo: what should dstProc be??
328 #endif
329         status = RPMessage_send(handle, remoteProcId, ENDPT1, myEndPt, (Ptr)buf, len);
331         if (status != IPC_SOK)
332         {
333             Ipc_reportResult(TEST_RPMSG_SND_UNPAIR_CORE, IPC_SOK);
334         }
335         else
336         {
337             Ipc_reportResult(TEST_RPMSG_SND_UNPAIR_CORE, IPC_EFAIL);
338             return IPC_EFAIL;
339         }
340     }
342     /* Testing TEST_RPMSG_SND_HNDL_NULL */
343     {
344         status = RPMessage_send(NULL, remoteProcId, ENDPT1, myEndPt, (Ptr)buf, len);
345         if (status != IPC_SOK)
346         {
347             Ipc_reportResult(TEST_RPMSG_SND_HNDL_NULL, IPC_SOK);
348         }
349         else
350         {
351             Ipc_reportResult(TEST_RPMSG_SND_HNDL_NULL, IPC_EFAIL);
352             return IPC_EFAIL;
353         }
354     }
356     /* Testing TEST_RPMSG_RCV_HNDL_NULL */
357     {
358         status = RPMessage_recv(NULL, (Ptr)str, &len, &remoteEndPt, &remoteProcId,
359                     IPC_RPMESSAGE_TIMEOUT_FOREVER);
360         if (status != IPC_SOK)
361         {
362             Ipc_reportResult(TEST_RPMSG_RCV_HNDL_NULL, IPC_SOK);
363         }
364         else
365         {
366             Ipc_reportResult(TEST_RPMSG_RCV_HNDL_NULL, IPC_EFAIL);
367             return IPC_EFAIL;
368         }
369     }
371     /* Testing TEST_RPMSG_RCV_TIMEOUT */
372     {
373         System_printf("[%s] calling RPMessage_recv with timeout 100...\n", Ipc_mpGetSelfName());
374         status = RPMessage_recv(handleTimeout, (Ptr)str, &len, &remoteEndPt, &remoteProcId, 100);
376         if (status != IPC_ETIMEOUT)
377         {
378             Ipc_reportResult(TEST_RPMSG_RCV_TIMEOUT, IPC_EFAIL);
379             return IPC_EFAIL;
380         }
381         else
382         {
383             Ipc_reportResult(TEST_RPMSG_RCV_TIMEOUT, IPC_SOK);
384         }
385     }
387     return IPC_SOK;
390 int32_t ipc_neg_test(uint32_t testId)
392     uint32_t          numProc = gNumRemoteProc;
393     Ipc_VirtIoParams  vqParam;
394     uint32_t          index = 0;
395     int32_t           status;
397     /* Step1 : Initialize the multiproc */
398     Ipc_mpSetConfig(selfProcId, numProc, pRemoteProcArray);
400     System_printf("IPC_echo_test (core : %s) .....\r\n%s\r\n",
401             Ipc_mpGetSelfName(), IPC_DRV_VERSION_STR);
403     Ipc_init(NULL);
405     /* Step2 : Initialize Virtio */
406     vqParam.vqObjBaseAddr = (void*)pSysVqBuf;
407     vqParam.vqBufSize     = numProc * Ipc_getVqObjMemoryRequiredPerCore();
408     vqParam.vringBaseAddr = (void*)VRING_BASE_ADDRESS;
409     vqParam.vringBufSize  = IPC_VRING_BUFFER_SIZE;
410     vqParam.timeoutCnt    = 100;  /* Wait for counts */
412     /* Testing TEST_VIRTIO_INIT_PARAM_NULL */
413     {
414         status = Ipc_initVirtIO( NULL );
415         if(status != IPC_SOK)
416         {
417             Ipc_reportResult(TEST_VIRTIO_INIT_PARAM_NULL, IPC_SOK);
418         }
419         else
420         {
421             Ipc_reportResult(TEST_VIRTIO_INIT_PARAM_NULL, IPC_EFAIL);
422             return IPC_EFAIL;
423         }
424     }
426     /* Testing TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO */
427     {
428         vqParam.vqBufSize     = 0;
430         status = Ipc_initVirtIO(&vqParam);
431         if(status != IPC_SOK)
432         {
433             Ipc_reportResult(TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, IPC_SOK);
434         }
435         else
436         {
437             Ipc_reportResult(TEST_VIRTIO_PARAM_VQBUF_SIZE_ZERO, IPC_EFAIL);
438             return IPC_EFAIL;
439         }
440     }
442     /* Testing TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO */
443     {
444         vqParam.vqBufSize     = numProc * Ipc_getVqObjMemoryRequiredPerCore();
445         vqParam.vringBufSize  = 0;
447         status = Ipc_initVirtIO(&vqParam);
448         if(status != IPC_SOK)
449         {
450             Ipc_reportResult(TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, IPC_SOK);
451         }
452         else
453         {
454             Ipc_reportResult(TEST_VIRTIO_PARAM_VRINGBUF_SIZE_ZERO, IPC_EFAIL);
455             return IPC_EFAIL;
456         }
457     }
460     System_printf("Ipc_initVirtIO\n");
461     vqParam.vringBufSize  = IPC_VRING_BUFFER_SIZE;
462     status = Ipc_initVirtIO(&vqParam);
463     if (status != IPC_SOK)
464     {
465         System_printf("[%s] Ipc_initVirtIO failed\n");
466         return IPC_EFAIL;
467     }
469     /* Step 3: Initialize RPMessage */
470     RPMessage_Params cntrlParam;
472     /* Initialize the param */
473     RPMessageParams_init(&cntrlParam);
475     /* Set memory for HeapMemory for control task */
476     cntrlParam.buf         = pCntrlBuf;
477     cntrlParam.bufSize     = rpmsgNegDataSize;
478     cntrlParam.stackBuffer = &pTaskBuf[index * IPC_TASK_STACKSIZE];
479     cntrlParam.stackSize   = IPC_TASK_STACKSIZE;
481     /* Testing TEST_RPMSG_INIT_PARAM_NULL */
482     {
483         status = RPMessage_init(NULL);
484         if(status != IPC_SOK)
485         {
486             Ipc_reportResult(TEST_RPMSG_INIT_PARAM_NULL, IPC_SOK);
487         }
488         else
489         {
490             Ipc_reportResult(TEST_RPMSG_INIT_PARAM_NULL, IPC_EFAIL);
491             return IPC_EFAIL;
492         }
493     }
495     /* Testing TEST_RPMSG_PARAM_BUF_NULL */
496     {
497         cntrlParam.buf =  NULL;
499         status = RPMessage_init(&cntrlParam);
500         if(status != IPC_SOK)
501         {
502             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_NULL, IPC_SOK);
503         }
504         else
505         {
506             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_NULL, IPC_EFAIL);
507             return IPC_EFAIL;
508         }
509     }
511     /* Testing TEST_RPMSG_PARAM_BUF_SIZE_ZERO */
512     {
513         cntrlParam.buf = pCntrlBuf;
514         cntrlParam.bufSize = 0;
516         status = RPMessage_init(&cntrlParam);
517         if(status != IPC_SOK)
518         {
519             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_SIZE_ZERO, IPC_SOK);
520         }
521         else
522         {
523             Ipc_reportResult(TEST_RPMSG_PARAM_BUF_SIZE_ZERO, IPC_EFAIL);
524             return IPC_EFAIL;
525         }
526     }
527 #ifndef IPC_EXCLUDE_CTRL_TASKS
528     /* Testing TEST_RPMSG_PARAM_STKBUF_NULL */
529     {
530         cntrlParam.bufSize     = rpmsgNegDataSize;
531         cntrlParam.stackBuffer = NULL;
533         status = RPMessage_init(&cntrlParam);
534         if(status != IPC_SOK)
535         {
536             Ipc_reportResult(TEST_RPMSG_PARAM_STKBUF_NULL, IPC_SOK);
537         }
538         else
539         {
540             Ipc_reportResult(TEST_RPMSG_PARAM_STKBUF_NULL, IPC_EFAIL);
541             return IPC_EFAIL;
542         }
543     }
544     /* Testing TEST_RPMSG_PARAM_STK_SIZE_ZERO */
545     {
546         cntrlParam.stackBuffer = &pTaskBuf[index * IPC_TASK_STACKSIZE];
547         cntrlParam.stackSize = 0;
549         status = RPMessage_init(&cntrlParam);
550         if(status != IPC_SOK)
551         {
552             Ipc_reportResult(TEST_RPMSG_PARAM_STK_SIZE_ZERO, IPC_SOK);
553         }
554         else
555         {
556             Ipc_reportResult(TEST_RPMSG_PARAM_STK_SIZE_ZERO, IPC_EFAIL);
557             return IPC_EFAIL;
558         }
559     }
560 #endif /* IPC_EXCLUDE_CTRL_TASKS */
562     System_printf("RPMessage_init\n");
563     cntrlParam.stackSize   = IPC_TASK_STACKSIZE;
564     status = RPMessage_init(&cntrlParam);
565     if (status != IPC_SOK)
566     {
567         System_printf("[%s] RPMessage_init failed\n", Ipc_mpGetSelfName());
568         return IPC_EFAIL;
569     }
571     return rpmsg_neg_responderFxn(testId);
574 int32_t Ipc_echo_neg_test(void)
576     uint32_t i = 0;
578     ipc_neg_test(i);
580     UART_printf("Tests finished\n");
581     UART_printf("Total tests: %d Passed: %d Failed %d\n", gTotalTests, gTotalTestsPassed, gTotalTestsFailed);
582     if (gTotalTests == gTotalTestsPassed)
583     {
584         UART_printf("All tests have passed.\n\n\n");
585     }
586     return 0;