//-------------------------------------------------------------------------------------------------- void TestSim_SimCardInformation ( void ) { char iccid[PA_SIM_CARDID_MAX_LEN+1]; char imsi[PA_SIM_IMSI_MAX_LEN+1]; char phoneNumber[LE_MDMDEFS_PHONE_NUM_MAX_BYTES]; // Start in ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get information: error are expected as there's no SIM LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN) == LE_FAULT ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN) == LE_FAULT ); LE_ASSERT( le_sim_GetSubscriberPhoneNumber( CurrentSimId, phoneNumber, LE_MDMDEFS_PHONE_NUM_MAX_BYTES ) == LE_FAULT ); // SIM is now ready CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get informations, check values (OK expected) LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN+1) == LE_OK ); LE_ASSERT( strncmp(iccid,Iccid,PA_SIM_CARDID_MAX_LEN) == 0 ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN+1) == LE_OK ); LE_ASSERT( strncmp(imsi,Imsi,PA_SIM_IMSI_MAX_LEN) == 0 ); LE_ASSERT( le_sim_GetSubscriberPhoneNumber( CurrentSimId, phoneNumber, LE_MDMDEFS_PHONE_NUM_MAX_BYTES ) == LE_OK ); LE_ASSERT( strncmp(phoneNumber,PhoneNum,LE_MDMDEFS_PHONE_NUM_MAX_BYTES) == 0 ); // Try to get infomartions with a too small buffer (error expected) LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN) == LE_OVERFLOW ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN) == LE_OVERFLOW ); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void TestSim_LockUnlockChange ( void ) { // Go into ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check the states CheckSimStates(); // Try to lock/unlock/change PIN w/o SIN inserted: errors are expected LE_ASSERT(le_sim_Unlock(CurrentSimId,Pin) == LE_NOT_FOUND); LE_ASSERT(le_sim_Lock(CurrentSimId,Pin) == LE_NOT_FOUND); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,NewPin) == LE_NOT_FOUND); // Go in READY state CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to lock/unclock/Change PIN with bad PIN: errors are expected LE_ASSERT(le_sim_Lock(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_Unlock(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,ShortPin,NewPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,ShortPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,ShortPin,ShortPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,BadPin,NewPin) == LE_FAULT); // Lock/unlock/change PIN with correct values: OK is expected LE_ASSERT(le_sim_Lock(CurrentSimId,Pin) == LE_OK); LE_ASSERT(le_sim_Unlock(CurrentSimId,Pin) == LE_OK); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,NewPin) == LE_OK); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void Testle_ecall_RemoveHandlers ( void ) { int i; // Remove handlers: add le_ecall_RemoveStateChangeHandler to the eventLoop of tasks for (i=0; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread(AppCtx[i].appThreadRef, RemoveHandler, &AppCtx[i], NULL); } // Wait for the tasks SynchTest(); // Provoke event which should call the handlers pa_ecallSimu_ReportEcallState(LE_ECALL_STATE_STARTED); // Wait for the semaphore timeout to check that handlers are not called LE_ASSERT( le_sem_WaitWithTimeOut(ThreadSemaphore, TimeToWait) == LE_TIMEOUT ); }
//-------------------------------------------------------------------------------------------------- void TestSim_RemoveHandlers ( void ) { int i; // Remove handlers: add le_sim_RemoveNewStateHandler and le_sim_RemoveSimToolkitEventHandler // to the eventLoop of tasks for (i=0; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread( AppCtx[i].appThreadRef, RemoveHandler, &AppCtx[i], NULL ); } // Wait for the tasks SynchTest(); // Provoke events which called the handlers (sim state event, and stk event) // Go into ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Invoke Stk event, and check that no handler is called pa_simSimu_ReportStkEvent(StkEvent); // Wait for the semaphore timeout to check that handlers are not called LE_ASSERT( le_sem_WaitWithTimeOut(ThreadSemaphore, TimeToWait) == LE_TIMEOUT ); }
//-------------------------------------------------------------------------------------------------- static void Testle_Temp_RemoveHandlers ( void ) { int i; // Remove handlers: add le_temp_RemoveThresholdEventHandler to the eventLoop of tasks for (i=0; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread( AppCtx[i].appThreadRef, RemoveHandler, &AppCtx[i], NULL ); } // Wait for the tasks SynchTest(); // trigger an event report ExpectedStatus = 0; pa_tempSimu_TriggerEventReport(ExpectedStatus); // Wait for the semaphore timeout to check that handlers are not called LE_ASSERT( le_sem_WaitWithTimeOut(ThreadSemaphore, TimeToWait) == LE_TIMEOUT ); }
//-------------------------------------------------------------------------------------------------- void TestSim_AddHandlers ( void ) { int i; // Create a semaphore to coordinate the test ThreadSemaphore = le_sem_Create("HandlerSem",0); // int app context memset(AppCtx, 0, NB_CLIENT*sizeof(AppContext_t)); // Start tasks: simulate multi-user of le_sim // each thread subcribes to state handler using le_sim_AddNewStateHandler for (i=0; i < NB_CLIENT; i++) { char string[20]={0}; snprintf(string,20,"app%dhandler", i); AppCtx[i].appId = i; AppCtx[i].appThreadRef = le_thread_Create(string, AppHandler, &AppCtx[i]); le_thread_Start(AppCtx[i].appThreadRef); } // Wait that the tasks have started before continuing the test SynchTest(); // Sim is absent in this test CurrentSimState = LE_SIM_ABSENT; pa_simSimu_SetSelectCard(CurrentSimId); le_sim_SelectCard(CurrentSimId); pa_simSimu_ReportSimState(CurrentSimState); // The tasks have subscribe to state event handler: // wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check that we are in the expected states (sim absent) CheckSimStates(); // Check that no more call of the semaphore LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void TestSim_Stk ( void ) { // Stk handler semaphore StkHandlerSem = (le_sem_Ref_t) le_sem_Create("StkHandlerSem",1); // each thread subscribes to state handler using le_sim_AddSimToolkitEventHandler // This API has to be called by threads int i=0; for (; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread( AppCtx[i].appThreadRef, AddStkHandler, &AppCtx[i], NULL ); } // Wait for the tasks SynchTest(); StkEvent = LE_SIM_REFRESH; // Invoke Stk event pa_simSimu_ReportStkEvent(StkEvent); // Wait for the call of the handlers SynchTest(); // Check the result for (i=0; i<NB_CLIENT; i++) { LE_ASSERT(AppCtx[i].stkEvent == StkEvent); AppCtx[i].stkEvent = 0; } // Test le_sim_AcceptSimToolkitCommand and le_sim_RejectSimToolkitCommand pa_simSimu_SetExpectedStkConfirmationCommand(true); LE_ASSERT( le_sim_AcceptSimToolkitCommand(CurrentSimId) == LE_OK ); pa_simSimu_SetExpectedStkConfirmationCommand(false); LE_ASSERT( le_sim_RejectSimToolkitCommand(CurrentSimId) == LE_OK ); // Check that all handlers have been called as expected LE_ASSERT( le_sem_GetValue(ThreadSemaphore) == 0 ); }
//-------------------------------------------------------------------------------------------------- void TestSim_HomeNetwork ( void ) { char mcc[LE_MRC_MCC_BYTES]; char mnc[LE_MRC_MNC_BYTES]; char homeNetwork[20]; // Start in ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get home network: error are expected as there's no SIM LE_ASSERT(le_sim_GetHomeNetworkMccMnc(CurrentSimId,mcc,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES) == LE_FAULT); LE_ASSERT(le_sim_GetHomeNetworkOperator(CurrentSimId,homeNetwork,20) == LE_FAULT); // SIM is now ready CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get home network, check values (OK expected) LE_ASSERT(le_sim_GetHomeNetworkMccMnc(CurrentSimId,mcc,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES) == LE_OK); LE_ASSERT(strcmp(mcc,Mcc)==0); LE_ASSERT(strcmp(mnc,Mnc)==0); LE_ASSERT(le_sim_GetHomeNetworkOperator(CurrentSimId,homeNetwork,20) == LE_OK); LE_ASSERT(strcmp(homeNetwork,Operator)==0); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void Testle_ecall_AddHandlers ( void ) { int i; // Create a semaphore to coordinate the test ThreadSemaphore = le_sem_Create("HandlerSem",0); // int app context memset(AppCtx, 0, NB_CLIENT*sizeof(AppContext_t)); // Start tasks: simulate multi-user of le_ecall // each thread subcribes to state handler using le_ecall_AddStateChangeHandler for (i=0; i < NB_CLIENT; i++) { char string[20]={0}; snprintf(string,20,"app%dhandler", i); AppCtx[i].appId = i; AppCtx[i].appThreadRef = le_thread_Create(string, AppHandler, &AppCtx[i]); le_thread_Start(AppCtx[i].appThreadRef); } // Wait that the tasks have started before continuing the test SynchTest(); LE_ASSERT((CurrentEcallRef=le_ecall_Create()) != NULL); SimulateAndCheckState(LE_ECALL_STATE_STARTED); SimulateAndCheckState(LE_ECALL_STATE_CONNECTED); SimulateAndCheckState(LE_ECALL_STATE_WAITING_PSAP_START_IND); SimulateAndCheckState(LE_ECALL_STATE_PSAP_START_IND_RECEIVED); SimulateAndCheckState(LE_ECALL_STATE_MSD_TX_STARTED); SimulateAndCheckState(LE_ECALL_STATE_LLNACK_RECEIVED); SimulateAndCheckState(LE_ECALL_STATE_LLACK_RECEIVED); SimulateAndCheckState(LE_ECALL_STATE_MSD_TX_COMPLETED); SimulateAndCheckState(LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE); SimulateAndCheckState(LE_ECALL_STATE_COMPLETED); SimulateAndCheckState(LE_ECALL_STATE_RESET); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T2); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T3); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T5); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T6); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T7); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T9); SimulateAndCheckState(LE_ECALL_STATE_TIMEOUT_T10); // TODO: will be completed once pa_mcc_simu will be ready // SimulateAndCheckState(LE_ECALL_STATE_DISCONNECTED); // Check that no more call of the semaphore LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); le_ecall_Delete(CurrentEcallRef); }
//-------------------------------------------------------------------------------------------------- static void Testle_Temp_AddHandlers ( void ) { int i; // int app context memset(AppCtx, 0, NB_CLIENT*sizeof(AppContext_t)); // Start tasks: simulate multi-user of le_sim // each thread subcribes to state handler using le_sim_AddNewStateHandler for (i=0; i < NB_CLIENT; i++) { char string[20]={0}; snprintf(string,20,"app%dhandler", i); AppCtx[i].appId = i; AppCtx[i].appThreadRef = le_thread_Create(string, AppHandler, &AppCtx[i]); le_thread_Start(AppCtx[i].appThreadRef); } // Wait that the tasks have started before continuing the test SynchTest(); ExpectedStatus = 0; for (; ExpectedStatus <= LE_TEMP_PLATFORM_LOW_CRITICAL; ExpectedStatus++) { pa_tempSimu_TriggerEventReport(ExpectedStatus); // wait the handlers' calls SynchTest(); } // Check that no more call of the semaphore LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- static void SimulateAndCheckState ( le_ecall_State_t state ) { CurrentEcallState = state; LE_INFO("Simulate state.%d", CurrentEcallState); pa_ecallSimu_ReportEcallState(CurrentEcallState); // The tasks have subscribe to state event handler: // wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); }
//-------------------------------------------------------------------------------------------------- void TestSim_LocalSwap ( void ) { int i; int doItAgain = 2; while (doItAgain) { doItAgain--; // The thread is calling le_sim_LocalSwapToCommercialSubscription and // le_sim_LocalSwapToEmergencyCallSubscription (that's why we do this operation twice) le_event_QueueFunctionToThread( AppCtx[0].appThreadRef, LocalSwap, &AppCtx[0], NULL ); // Wait a while for le_sim treatment sleep(1); // There's a semaphore in the le_sim to wait for the refresh => report refresh event StkEvent = LE_SIM_REFRESH; // Invoke Stk event pa_simSimu_ReportStkEvent(StkEvent); // Wait for the call of the handlers SynchTest(); // Check the result for (i=0; i<NB_CLIENT; i++) { LE_ASSERT(AppCtx[i].stkEvent == StkEvent); AppCtx[i].stkEvent = 0; } // Check that all handlers have been called as expected LE_ASSERT( le_sem_GetValue(ThreadSemaphore) == 0 ); } }
//-------------------------------------------------------------------------------------------------- void TestSim_PinPuk ( void ) { // Check the states CheckSimStates(); // The test is started with no sim inserted (end of the previous test) // Sim absent, test Pin and Puk (error expected as no sim inserted) LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_NOT_FOUND); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_NOT_FOUND); LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == LE_NOT_FOUND); // Insert SIM (busy state) CurrentSimState = LE_SIM_BUSY; pa_simSimu_ReportSimState(CurrentSimState); // Note that in LE_SIM_BUSY state, no handlers are called // Check that we are in the expected states (sim busy) CheckSimStates(); // test pin and puk: error is expected as sim in BUSY state LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_FAULT); LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == LE_FAULT); // SIM is inserted CurrentSimState = LE_SIM_INSERTED; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check that we are in the expected states (sim busy) CheckSimStates(); // block the pin int i=3; for (;i!=0;i--) { // Test the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == i); if (i==1) { // Update CurrentSimState for handlers' checks CurrentSimState = LE_SIM_BLOCKED; } // Try to enter the PIN: the PIN is wrong, an error is expected LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_FAULT); // Don't try to unlock the SIM in the last failed PIN, PUK tests are done behind if (i != 1) { // Try to unblock the SIM whereas the sim is not in PUK state (error expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_FAULT); } else { // The last time, check that handlers have been called (the SIM is in BLOCKED state, // handers have been called to warn the state modification) SynchTest(); } // Get the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == i-1); // Check that we are in the expected states CheckSimStates(); } // Try the puk (bad puk or bad pin, errors are expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, ShortPuk, BadPin) == LE_OUT_OF_RANGE); LE_ASSERT(le_sim_Unblock(CurrentSimId, LongPuk, BadPin) == LE_OUT_OF_RANGE); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, ShortPin) == LE_UNDERFLOW); // The next operation unblocks the pin: we change the gloabal variable here to be ready when the // handlers will be called CurrentSimState = LE_SIM_READY; // Unblock the SIM (OK expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk,Pin) == LE_OK); // Get the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == 3); // Wait the handlers' calls (SIM is supposed to be in READY state now) SynchTest(); // Return into INSERTED state: check PIN CurrentSimState = LE_SIM_INSERTED; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Now, try to enter the PIN (bad pin code, error expected) LE_ASSERT(le_sim_EnterPIN(CurrentSimId, ShortPin) == LE_UNDERFLOW); // Enter the correct PIN (OK expected) CurrentSimState = LE_SIM_READY; LE_ASSERT(le_sim_EnterPIN(CurrentSimId, Pin) == LE_OK); // Wait the handlers' calls SynchTest(); // Check that we are in the expected states CheckSimStates(); LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }