static void harness_initialize(void) { int res; EMBX_FACTORY hFactory; EMBXSHM_EMPIMailboxConfig_t config = { { "shm", /* name */ 1, /* cpuID */ { 1, 1, 0, 0 }, /* participants */ 0 /* pointerWarp */ }, (void *) 0x7b130000 /* empiAddr */ }; /* register the mailbox with embxmailbox */ EMBX(Mailbox_Init()); EMBX(Mailbox_Register((void *) 0x7b150000, 48, 7, EMBX_MAILBOX_FLAGS_ST20 | EMBX_MAILBOX_FLAGS_PASSIVE)); /* register the transport */ res = EMBX_RegisterTransport( EMBXSHM_empi_mailbox_factory, &config, sizeof(config), &hFactory); assert(EMBX_SUCCESS == res); /* make sure the shared memory is not cached */ res = cache_config_data((void*) 0x60000000, (void*) 0x7fffffff, cache_config_disable); assert(0 == res); }
static void harness_initialize(void) { int res; EMBX_FACTORY hFactory; EMBXSHM_MailboxConfig_t config = { "shm", /* name */ 1, /* cpuID */ { 1, 1, 0, 0 }, /* participants */ #ifdef ENABLE_EMBXSHMC 0x44000000 /* pointerWarp */ #else 0 /* pointerWarp */ #endif }; /* register the mailbox with embxmailbox */ EMBX(Mailbox_Init()); EMBX(Mailbox_Register((void *) 0x19160000, 35, 7, EMBX_MAILBOX_FLAGS_ST20 | EMBX_MAILBOX_FLAGS_LOCKS)); /* register the transport */ res = EMBX_RegisterTransport( EMBXSHM_mailbox_factory, &config, sizeof(config), &hFactory); assert(EMBX_SUCCESS == res); }
int init_comms(EMBX_FACTORY *pFact,EMBX_TRANSPORT *pTrans,EMBX_PORT *pPort) { EMBX_ERROR err; EMBX_TPINFO tpinfo; *pFact = 0; *pTrans = 0; *pPort = 0; /* * Register the transport factory for the shared memory * transport configuration we require. */ err = EMBX_RegisterTransport(EMBXSHM_mailbox_factory, &config, sizeof(config), pFact); if(err != EMBX_SUCCESS) { printf("Factory registration failed err = %d\n",err); return -1; } /* * Initialise the EMBX library, this will attempt to create * a transport based on the factory we just registered. */ if((err = EMBX_Init()) != EMBX_SUCCESS) { printf("EMBX initialisation failed err = %d\n",err); return -1; } /* * Try and get the information structure for the transport * we hope has just been created. If this returns an error * no transports were created during EMBX_Init, which means * something went wrong in the transport factory we registered. */ if((err = EMBX_GetFirstTransport(&tpinfo)) != EMBX_SUCCESS) { printf("Querying transport failed err = %d\n",err); return -1; } return 0; }
EMBX_ERROR STb5525_RegisterTransport(const char *name, EMBX_FACTORY *phFactory) { void *physicalSharedAddr = (void *) 0x84200000; void *virtualSharedAddr = mmap_translate_virtual(physicalSharedAddr); void *uncachedSharedAddr = mmap_translate_uncached(virtualSharedAddr); EMBXSHM_GenericConfig_t config = { "shm", /* name */ 0, /* cpuID */ { 1, 1, 0, 0 }, /* participants */ 0, /* pointerWarp */ (void *) 0, /* sharedAddr */ 2 * 1024 * 1024, /* sharedSize */ STb5525_NotifyFunction, /* interrupt knocking function */ &STb5525_Context, /* data structure used by above */ 0, /* maxPorts */ 0, /* maxObjects */ 0 /* freeListSize */ }; strcpy(config.name, name); config.sharedAddr = uncachedSharedAddr; if (IS_HOST()) { config.maxObjects = 64; config.freeListSize = 64; } else { config.cpuID = 1; STb5525_ReserveSharedMemory(physicalSharedAddr, config.sharedSize); } return EMBX_RegisterTransport(EMBXSHM_generic_factory, &config, sizeof(config), phFactory); }
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 __init embxshm_init( void ) { int err; EMBX_ERROR res; EMBXSHM_EMPIMailboxConfig_t config[4]; /* Allow for alternative embxmailbox parameter naming */ mailbox0 = embxmailbox0 ? embxmailbox0 : mailbox0; mailbox1 = embxmailbox1 ? embxmailbox1 : mailbox1; mailbox2 = embxmailbox2 ? embxmailbox2 : mailbox2; mailbox3 = embxmailbox3 ? embxmailbox3 : mailbox3; /* check for mismatched structures */ if ((empi0 && !mailbox0) || (empi1 && !mailbox1) || (empi2 && !mailbox2) || (empi3 && !mailbox3)) { return -EINVAL; } memset(config, 0, sizeof(config)); err = (NULL == mailbox0 ? 0 : parseMailboxString(mailbox0, &(config[0].mailbox))); err += (NULL == mailbox1 ? 0 : parseMailboxString(mailbox1, &(config[1].mailbox))); err += (NULL == mailbox2 ? 0 : parseMailboxString(mailbox2, &(config[2].mailbox))); err += (NULL == mailbox3 ? 0 : parseMailboxString(mailbox3, &(config[3].mailbox))); err += (NULL == empi0 ? 0 : parseEmpiString(empi0, config+0)); err += (NULL == empi1 ? 0 : parseEmpiString(empi1, config+1)); err += (NULL == empi2 ? 0 : parseEmpiString(empi2, config+2)); err += (NULL == empi3 ? 0 : parseEmpiString(empi3, config+3)); if (0 != err) { return -EINVAL; } if (mailbox0) { #ifdef EMBXSHM_CACHED_HEAP res = EMBX_RegisterTransport(empi0 ? EMBXSHMC_empi_mailbox_factory : EMBXSHMC_mailbox_factory, config+0, sizeof(config[0]), &(registeredFactories[numRegisteredFactories])); #else res = EMBX_RegisterTransport(empi0 ? EMBXSHM_empi_mailbox_factory : EMBXSHM_mailbox_factory, config+0, sizeof(config[0]), &(registeredFactories[numRegisteredFactories])); #endif numRegisteredFactories += (EMBX_SUCCESS == res ? 1 : 0); } if (mailbox1) { #ifdef EMBXSHM_CACHED_HEAP res = EMBX_RegisterTransport(empi1 ? EMBXSHMC_empi_mailbox_factory : EMBXSHMC_mailbox_factory, config+1, sizeof(config[1]), &(registeredFactories[numRegisteredFactories])); #else res = EMBX_RegisterTransport(empi1 ? EMBXSHM_empi_mailbox_factory : EMBXSHM_mailbox_factory, config+1, sizeof(config[1]), &(registeredFactories[numRegisteredFactories])); #endif numRegisteredFactories += (EMBX_SUCCESS == res ? 1 : 0); } if (mailbox2) { #ifdef EMBXSHM_CACHED_HEAP res = EMBX_RegisterTransport(empi2 ? EMBXSHMC_empi_mailbox_factory : EMBXSHMC_mailbox_factory, config+2, sizeof(config[2]), &(registeredFactories[numRegisteredFactories])); #else res = EMBX_RegisterTransport(empi2 ? EMBXSHM_empi_mailbox_factory : EMBXSHM_mailbox_factory, config+2, sizeof(config[2]), &(registeredFactories[numRegisteredFactories])); #endif numRegisteredFactories += (EMBX_SUCCESS == res ? 1 : 0); } if (mailbox3) { #ifdef EMBXSHM_CACHED_HEAP res = EMBX_RegisterTransport(empi3 ? EMBXSHMC_empi_mailbox_factory : EMBXSHMC_mailbox_factory, config+3, sizeof(config[3]), &(registeredFactories[numRegisteredFactories])); #else res = EMBX_RegisterTransport(empi3 ? EMBXSHM_empi_mailbox_factory : EMBXSHM_mailbox_factory, config+3, sizeof(config[3]), &(registeredFactories[numRegisteredFactories])); #endif numRegisteredFactories += (EMBX_SUCCESS == res ? 1 : 0); } 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; }