Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
main.c File Reference
#include <zephyr.h>
#include <tc_util.h>
#include <ztest.h>
#include <kernel.h>
#include <ksched.h>
#include <kernel_structs.h>

Data Structures

struct  thread_info
 

Macros

#define T2_STACK_SIZE   (2048 + CONFIG_TEST_EXTRA_STACKSIZE)
 
#define STACK_SIZE   (384 + CONFIG_TEST_EXTRA_STACKSIZE)
 
#define DELAY_US   50000
 
#define TIMEOUT   1000
 
#define EQUAL_PRIORITY   1
 
#define TIME_SLICE_MS   500
 
#define THREAD_DELAY   1
 
#define THREADS_NUM   CONFIG_MP_NUM_CPUS
 
#define LOOP_COUNT   20000
 

Enumerations

enum  sync_t { LOCK_IRQ , LOCK_SEM , LOCK_MUTEX }
 

Functions

 K_THREAD_STACK_DEFINE (t2_stack,(2048+CONFIG_TEST_EXTRA_STACKSIZE))
 
 K_SEM_DEFINE (cpuid_sema, 0, 1)
 
 K_SEM_DEFINE (sema, 0, 1)
 
static K_THREAD_STACK_ARRAY_DEFINE (tstack, CONFIG_MP_NUM_CPUS,(384+CONFIG_TEST_EXTRA_STACKSIZE))
 
static int curr_cpu (void)
 
static void t2_fn (void *a, void *b, void *c)
 
void test_smp_coop_threads (void)
 Verify SMP with 2 cooperative threads. More...
 
static void child_fn (void *p1, void *p2, void *p3)
 
void test_cpu_id_threads (void)
 Verify CPU IDs of threads in SMP. More...
 
static void thread_entry (void *p1, void *p2, void *p3)
 
static void spin_for_threads_exit (void)
 
static void spawn_threads (int prio, int thread_num, int equal_prio, k_thread_entry_t thread_entry, int delay)
 
static void abort_threads (int num)
 
static void cleanup_resources (void)
 
void test_coop_resched_threads (void)
 Test cooperative threads non-preemption. More...
 
void test_preempt_resched_threads (void)
 Test preemptness of preemptive thread. More...
 
void test_yield_threads (void)
 Validate behavior of thread when it yields. More...
 
void test_sleep_threads (void)
 Test behavior of thread when it sleeps. More...
 
static void thread_wakeup_entry (void *p1, void *p2, void *p3)
 
static void wakeup_on_start_thread (int tnum)
 
static void check_wokeup_threads (int tnum)
 
void test_wakeup_threads (void)
 Test behavior of wakeup() in SMP case. More...
 
static void thread_get_cpu_entry (void *p1, void *p2, void *p3)
 
void test_get_cpu (void)
 Test get a pointer of CPU. More...
 
void test_smp_ipi (void)
 Test interprocessor interrupt. More...
 
void k_sys_fatal_error_handler (unsigned int reason, const z_arch_esf_t *pEsf)
 Fatal error policy handler. More...
 
void entry_oops (void *p1, void *p2, void *p3)
 
void test_fatal_on_smp (void)
 Test fatal error can be triggered on different core. More...
 
static void workq_handler (struct k_work *work)
 
void test_workq_on_smp (void)
 Test system workq run on different core. More...
 
static void t1_mutex_lock (void *p1, void *p2, void *p3)
 
static void t2_mutex_lock (void *p1, void *p2, void *p3)
 
void test_smp_release_global_lock (void)
 Test scenairo that a thread release the global lock. More...
 
static void sync_lock_dummy (void *k)
 
static void sync_lock_irq (void *k)
 
static void sync_unlock_irq (void *k)
 
static void sync_lock_sem (void *k)
 
static void sync_unlock_sem (void *k)
 
static void sync_lock_mutex (void *k)
 
static void sync_unlock_mutex (void *k)
 
static void sync_init (int lock_type)
 
static void inc_global_cnt (void *a, void *b, void *c)
 
static int run_concurrency (int type, void *func)
 
void test_inc_concurrency (void)
 Test if the concurrency of SMP works or not. More...
 
void test_main (void)
 

Variables

struct k_thread t2
 
volatile int t2_count
 
volatile int sync_count = -1
 
static int main_thread_id
 
static int child_thread_id
 
volatile int rv
 
static struct k_mutex smutex
 
static struct k_sem smp_sem
 
static ZTEST_BMEM volatile struct thread_info tinfo [CONFIG_MP_NUM_CPUS]
 
static struct k_thread tthread [CONFIG_MP_NUM_CPUS]
 
static volatile int thread_started [CONFIG_MP_NUM_CPUS - 1]
 
static int global_cnt
 
static struct k_mutex smp_mutex
 
static void(* sync_lock )(void *)
 
static void(* sync_unlock )(void *)
 

Macro Definition Documentation

◆ DELAY_US

#define DELAY_US   50000

◆ EQUAL_PRIORITY

#define EQUAL_PRIORITY   1

◆ LOOP_COUNT

#define LOOP_COUNT   20000

◆ STACK_SIZE

