Test Specification for ChibiOS/NIL. Test suite for ChibiOS/NIL. The purpose of this suite is to perform unit tests on the NIL modules and to converge to 100% code coverage through successive improvements. Internal Tests Threads Functionality. This sequence tests the ChibiOS/NIL functionalities related to threading. System Tick Counter functionality. The functionality of the API @p chVTGetSystemTimeX() is tested. A System Tick Counter increment is expected, the test simply hangs if it does not happen. Thread Sleep functionality. The functionality of @p chThdSleep() and derivatives is tested. The current system time is read then a sleep is performed for 100 system ticks and on exit the system time is verified again. The current system time is read then a sleep is performed for 100000 microseconds and on exit the system time is verified again. The current system time is read then a sleep is performed for 100 milliseconds and on exit the system time is verified again. The current system time is read then a sleep is performed for 1 second and on exit the system time is verified again. Function chThdSleepUntil() is tested with a timeline of "now" + 100 ticks. Internal Tests Semaphores. This sequence tests the ChibiOS/NIL functionalities related to counter semaphores. CH_CFG_USE_SEMAPHORES Semaphore primitives, no state change. Wait, Signal and Reset primitives are tested. The testing thread does not trigger a state change. The function chSemWait() is invoked, after return the counter and the returned message are tested. The function chSemSignal() is invoked, after return the counter is tested. The function chSemReset() is invoked, after return the counter is tested. Semaphore primitives, with state change. Wait, Signal and Reset primitives are tested. The testing thread triggers a state change. The function chSemWait() is invoked, after return the counter and the returned message are tested. The semaphore is signaled by another thread. The function chSemWait() is invoked, after return the counter and the returned message are tested. The semaphore is reset by another thread. Semaphores timeout. Timeout on semaphores is tested. The function chSemWaitTimeout() is invoked a first time, after return the system time, the counter and the returned message are tested. The function chSemWaitTimeout() is invoked again, after return the system time, the counter and the returned message are tested. Internal Tests Suspend/Resume and Event Flags. This sequence tests the ChibiOS/NIL functionalities related to threads suspend/resume and event flags. Suspend and Resume functionality. The functionality of chThdSuspendTimeoutS() and chThdResumeI() is tested. The function chThdSuspendTimeoutS() is invoked, the thread is remotely resumed with message @p MSG_OK. On return the message and the state of the reference are tested. The function chThdSuspendTimeoutS() is invoked, the thread is not resumed so a timeout must occur. On return the message and the state of the reference are tested. Events Flags functionality. Event flags functionality is tested. CH_CFG_USE_EVENTS A set of event flags are set on the current thread then the function chEvtWaitAnyTimeout() is invoked, the function is supposed to return immediately because the event flags are already pending, after return the events mask is tested. The pending event flags mask is cleared then the function chEvtWaitAnyTimeout() is invoked, after return the events mask is tested. The thread is signaled by another thread. epmask = 0; events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000)); test_assert((eventmask_t)0 != events, "timed out"); test_assert((eventmask_t)0x55 == events, "wrong events mask");]]> The function chEvtWaitAnyTimeout() is invoked, no event can wakeup the thread, the function must return because timeout. Internal Tests Mailboxes. This sequence tests the ChibiOS/NIL functionalities related to mailboxes. CH_CFG_USE_MAILBOXES Mailbox normal API, non-blocking tests. The mailbox normal API is tested without triggering blocking conditions. Testing the mailbox size. Resetting the mailbox, conditions are checked, no errors expected. Testing the behavior of API when the mailbox is in reset state then return in active state. Filling the mailbox using chMBPost() and chMBPostAhead() once, no errors expected. Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked. Emptying the mailbox using chMBFetch(), no errors expected. Posting and then fetching one more message, no errors expected. Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked. Mailbox I-Class API, non-blocking tests. The mailbox I-Class API is tested without triggering blocking conditions. Testing the mailbox size. Resetting the mailbox, conditions are checked, no errors expected. Filling the mailbox using chMBPostI() and chMBPostAheadI() once, no errors expected. Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked. Emptying the mailbox using chMBFetchI(), no errors expected. Posting and then fetching one more message, no errors expected. Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked. Mailbox timeouts. The mailbox API is tested for timeouts. Filling the mailbox. Testing chMBPost(), chMBPostI(), chMBPostAhead() and chMBPostAheadI() timeout. Resetting the mailbox. Testing chMBFetch() and chMBFetchI() timeout. Internal Tests Memory Pools. This sequence tests the ChibiOS/NIL functionalities related to memory pools. CH_CFG_USE_MEMPOOLS Loading and emptying a memory pool. The memory pool functionality is tested by loading and emptying it, all conditions are tested. Adding the objects to the pool using chPoolLoadArray(). Emptying the pool using chPoolAlloc(). Now must be empty. Adding the objects to the pool using chPoolFree(). Emptying the pool using chPoolAlloc() again. Now must be empty again. Covering the case where a provider is unable to return more memory. Loading and emptying a guarded memory pool without waiting. The memory pool functionality is tested by loading and emptying it, all conditions are tested. CH_CFG_USE_SEMAPHORES Adding the objects to the pool using chGuardedPoolLoadArray(). Emptying the pool using chGuardedPoolAllocTimeout(). Now must be empty. Adding the objects to the pool using chGuardedPoolFree(). Emptying the pool using chGuardedPoolAllocTimeout() again. Now must be empty again. Guarded Memory Pools timeout. The timeout features for the Guarded Memory Pools is tested. CH_CFG_USE_SEMAPHORES Trying to allocate with 100mS timeout, must fail because the pool is empty. Internal Tests Memory Heaps. This sequence tests the ChibiOS/NIL functionalities related to memory heaps. CH_CFG_USE_HEAP Allocation and fragmentation. Series of allocations/deallocations are performed in carefully designed sequences in order to stimulate all the possible code paths inside the allocator. The test expects to find the heap back to the initial status after each sequence. Testing initial conditions, the heap must not be fragmented and one free block present. Trying to allocate an block bigger than available space, an error is expected. Single block allocation using chHeapAlloc() then the block is freed using chHeapFree(), must not fail. Using chHeapStatus() to assess the heap state. There must be at least one free block of sufficient size. = ALLOC_SIZE, "unexpected heap state"); test_assert(total_size == largest_size, "unexpected heap state");]]> Allocating then freeing in the same order. Allocating then freeing in reverse order. Small fragments handling. Checking the behavior when allocating blocks with size not multiple of alignment unit. Skipping a fragment, the first fragment in the list is too small so the allocator must pick the second one. Allocating the whole available space. Testing final conditions. The heap geometry must be the same than the one registered at beginning. Default Heap. The default heap is pre-allocated in the system. We test base functionality. Single block allocation using chHeapAlloc() then the block is freed using chHeapFree(), must not fail. Testing allocation failure.