static MME_ERROR createTransportInfo(const char *name, TransportInfo_t **tpInfo_p) { const char portName[] = "MMEHostReplyPort#0"; TransportInfo_t *tpInfo; EMBX_ERROR err; /* Allocate space for the transport descriptor */ tpInfo = EMBX_OS_MemAlloc(sizeof(TransportInfo_t)); if (!tpInfo) { return MME_NOMEM; } memset(tpInfo, 0, sizeof(TransportInfo_t)); /* Open a transport handle */ err = EMBX_OpenTransport(name, &tpInfo->handle); if (EMBX_SUCCESS != err) { goto error_recovery; } /* Create the reply port. */ memcpy(tpInfo->replyPortName, portName, sizeof(portName)); /* MULTIHOST support */ do { MME_Info(MME_INFO_MANAGER, (" EMBX_CreatePort(), port name <%s>...\n", tpInfo->replyPortName)); /* Create the reply port. This port is purely synchronous (it only receives * messages that are replies to outstanding messages) and as such does not * need its own management thread. */ err = EMBX_CreatePort(tpInfo->handle, tpInfo->replyPortName, &tpInfo->replyPort); } while (EMBX_ALREADY_BIND == err && tpInfo->replyPortName[sizeof(portName)-2]++ < '9'); if (EMBX_SUCCESS != err) { goto error_recovery; } *tpInfo_p = tpInfo; return MME_SUCCESS; error_recovery: if (tpInfo->handle) { err = EMBX_CloseTransport(tpInfo->handle); MME_Assert(EMBX_SUCCESS == err); } EMBX_OS_MemFree(tpInfo); return MME_EMBX_ERROR; }
MME_ERROR MME_RegisterTransport(const char *transportName) { const char portName[] = "MMECompanionAdmin#0"; EMBX_ERROR err; if (NULL == transportName) { return MME_INVALID_ARGUMENT; } if (NULL == manager) { return MME_DRIVER_NOT_INITIALIZED; } MME_Info(MME_INFO_MANAGER, ("EMBX_OpenTransport(), name <%s>...\n", transportName)); /* Open the transport. */ err = EMBX_OpenTransport(transportName, &manager->transportHandle); MME_Info(MME_INFO_MANAGER, ("EMBX_OpenTransport() - handle %d\n", manager->transportHandle)); if (EMBX_SUCCESS != err) { MME_Info(MME_INFO_MANAGER, ("Failed to open EMBX_OpenTransport() - EMBX err %d\n", err)); return MME_INVALID_ARGUMENT; } /* Create the administration port. */ memcpy(manager->adminPortName, portName, sizeof(portName)); do { MME_Info(MME_INFO_MANAGER, (" EMBX_CreatePort(), port name <%s>...\n", manager->adminPortName)); err = EMBX_CreatePort(manager->transportHandle, manager->adminPortName, &manager->adminPort); } while (EMBX_ALREADY_BIND == err && manager->adminPortName[sizeof(portName)-2]++ < '9'); if (err != EMBX_SUCCESS) { MME_Info(MME_INFO_MANAGER, ("EMBX_CreatePort(%s) failed - error %d\n", manager->adminPortName, err)); EMBX_CloseTransport(manager->transportHandle); manager->transportHandle = 0; return MME_INVALID_ARGUMENT; } MME_Info(MME_INFO_MANAGER, ("EMBX_CreatePort(%s) handle 0x%08x\n", manager->adminPortName, manager->adminPort)); manager->managerRunning = 1; return MME_SUCCESS; }
int main() { EMBX_TRANSPORT hTrans; EMBX_PORT bufferpool, consumer, mypoolconnection; EMBX_ERROR err; int i; embxRuntimeInit(); err = EMBX_OpenTransport("shm", &hTrans); assert(EMBX_SUCCESS == err); /* Create the port which will hold the pool of work buffers */ err = EMBX_CreatePort(hTrans, "bufferpool", &bufferpool); assert(EMBX_SUCCESS == err); /* Make a connection to the port we just created so we can inject * empty buffers onto the port's queue as part of the initialization */ err = EMBX_Connect(hTrans, "bufferpool", &mypoolconnection); assert(EMBX_SUCCESS == err); /* Now wait for the consumer port to come into existence and * make a connection to it. */ err = EMBX_ConnectBlock(hTrans, "consumer", &consumer); assert(EMBX_SUCCESS == err); /* Inject empty buffers into the buffer pool */ for(i=0;i<BUFFER_POOL_SIZE;i++) { EMBX_VOID *buffer; err = EMBX_Alloc(hTrans, BUFFER_SIZE, &buffer); assert(EMBX_SUCCESS == err); /* Send empty buffer to the buffer pool port */ err = EMBX_SendMessage(mypoolconnection, buffer, 0); assert(EMBX_SUCCESS == err); } /* We don't need our connection to the buffer pool anymore * so close it down. */ EMBX_ClosePort(mypoolconnection); for(i=0;i<100;i++) { EMBX_RECEIVE_EVENT ev; EMBX_UINT buffersize; /* Jabber ... */ printf("producer: Issuing message %d of 100\n", i+1); /* Get an empty buffer from the pool */ err = EMBX_ReceiveBlock(bufferpool, &ev); assert(EMBX_SUCCESS == err); /* The event size field does not represent the actual * size of the buffer in this case, hence if you need * to find that out use the following. However in this * case where all the buffers are the same known size * it wouldn't be necessary expect as self checking debug. */ err = EMBX_GetBufferSize(ev.data, &buffersize); assert(EMBX_SUCCESS == err); /* Do something to fill the buffer with stuff to be used * by the consumer...... use your imagination ...... */ /* Now send the buffer to the consumer with the real amount * of data in the buffer as the size argument (this can be * less than the buffer size). For this example we assume * the whole buffer contains valid data. */ err = EMBX_SendMessage(consumer, ev.data, buffersize); assert(EMBX_SUCCESS == err); } /* Shut the communication system down. This has the side effect * of causing the consumer to also close down, almost certainly * before outstanding messages have been processed. */ EMBX_ClosePort(bufferpool); EMBX_ClosePort(consumer); EMBX_CloseTransport(hTrans); EMBX_Deinit(); return 0; }
int run_test(void) { EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_TRANSPORT tp; EMBX_PORT localPort,remotePort; EMBX_VOID *buffer1,*buffer2; EMBX_FACTORY factory; bFailed = EMBX_FALSE; tp = EMBX_INVALID_HANDLE_VALUE; buffer1 = buffer2 = 0; /* Test 1 */ res = EMBX_SendMessage(EMBX_INVALID_HANDLE_VALUE, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory,&loopback_config,sizeof(EMBXLB_Config_t),&factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 8 */ res = EMBX_SendMessage(tp, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_SendMessage(localPort, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 10 */ res = EMBX_SendMessage(remotePort, 0, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 11 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE+1); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 13 - Ensure this allocation happens before buffer1 gets free'd * when the port is closed, so buffer1 and buffer2 will not point to * the same memory which is important for later tests. */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer2); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 15 - buffer1 has been freed by test14 so should be garbage */ res = EMBX_SendMessage(remotePort, buffer1, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 16 */ res = EMBX_SendMessage(remotePort, buffer2, BUFFER_SIZE); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 18 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 19 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* These test a different code path to the identical tests done before * EMBX_Init. */ /* Test 20 - Depends on buffer2 not having been freed so we get through * to checking the state of the driver. */ res = EMBX_SendMessage(remotePort, buffer2, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 21 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }
int run_test(void) { EMBX_ERROR res; EMBX_TRANSPORT tp; EMBX_FACTORY factory; tp = EMBX_INVALID_HANDLE_VALUE; /* Test 1 */ res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &blocking_loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_OpenTransport("lo_blocking", &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_RegisterTransport(EMBXLB_loopback_factory,&blocking_loopback_config,sizeof(EMBXLB_Config_t),&factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } if(!EMBX_OS_ThreadCreate(deinit_thread, (void *)2000, EMBX_DEFAULT_THREAD_PRIORITY, "deinit")) { EMBX_Info(EMBX_TRUE, ("Unable to create thread\n")); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_OpenTransport("lo_blocking", &tp); if(res != EMBX_TRANSPORT_CLOSED) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 8 */ res = EMBX_Deinit(); if(res != EMBX_DRIVER_NOT_INITIALIZED) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } return 0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }
int run_test(void) { EMBX_UINT i; EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_PORT localPort,remotePort; EMBX_VOID *buffer1; EMBX_FACTORY factory; EMBX_RECEIVE_EVENT ev; bFailed = EMBX_FALSE; buffer1 = 0; /* Test 1 */ res = EMBX_ReceiveBlock(EMBX_INVALID_HANDLE_VALUE, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_ReceiveBlock(tp, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 8 */ res = EMBX_ReceiveBlock(remotePort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_ReceiveBlock(localPort, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 10 */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } for(i=0;i<BUFFER_SIZE;i++) { ((unsigned char *)buffer1)[i] = (unsigned char)i; } /* Test 11 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test13 failed, event structure incorrect\n")); goto skip_remaining_tests; } for(i=0;i<ev.size;i++) { if( ((unsigned char *)ev.data)[i] != (unsigned char)i ) { EMBX_Info(EMBX_TRUE, ("Test13 failed, buffer contents incorrect\n")); bFailed = EMBX_TRUE; break; } } /* Test 13 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(!EMBX_OS_ThreadCreate(send_thread, (void *)remotePort, EMBX_DEFAULT_THREAD_PRIORITY, "send")) { EMBX_Info(EMBX_TRUE, ("Unable to create thread\n")); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test15 failed, event structure incorrect\n")); goto skip_remaining_tests; } /* Test 15 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 16 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 18 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 19 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* These test a different code path to the identical tests done before * EMBX_Init */ /* Test 20 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 21 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }
int main() { EMBX_TRANSPORT hTrans; EMBX_PORT consumer, bufferpool; EMBX_ERROR err; embxRuntimeInit(); err = EMBX_OpenTransport("shm", &hTrans); assert(err == EMBX_SUCCESS); /* Create the port which the consumer will receive work * messages on. */ err = EMBX_CreatePort(hTrans, "consumer", &consumer); assert(err == EMBX_SUCCESS); /* Connect to the buffer pool on the producer, we will send * back finished message buffers to this so the producer can * re-use them. */ err = EMBX_ConnectBlock(hTrans, "bufferpool", &bufferpool); assert(err == EMBX_SUCCESS); while(1) { EMBX_RECEIVE_EVENT ev; /* Wait for some work to do */ err = EMBX_ReceiveBlock(consumer, &ev); if(err != EMBX_SUCCESS) { /* Assume, for the purposes of this example * that this means the producer wants to close * down. Hence clean up the transport and close * down EMBX. */ EMBX_ClosePort(bufferpool); EMBX_ClosePort(consumer); EMBX_CloseTransport(hTrans); EMBX_Deinit(); exit(1); } /* Do some work with the received message data here */ printf("consumer: Processing message\n"); /* Now send the message buffer back, note the zero size * for the message length, this will prevent any data copying * on a non shared memory transport. */ err = EMBX_SendMessage(bufferpool, ev.data, 0); if(err != EMBX_SUCCESS) { EMBX_ClosePort(bufferpool); EMBX_ClosePort(consumer); EMBX_CloseTransport(hTrans); EMBX_Deinit(); exit(1); } } return 0; }
int run_test(void) { EMBX_UINT i; EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_TRANSPORT tp; EMBX_PORT localPort,remotePort; EMBX_HANDLE hObj; EMBX_FACTORY factory; EMBX_RECEIVE_EVENT ev; bFailed = EMBX_FALSE; tp = EMBX_INVALID_HANDLE_VALUE; hObj = EMBX_INVALID_HANDLE_VALUE; /* Test 1 */ res = EMBX_Receive(EMBX_INVALID_HANDLE_VALUE, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_RegisterObject(tp, object, BUFFER_SIZE, &hObj); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } for(i=0;i<BUFFER_SIZE;i++) { ((unsigned char *)object)[i] = (unsigned char)i; } /* Test 8 */ res = EMBX_SendObject(remotePort, hObj, 0, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_Receive(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != hObj || /* This is a specific quirk of the loopback transport */ ev.offset != 0 || ev.type != EMBX_REC_OBJECT || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test9 failed, event structure incorrect\n")); goto skip_remaining_tests; } for(i=0;i<ev.size;i++) { if( ((unsigned char *)ev.data)[i] != (unsigned char)i ) { EMBX_Info(EMBX_TRUE, ("Test9 failed, buffer contents incorrect\n")); bFailed = EMBX_TRUE; break; } } /* Test 10 */ res = EMBX_UpdateObject(remotePort, hObj, 0, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 11 */ res = EMBX_Receive(localPort, &ev); if(res != EMBX_INVALID_STATUS) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_DeregisterObject(tp, hObj); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 13 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 15 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 16 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }