Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS

Tests for the Timer kernel object. More...

Functions

void test_timer_duration_period (void)
 Test duration and period of Timer. More...
 
void test_timer_restart (void)
 Test restart the timer. More...
 
void test_timer_period_0 (void)
 Test Timer with zero period value. More...
 
void test_timer_period_k_forever (void)
 Test Timer with K_FOREVER period value. More...
 
void test_timer_expirefn_null (void)
 Test Timer without any timer expiry callback function. More...
 
void test_timer_periodicity (void)
 Test to check timer periodicity. More...
 
void test_timer_status_get (void)
 Test Timer status and time remaining before next expiry. More...
 
void test_timer_status_get_anytime (void)
 Test Timer status randomly after certain duration. More...
 
void test_timer_status_sync (void)
 Test Timer thread synchronization. More...
 
void test_timer_k_define (void)
 Test statically defined Timer init. More...
 
void test_timer_user_data (void)
 Test user-specific data associated with timer. More...
 
void test_timer_remaining (void)
 Test accuracy of k_timer_remaining_get() More...
 
void test_timer_start_null (void)
 Test k_timer_start() API. More...
 
void test_timer_stop_null (void)
 Test k_timer_stop() API. More...
 
void test_timer_status_get_null (void)
 Test k_timer_status_get() API. More...
 
void test_timer_status_sync_null (void)
 Test k_timer_status_sync() API. More...
 
void test_timer_remaining_ticks_null (void)
 Test k_timer_remaining_ticks() API. More...
 
void test_timer_expires_ticks_null (void)
 Test k_timer_expires_ticks() API. More...
 
void test_timer_user_data_get_null (void)
 Test k_timer_user_data_get() API. More...
 
void test_timer_user_data_set_null (void)
 Test k_timer_user_data_set() API. More...
 
void test_timer (void)
 Test monotonic timer. More...
 

Detailed Description

Tests for the Timer kernel object.

Function Documentation

◆ test_timer()

void test_timer ( void  )

#include <tests/kernel/timer/timer_monotonic/src/main.c>

Test monotonic timer.

Validates monotonic timer's clock calibration.

It reads the System clock’s h/w timer frequency value continuously using k_cycle_get_32() to verify its working and correctiveness. It also checks system tick frequency by checking the delta error between generated and system clock provided HW cycles per sec values.

See also
k_cycle_get_32(), sys_clock_hw_cycles_per_sec()

◆ test_timer_duration_period()

void test_timer_duration_period ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test duration and period of Timer.

Validates initial duration and period of timer.

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() with specific initial duration and period. Stops the timer using k_timer_stop() and checks for proper completion of duration and period.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_uptime_get(), k_busy_wait()

TESTPOINT: init timer via k_timer_init

TESTPOINT: check expire and stop times

◆ test_timer_expirefn_null()

void test_timer_expirefn_null ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer without any timer expiry callback function.

Validates timer without any expiry_fn(set to NULL). expiry_fn() is a function that is invoked each time the timer expires.

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start(). Stops the timer using k_timer_stop() and checks for expire_cnt to zero, as expiry_fn was not defined at all.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_uptime_get(), k_busy_wait()

TESTPOINT: expire function NULL

TESTPOINT: expire handler is not invoked

TESTPOINT: stop handler is invoked

◆ test_timer_expires_ticks_null()

void test_timer_expires_ticks_null ( void  )

◆ test_timer_k_define()

void test_timer_k_define ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test statically defined Timer init.

Validate statically defined timer init using K_TIMER_DEFINE

It creates prototype of K_TIMER_DEFINE to statically define timer init and starts the timer with k_timer_start() with specific initial duration and period. Stops the timer using k_timer_stop() and checks for proper completion of duration and period.

See also
k_timer_start(), K_TIMER_DEFINE(), k_timer_stop() k_uptime_get(), k_busy_wait()

TESTPOINT: init timer via k_timer_init

TESTPOINT: check expire and stop times

TESTPOINT: init timer via k_timer_init

TESTPOINT: check expire and stop times

◆ test_timer_period_0()

void test_timer_period_0 ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer with zero period value.

Validates initial timer duration, keeping timer period to zero. Basically, acting as one-shot timer. It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() with specific initial duration and period as zero. Stops the timer using k_timer_stop() and checks for proper completion.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_uptime_get(), k_busy_wait()

TESTPOINT: set period 0

TESTPOINT: ensure it is one-shot timer

◆ test_timer_period_k_forever()

void test_timer_period_k_forever ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer with K_FOREVER period value.

Validates initial timer duration, keeping timer period to K_FOREVER. Basically, acting as one-shot timer. It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() with specific initial duration and period as zero. Stops the timer using k_timer_stop() and checks for proper completion.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_uptime_get(), k_busy_wait()

TESTPOINT: set period 0

TESTPOINT: ensure it is one-shot timer

◆ test_timer_periodicity()

