]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/ipc/tests/messageq_multi.c
Initial commit
[ipc/ipcdev.git] / packages / ti / ipc / tests / messageq_multi.c
1 /*
2  * Copyright (c) 2012-2013, Texas Instruments Incorporated
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 distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  *  ======== messageq_multi.c ========
34  *
35  *  Test for messageq operating in multiple simultaneous threads.
36  *
37  */
39 #include <xdc/std.h>
40 #include <xdc/runtime/Error.h>
41 #include <xdc/runtime/Memory.h>
42 #include <xdc/runtime/System.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/sysbios/knl/Task.h>
46 #include <ti/sysbios/heaps/HeapBuf.h>
48 #include <ti/ipc/MessageQ.h>
49 #include <ti/ipc/MultiProc.h>
51 #define SLAVE_MESSAGEQNAME "SLAVE"
52 #define HOST_MESSAGEQNAME "HOST"
53 #define NUMTHREADS 10
54 #define NUMLOOPS 1000
56 static int numTests = 0;
58 /*
59  *  ======== loopbackFxn========
60  *  Receive and return messages.
61  *  Run at priority lower than tsk1Fxn above.
62  *  Inputs:
63  *     - arg0: number of the thread, appended to MessageQ host and slave names.
64  */
65 Void loopbackFxn(UArg arg0, UArg arg1)
66 {
67     MessageQ_Msg     getMsg;
68     MessageQ_Handle  messageQ;
69     MessageQ_QueueId remoteQueueId;
70     Int              status;
71     UInt16           msgId = 0;
72     Char             localQueueName[64];
73     Char             hostQueueName[64];
75     System_printf("Thread loopbackFxn: %d\n", arg0);
77     System_sprintf(localQueueName, "%s_%d", SLAVE_MESSAGEQNAME, arg0);
78     System_sprintf(hostQueueName,  "%s_%d", HOST_MESSAGEQNAME,  arg0);
80     /* Create a message queue. */
81     messageQ = MessageQ_create(localQueueName, NULL);
82     if (messageQ == NULL) {
83         System_abort("MessageQ_create failed\n");
84     }
86     System_printf("loopbackFxn: created MessageQ: %s; QueueID: 0x%x\n",
87         localQueueName, MessageQ_getQueueId(messageQ));
89     System_printf("Start the main loop: %d\n", arg0);
90     while (msgId < NUMLOOPS) {
91         /* Get a message */
92         status = MessageQ_get(messageQ, &getMsg, MessageQ_FOREVER);
93         if (status != MessageQ_S_SUCCESS) {
94            System_abort("This should not happen since timeout is forever\n");
95         }
96         remoteQueueId = MessageQ_getReplyQueue(getMsg);
98 #ifndef BENCHMARK
99         System_printf("%d: Received message #%d from core %d\n",
100                 arg0, MessageQ_getMsgId(getMsg),
101                 MessageQ_getProcId(remoteQueueId));
102 #endif
103         /* test id of message received */
104         if (MessageQ_getMsgId(getMsg) != msgId) {
105             System_abort("The id received is incorrect!\n");
106         }
108 #ifndef BENCHMARK
109         /* Send it back */
110         System_printf("%d: Sending message Id #%d to core %d\n",
111                       arg0, msgId, MessageQ_getProcId(remoteQueueId));
112 #endif
113         status = MessageQ_put(remoteQueueId, getMsg);
114         if (status != MessageQ_S_SUCCESS) {
115            System_abort("MessageQ_put had a failure/error\n");
116         }
117         msgId++;
118     }
120     MessageQ_delete(&messageQ);
121     numTests += NUMLOOPS;
123     System_printf("Test thread %d complete!\n", arg0);
126 /*
127  *  ======== main ========
128  */
129 Int main(Int argc, Char* argv[])
131     Task_Params params;
132     Int i;
134     System_printf("%s:main: MultiProc id = %d\n", __FILE__, MultiProc_self());
136     /* Create N threads to correspond with host side N thread test app: */
137     Task_Params_init(&params);
138     params.priority = 3;
139     for (i = 0; i < NUMTHREADS; i++) {
140         params.arg0 = i;
141         Task_create(loopbackFxn, &params, NULL);
142     }
144     BIOS_start();
146     return (0);
147  }