Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
main.c File Reference

Offload to the Kernel workqueue. More...

#include <zephyr.h>
#include <linker/sections.h>
#include <ztest.h>

Macros

#define NUM_MILLISECONDS   50
 
#define TEST_TIMEOUT   200
 
#define OFFLOAD_WORKQUEUE_STACK_SIZE   1024
 
#define STACK_SIZE   (1024 + CONFIG_TEST_EXTRA_STACKSIZE)
 

Functions

static K_THREAD_STACK_DEFINE (offload_work_q_stack, 1024)
 
static K_THREAD_STACK_DEFINE (stack1,(1024+CONFIG_TEST_EXTRA_STACKSIZE))
 
static K_THREAD_STACK_DEFINE (stack2,(1024+CONFIG_TEST_EXTRA_STACKSIZE))
 
 K_SEM_DEFINE (ALT_SEM, 0, UINT_MAX)
 
 K_SEM_DEFINE (REGRESS_SEM, 0, UINT_MAX)
 
 K_SEM_DEFINE (TEST_SEM, 0, UINT_MAX)
 
void critical_rtn (struct k_work *unused)
 Routine to be called from a workqueue. More...
 
uint32_t critical_loop (const char *tag, uint32_t count)
 Common code for invoking work. More...
 
void alternate_thread (void *arg1, void *arg2, void *arg3)
 Alternate thread. More...
 
void regression_thread (void *arg1, void *arg2, void *arg3)
 Regression thread. More...
 
void test_offload_workqueue (void)
 Verify thread context. More...
 
void test_main (void)
 

Variables

static uint32_t critical_var
 
static uint32_t alt_thread_iterations
 
static struct k_work_q offload_work_q
 
static struct k_thread thread1
 
static struct k_thread thread2
 

Detailed Description

Offload to the Kernel workqueue.

This test verifies that the kernel workqueue operates as expected.

This test has two threads that increment a counter. The routine that increments the counter is invoked from workqueue due to the two threads calling using it. The final result of the counter is expected to be the the number of times work item was called to increment the counter.

This is done with time slicing both disabled and enabled to ensure that the result always matches the number of times the workqueue is called.

Macro Definition Documentation

◆ NUM_MILLISECONDS

#define NUM_MILLISECONDS   50

◆ OFFLOAD_WORKQUEUE_STACK_SIZE

#define OFFLOAD_WORKQUEUE_STACK_SIZE   1024

◆ STACK_SIZE

#define STACK_SIZE   (1024 + CONFIG_TEST_EXTRA_STACKSIZE)

◆ TEST_TIMEOUT

#define TEST_TIMEOUT   200

Function Documentation

◆ alternate_thread()

void alternate_thread ( void arg1,
void arg2,
void arg3 
)

Alternate thread.

This routine invokes the workqueue many times.

◆ critical_loop()

uint32_t critical_loop ( const char *  tag,
uint32_t  count 
)

Common code for invoking work.

Parameters
tagtext identifying the invocation context
countnumber of critical section calls made thus far
Returns
number of critical section calls made by a thread

◆ critical_rtn()

void critical_rtn ( struct k_work unused)

Routine to be called from a workqueue.

This routine increments the global variable critical_var.

◆ K_SEM_DEFINE() [1/3]

K_SEM_DEFINE ( ALT_SEM  ,
,
UINT_MAX   
)

◆ K_SEM_DEFINE() [2/3]

K_SEM_DEFINE ( REGRESS_SEM  ,
,
UINT_MAX   
)

◆ K_SEM_DEFINE() [3/3]

K_SEM_DEFINE ( TEST_SEM  ,
,
UINT_MAX   
)

◆ K_THREAD_STACK_DEFINE() [1/3]

static K_THREAD_STACK_DEFINE ( offload_work_q_stack  ,
1024   
)
static

◆ K_THREAD_STACK_DEFINE() [2/3]

static K_THREAD_STACK_DEFINE ( stack1  ,
(1024+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ K_THREAD_STACK_DEFINE() [3/3]

static K_THREAD_STACK_DEFINE ( stack2  ,
(1024+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ regression_thread()

void regression_thread ( void arg1,
void arg2,
void arg3 
)

Regression thread.

This routine invokes the workqueue many times. It also checks to ensure that the number of times it is called matches the global variable critical_var.

◆ test_main()

void test_main ( void  )

test case main entry

Variable Documentation

◆ alt_thread_iterations

uint32_t alt_thread_iterations
static

◆ critical_var

uint32_t critical_var
static

◆ offload_work_q

struct k_work_q offload_work_q
static

◆ thread1

struct k_thread thread1
static

◆ thread2

struct k_thread thread2
static