void test_timer_periodicity ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test to check timer periodicity.

Timer test to check for the predictability with which the timer expires depending on the period configured.

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() with specific period. It resets the timer’s status to zero with k_timer_status_sync and identifies the delta between each timer expiry to check for the timer expiration period correctness. Finally, stops the timer using k_timer_stop().

See also
k_timer_init(), k_timer_start(), k_timer_status_sync(), k_timer_stop(), k_uptime_get(), k_uptime_delta()

TESTPOINT: set duration 0

TESTPOINT: expired times returned by status sync

TESTPOINT: check if timer fired within 1ms of the expected period (firing time).

Please note, that expected firing time is not the one requested, as the kernel uses the ticks to manage time. The actual perioid will be equal to [tick time] multiplied by k_ms_to_ticks_ceil32(PERIOD).

In the case of inexact conversion the delta will occasionally be one less than the expected number.

◆ test_timer_remaining()

void test_timer_remaining ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test accuracy of k_timer_remaining_get()

Validate countdown of time to expiration

Starts a timer, busy-waits for half the DURATION, then checks the remaining time to expiration and stops the timer. The remaining time should reflect the passage of at least the busy-wait interval.

See also
k_timer_init(), k_timer_start(), k_timer_stop(), k_timer_remaining_get()

◆ test_timer_remaining_ticks_null()

void test_timer_remaining_ticks_null ( void  )

◆ test_timer_restart()

void test_timer_restart ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test restart the timer.

Validates initial duration and period of timer. Start the timer with specific duration and period. Then starts the timer again, and check the status of timer.

See also
k_timer_init(), k_timer_start(), k_timer_stop, k_uptime_get(), k_busy_wait()

TESTPOINT: restart the timer

◆ test_timer_start_null()

void test_timer_start_null ( void  )

#include <tests/kernel/timer/timer_error_case/src/main.c>

Test k_timer_start() API.

Create a thread and set k_timer_start() input to NULL and set a duration and period.

See also
k_timer_start()

◆ test_timer_status_get()

void test_timer_status_get ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer status and time remaining before next expiry.

Timer test to validate timer status and next trigger expiry time

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() and checks for timer current status with k_timer_status_get() and remaining time before next expiry using k_timer_remaining_get(). Stops the timer using k_timer_stop().

See also
k_timer_init(), k_timer_start(), k_timer_status_get(), k_timer_remaining_get(), k_timer_stop()

TESTPOINT: status get upon timer starts

TESTPOINT: remaining get upon timer starts

◆ test_timer_status_get_anytime()

void test_timer_status_get_anytime ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer status randomly after certain duration.

Validate timer status function using k_timer_status_get().

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() with specific initial duration and period. Checks for timer status randomly after certain duration. Stops the timer using k_timer_stop().

See also
k_timer_init(), k_timer_start(), k_timer_status_get(), k_timer_stop(), k_busy_wait()

TESTPOINT: status get at any time

◆ test_timer_status_get_null()

void test_timer_status_get_null ( void  )

#include <tests/kernel/timer/timer_error_case/src/main.c>

Test k_timer_status_get() API.

Create a thread and set k_timer_status_get() input to NULL

See also
k_timer_status_get()

◆ test_timer_status_sync()

void test_timer_status_sync ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test Timer thread synchronization.

Validate thread synchronization by blocking the calling thread until the timer expires.

It initializes the timer with k_timer_init(), then starts the timer using k_timer_start() and checks timer status with k_timer_status_sync() for thread synchronization with expiry count. Stops the timer using k_timer_stop.

See also
k_timer_init(), k_timer_start(), k_timer_status_sync(), k_timer_stop()

TESTPOINT: check timer not expire

TESTPOINT: expired times returned by status sync

TESTPOINT: check timer not expire

◆ test_timer_status_sync_null()

void test_timer_status_sync_null ( void  )

◆ test_timer_stop_null()

void test_timer_stop_null ( void  )

#include <tests/kernel/timer/timer_error_case/src/main.c>

Test k_timer_stop() API.

Create a thread and set k_timer_stop() input to NULL

See also
k_timer_stop()

◆ test_timer_user_data()

void test_timer_user_data ( void  )

#include <tests/kernel/timer/timer_api/src/main.c>

Test user-specific data associated with timer.

Validate user-specific data associated with timer

It creates prototype of K_TIMER_DEFINE and starts the timer using k_timer_start() with specific initial duration, alongwith associated user data using k_timer_user_data_set and k_timer_user_data_get(). Stops the timer using k_timer_stop() and checks for correct data retrieval after timer completion.

See also
K_TIMER_DEFINE(), k_timer_user_data_set(), k_timer_start(), k_timer_user_data_get(), k_timer_stop()

◆ test_timer_user_data_get_null()

void test_timer_user_data_get_null ( void  )

◆ test_timer_user_data_set_null()

void test_timer_user_data_set_null ( void  )