Example #1
0
void testCreateDestroy(void)
{
    le_sem_Ref_t semPtr=NULL,semPtr2=NULL;

    semPtr     = le_sem_Create( "SEMAPHORE-1", 10);
    CU_ASSERT_PTR_NOT_EQUAL(semPtr, NULL);

    semPtr2    = le_sem_Create( "SEMAPHORE-2", 1);
    CU_ASSERT_PTR_NOT_EQUAL(semPtr2, NULL);


    le_sem_Delete(semPtr);
    CU_PASS("Destruct semaphore\n");
    le_sem_Delete(semPtr2);
    CU_PASS("Destruct semaphore\n");
}
Example #2
0
// A thread "main" function which creates a series of sems.
static void* ThreadCreateSem
(
    void* context
)
{
    char semNameBuffer[LIMIT_MAX_SEMAPHORE_NAME_BYTES] = {0};


    LE_INFO("Thread [%s] has started. Waiting on a semaphore.", le_thread_GetMyName());

    le_mutex_Lock(SemIndexMutexRef);

    snprintf(semNameBuffer, LIMIT_MAX_SEMAPHORE_NAME_BYTES, "[%s]Sem%ld",
             le_thread_GetMyName(), SemCreateIdx);

    le_sem_Ref_t sem = le_sem_Create(semNameBuffer, 0);

    SemRefArray[SemCreateIdx] = (SemRef_t){le_thread_GetCurrent(), sem};

    SemCreateIdx++;

    le_mutex_Unlock(SemIndexMutexRef);

    LE_INFO("In thread [%s], about to wait sem", le_thread_GetMyName());

    // notify the calling thread that this thread is about to wait on its sema.
    le_sem_Post(SemaRef);

    le_sem_Wait(sem);
    LE_INFO("In thread [%s], sema is posted", le_thread_GetMyName());

    le_event_RunLoop();
    return NULL;
}
Example #3
0
//--------------------------------------------------------------------------------------------------
static void StartStressECall
(
    void
)
{
    LE_INFO("Start StartStressECall");

    LastECallState = LE_ECALL_STATE_DISCONNECTED;
    TestCount = 0;

    ThreadSemaphore = le_sem_Create("ThreadSem",0);

    LE_ASSERT(le_ecall_AddStateChangeHandler(MyECallEventHandler, NULL) != NULL);

    LE_ASSERT(le_ecall_SetPsapNumber(PsapNumber) == LE_OK);

    LE_ASSERT(le_ecall_SetMsdTxMode(LE_ECALL_TX_MODE_PUSH) == LE_OK);

    LE_ASSERT((MytECallRef=le_ecall_Create()) != NULL);

    LE_ASSERT(le_ecall_SetMsdPosition(MytECallRef, true, +48898064, +2218092, 0) == LE_OK);

    LE_ASSERT(le_ecall_SetMsdPassengersCount(MytECallRef, 3) == LE_OK);

    le_thread_Start(le_thread_Create("ECallLoopThread", ECallLoopThread, NULL));
    // Start Test
    le_sem_Post(ThreadSemaphore);
}
Example #4
0
// -------------------------------------------------------------------------------------------------
void fjm_Start
(
    void
)
// -------------------------------------------------------------------------------------------------
{
    LE_TEST_INFO("FJM TESTS START");

    memset(TestResults, 0, sizeof(TestResults));
    Counter = 0;

    // Compute the expected ending counter value.
    ExpectedCounterValue = GetExpectedCounterValue();

    // Create semaphore to trigger
    CounterSemRef = le_sem_Create("CounterSem", 0);

    // Create the mutex.
    MutexRef = le_mutex_CreateNonRecursive("fork-join-mutex-test");

    // Create the Context Pool.
    if (ContextPoolRef == NULL)
    {
        LE_TEST_INFO("Initializing FJM-ContextPool");
        ContextPoolRef = le_mem_CreatePool("FJM-ContextPool", sizeof(Context_t));
        le_mem_ExpandPool(ContextPoolRef, ExpectedCounterValue);
    }

    // Spawn the first child thread.
    SpawnChildren(1);
}
Example #5
0
//--------------------------------------------------------------------------------------------------
static void TestMdc_Handler ( void )
{
    le_result_t res;

    /* Create the thread to subcribe and call the handlers */
    ThreadSemaphore = le_sem_Create("HandlerSem",0);
    le_thread_Ref_t thread = le_thread_Create("Threadhandler", ThreadTestHandler, NULL);
    le_thread_Start(thread);
    int i;
    le_clk_Time_t   timeToWait;
    timeToWait.sec = 0;
    timeToWait.usec = 1000000;

    /* Wait the thread to be ready */
    le_sem_Wait(ThreadSemaphore);

    for (i = 0; i < NB_PROFILE; i++)
    {
        /* Start a session for the current profile: the handler should be called */
        res = le_mdc_StartSession(ProfileRef[i]);
        LE_ASSERT(res == LE_OK);
        /* Wait for the call of the handler (error if timeout) */
        LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, timeToWait) == LE_OK);
        /* Check the the handler parameters */
        LE_ASSERT(ProfileRefReceivedByHandler == ProfileRef[i]);
        LE_ASSERT(ConnectionStateReceivedByHandler == true);
        ConnectionStateReceivedByHandler = false;
    }

    for (i = 0; i < NB_PROFILE; i++)
    {
        /* Stop a session for the current profile: the handler should be called */
        res = le_mdc_StopSession(ProfileRef[i]);
        LE_ASSERT(res == LE_OK);
        /* Wait for the call of the handler (error if timeout) */
        LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, timeToWait) == LE_OK);
        /* Check the the handler parameters */
        LE_ASSERT(ProfileRefReceivedByHandler == ProfileRef[i]);
        LE_ASSERT(ConnectionStateReceivedByHandler == false);
        ConnectionStateReceivedByHandler = true;
    }

    /* Remove the handler of the profile 1: ther handler can be removed only by the thread which
     * subscribed to the handler, so put the RemoveHandler() function in queue of this thread */
    le_event_QueueFunctionToThread(         thread,
                                            RemoveHandler,
                                            SessionStateHandler[1],
                                            NULL);
    le_sem_Wait(ThreadSemaphore);
    /* Start a session for the current profile: no handler should be called */
    res = le_mdc_StartSession(ProfileRef[1]);
    /* No semaphore post is waiting, we are expecting a timeout */
    LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, timeToWait) == LE_TIMEOUT);
    res = le_mdc_StopSession(ProfileRef[1]);
    /* No semaphore post is waiting, we are expecting a timeout */
    LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, timeToWait) == LE_TIMEOUT);

}
Example #6
0
//--------------------------------------------------------------------------------------------------
static void InitSimRefresh
(
    void
)
{
    // Create a semaphore to coordinate the test when SIM is refreshed
    SimRefreshSemaphore = le_sem_Create("SimRefreshSem", 0);

    le_sim_AddSimToolkitEventHandler(SimRefreshHandler, NULL);
}
Example #7
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);
}
Example #8
0
//--------------------------------------------------------------------------------------------------
void Testle_Temp_Init
(
    void
)
{
    // Create a semaphore to coordinate the test
    ThreadSemaphore = le_sem_Create("HandlerSem",0);

    le_thread_Start(le_thread_Create("PaTempThread", TempThread, NULL));

    le_sem_Wait(ThreadSemaphore);
}
Example #9
0
void testPostOK(void)
{
    le_sem_Ref_t semPtr=NULL;

    semPtr     = le_sem_Create( "SEMAPHORE-1", 10);
    CU_ASSERT_PTR_NOT_EQUAL(semPtr, NULL);

    le_sem_Post(semPtr);
    CU_ASSERT_EQUAL(le_sem_GetValue(semPtr),11);

    le_sem_Delete(semPtr);
    CU_PASS("Destruct semaphore\n");
}
Example #10
0
// This is testing if Semaphore_t.waitingList is displayed correctly.
// Thread 1, 2, and 3 are all waiting on Sem1. Thread4 is waiting on Sem2. Thread5 is waiting on Sem3.
// Therefore the expected result is that Sem1's waiting list has Thread 1, 2, and 3.
// Sem2's waiting list has Thread4.  Sem3's waiting list has Thread5.
void testWaitingList
(
    void
)
{
    le_sem_Ref_t sema1Ref = le_sem_Create("Semaphore1", 0);
    le_sem_Ref_t sema2Ref = le_sem_Create("Semaphore2", 0);
    le_sem_Ref_t sema3Ref = le_sem_Create("Semaphore3", 0);

    // create thread refs
    le_thread_Ref_t thread1Ref = le_thread_Create("Thread1", WaitOnSem, (void*)sema1Ref);
    le_thread_Ref_t thread2Ref = le_thread_Create("Thread2", WaitOnSem, (void*)sema1Ref);
    le_thread_Ref_t thread3Ref = le_thread_Create("Thread3", WaitOnSem, (void*)sema1Ref);
    le_thread_Ref_t thread4Ref = le_thread_Create("Thread4", WaitOnSem, (void*)sema2Ref);
    le_thread_Ref_t thread5Ref = le_thread_Create("Thread5", WaitOnSem, (void*)sema3Ref);

    // start the threads
    le_thread_Start(thread1Ref);
    le_thread_Start(thread2Ref);
    le_thread_Start(thread3Ref);
    le_thread_Start(thread4Ref);
    le_thread_Start(thread5Ref);
}
Example #11
0
//--------------------------------------------------------------------------------------------------
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);
}
Example #12
0
void launch_thread()
{
        int i;
        le_thread_Ref_t thread[NB_THREADS];

        GSemPtr  = le_sem_Create( SEM_NAME_1, 5);
        GSem2Ptr = le_sem_Create( SEM_NAME_2, 2);

        CU_ASSERT_PTR_NOT_EQUAL(GSemPtr, NULL);
        for (i = 0; i < NB_THREADS; i ++) {
            char threadName[20];
            snprintf(threadName,20,"Thread_%d",i);
            thread[i] = le_thread_Create(threadName, fonction_thread, NULL);
            le_thread_SetJoinable(thread[i]);
            le_thread_Start(thread[i]);
            usleep(10000);
        }
        for (i = 0; i < NB_THREADS; i ++) {
            le_thread_Join(thread[i], NULL);
        }
        le_sem_Delete(GSem2Ptr);
        le_sem_Delete(GSemPtr);
        CU_PASS("GlobalSemaphore destroy");
}
Example #13
0
//--------------------------------------------------------------------------------------------------
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);
}
Example #14
0
static void Init
(
    void
)
{
    // Create the key for thread specific data; ie. mutex refs.
    (void) pthread_key_create(&TsdMutexRefKey, NULL);

    // mutex for accessing the mutex index variable.
    MutexIndexMutexRef = le_mutex_CreateNonRecursive("MutexIndexMutex");

    // syncrhonizing among threads for locking/unlocking mutexes
    SemaRef = le_sem_Create("MutexFluxSemaphore", 0);

    // Initializing the array storing thread refs.
    ThreadRefArray = malloc(ThreadNum * sizeof(le_thread_Ref_t));
}
Example #15
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 );
}
Example #16
0
static void Init
(
    void
)
{
    // mutex for accessing the sem index variable.
    SemIndexMutexRef = le_mutex_CreateNonRecursive("SemIndexMutex");

    // syncrhonizing among threads for waiting/posting semas.
    SemaRef = le_sem_Create("semaphoreFluxSemaphore", 0);

    // Initializing the array storing thread refs.
    ThreadRefArray = malloc(ThreadNum * sizeof(le_thread_Ref_t));

    // Initializing the array storing sem refs.
    SemRefArray = malloc(ThreadNum * sizeof(SemRef_t));
}
Example #17
0
void testTryWait(void)
{
    le_sem_Ref_t semPtr=NULL;
    le_result_t     result;

    semPtr     = le_sem_Create( "SEMAPHORE-1", 2);
    CU_ASSERT_PTR_NOT_EQUAL(semPtr, NULL);

    result=le_sem_TryWait(semPtr);
    CU_ASSERT_EQUAL(result,LE_OK);
    CU_ASSERT_EQUAL(le_sem_GetValue(semPtr),1);
    result=le_sem_TryWait(semPtr);
    CU_ASSERT_EQUAL(result,LE_OK);
    CU_ASSERT_EQUAL(le_sem_GetValue(semPtr),0);
    result=le_sem_TryWait(semPtr);
    CU_ASSERT_EQUAL(result,LE_WOULD_BLOCK);

    le_sem_Delete(semPtr);
    CU_PASS("Destruct semaphore\n");
}
Example #18
0
//--------------------------------------------------------------------------------------------------
le_result_t Testle_atServer_Bridge
(
    int socketFd,
    int epollFd,
    SharedData_t* sharedDataPtr
)
{
    LE_INFO("======== Test AT server bridge API ========");
    le_result_t ret;
    le_atServer_BridgeRef_t bridgeRef = NULL;

    BridgeSemaphore = le_sem_Create("BridgeSem", 0);

    le_event_QueueFunctionToThread( sharedDataPtr->atServerThread,
                                    StartBridge,
                                    (void*) &bridgeRef,
                                    (void*) sharedDataPtr->devRef);

    le_sem_Wait(BridgeSemaphore);

    ret = SendCommandsAndTest(socketFd, epollFd, AtPlusCpinRead,
                "\r\n+CPIN: READY\r\n"
                "\r\nOK\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    ret = SendCommandsAndTest(socketFd, epollFd, AtPlusCgdcontPara,
                "\r\nOK\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    ret = SendCommandsAndTest(socketFd, epollFd, AtPlusBad,
                "\r\nERROR\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    ret = SendCommandsAndTest(socketFd, epollFd, AtPlusUnknown,
                "\r\nERROR\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    ret = SendCommandsAndTest(socketFd, epollFd, ConcatCpinReadCgdcontRead,
                "\r\n+CPIN: READY\r\n"
                "\r\n+CGDCONT: 1,\"IP\",\"orange\"\r\n"
                "+CGDCONT: 2,\"IP\",\"bouygues\"\r\n"
                "+CGDCONT: 3,\"IP\",\"sfr\"\r\n"
                "\r\nOK\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    ret = SendCommandsAndTest(socketFd, epollFd, ConcatQ1CpinReadAbcdReadCgdcontTest,
                "\r\nQ1\r\n"
                "\r\n+CPIN: READY\r\n"
                "\r\n+ABCD TYPE: READ\r\n"
                "\r\n+CGDCONT: (1-16),\"IP\",,,(0-2),(0-4)\r\n"
                "+CGDCONT: (1-16),\"PPP\",,,(0-2),(0-4)\r\n"
                "+CGDCONT: (1-16),\"IPV6\",,,(0-2),(0-4)\r\n"
                "+CGDCONT: (1-16),\"IPV4V6\",,,(0-2),(0-4)\r\n"
                "\r\nOK\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    // Test unsolicited handler
    LE_ASSERT(UnsolHandler != NULL);
    UnsolHandler( "+CREG: 1", UnsolHandlerContextPtr);
    ret = TestResponses(socketFd, epollFd, "\r\n+CREG: 1\r\n");

    if (ret != LE_OK)
    {
        return ret;
    }

    LE_ASSERT_OK(le_atServer_RemoveDeviceFromBridge(sharedDataPtr->devRef, bridgeRef));

    LE_ASSERT_OK(le_atServer_CloseBridge(bridgeRef));

    LE_INFO("======== AT server bridge API test success ========");

    return ret;
}