Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
main.c File Reference
#include <ztest.h>
#include <kernel_structs.h>
#include <arch/cpu.h>
#include <irq_offload.h>
#include <sys_clock.h>
#include <soc.h>

Data Structures

struct  ISR_INFO
 
struct  timeout_order
 

Macros

#define THREAD_STACKSIZE   (512 + CONFIG_TEST_EXTRA_STACKSIZE)
 
#define THREAD_STACKSIZE2   (384 + CONFIG_TEST_EXTRA_STACKSIZE)
 
#define THREAD_PRIORITY   4
 
#define THREAD_SELF_CMD   0
 
#define EXEC_CTX_TYPE_CMD   1
 
#define UNKNOWN_COMMAND   -1
 
#define HAS_POWERSAVE_INSTRUCTION
 
#define NUM_TIMEOUT_THREADS   ARRAY_SIZE(timeouts)
 

Typedefs

typedef int(* disable_int_func) (int)
 
typedef void(* enable_int_func) (int)
 

Functions

static K_THREAD_STACK_DEFINE (thread_stack1,(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
static K_THREAD_STACK_DEFINE (thread_stack2,(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
static K_THREAD_STACK_DEFINE (thread_stack3,(512+CONFIG_TEST_EXTRA_STACKSIZE))
 
static void test_kernel_cpu_idle (void)
 Test cpu idle function. More...
 
static void test_kernel_cpu_idle_atomic (void)
 Test cpu idle function. More...
 
static void isr_handler (const void *data)
 Handler to perform various actions from within an ISR context. More...
 
static void isr_handler_trigger (void)
 
static void kernel_init_objects (void)
 Initialize kernel objects. More...
 
int irq_lock_wrapper (int unused)
 A wrapper for irq_lock() More...
 
void irq_unlock_wrapper (int imask)
 A wrapper for irq_unlock() More...
 
int irq_disable_wrapper (int irq)
 A wrapper for irq_disable() More...
 
void irq_enable_wrapper (int irq)
 A wrapper for irq_enable() More...
 
static void test_kernel_interrupts (void)
 Test routines for disabling and enabling interrupts. More...
 
static void test_kernel_timer_interrupts (void)
 Test routines for disabling and enabling interrupts (disable timer) More...
 
static void test_kernel_ctx_thread (void)
 Test some context routines. More...
 
static void thread_helper (void *arg1, void *arg2, void *arg3)
 Entry point to the thread's helper. More...
 
static void k_yield_entry (void *arg0, void *arg1, void *arg2)
 Entry point to thread started by another thread. More...
 
static void kernel_thread_entry (void *_thread_id, void *arg1, void *arg2)
 
static K_THREAD_STACK_ARRAY_DEFINE (timeout_stacks, ARRAY_SIZE(timeouts),(384+CONFIG_TEST_EXTRA_STACKSIZE))
 
static void busy_wait_thread (void *mseconds, void *arg2, void *arg3)
 
static void thread_sleep (void *delta, void *arg2, void *arg3)
 
static void delayed_thread (void *num, void *arg2, void *arg3)
 
static void test_busy_wait (void)
 Test timouts. More...
 
static void test_k_sleep (void)
 Test timouts. More...
 
void test_k_yield (void)
 Test the k_yield() routine. More...
 
void test_kernel_thread (void)
 Test kernel thread creation. More...
 
void test_main (void)
 

Variables

static struct k_sem sem_thread
 
static struct k_timer timer
 
static struct k_sem reply_timeout
 
struct k_fifo timeout_order_fifo
 
static int thread_evidence
 
static struct k_thread thread_data1
 
static struct k_thread thread_data2
 
static struct k_thread thread_data3
 
static ISR_INFO isr_info
 
struct timeout_order timeouts []
 
static struct k_thread timeout_threads [ARRAY_SIZE(timeouts)]
 

Macro Definition Documentation

◆ EXEC_CTX_TYPE_CMD

#define EXEC_CTX_TYPE_CMD   1

◆ HAS_POWERSAVE_INSTRUCTION

#define HAS_POWERSAVE_INSTRUCTION

◆ NUM_TIMEOUT_THREADS

#define NUM_TIMEOUT_THREADS   ARRAY_SIZE(timeouts)

◆ THREAD_PRIORITY

#define THREAD_PRIORITY   4

◆ THREAD_SELF_CMD

#define THREAD_SELF_CMD   0

◆ THREAD_STACKSIZE

#define THREAD_STACKSIZE   (512 + CONFIG_TEST_EXTRA_STACKSIZE)

◆ THREAD_STACKSIZE2

#define THREAD_STACKSIZE2   (384 + CONFIG_TEST_EXTRA_STACKSIZE)

◆ UNKNOWN_COMMAND

#define UNKNOWN_COMMAND   -1

Typedef Documentation

◆ disable_int_func

typedef int(* disable_int_func) (int)

◆ enable_int_func

typedef void(* enable_int_func) (int)

Function Documentation

◆ busy_wait_thread()

static void busy_wait_thread ( void mseconds,
void arg2,
void arg3 
)
static

◆ delayed_thread()

static void delayed_thread ( void num,
void arg2,
void arg3 
)
static

◆ irq_disable_wrapper()

int irq_disable_wrapper ( int  irq)

A wrapper for irq_disable()

Returns
irq

◆ irq_enable_wrapper()

void irq_enable_wrapper ( int  irq)

A wrapper for irq_enable()

Returns
N/A

◆ irq_lock_wrapper()

int irq_lock_wrapper ( int  unused)

A wrapper for irq_lock()

Returns
irq_lock() return value

◆ irq_unlock_wrapper()

void irq_unlock_wrapper ( int  imask)

A wrapper for irq_unlock()

Returns
N/A

◆ isr_handler()

static void isr_handler ( const void data)
static

Handler to perform various actions from within an ISR context.

This routine is the ISR handler for isr_handler_trigger(). It performs the command requested in <isr_info.command>.

Returns
N/A

◆ isr_handler_trigger()

static void isr_handler_trigger ( void  )
static

◆ K_THREAD_STACK_ARRAY_DEFINE()

static K_THREAD_STACK_ARRAY_DEFINE ( timeout_stacks  ,
ARRAY_SIZE(timeouts ,
(384+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ K_THREAD_STACK_DEFINE() [1/3]

static K_THREAD_STACK_DEFINE ( thread_stack1  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ K_THREAD_STACK_DEFINE() [2/3]

static K_THREAD_STACK_DEFINE ( thread_stack2  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ K_THREAD_STACK_DEFINE() [3/3]

static K_THREAD_STACK_DEFINE ( thread_stack3  ,
(512+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ k_yield_entry()

static void k_yield_entry ( void arg0,
void arg1,
void arg2 
)
static

Entry point to thread started by another thread.

This routine is the entry point to the thread started by the thread.

◆ kernel_init_objects()

static void kernel_init_objects ( void  )
static

Initialize kernel objects.

This routine initializes the kernel objects used in this module's tests.

◆ kernel_thread_entry()

static void kernel_thread_entry ( void _thread_id,
void arg1,
void arg2 
)
static

◆ test_busy_wait()

static void test_busy_wait ( void  )
static

Test timouts.

See also
k_busy_wait(), k_sleep()

◆ test_k_sleep()

static void test_k_sleep ( void  )
static

Test timouts.

See also
k_sleep()

◆ test_k_yield()

void test_k_yield ( void  )

Test the k_yield() routine.

Tests the k_yield() routine. It starts another thread (thus also testing k_thread_create()) and checks that behavior of k_yield() against the a higher priority thread, a lower priority thread, and another thread of equal priority.

See also
k_yield()

◆ test_kernel_cpu_idle()

static void test_kernel_cpu_idle ( void  )
static

Test cpu idle function.

Test Objectve:

  • The kernel architecture provide an idle function to be run when the system has no work for the current CPU
  • This routine tests the k_cpu_idle() routine

Testing techniques

  • Functional and black box testing
  • Interface testing

Prerequisite Condition:

  • HAS_POWERSAVE_INSTRUCTION is set

Input Specifications:

  • N/A

Test Procedure:

  1. Record system time before cpu enters idle state
  2. Enter cpu idle state by k_cpu_idle()
  3. Record system time after cpu idle state is interrupted
  4. Compare the two system time values.

Expected Test Result:

  • cpu enters idle state for a given time

Pass/Fail criteria:

  • Success if the cpu enters idle state, failure otherwise.

Assumptions and Constraints

  • N/A
See also
k_cpu_idle()

◆ test_kernel_cpu_idle_atomic()

static void test_kernel_cpu_idle_atomic ( void  )
static

Test cpu idle function.

Test the k_cpu_idle() routine.

Test Objectve:

  • The kernel architecture provide an idle function to be run when the system has no work for the current CPU
  • This routine tests the k_cpu_atomic_idle() routine

Testing techniques

  • Functional and black box testing
  • Interface testing

Prerequisite Condition:

  • HAS_POWERSAVE_INSTRUCTION is set

Input Specifications:

  • N/A

Test Procedure:

  1. Record system time befor cpu enters idle state
  2. Enter cpu idle state by k_cpu_atomic_idle()
  3. Record system time after cpu idle state is interrupted
  4. Compare the two system time values.

Expected Test Result:

  • cpu enters idle state for a given time

Pass/Fail criteria:

  • Success if the cpu enters idle state, failure otherwise.

Assumptions and Constraints

  • N/A
See also
k_cpu_atomic_idle()

This tests the k_cpu_idle() routine. The first thing it does is align to a tick boundary. The only source of interrupts while the test is running is expected to be the tick clock timer which should wake the CPU. Thus after each call to k_cpu_idle(), the tick count should be one higher.

See also
k_cpu_idle()

◆ test_kernel_ctx_thread()

static void test_kernel_ctx_thread ( void  )
static

Test some context routines.

Test Objectve:

  • Thread context handles derived from context switches must be able to be restored upon interrupt exit

Testing techniques

  • Functional and black box testing
  • Interface testing

Prerequisite Condition:

  • N/A

Input Specifications:

  • N/A

Test Procedure:

  1. Set priority of current thread to 0 as a preemptible thread
  2. Trap to interrupt context, get thread id of the interrupted thread and pass back to that thread.
  3. Return to thread context and make sure this context is interrupted by comparing its thread ID and the thread ID passed by isr.
  4. Pass command to isr to check whether the isr is executed in interrupt context
  5. When return to thread context, check the return value of command.

Expected Test Result:

  • Thread context restored upon interrupt exit

Pass/Fail criteria:

  • Success if context of thread restored correctly, failure otherwise.

Assumptions and Constraints

  • N/A
See also
k_current_get(), k_is_in_isr()

◆ test_kernel_interrupts()

static void test_kernel_interrupts ( void  )
static

Test routines for disabling and enabling interrupts.

Test Objective:

  • To verify kernel architecture layer shall provide a mechanism to selectively disable and enable specific numeric interrupts.
  • This routine tests the routines for disabling and enabling interrupts. These include irq_lock() and irq_unlock().

Testing techniques:

  • Interface testing, function and black box testing, dynamic analysis and testing

Prerequisite Conditions:

  • CONFIG_TICKLESS_KERNEL is not set.

Input Specifications:

  • N/A

Test Procedure:

  1. Do action to align to a tick boundary.
  2. Left shift 4 bits for the value of counts.
  3. Call irq_lock() and restore its return value to imask.
  4. Call sys_clock_tick_get_32() and store its return value to tick.
  5. Repeat counts of calling sys_clock_tick_get_32().
  6. Call sys_clock_tick_get_32() and store its return value to tick2.
  7. Call irq_unlock() with parameter imask.
  8. Check if tick is equal to tick2.
  9. Repeat counts of calling sys_clock_tick_get_32().
  10. Call sys_clock_tick_get_32() and store its return value to tick2.
  11. Check if tick is NOT equal to tick2.

Expected Test Result:

  • The ticks shall not increase while interrupt locked.

Pass/Fail Criteria:

  • Successful if check points in test procedure are all passed, otherwise failure.

Assumptions and Constraints:

  • N/A
See also
irq_lock(), irq_unlock()

◆ test_kernel_thread()

void test_kernel_thread ( void  )

Test kernel thread creation.

See also
k_thread_create

◆ test_kernel_timer_interrupts()

static void test_kernel_timer_interrupts ( void  )
static

Test routines for disabling and enabling interrupts (disable timer)

Test Objective:

  • To verify the kernel architecture layer shall provide a mechanism to simultenously mask all local CPU interrupts and return the previous mask state for restoration.
  • This routine tests the routines for disabling and enabling interrupts. These include irq_disable() and irq_enable().

Testing techniques:

  • Interface testing, function and black box testing, dynamic analysis and testing

Prerequisite Conditions:

  • TICK_IRQ is defined.

Input Specifications:

  • N/A

Test Procedure:

  1. Do action to align to a tick boundary.
  2. Left shift 4 bit for the value of counts.
  3. Call irq_disable() and restore its return value to imask.
  4. Call sys_clock_tick_get_32() and store its return value to tick.
  5. Repeat counts of calling sys_clock_tick_get_32().
  6. Call sys_clock_tick_get_32() and store its return value to tick2.
  7. Call irq_enable() with parameter imask.
  8. Check if tick is equal to tick2.
  9. Repeat counts of calling sys_clock_tick_get_32().
  10. Call sys_clock_tick_get_32() and store its return value to tick2.
  11. Check if tick is NOT equal to tick2.

Expected Test Result:

  • The ticks shall not increase while interrupt locked.

Pass/Fail Criteria:

  • Successful if check points in test procedure are all passed, otherwise failure.

Assumptions and Constraints:

  • Note that this test works by disabling the timer interrupt directly, without any interaction with the timer driver or timeout subsystem. NOT ALL ARCHITECTURES will latch and deliver a timer interrupt that arrives while the interrupt is disabled, which means that the timeout list will become corrupted (because it contains items that should have expired in the past). Any use of kernel timeouts after completion of this test is disallowed. RUN THIS TEST LAST IN THE SUITE.
See also
irq_disable(), irq_enable()

◆ test_main()

void test_main ( void  )

◆ thread_helper()

static void thread_helper ( void arg1,
void arg2,
void arg3 
)
static

Entry point to the thread's helper.

This routine is the entry point to the thread's helper thread. It is used to help test the behavior of the k_yield() routine.

Parameters
arg1unused
arg2unused
arg3unused
Returns
N/A

◆ thread_sleep()

static void thread_sleep ( void delta,
void arg2,
void arg3 
)
static

Variable Documentation

◆ isr_info

ISR_INFO isr_info
static

◆ reply_timeout

struct k_sem reply_timeout
static

◆ sem_thread

struct k_sem sem_thread
static

◆ thread_data1

struct k_thread thread_data1
static

◆ thread_data2

struct k_thread thread_data2
static

◆ thread_data3

struct k_thread thread_data3
static

◆ thread_evidence

int thread_evidence
static

◆ timeout_order_fifo

struct k_fifo timeout_order_fifo

◆ timeout_threads

struct k_thread timeout_threads[ARRAY_SIZE(timeouts)]
static

◆ timeouts

struct timeout_order timeouts[]
Initial value:
= {
{ 0, 1000, 2, 0 },
{ 0, 1500, 4, 1 },
{ 0, 500, 0, 2 },
{ 0, 750, 1, 3 },
{ 0, 1750, 5, 4 },
{ 0, 2000, 6, 5 },
{ 0, 1250, 3, 6 },
}

◆ timer

struct k_timer timer
static