Added Linux example and updated release notes
[keystone-rtos/rm-lld.git] / test / k2h / armv7 / linux / rm_client_test.c
1 /*
2  *   rm_arm_test.c
3  *
4  *   Multi-process Resource Manager test that uses sockets to allow a Linux
5  *   User-space application to request RM services from a RM Server, 
6  *   Client Delegate, and Client.
7  *
8  *  ============================================================================
9  *
10  * Copyright (c) 2012-2013, Texas Instruments Incorporated
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * *  Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  *
20  * *  Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * *  Neither the name of Texas Instruments Incorporated nor the names of
25  *    its contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
32  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41  
42  /* Standard includes */
43 #include <stdio.h>
44 #include <errno.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <sys/mman.h>
48 #include <sys/stat.h>
49 #include <fcntl.h>
51 /* Socket Includes */
52 #include "sockutils.h"
53 #include "sockrmmsg.h"
55 /* RM Includes */
56 #include <ti/drv/rm/rm.h>
57 #include <ti/drv/rm/rm_transport.h>
58 #include <ti/drv/rm/rm_services.h>
60 /**********************************************************************
61  ************************** RM Test Symbols ***************************
62  **********************************************************************/
64 #define error_msg printf
65 #define info_msg  printf
67 /* Test FALSE */
68 #define RM_TEST_FALSE                0
69 /* Test TRUE */
70 #define RM_TEST_TRUE                 1
72 /* Socket timeout */
73 #define CLIENT_SOCK_TIMEOUT_USEC     (500)
75 /* Application's registered RM transport indices */
76 #define SERVER_TO_CLIENT_MAP_ENTRY   0
77 /* Maximum number of registered RM transports */
78 #define MAX_MAPPING_ENTRIES          1
80 /* Size of RM static allocation response queue.  Must be greater than number of APPROVED
81  * static allocations */
82 #define MAX_STATIC_ALLOCATION_RESPS  5 
84 /* Size of RM service response queue */
85 #define MAX_QUEUED_SERVICE_RESPONSES 10
87 /* Error checking macro */
88 #define ERROR_CHECK(checkVal, resultVal, rmInstName, printMsg)            \
89     if (resultVal != checkVal) {                                          \
90         char errorMsgToPrint[] = printMsg;                                \
91         printf("Error Core %d : %s : ", coreNum, rmInstName);             \
92         printf("%s with error code : %d\n", errorMsgToPrint, resultVal);  \
93         testErrors++;                                                     \
94     }
96 #define POSITIVE_PASS_CHECK(title, core, instName, resName, resStart, resLen, align, state, check)  \
97     do {                                                                                            \
98         int32_t start = resStart;                                                                   \
99         int32_t alignment = align;                                                                  \
100         char    titleMsg[] = title;                                                                 \
101         printf ("Core %d : ---------------------------------------------------------\n",     \
102                        core);                                                                       \
103         printf ("Core %d : %s\n", core, titleMsg);                                           \
104         printf ("Core %d : - Instance Name: %-32s       -\n", core, instName);               \
105         printf ("Core %d : - Resource Name: %-32s       -\n", core, resName);                \
106         if (start == RM_RESOURCE_BASE_UNSPECIFIED) {                                                \
107             printf ("Core %d : - Start:         UNSPECIFIED                            -\n", \
108                            core);                                                                   \
109             printf ("Core %d : - Length:        %-16d                       -\n",            \
110                            core, resLen);                                                           \
111         }                                                                                           \
112         else {                                                                                      \
113             printf ("Core %d : - Start:         %-16d                       -\n",            \
114                            core, resStart);                                                         \
115             printf ("Core %d : - End:           %-16d                       -\n", core,      \
116                            (start + resLen - 1));                                                   \
117         }                                                                                           \
118         if (alignment == RM_RESOURCE_ALIGNMENT_UNSPECIFIED) {                                       \
119             printf ("Core %d : - Alignment:     UNSPECIFIED                            -\n", \
120                            core);                                                                   \
121         }                                                                                           \
122         else {                                                                                      \
123             printf ("Core %d : - Alignment:     %-16d                       -\n",            \
124                            core, alignment);                                                        \
125         }                                                                                           \
126         printf ("Core %d : -                                                       -\n",     \
127                        core);                                                                       \
128         if (state == check) {                                                                       \
129             printf ("Core %d : - PASSED                                                -\n", \
130                            core);                                                                   \
131         }                                                                                           \
132         else {                                                                                      \
133             printf ("Core %d : - FAILED - Denial: %-6d                               -\n",   \
134                            core, state);                                                            \
135             testErrors++;                                                                           \
136         }                                                                                           \
137         printf ("Core %d : ---------------------------------------------------------\n",     \
138                        core);                                                                       \
139         printf ("\n");                                                                       \
140     } while(0);
142 #define NEGATIVE_PASS_CHECK(title, core, instName, resName, resStart, resLen, align, state, check)  \
143     do {                                                                                            \
144         int32_t start = resStart;                                                                   \
145         int32_t alignment = align;                                                                  \
146         char    titleMsg[] = title;                                                                 \
147         printf ("Core %d : ---------------------------------------------------------\n",     \
148                        core);                                                                       \
149         printf ("Core %d : %s\n", core, titleMsg);                                           \
150         printf ("Core %d : - Instance Name: %-32s       -\n", core, instName);               \
151         printf ("Core %d : - Resource Name: %-32s       -\n", core, resName);                \
152         if (start == RM_RESOURCE_BASE_UNSPECIFIED) {                                                \
153             printf ("Core %d : - Start:         UNSPECIFIED                            -\n", \
154                            core);                                                                   \
155             printf ("Core %d : - Length:        %-16d                       -\n",            \
156                            core, resLen);                                                           \
157         }                                                                                           \
158         else {                                                                                      \
159             printf ("Core %d : - Start:         %-16d                       -\n",            \
160                            core, resStart);                                                         \
161             printf ("Core %d : - End:           %-16d                       -\n", core,      \
162                            (start + resLen - 1));                                                   \
163         }                                                                                           \
164         if (alignment == RM_RESOURCE_ALIGNMENT_UNSPECIFIED) {                                       \
165             printf ("Core %d : - Alignment:     UNSPECIFIED                            -\n", \
166                            core);                                                                   \
167         }                                                                                           \
168         else {                                                                                      \
169             printf ("Core %d : - Alignment:     %-16d                       -\n",            \
170                            core, alignment);                                                        \
171         }                                                                                           \
172         printf ("Core %d : -                                                       -\n",     \
173                        core);                                                                       \
174         if (state != check) {                                                                       \
175             printf ("Core %d : - PASSED - Denial: %-6d                               -\n",   \
176                            core, state);                                                            \
177         }                                                                                           \
178         else {                                                                                      \
179             printf ("Core %d : - FAILED - Expected Denial                              -\n", \
180                            core);                                                                   \
181             testErrors++;                                                                           \
182         }                                                                                           \
183         printf ("Core %d : ---------------------------------------------------------\n",     \
184                        core);                                                                       \
185         printf ("\n");                                                                       \
186     } while(0);    
188 #define STATUS_PASS_CHECK(title, core, instName, resName, resStart, resLen, refCnt, state, check, expectRefCnt) \
189     do {                                                                                                        \
190         int32_t start = resStart;                                                                               \
191         char    titleMsg[] = title;                                                                             \
192         printf ("Core %d : ---------------------------------------------------------\n",                 \
193                        core);                                                                                   \
194         printf ("Core %d : %s\n", core, titleMsg);                                                       \
195         printf ("Core %d : - Instance Name: %-32s       -\n", core, instName);                           \
196         printf ("Core %d : - Resource Name: %-32s       -\n", core, resName);                            \
197         printf ("Core %d : - Start:         %-16d                       -\n",                            \
198                            core, resStart);                                                                     \
199         printf ("Core %d : - End:           %-16d                       -\n", core,                      \
200                            (start + resLen - 1));                                                               \
201         printf ("Core %d : - Expected Owner Count: %-16d                -\n",                            \
202                        core, expectRefCnt);                                                                     \
203         printf ("Core %d : - Returned Owner Count: %-16d                -\n",                            \
204                        core, refCnt);                                                                           \
205         printf ("Core %d : -                                                       -\n", core);          \
206         if ((state == check) && (refCnt == expectRefCnt)) {                                                     \
207             printf ("Core %d : - PASSED                                                -\n", core);      \
208         }                                                                                                       \
209         else {                                                                                                  \
210             if (refCnt != expectRefCnt) {                                                                       \
211                 printf ("Core %d : - FAILED - Owner Count Mismatch                         -\n",         \
212                                core);                                                                           \
213             }                                                                                                   \
214             else {                                                                                              \
215                 printf ("Core %d : - FAILED - Denial: %-6d                               -\n",           \
216                                core, state);                                                                    \
217             }                                                                                                   \
218             testErrors++;                                                                                       \
219         }                                                                                                       \
220         printf ("Core %d : ---------------------------------------------------------\n",                 \
221                        core);                                                                                   \
222         printf ("\n");                                                                                   \
223     } while(0);
225 /**********************************************************************
226  ********************** RM Test Data Structures ***********************
227  **********************************************************************/
229 /* RM registered transport mapping structure */
230 typedef struct trans_map_entry_s {
231     /* Registered RM transport handle */
232     Rm_TransportHandle        transportHandle;
233     /* Remote socket tied to the transport handle */
234     sock_name_t              *remote_sock;
235 } Transport_MapEntry;
237 /**********************************************************************
238  ********************** Extern Variables ******************************
239  **********************************************************************/
241 /* Alloc and free OSAL variables */
242 extern uint32_t rmMallocCounter;
243 extern uint32_t rmFreeCounter;
245 /**********************************************************************
246  ********************** Global Variables ******************************
247  **********************************************************************/
249 /* Core number */
250 uint16_t            coreNum;
251 /* Number of errors that occurred during the test */
252 uint16_t            testErrors;
254 /* Client instance name (must match with RM Global Resource List (GRL) and policies */
255 char                rmClientName[RM_NAME_MAX_CHARS] = "RM_Client";
257 /* Client socket name */
258 char                rmClientSockName[] = "/tmp/var/run/rm/rm_client";
260 /* Client socket handle */
261 sock_h              rmClientSocket;
263 /* Client instance handles */
264 Rm_Handle           rmClientHandle = NULL;
266 /* Client instance service handles */
267 Rm_ServiceHandle   *rmClientServiceHandle = NULL;
269 /* Transport map stores the RM transport handle to IPC MessageQ queue mapping */
270 Transport_MapEntry  rmTransportMap[MAX_MAPPING_ENTRIES];
272 /* Static allocation response queue */
273 Rm_ServiceRespInfo  staticResponseQueue[MAX_STATIC_ALLOCATION_RESPS];
274 /* Static allocation response queue index */
275 uint32_t            numStaticResponses;
277 /* RM response info queue used to store service responses received via the callback function */
278 Rm_ServiceRespInfo  responseInfoQueue[MAX_QUEUED_SERVICE_RESPONSES];
280 /* RM resource names (must match resource node names in GRL and policies */
281 char                resourceNameMemRegion[RM_NAME_MAX_CHARS]  = "memory-regions";
282 char                resourceNameAccumCh[RM_NAME_MAX_CHARS]    = "accumulator-ch";
283 char                resourceNameGpQ[RM_NAME_MAX_CHARS]        = "gp-queue";
284 char                resourceNameAifQ[RM_NAME_MAX_CHARS]       = "aif-queue";
285 char                resourceNameQosCluster[RM_NAME_MAX_CHARS] = "qos-cluster";
286 char                resourceNameAifRxCh[RM_NAME_MAX_CHARS]    = "aif-rx-ch";
287 char                resourceNameInfraQ[RM_NAME_MAX_CHARS]     = "infra-queue";
289 /* Test RM NameServer name */
290 char                nameServerNameFavQ[RM_NAME_MAX_CHARS]     = "My_Favorite_Queue";
292 /**********************************************************************
293  *************************** Test Functions ***************************
294  **********************************************************************/
296 Rm_Packet *transportAlloc(Rm_AppTransportHandle appTransport, uint32_t pktSize, Rm_PacketHandle *pktHandle)
298     Rm_Packet *rm_pkt = NULL;
300     rm_pkt = calloc(1, sizeof(*rm_pkt));
301     if (!rm_pkt) {
302         error_msg("can't malloc for RM send message (err: %s)\n",
303                   strerror(errno));
304         return (NULL);
305     }
306     rm_pkt->pktLenBytes = pktSize;
307     *pktHandle = rm_pkt;
309     return(rm_pkt);
312 void transportFree (Rm_Packet *rm_pkt)
314     uint32_t pkt_size = rm_pkt->pktLenBytes;
315     int32_t  status;
317     if (rm_pkt) {
318         free (rm_pkt);
319     }         
322 int32_t transportSend (Rm_AppTransportHandle appTransport, Rm_PacketHandle pktHandle)
324     sock_name_t *server_sock_name = (sock_name_t *)appTransport;
325     Rm_Packet   *rm_pkt = (Rm_Packet *)pktHandle;
326     
327     if (sock_send(rmClientSocket, (char *)rm_pkt, (int) rm_pkt->pktLenBytes, server_sock_name)) {
328         error_msg("send data failed\n");
329     }
330  
331     return (0);
334 void transportReceive (void)
336     int32_t             rm_result;
337     int                 retval;
338     int                 length = 0;
339     sock_name_t         serv_sock_name;
340     sock_name_t         server_sock_addr;
341     Rm_Packet          *rm_pkt = NULL;
342     struct timeval      tv = {0, CLIENT_SOCK_TIMEOUT_USEC};
343     struct sockaddr_un  server_addr;    
344     
345     retval = sock_wait(rmClientSocket, &length, &tv, -1);
346     if (retval == -2) {
347         /* Timeout */
348         return;
349     }
350     else if (retval < 0) {
351         error_msg("Error in reading from socket, error %d\n", retval);
352         return;
353     }
354     
355     if (length < sizeof(rm_pkt)) {
356         error_msg("invalid RM message length %d\n", length);
357         return;
358     }
359     rm_pkt = calloc(1, length);
360     if (!rm_pkt) {
361         error_msg("can't malloc for recv'd RM message (err: %s)\n",
362                   strerror(errno));
363         return;
364     }
365     
366     server_sock_addr.type = sock_addr_e;
367     server_sock_addr.s.addr = &server_addr;
368     retval = sock_recv(rmClientSocket, (char *)rm_pkt, length, &server_sock_addr);
369     if (retval != length) {
370         error_msg("recv RM pkt failed from socket, received = %d, expected = %d\n",
371                   retval, length);
372         return;
373     }
374     
375     info_msg("received RM pkt of size %d bytes from %s\n", length, server_sock_addr.s.addr->sun_path);
377     /* Provide packet to RM Server for processing */       
378     if (rm_result = Rm_receivePacket(rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].transportHandle, rm_pkt)) {
379         printf("RM failed to process received packet: %d\n", rm_result);
380     }
382     transportFree(rm_pkt);
386 void serviceCallback(Rm_ServiceRespInfo *serviceResponse)
388     uint32_t qIndex = 0;
389     
390     /* Populate next free entry in the responseInfoQueue */
391     while (responseInfoQueue[qIndex].serviceId != 0) {
392         qIndex++;
393         if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
394             qIndex = 0;
395         }
396     }
398     /* Save the response in the response queue for the test task to pick up */
399     memcpy((void *)&responseInfoQueue[qIndex], (void *)serviceResponse, sizeof(Rm_ServiceRespInfo));
402 void waitForResponse(Rm_ServiceRespInfo *respInfo)
404     uint32_t qIndex = 0;
406     if ((respInfo->serviceState == RM_SERVICE_PROCESSING) ||
407         (respInfo->serviceState == RM_SERVICE_PENDING_SERVER_RESPONSE)) {
408         /* Scan responseInfoQueue for the response received via the callback function */
409         while((responseInfoQueue[qIndex].serviceId != respInfo->serviceId) ||
410               (responseInfoQueue[qIndex].rmHandle != respInfo->rmHandle)) {
411             /* Check socket for response packets */
412             transportReceive();
413             
414             qIndex++;
415             if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
416                 qIndex = 0;
417             }
418         }  
420         memcpy((void *)respInfo, (void *)&responseInfoQueue[qIndex], sizeof(Rm_ServiceRespInfo));
421         memset((void *)&responseInfoQueue[qIndex], 0, sizeof(Rm_ServiceRespInfo));
422     }
425 void setRmRequest(Rm_ServiceReqInfo *reqInfo, Rm_ServiceType type, const char *resName, int32_t resBase,
426                   uint32_t resLen, int32_t resAlign, const char *nsName, int setCallback, Rm_ServiceRespInfo *respInfo)
427 {                                                                                
428     memset((void *)reqInfo, 0, sizeof(Rm_ServiceReqInfo));                                        
429     reqInfo->type = type;                                                                           
430     reqInfo->resourceName = resName;                                                                
431     reqInfo->resourceBase = resBase;                                                                
432     reqInfo->resourceLength = resLen;                                                               
433     reqInfo->resourceAlignment = resAlign;                                                          
434     reqInfo->resourceNsName = nsName;
435     if (setCallback) {
436         reqInfo->callback.serviceCallback = serviceCallback;  
437     }
438     memset((void *)respInfo, 0, sizeof(Rm_ServiceRespInfo));                                     
441 void cleanup(void)
443     Rm_ServiceReqInfo  requestInfo;
444     Rm_ServiceRespInfo responseInfo;     
445     int32_t            result;
446     int32_t            finalMallocFree;
448     /* Free all allocated resources */
449     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAccumCh, 
450                  0, 7, 0, NULL, RM_TEST_TRUE, &responseInfo);     
451     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
452     waitForResponse(&responseInfo); 
453     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
454                         coreNum, rmClientName, responseInfo.resourceName,
455                         responseInfo.resourceBase, responseInfo.resourceLength, 
456                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);    
457     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAccumCh, 
458                  40, 2, 0, NULL, RM_TEST_TRUE, &responseInfo);     
459     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
460     waitForResponse(&responseInfo); 
461     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
462                         coreNum, rmClientName, responseInfo.resourceName,
463                         responseInfo.resourceBase, responseInfo.resourceLength, 
464                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);
466     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameQosCluster, 
467                  0, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
468     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
469     waitForResponse(&responseInfo); 
470     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
471                         coreNum, rmClientName, responseInfo.resourceName,
472                         responseInfo.resourceBase, responseInfo.resourceLength, 
473                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);   
474     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameQosCluster, 
475                  2, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
476     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
477     waitForResponse(&responseInfo); 
478     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
479                         coreNum, rmClientName, responseInfo.resourceName,
480                         responseInfo.resourceBase, responseInfo.resourceLength, 
481                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);      
483     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifQ, 
484                  525, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
485     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
486     waitForResponse(&responseInfo); 
487     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
488                         coreNum, rmClientName, responseInfo.resourceName,
489                         responseInfo.resourceBase, responseInfo.resourceLength, 
490                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);       
492     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameInfraQ, 
493                  800, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
494     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
495     waitForResponse(&responseInfo); 
496     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
497                         coreNum, rmClientName, responseInfo.resourceName,
498                         responseInfo.resourceBase, responseInfo.resourceLength, 
499                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);    
501     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameGpQ, 
502                  7000, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
503     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
504     waitForResponse(&responseInfo); 
505     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
506                         coreNum, rmClientName, responseInfo.resourceName,
507                         responseInfo.resourceBase, responseInfo.resourceLength, 
508                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED); 
509     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameGpQ, 
510                  7005, 25, 0, NULL, RM_TEST_TRUE, &responseInfo);     
511     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
512     waitForResponse(&responseInfo); 
513     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
514                         coreNum, rmClientName, responseInfo.resourceName,
515                         responseInfo.resourceBase, responseInfo.resourceLength, 
516                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);  
518     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
519                  0, 6, 0, NULL, RM_TEST_TRUE, &responseInfo);     
520     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
521     waitForResponse(&responseInfo); 
522     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
523                         coreNum, rmClientName, responseInfo.resourceName,
524                         responseInfo.resourceBase, responseInfo.resourceLength, 
525                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED); 
526     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
527                  50, 7, 0, NULL, RM_TEST_TRUE, &responseInfo);     
528     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
529     waitForResponse(&responseInfo); 
530     POSITIVE_PASS_CHECK("-------------------- Resource Cleanup -------------------", 
531                         coreNum, rmClientName, responseInfo.resourceName,
532                         responseInfo.resourceBase, responseInfo.resourceLength, 
533                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
535     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
536     result = Rm_serviceCloseHandle(rmClientServiceHandle);
537     ERROR_CHECK(RM_OK, result, rmClientName, "Service handle close failed");
539     result = Rm_transportUnregister(rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].transportHandle);
540     ERROR_CHECK(RM_OK, result, rmClientName, "Unregister of Server transport failed");
542         sock_close(rmClientSocket);
543  
544     result = Rm_delete(rmClientHandle, RM_TEST_TRUE);
545     ERROR_CHECK(RM_OK, result, rmClientName, "Instance delete failed");
547     printf ("Core %d : ---------------------------------------------------------\n", coreNum);
548     printf ("Core %d : ------------------ Memory Leak Check --------------------\n", coreNum);
549     printf ("Core %d : -                       : malloc count   |   free count -\n", coreNum);
550     printf ("Core %d : - Example Completion    :  %6d        |  %6d      -\n", coreNum,
551                    rmMallocCounter, rmFreeCounter);
552     finalMallocFree = rmMallocCounter - rmFreeCounter; 
553     if (finalMallocFree > 0) {
554         printf ("Core %d : - FAILED - %6d unfreed mallocs                       -\n",
555                        coreNum, finalMallocFree);
556         testErrors++;
557     }
558     else if (finalMallocFree < 0) {
559         printf ("Core %d : - FAILED - %6d more frees than mallocs               -\n",
560                        coreNum, -finalMallocFree);
561         testErrors++;
562     }
563     else {
564         printf ("Core %d : - PASSED                                                -\n",
565                        coreNum);
566     }
567     printf ("Core %d : ---------------------------------------------------------\n", coreNum);
568     printf ("\n");  
570     printf ("Core %d : ---------------------------------------------------------\n", coreNum);
571     printf ("Core %d : ------------------ Example Completion -------------------\n", coreNum);
572     if (testErrors) {
573         printf ("Core %d : - Test Errors: %-32d         -\n", coreNum, testErrors);
574     }
575     printf ("Core %d : ---------------------------------------------------------\n", coreNum);
576     printf ("\n"); 
579 void client_test(void)
581     Rm_ServiceReqInfo  requestInfo;
582     Rm_ServiceRespInfo responseInfo;    
583     uint32_t           i, j;
585     /* Create new NameServer object */                
586     setRmRequest(&requestInfo, Rm_service_RESOURCE_MAP_TO_NAME, resourceNameGpQ, 
587                  1002, 1, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
588     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
589     waitForResponse(&responseInfo); 
590     POSITIVE_PASS_CHECK("--------------- Create NameServer Object ----------------", 
591                         coreNum, rmClientName, resourceNameGpQ,
592                         requestInfo.resourceBase, responseInfo.resourceLength, 
593                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED); 
595     /* Retrieve a resource via a NameServer name */
596     setRmRequest(&requestInfo, Rm_service_RESOURCE_GET_BY_NAME, NULL, 
597                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
598     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
599     waitForResponse(&responseInfo); 
600     POSITIVE_PASS_CHECK("------- Retrieve Resource Via NameServer Object ---------", 
601                         coreNum, rmClientName, responseInfo.resourceName,
602                         responseInfo.resourceBase, responseInfo.resourceLength, 
603                         0, responseInfo.serviceState, RM_SERVICE_APPROVED);     
605     /* Allocate the resource returned from the NameServer request */
606     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo)); 
607     requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
608     requestInfo.resourceName = responseInfo.resourceName;
609     requestInfo.resourceBase = responseInfo.resourceBase;
610     requestInfo.resourceLength = responseInfo.resourceLength;
611     requestInfo.resourceNsName = NULL;
612     requestInfo.callback.serviceCallback = serviceCallback;     
613     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
614     waitForResponse(&responseInfo); 
615     POSITIVE_PASS_CHECK("-------- Init Allocate Using Retrieved Resource ---------", 
616                         coreNum, rmClientName, responseInfo.resourceName,
617                         requestInfo.resourceBase, requestInfo.resourceLength, 
618                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
620     /* Retrieve the resource status via the NameServer name */
621     setRmRequest(&requestInfo, Rm_service_RESOURCE_STATUS, NULL, 
622                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
623     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
624     waitForResponse(&responseInfo); 
625     STATUS_PASS_CHECK("---- Retrieve Resource Status Via NameServer Object -----", 
626                       coreNum, rmClientName, responseInfo.resourceName,
627                       responseInfo.resourceBase, responseInfo.resourceLength, 
628                       responseInfo.resourceNumOwners, responseInfo.serviceState, RM_SERVICE_APPROVED, 1);  
630     /* Free resource via a NameServer name */
631     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, NULL, 
632                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
633     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
634     waitForResponse(&responseInfo); 
635     POSITIVE_PASS_CHECK("--- Free of Retrieved Resource Using NameServer Name ----", 
636                         coreNum, rmClientName, nameServerNameFavQ,
637                         0, 1, 0, responseInfo.serviceState, RM_SERVICE_APPROVED);      
639     /* Delete the NameServer name */
640     setRmRequest(&requestInfo, Rm_service_RESOURCE_UNMAP_NAME, NULL, 
641                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
642     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
643     waitForResponse(&responseInfo); 
644     POSITIVE_PASS_CHECK("--------------- Delete NameServer Object ----------------", 
645                         coreNum, rmClientName, nameServerNameFavQ,
646                         0, 1, 0, responseInfo.serviceState, RM_SERVICE_APPROVED);      
648     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
649     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
650                  0, 6, 0, NULL, RM_TEST_TRUE, &responseInfo);     
651     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
652     waitForResponse(&responseInfo);    
653     POSITIVE_PASS_CHECK("- Resource Node Expand/Contract Testing (Use Allocate) --", 
654                         coreNum, rmClientName, resourceNameAifRxCh,
655                         requestInfo.resourceBase, requestInfo.resourceLength, 
656                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
657     
658     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifRxCh, 
659                  50, 7, 0, NULL, RM_TEST_TRUE, &responseInfo);        
660     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
661     waitForResponse(&responseInfo);    
662     POSITIVE_PASS_CHECK("- Resource Node Expand/Contract Testing (Init Allocate) -", 
663                         coreNum, rmClientName, resourceNameAifRxCh,
664                         requestInfo.resourceBase, requestInfo.resourceLength, 
665                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
666     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */
668     /* BEGIN testing allocations with UNSPECIFIED base and alignment values */
669     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
670                  RM_RESOURCE_BASE_UNSPECIFIED, 5, 4, NULL, RM_TEST_TRUE, &responseInfo);        
671     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
672     waitForResponse(&responseInfo); 
673     POSITIVE_PASS_CHECK("---------- Use Allocation w/ UNSPECIFIED Base -----------", 
674                         coreNum, rmClientName, resourceNameAccumCh,
675                         RM_RESOURCE_BASE_UNSPECIFIED, requestInfo.resourceLength, 
676                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);    
678     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
679                  RM_RESOURCE_BASE_UNSPECIFIED, 2, 1, NULL, RM_TEST_TRUE, &responseInfo);      
680     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
681     waitForResponse(&responseInfo); 
682     POSITIVE_PASS_CHECK("---------- Use Allocation w/ UNSPECIFIED Base -----------", 
683                         coreNum, rmClientName, resourceNameAccumCh,
684                         RM_RESOURCE_BASE_UNSPECIFIED, requestInfo.resourceLength, 
685                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
687     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
688                  RM_RESOURCE_BASE_UNSPECIFIED, 2, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, RM_TEST_TRUE, &responseInfo);     
689     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
690     waitForResponse(&responseInfo); 
691     POSITIVE_PASS_CHECK("---- Use Allocation w/ UNSPECIFIED Base & Alignment -----", 
692                         coreNum, rmClientName, resourceNameAccumCh,
693                         RM_RESOURCE_BASE_UNSPECIFIED, requestInfo.resourceLength, 
694                         RM_RESOURCE_ALIGNMENT_UNSPECIFIED, responseInfo.serviceState, RM_SERVICE_APPROVED);     
695     /* END testing allocations with UNSPECIFIED base and alignment values */    
697     /* Allocate infrastructure queue shared between Linux kernel and Client */
698     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
699                  800, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
700     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
701     waitForResponse(&responseInfo); 
702     POSITIVE_PASS_CHECK("-- Init Allocation of Shared Linux and Client Resource --", 
703                         coreNum, rmClientName, resourceNameInfraQ,
704                         requestInfo.resourceBase, requestInfo.resourceLength, 
705                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);      
707     /* BEGIN Allocating some resources without providing a callback function.  RM should block and not return until the result
708      * is returned by the server. */
709     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
710                  7000, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
711     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
712     waitForResponse(&responseInfo); 
713     POSITIVE_PASS_CHECK("- Init Allocation (RM Blocked Until Resource Returned) --", 
714                         coreNum, rmClientName, resourceNameGpQ,
715                         requestInfo.resourceBase, requestInfo.resourceLength, 
716                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);      
718     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
719                  7005, 25, 0, NULL, RM_TEST_TRUE, &responseInfo);     
720     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);  
721     waitForResponse(&responseInfo); 
722     POSITIVE_PASS_CHECK("-- Use Allocation (RM Blocked Until Resource Returned) --", 
723                         coreNum, rmClientName, resourceNameGpQ,
724                         requestInfo.resourceBase, requestInfo.resourceLength, 
725                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
726     
727     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
728                  7010, 5, 0, NULL, RM_TEST_TRUE, &responseInfo);     
729     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
730     waitForResponse(&responseInfo); 
731     POSITIVE_PASS_CHECK("-- Use Allocation (RM Blocked Until Resource Returned) --", 
732                         coreNum, rmClientName, resourceNameGpQ,
733                         requestInfo.resourceBase, requestInfo.resourceLength, 
734                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
736     /* Init allocation of resource already owned by Client should return approved and there should only
737      * be one instance of Client in resource's owner list. */
738     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
739                  7011, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
740     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);  
741     waitForResponse(&responseInfo); 
742     POSITIVE_PASS_CHECK("----- Use Allocation of Owned Resource (RM Blocked) -----", 
743                         coreNum, rmClientName, resourceNameGpQ,
744                         requestInfo.resourceBase, requestInfo.resourceLength, 
745                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED);     
746     /* END Allocating some resources without providing a callback function.  RM should block and not return
747      * until the result is returned by the Server. */   
749     /* BEGIN Getting the status of resources from Client and CD */
750     setRmRequest(&requestInfo, Rm_service_RESOURCE_STATUS, resourceNameGpQ, 
751                  7012, 2, 0, NULL, RM_TEST_TRUE, &responseInfo);     
752     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
753     waitForResponse(&responseInfo);  
754     STATUS_PASS_CHECK("-- Status Check of Resources from Client (Non-Blocking) -", 
755                       coreNum, rmClientName, responseInfo.resourceName,
756                       responseInfo.resourceBase, responseInfo.resourceLength, 
757                       responseInfo.resourceNumOwners, responseInfo.serviceState, RM_SERVICE_APPROVED, 1);   
758     
759     setRmRequest(&requestInfo, Rm_service_RESOURCE_STATUS, resourceNameGpQ, 
760                  4025, 20, 0, NULL, RM_TEST_TRUE, &responseInfo);     
761     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
762     waitForResponse(&responseInfo);   
763     STATUS_PASS_CHECK("---- Status Check of Resources from Client (Blocking) ---", 
764                       coreNum, rmClientName, responseInfo.resourceName,
765                       responseInfo.resourceBase, responseInfo.resourceLength, 
766                       responseInfo.resourceNumOwners, responseInfo.serviceState, RM_SERVICE_APPROVED, 1);  
767     /* END Getting the status of resources from Client and CD */    
769     /* Verify static allocations were validated.  Validation responses should have been received after the
770      * first service requests were made on the Client and CD post transport path registration. */
771     while (numStaticResponses > 0) {
772         /* Loop until all static request validations have been received */
773         for (i = 0; i < MAX_STATIC_ALLOCATION_RESPS; i++) {
774             if (staticResponseQueue[i].serviceId != 0) {            
775                 for (j = 0; j < MAX_QUEUED_SERVICE_RESPONSES; j++) {
776                     if ((staticResponseQueue[i].serviceId == responseInfoQueue[j].serviceId) &&
777                         (staticResponseQueue[i].rmHandle == responseInfoQueue[j].rmHandle)) {                   
778                         POSITIVE_PASS_CHECK("------------- Static Allocation Validation --------------", 
779                                             coreNum, rmClientName, responseInfoQueue[j].resourceName,
780                                             responseInfoQueue[j].resourceBase, responseInfoQueue[j].resourceLength, 
781                                             0, responseInfoQueue[j].serviceState, 
782                                             RM_SERVICE_APPROVED); 
783                         memset((void *)&staticResponseQueue[i], 0, sizeof(Rm_ServiceRespInfo));
784                         memset((void *)&responseInfoQueue[j], 0, sizeof(Rm_ServiceRespInfo));
785                         numStaticResponses--;                        
786                         break;
787                     }
788                 }
789             }
790         }    
791     }  
793 #if PRINT_USED_RESOURCES
794     Rm_resourceStatus(rmCdHandle, RM_TEST_TRUE);
795 #endif
798 void connection_setup(void)
800     Rm_TransportCfg rmTransCfg;
801     int32_t         rm_result;
802     int             i;
803     sock_name_t     sock_name;
804     int32_t         result = 0;
805     char            server_sock_name[] = RM_SERVER_SOCKET_NAME;
806     
807     /* Initialize the transport map */
808     for (i = 0; i < MAX_MAPPING_ENTRIES; i++) {
809         rmTransportMap[i].transportHandle = NULL;
810     }
812         sock_name.type = sock_name_e;
813         sock_name.s.name = rmClientSockName;
815         rmClientSocket = sock_open(&sock_name);
816         if (!rmClientSocket) {
817                 error_msg("Client socket open failed\n");
818                 exit(EXIT_FAILURE);
819         }
821     rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].remote_sock = calloc(1, sizeof(sock_name_t));
822     rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].remote_sock->type = sock_name_e;    
823     rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].remote_sock->s.name = calloc(1, strlen(server_sock_name)+1);
824     strncpy(rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].remote_sock->s.name, server_sock_name, strlen(server_sock_name)+1);
826     /* Register the Server with the Client instance */
827     rmTransCfg.rmHandle = rmClientHandle;
828     rmTransCfg.appTransportHandle = (Rm_AppTransportHandle) rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].remote_sock;
829     rmTransCfg.remoteInstType = Rm_instType_SERVER;
830     rmTransCfg.transportCallouts.rmAllocPkt = transportAlloc;
831     rmTransCfg.transportCallouts.rmSendPkt = transportSend;
832     rmTransportMap[SERVER_TO_CLIENT_MAP_ENTRY].transportHandle = Rm_transportRegister(&rmTransCfg, &rm_result);    
835 int main(int argc, char *argv[])
837     int                 fd;
838     struct stat         file_stat;
839     char               *static_policy_addr = NULL;    
840     Rm_InitCfg          rmInitCfg;
841     int                status;
842     Rm_ServiceReqInfo  requestInfo;
843     Rm_ServiceRespInfo responseInfo;
844     int32_t            result;
846     printf ("*********************************************************\n");
847     printf ("*************** RM Linux Client Testing *****************\n");
848     printf ("*********************************************************\n");
850     printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
852     coreNum = 0;
853     testErrors = 0;
855     if (argc > 2)
856     {
857         error_msg("Invalid number of input arguments\n");
858         exit(EXIT_FAILURE);        
859     }
861     if (argc == 2){
862         /* mmap static policy */
863         fd = open(argv[1], O_RDONLY);
864         if (fd == -1) {
865             error_msg("Error opening static policy\n");
866             exit(EXIT_FAILURE);
867         }
868         /* Obtain file size */
869         if (fstat(fd, &file_stat) == -1) {
870             error_msg("Error getting static policy size\n");
871             exit(EXIT_FAILURE);
872         }
873         static_policy_addr = mmap(NULL, file_stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
874         if (static_policy_addr == MAP_FAILED) {
875             error_msg("mmap of static failed\n");
876             exit(EXIT_FAILURE);
877         }
878     }   
880     /* Initialize the RM Client - RM must be initialized before anything else in the system */
881     memset(&rmInitCfg, 0, sizeof(rmInitCfg));
882     rmInitCfg.instName = rmClientName;
883     rmInitCfg.instType = Rm_instType_CLIENT;
884     if (static_policy_addr) {
885         rmInitCfg.instCfg.clientCfg.staticPolicy = (void *)static_policy_addr;
886     }
887     rmClientHandle = Rm_init(&rmInitCfg, &result);
888     ERROR_CHECK(RM_OK, result, rmClientName, "Initialization failed");
890     printf("\n\nInitialized %s\n\n", rmClientName);
892     /* Open Client service handle */
893     rmClientServiceHandle = Rm_serviceOpenHandle(rmClientHandle, &result);
894     ERROR_CHECK(RM_OK, result, rmClientName, "Service handle open failed");
896     /* Initialize the static allocation response queue */
897     for (numStaticResponses = 0; numStaticResponses < MAX_STATIC_ALLOCATION_RESPS; numStaticResponses++) {
898         memset((void *)&staticResponseQueue[numStaticResponses], 0, sizeof(Rm_ServiceRespInfo));
899     }
900     numStaticResponses = 0;
902     /* Static allocation tests */
903     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
904                  0, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);
905     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);               
906     POSITIVE_PASS_CHECK("---------------- Static Init Allocation -----------------", 
907                         coreNum, rmClientName, resourceNameQosCluster,
908                         requestInfo.resourceBase, requestInfo.resourceLength, 
909                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED_STATIC);     
910     if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
911         memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(responseInfo));
912     }        
913     
914     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
915                  2, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);        
916     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
917     POSITIVE_PASS_CHECK("---------------- Static Init Allocation -----------------", 
918                         coreNum, rmClientName, resourceNameQosCluster,
919                         requestInfo.resourceBase, requestInfo.resourceLength, 
920                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED_STATIC);     
921     if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
922         memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(responseInfo));
923     }           
925     /* Request resource from Client that can only be allocated to CD according to static policy */
926     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
927                  1, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);        
928     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
929     NEGATIVE_PASS_CHECK("---------------- Static Init Allocation -----------------", 
930                         coreNum, rmClientName, resourceNameQosCluster,
931                         requestInfo.resourceBase, requestInfo.resourceLength, 
932                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED_STATIC);          
934     /* Request resource from both Client and CD that is shared according to static policy */
935     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
936                  525, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);        
937     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
938     POSITIVE_PASS_CHECK("---------------- Static Init Allocation -----------------", 
939                         coreNum, rmClientName, resourceNameAifQ,
940                         requestInfo.resourceBase, requestInfo.resourceLength, 
941                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED_STATIC);     
942     if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
943         memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(responseInfo));
944     }           
946     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
947                  525, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);        
948     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
949     POSITIVE_PASS_CHECK("---------------- Static Init Allocation -----------------", 
950                         coreNum, rmClientName, resourceNameAifQ,
951                         requestInfo.resourceBase, requestInfo.resourceLength, 
952                         requestInfo.resourceAlignment, responseInfo.serviceState, RM_SERVICE_APPROVED_STATIC);     
953     if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
954         memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(responseInfo));
955     }           
957     connection_setup();
958     client_test();
959     cleanup();    
961     return (0);