Zephyr Project API 3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Timer

Tests for the Timer kernel object. More...

Functions

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

Detailed Description

Tests for the Timer kernel object.

Function Documentation

◆ ZTEST()

ZTEST ( timer_fn  ,
test_timer   
)

#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 correctness. 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()

◆ ZTEST_USER() [1/20]

ZTEST_USER ( timer_api  ,
test_timer_duration_period   
)

#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

◆ ZTEST_USER() [2/20]

ZTEST_USER ( timer_api  ,
test_timer_expirefn_null   
)

#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

◆ ZTEST_USER() [3/20]

ZTEST_USER ( timer_api  ,
test_timer_k_define   
)

#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

◆ ZTEST_USER() [4/20]

ZTEST_USER ( timer_api  ,
test_timer_period_0   
)

#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

◆ ZTEST_USER() [5/20]

ZTEST_USER ( timer_api  ,
test_timer_period_k_forever   
)

#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

◆ ZTEST_USER() [6/20]

ZTEST_USER ( timer_api  ,
test_timer_periodicity   
)

#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 period 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.

◆ ZTEST_USER() [7/20]

ZTEST_USER ( timer_api  ,
test_timer_remaining   
)

#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()

◆ ZTEST_USER() [8/20]

ZTEST_USER ( timer_api  ,
test_timer_restart   
)

#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

◆ ZTEST_USER() [9/20]

ZTEST_USER ( timer_api  ,
test_timer_status_get   
)

#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

◆ ZTEST_USER() [10/20]

ZTEST_USER ( timer_api  ,
test_timer_status_get_anytime   
)

#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

◆ ZTEST_USER() [11/20]

ZTEST_USER ( timer_api  ,
test_timer_status_sync   
)

#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

◆ ZTEST_USER() [12/20]

ZTEST_USER ( timer_api  ,
test_timer_user_data   
)

#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, along with 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()

◆ ZTEST_USER() [13/20]

ZTEST_USER ( timer_api_error  ,
test_timer_expires_ticks_null   
)

◆ ZTEST_USER() [14/20]

ZTEST_USER ( timer_api_error  ,
test_timer_remaining_ticks_null   
)

◆ ZTEST_USER() [15/20]

ZTEST_USER ( timer_api_error  ,
test_timer_start_null   
)

#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()

◆ ZTEST_USER() [16/20]

ZTEST_USER ( timer_api_error  ,
test_timer_status_get_null   
)

#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()

◆ ZTEST_USER() [17/20]

ZTEST_USER ( timer_api_error  ,
test_timer_status_sync_null   
)

◆ ZTEST_USER() [18/20]

ZTEST_USER ( timer_api_error  ,
test_timer_stop_null   
)

#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()

◆ ZTEST_USER() [19/20]

ZTEST_USER ( timer_api_error  ,
test_timer_user_data_get_null   
)

◆ ZTEST_USER() [20/20]

ZTEST_USER ( timer_api_error  ,
test_timer_user_data_set_null   
)