#define STACK_SIZE   (384 + CONFIG_TEST_EXTRA_STACKSIZE)

◆ T2_STACK_SIZE

#define T2_STACK_SIZE   (2048 + CONFIG_TEST_EXTRA_STACKSIZE)

◆ THREAD_DELAY

#define THREAD_DELAY   1

◆ THREADS_NUM

#define THREADS_NUM   CONFIG_MP_NUM_CPUS

◆ TIME_SLICE_MS

#define TIME_SLICE_MS   500

◆ TIMEOUT

#define TIMEOUT   1000

Enumeration Type Documentation

◆ sync_t

enum sync_t
Enumerator
LOCK_IRQ 
LOCK_SEM 
LOCK_MUTEX 

Function Documentation

◆ abort_threads()

static void abort_threads ( int  num)
static

◆ check_wokeup_threads()

static void check_wokeup_threads ( int  tnum)
static

◆ child_fn()

static void child_fn ( void p1,
void p2,
void p3 
)
static

◆ cleanup_resources()

static void cleanup_resources ( void  )
static

◆ curr_cpu()

static int curr_cpu ( void  )
static

◆ entry_oops()

void entry_oops ( void p1,
void p2,
void p3 
)

◆ inc_global_cnt()

static void inc_global_cnt ( void a,
void b,
void c 
)
static

◆ K_SEM_DEFINE() [1/2]

K_SEM_DEFINE ( cpuid_sema  ,
,
 
)

◆ K_SEM_DEFINE() [2/2]

K_SEM_DEFINE ( sema  ,
,
 
)

◆ K_THREAD_STACK_ARRAY_DEFINE()

static K_THREAD_STACK_ARRAY_DEFINE ( tstack  ,
CONFIG_MP_NUM_CPUS  ,
(384+CONFIG_TEST_EXTRA_STACKSIZE)   
)
static

◆ K_THREAD_STACK_DEFINE()

K_THREAD_STACK_DEFINE ( t2_stack  ,
(2048+CONFIG_TEST_EXTRA_STACKSIZE)   
)

◆ run_concurrency()

static int run_concurrency ( int  type,
void func 
)
static

◆ spawn_threads()

static void spawn_threads ( int  prio,
int  thread_num,
int  equal_prio,
k_thread_entry_t  thread_entry,
int  delay 
)
static

◆ spin_for_threads_exit()

static void spin_for_threads_exit ( void  )
static

◆ sync_init()

static void sync_init ( int  lock_type)
static

◆ sync_lock_dummy()

static void sync_lock_dummy ( void k)
static

◆ sync_lock_irq()

static void sync_lock_irq ( void k)
static

◆ sync_lock_mutex()

static void sync_lock_mutex ( void k)
static

◆ sync_lock_sem()

static void sync_lock_sem ( void k)
static

◆ sync_unlock_irq()

static void sync_unlock_irq ( void k)
static

◆ sync_unlock_mutex()

static void sync_unlock_mutex ( void k)
static

◆ sync_unlock_sem()

static void sync_unlock_sem ( void k)
static

◆ t1_mutex_lock()

static void t1_mutex_lock ( void p1,
void p2,
void p3 
)
static

◆ t2_fn()

static void t2_fn ( void a,
void b,
void c 
)
static

◆ t2_mutex_lock()

static void t2_mutex_lock ( void p1,
void p2,
void p3 
)
static

TESTPOINT: z_smp_release_global_lock() has been call during context switch but global_lock_cnt has not been decrease because no irq_lock() was called.

◆ test_main()

void test_main ( void  )

test case main entry

◆ thread_entry()

static void thread_entry ( void p1,
void p2,
void p3 
)
static

◆ thread_get_cpu_entry()

static void thread_get_cpu_entry ( void p1,
void p2,
void p3 
)
static

TESTPOINT: call arch_curr_cpu() to get cpu struct

◆ thread_wakeup_entry()

static void thread_wakeup_entry ( void p1,
void p2,
void p3 
)
static

◆ wakeup_on_start_thread()

static void wakeup_on_start_thread ( int  tnum)
static

◆ workq_handler()

static void workq_handler ( struct k_work work)
static

Variable Documentation

◆ child_thread_id

int child_thread_id
static

◆ global_cnt

int global_cnt
static

◆ main_thread_id

int main_thread_id
static

◆ rv

volatile int rv

◆ smp_mutex

struct k_mutex smp_mutex
static

◆ smp_sem

struct k_sem smp_sem
static

◆ smutex

struct k_mutex smutex
static

◆ sync_count

volatile int sync_count = -1

◆ sync_lock

void(* sync_lock) (void *) ( void )
static

◆ sync_unlock

void(* sync_unlock) (void *) ( void )
static

◆ t2

struct k_thread t2

◆ t2_count

volatile int t2_count

◆ thread_started

volatile int thread_started[CONFIG_MP_NUM_CPUS - 1]
static

◆ tinfo

ZTEST_BMEM volatile struct thread_info tinfo[CONFIG_MP_NUM_CPUS]
static

◆ tthread

struct k_thread tthread[CONFIG_MP_NUM_CPUS]
static