static void RunTests ( void ) { if (strcmp(TestType, "TestWaitingList") == 0) { testWaitingList(); } else if (strcmp(TestType, "TestRecursive") == 0) { testRecursive(); } else if (strcmp(TestType, "TestTraceableRecursive") == 0) { testTraceableRecursive(); } else if (strcmp(TestType, "1toN-1") == 0) { createAllMutexes(); queueFuncToAllThreads(DelMutex1toNMinus1PerThread); } else if (strcmp(TestType, "AllMutexes1stThread") == 0) { createAllMutexes(); queueFuncToAllThreads(DelAllMutexesFor1stThread); } else if (strcmp(TestType, "AllMutexesMidThread") == 0) { createAllMutexes(); queueFuncToAllThreads(DelAllMutexesForMidThread); } else if (strcmp(TestType, "1stThread") == 0) { createAllMutexes(); LE_INFO("Deleting the 1st thread"); le_thread_Cancel(ThreadRefArray[0]); } else if (strcmp(TestType, "MidThread") == 0) { createAllMutexes(); LE_INFO("Deleting the middle thread"); le_thread_Cancel(ThreadRefArray[ThreadNum / 2]); } else if (strcmp(TestType, "None") == 0) { createAllMutexes(); } else { // should never get here. PrintHelp(); } }
//-------------------------------------------------------------------------------------------------- static void TestMdc_StartStopAsync ( void ) { le_clk_Time_t timeToWait; timeToWait.sec = 0; timeToWait.usec = 1000000; const StartStopAsyncFunc_t testFunc[] = { le_mdc_StartSessionAsync, le_mdc_StopSessionAsync, NULL }; int i=0; while (testFunc[i]) { le_thread_Ref_t testThread = le_thread_Create("AsyncStartStopSessionThread", AsyncStartStopSessionThread, testFunc[i]); // Start the thread le_thread_Start(testThread); LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, timeToWait) != LE_TIMEOUT); le_thread_Cancel(testThread); i++; } }
//-------------------------------------------------------------------------------------------------- static void TestLeGnssPositionHandler ( void ) { le_thread_Ref_t positionThreadRef; LE_INFO("Start Test Testle_gnss_PositionHandlerTest"); LE_INFO("Start GNSS"); LE_ASSERT((le_gnss_Start()) == LE_OK); LE_INFO("Wait 5 seconds"); sleep(5); // Add Position Handler Test positionThreadRef = le_thread_Create("PositionThread",PositionThread,NULL); le_thread_Start(positionThreadRef); LE_INFO("Wait for a 3D fix"); sleep(60); le_gnss_RemovePositionHandler(PositionHandlerRef); LE_INFO("Wait 5 seconds"); sleep(5); // stop thread le_thread_Cancel(positionThreadRef); LE_INFO("Stop GNSS"); LE_ASSERT((le_gnss_Stop()) == LE_OK); }
//-------------------------------------------------------------------------------------------------- void simTest_SimPowerUpDown ( void ) { le_sim_States_t state; le_sim_Id_t simId; le_result_t res; le_clk_Time_t timeOut; //set timeout seconds for waiting for asynchronous power down event. timeOut.sec = 5; timeOut.usec = 0; SimPowerCycleSemaphore = le_sem_Create("HandlerSimPowerCycle", 0); SimPowerCycleThreadRef= le_thread_Create("ThreadSimPowerCycle", SimPowerCycleIndThread, NULL); le_thread_Start(SimPowerCycleThreadRef); // get blocked here until our event handler is registered and powerCycle thread is running res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut); LE_ASSERT_OK(res); // Power down cases simId = le_sim_GetSelectedCard(); state = le_sim_GetState(simId); LE_INFO("test: SIM state %d", state); LE_ASSERT(LE_SIM_READY == state); LE_ASSERT_OK(le_sim_SetPower(simId, LE_OFF)); // Wait for complete asynchronous event of powered down (LE_SIM_POWER_DOWN) res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut); LE_ASSERT_OK(res); LE_INFO("Powers Down current SIM: success"); // Power up cases LE_ASSERT_OK(le_sim_SetPower(simId, LE_ON)); // Wait for complete asynchronous event of powered up (LE_SIM_READY) res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut); LE_ASSERT_OK(res); LE_INFO("Powers On current SIM: success"); // Remove the handler le_sim_RemoveNewStateHandler(SimPowerCycleHdlrRef); // cancel the power cycle test thread le_thread_Cancel(SimPowerCycleThreadRef); }
//-------------------------------------------------------------------------------------------------- static void TestLeGnssTtffMeasurement ( void ) { uint32_t ttff = 0; uint32_t ttffSave = 0; le_thread_Ref_t positionThreadRef; LE_INFO("Start Test Testle_gnss_ttffTest"); LE_INFO("Start GNSS"); LE_ASSERT((le_gnss_Start()) == LE_OK); // Add Position Handler Test positionThreadRef = le_thread_Create("PositionThread",PositionThread,NULL); le_thread_Start(positionThreadRef); LE_INFO("loop to Wait for a 3D fix"); LoopToGet3Dfix(&ttff); ttffSave = ttff; /* HOT Restart */ LE_INFO("Ask for a Hot restart in 3 seconds..."); sleep(3); LE_ASSERT(le_gnss_ForceHotRestart() == LE_OK); LE_INFO("loop to Wait for a 3D fix"); LoopToGet3Dfix(&ttff); le_gnss_RemovePositionHandler(PositionHandlerRef); LE_INFO("Wait 5 seconds"); sleep(5); // stop thread le_thread_Cancel(positionThreadRef); LE_INFO("Stop GNSS"); LE_ASSERT((le_gnss_Stop()) == LE_OK); LE_INFO("TTFF start = %d msec", ttffSave); LE_INFO("TTFF Hot restart = %d msec", ttff); }
//-------------------------------------------------------------------------------------------------- static le_result_t Testle_sms_AsyncSendPdu ( void ) { le_result_t res; bool pdu_type = true; NbSmsTx = NB_SMS_ASYNC_TO_SEND; // Init the semaphore for asynchronous callback sem_init(&SmsTxSynchronization,0,0); TxCallBack = le_thread_Create("Tx CallBack", MyTxThread, &pdu_type); le_thread_Start(TxCallBack); res = WaitFunction(&SmsTxSynchronization, 10000); le_thread_Cancel(TxCallBack); return res; }
//-------------------------------------------------------------------------------------------------- static le_result_t Testle_sms_AsyncSendText ( void ) { le_result_t res; bool pdu_type = false; NbSmsTx = NB_SMS_ASYNC_TO_SEND * 2 ; // Init the semaphore for asynchronous callback sem_init(&SmsTxSynchronization,0,0); TxCallBack = le_thread_Create("Tx CallBack", MyTxThread, &pdu_type); le_thread_Start(TxCallBack); res = WaitFunction(&SmsTxSynchronization, 120000); LE_ERROR_IF(res != LE_OK, "SYNC FAILED"); le_thread_Cancel(TxCallBack); return res; }
//-------------------------------------------------------------------------------------------------- static void TryConnect ( ConnectServiceFunc_t connectFuncPtr, ///< Function to call to connect to service char* serviceNamePtr ///< String containing name of the service ) { // Print out message before trying to connect to service to give user some kind of feedback printf("Connecting to service ...\n"); fflush(stdout); // Use a separate thread for recovery. It will be stopped once connected to the service. // Make the thread joinable, so we can be sure the thread is stopped before continuing. le_thread_Ref_t threadRef = le_thread_Create("timout thread", TimeoutThread, serviceNamePtr); le_thread_SetJoinable(threadRef); le_thread_Start(threadRef); // Try connecting to the service connectFuncPtr(); // Connected to the service, so stop the timeout thread le_thread_Cancel(threadRef); le_thread_Join(threadRef, NULL); }
//-------------------------------------------------------------------------------------------------- static le_result_t Testle_sms_Send_UCS2 ( void ) { le_result_t res = LE_FAULT; le_sms_MsgRef_t myMsg; NbSmsRx = 1; // Init the semaphore for synchronous API (hangup, answer) sem_init(&SmsRxSynchronization,0,0); RxThread = le_thread_Create("Rx SMS reception", MyRxThread, NULL); le_thread_Start(RxThread); // Wait for thread starting. sleep(2); // Check if Thread SMS RX handler has been started if (!RxHdlrRef) { LE_ERROR("Handler not ready !!"); return LE_FAULT; } myMsg = le_sms_Create(); if (myMsg) { LE_DEBUG("-TEST- Create Msg %p", myMsg); res = le_sms_SetDestination(myMsg, DEST_TEST_PATTERN); if (res != LE_OK) { le_sms_Delete(myMsg); return LE_FAULT; } res = le_sms_SetUCS2(myMsg, UCS2_TEST_PATTERN, sizeof(UCS2_TEST_PATTERN) / 2); if (res != LE_OK) { le_sms_Delete(myMsg); return LE_FAULT; } res = le_sms_Send(myMsg); if ((res == LE_FAULT) || (res == LE_FORMAT_ERROR)) { le_sms_Delete(myMsg); return LE_FAULT; } res = WaitFunction(&SmsRxSynchronization, 120000); LE_ERROR_IF(res != LE_OK, "SYNC FAILED"); le_sms_Delete(myMsg); } le_sms_RemoveRxMessageHandler(RxHdlrRef); le_thread_Cancel(RxThread); return res; }
static void RunTests ( void ) { if (strcmp(TestType, "TestWaitingList") == 0) { testWaitingList(); } else if (strcmp(TestType, "1toN-1Threads") == 0) { createAllSemaphores(); int i = 0; while (i <= (ThreadNum - 2)) { LE_INFO("Cancelling the %dth thread", i); le_thread_Cancel(ThreadRefArray[i]); usleep(DelInv); i++; } } else if (strcmp(TestType, "Sem1toN-1Threads") == 0) { createAllSemaphores(); int i = 0; while (i <= (ThreadNum - 2)) { PostSemInThread(i); usleep(DelInv); i++; } } else if (strcmp(TestType, "Sem1stThread") == 0) { createAllSemaphores(); PostSemInThread(0); } else if (strcmp(TestType, "SemMidThread") == 0) { createAllSemaphores(); PostSemInThread(ThreadNum / 2); } else if (strcmp(TestType, "1stThread") == 0) { createAllSemaphores(); LE_INFO("Cancelling the 1st thread"); le_thread_Cancel(ThreadRefArray[0]); } else if (strcmp(TestType, "MidThread") == 0) { createAllSemaphores(); LE_INFO("Cancelling the middle thread"); le_thread_Cancel(ThreadRefArray[ThreadNum / 2]); } else if (strcmp(TestType, "None") == 0) { createAllSemaphores(); } else { // should never get here. PrintHelp(); } }