Zephyr Project API 3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
test_thread_runtime_stats.c File Reference
#include <zephyr/ztest.h>

Macros

#define HELPER_STACK_SIZE   500
 
#define TEST_WITHIN_X_PERCENT(val1, val2, pcnt)
 Verify va1 and val2 are within pcnt % of each other.
 
#define IDLE_EVENT_STATS_PRECISION   1
 

Functions

static K_THREAD_STACK_DEFINE (helper_stack, 500)
 
void helper1 (void *p1, void *p2, void *p3)
 Helper thread to test_thread_runtime_stats_get()
 
void busy_loop (uint32_t ticks)
 Busy wait for specified number of ticks.
 
 ZTEST (usage_api, test_all_stats_usage)
 Test the k_threads_runtime_stats_all_get() API.
 
 ZTEST (usage_api, test_thread_stats_enable_disable)
 
 ZTEST (usage_api, test_sys_stats_enable_disable)
 
void resume_main (struct k_timer *timer)
 Timer handler to resume the main thread.
 
 ZTEST (usage_api, test_thread_stats_usage)
 Test the k_thread_runtime_stats_get() API.
 
 ZTEST_SUITE (usage_api, NULL, NULL, ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL)
 

Variables

static struct k_thread helper_thread
 
static struct k_threadmain_thread
 

Macro Definition Documentation

◆ HELPER_STACK_SIZE

#define HELPER_STACK_SIZE   500

◆ IDLE_EVENT_STATS_PRECISION

#define IDLE_EVENT_STATS_PRECISION   1

◆ TEST_WITHIN_X_PERCENT

#define TEST_WITHIN_X_PERCENT (   val1,
  val2,
  pcnt 
)
Value:
((((val1) * 100) < ((val2) * (100 + (pcnt)))) && \
(((val1) * 100) > ((val2) * (100 - (pcnt))))) ? true : false
#define false
Definition stdbool.h:15

Verify va1 and val2 are within pcnt % of each other.

Function Documentation

◆ busy_loop()

void busy_loop ( uint32_t  ticks)

Busy wait for specified number of ticks.

◆ helper1()

void helper1 ( void *  p1,
void *  p2,
void *  p3 
)

Helper thread to test_thread_runtime_stats_get()

◆ K_THREAD_STACK_DEFINE()

static K_THREAD_STACK_DEFINE ( helper_stack  ,
500   
)
static

◆ resume_main()

void resume_main ( struct k_timer *  timer)

Timer handler to resume the main thread.

◆ ZTEST() [1/4]

ZTEST ( usage_api  ,
test_all_stats_usage   
)

Test the k_threads_runtime_stats_all_get() API.

  1. Create a helper thread.
  2. Busy loop for 2 ticks.
    • Idle time should not increase.
  3. Sleep for two ticks. Helper executes and busy loops.
    • Idle time should not increase
  4. Kill helper thread, and sleep for 2 ticks
    • Idle time should increase
  5. Busy loop for 3 ticks
    • Idle time should not increase
    • current, peak and average cycles should be different

◆ ZTEST() [2/4]

ZTEST ( usage_api  ,
test_sys_stats_enable_disable   
)

◆ ZTEST() [3/4]

ZTEST ( usage_api  ,
test_thread_stats_enable_disable   
)

◆ ZTEST() [4/4]

ZTEST ( usage_api  ,
test_thread_stats_usage   
)

Test the k_thread_runtime_stats_get() API.

This routine tests the k_thread_runtime_stats_get() routine. It verifies that the contents of the fields guarded by CONFIG_SCHED_THREAD_USAGE are correct.

◆ ZTEST_SUITE()

ZTEST_SUITE ( usage_api  ,
NULL  ,
NULL  ,
ztest_simple_1cpu_before  ,
ztest_simple_1cpu_after  ,
NULL   
)

Variable Documentation

◆ helper_thread

struct k_thread helper_thread ( void  )
static

◆ main_thread

struct k_thread* main_thread
static