distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp} Namespace Reference

Functions

bool testPost (Semaphore &semaphore)
 Tests Semaphore::post() - it must succeed immediately. More...
 
bool testTryWaitWhenLocked (Semaphore &semaphore)
 Tests Semaphore::tryWait() when semaphore is locked - it must fail immediately and return EAGAIN. More...
 
bool phase1 ()
 Phase 1 of test case. More...
 
bool phase2 ()
 Phase 2 of test case. More...
 
bool phase3 ()
 Phase 3 of test case. More...
 
bool phase4 ()
 Phase 4 of test case. More...
 
bool phase5 ()
 Phase 5 of test case. More...
 

Variables

constexpr auto singleDuration = TickClock::duration{1}
 single duration used in tests More...
 
constexpr auto longDuration = singleDuration * 10
 long duration used in tests More...
 
decltype(statistics::getContextSwitchCount()) constexpr waitForNextTickContextSwitchCount {2}
 expected number of context switches in waitForNextTick(): main -> idle -> main More...
 
decltype(statistics::getContextSwitchCount()) constexpr phase1TryWaitForUntilContextSwitchCount {2}
 
decltype(statistics::getContextSwitchCount()) constexpr phase3ThreadContextSwitchCount {5}
 
decltype(statistics::getContextSwitchCount()) constexpr phase4SoftwareTimerContextSwitchCount {2}
 

Function Documentation

◆ phase1()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase1 ( )

Phase 1 of test case.

Tests whether all tryWait*() functions properly return some error when dealing with locked semaphore.

Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ phase2()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase2 ( )

Phase 2 of test case.

Tests whether all tryWait*() functions properly lock unlocked semaphore.

Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ phase3()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase3 ( )

Phase 3 of test case.

Tests thread-thread signaling scenario. Main (current) thread waits for a locked semaphore to become available. Test thread posts the semaphore at specified time point, main thread is expected to acquire ownership of this semaphore (with wait(), tryWaitFor() and tryWaitUntil()) in the same moment.

Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ phase4()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase4 ( )

Phase 4 of test case.

Tests interrupt-thread signaling scenario. Main (current) thread waits for a locked semaphore to become available. Software timer is used to posts the semaphore at specified time point from interrupt context, main thread is expected to acquire ownership of this semaphore (with wait(), tryWaitFor() and tryWaitUntil()) in the same moment.

Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ phase5()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase5 ( )

Phase 5 of test case.

Tests correction of invalid initialization and overflow detection of semaphore with explicit max value. Semaphore's initial value cannot be higher than given max value - value must be truncated in the constructor. Semaphore's value must never be higher than the max value - any call to Semaphore::post() after the value reached max value must result in EOVERFLOW error.

Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ testPost()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::testPost ( Semaphore semaphore)

Tests Semaphore::post() - it must succeed immediately.

Parameters
[in]semaphoreis a reference to semaphore that will be posted
Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ testTryWaitWhenLocked()

bool distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::testTryWaitWhenLocked ( Semaphore semaphore)

Tests Semaphore::tryWait() when semaphore is locked - it must fail immediately and return EAGAIN.

Parameters
[in]semaphoreis a reference to semaphore that will be tested
Returns
true if test succeeded, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ longDuration

constexpr auto distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::longDuration = singleDuration * 10

long duration used in tests

◆ phase1TryWaitForUntilContextSwitchCount

decltype(statistics::getContextSwitchCount()) constexpr distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase1TryWaitForUntilContextSwitchCount {2}

expected number of context switches in phase1 block involving tryWaitFor() or tryWaitUntil() (excluding waitForNextTick()): 1 - main thread blocks on semaphore (main -> idle), 2 - main thread wakes up (idle -> main)

◆ phase3ThreadContextSwitchCount

decltype(statistics::getContextSwitchCount()) constexpr distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase3ThreadContextSwitchCount {5}

expected number of context switches in phase3 block involving test thread (excluding waitForNextTick()): 1 - test thread starts (main -> test), 2 - test thread goes to sleep (test -> main), 3 - main thread blocks on semaphore (main -> idle), 4 - test thread wakes (idle -> test), 5 - test thread terminates (test -> main)

◆ phase4SoftwareTimerContextSwitchCount

decltype(statistics::getContextSwitchCount()) constexpr distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::phase4SoftwareTimerContextSwitchCount {2}

expected number of context switches in phase4 block involving software timer (excluding waitForNextTick()): 1 - main thread blocks on semaphore (main -> idle), 2 - main thread is unblocked by interrupt (idle -> main)

◆ singleDuration

constexpr auto distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::singleDuration = TickClock::duration{1}

single duration used in tests

◆ waitForNextTickContextSwitchCount

decltype(statistics::getContextSwitchCount()) constexpr distortos::test::anonymous_namespace{SemaphoreOperationsTestCase.cpp}::waitForNextTickContextSwitchCount {2}

expected number of context switches in waitForNextTick(): main -> idle -> main