Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
main.c File Reference
#include <zephyr/tc_util.h>
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#include <ksched.h>
#include <zephyr/kernel_structs.h>

Data Structures

struct  thread_info
 

Macros

#define RUN_FACTOR   (CONFIG_SMP_TEST_RUN_FACTOR / 100.0)
 
#define T2_STACK_SIZE   (2048 + CONFIG_TEST_EXTRA_STACK_SIZE)
 
#define STACK_SIZE   (384 + CONFIG_TEST_EXTRA_STACK_SIZE)
 
#define DELAY_US   50000
 
#define TIMEOUT   1000
 
#define EQUAL_PRIORITY   1
 
#define TIME_SLICE_MS   500
 
#define THREAD_DELAY   1
 
#define SLEEP_MS_LONG   ((int)(15000 * RUN_FACTOR))
 
#define MAX_NUM_THREADS   CONFIG_MP_MAX_NUM_CPUS
 
#define SPAWN_AB_PRIO   K_PRIO_COOP(10)
 
#define LOOP_COUNT   ((int)(20000 * RUN_FACTOR))
 

Enumerations

enum  sync_t { LOCK_IRQ , LOCK_SEM , LOCK_MUTEX }
 

Functions

 K_THREAD_STACK_DEFINE (t2_stack,(2048+CONFIG_TEST_EXTRA_STACK_SIZE))
 
 K_SEM_DEFINE (cpuid_sema, 0, 1)
 
 K_SEM_DEFINE (sema, 0, 1)
 
static K_THREAD_STACK_ARRAY_DEFINE (tstack, CONFIG_MP_MAX_NUM_CPUS,(384+CONFIG_TEST_EXTRA_STACK_SIZE))
 
static int curr_cpu (void)
 
static void t2_fn (void *a, void *b, void *c)
 
 ZTEST (smp, test_smp_coop_threads)
 Verify SMP with 2 cooperative threads.
 
static void child_fn (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_cpu_id_threads)
 Verify CPU IDs of threads in SMP.
 
static void thread_entry_fn (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)
 
static void __no_optimization thread_ab_entry (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_coop_switch_in_abort)
 Verify the code path when we do context switch in k_thread_abort on SMP system.
 
 ZTEST (smp, test_coop_resched_threads)
 Test cooperative threads non-preemption.
 
 ZTEST (smp, test_preempt_resched_threads)
 Test preemptness of preemptive thread.
 
 ZTEST (smp, test_yield_threads)
 Validate behavior of thread when it yields.
 
 ZTEST (smp, test_sleep_threads)
 Test behavior of thread when it sleeps.
 
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)
 
 ZTEST (smp, test_wakeup_threads)
 Test behavior of wakeup() in SMP case.
 
static void thread_get_cpu_entry (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_get_cpu)
 
void k_sys_fatal_error_handler (unsigned int reason, const struct arch_esf *esf)
 Test interprocessor interrupt.
 
void entry_oops (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_fatal_on_smp)
 Test fatal error can be triggered on different core.
 
static void workq_handler (struct k_work *work)
 
 ZTEST (smp, test_workq_on_smp)
 Test system workq run on different core.
 
static void t1_mutex_lock (void *p1, void *p2, void *p3)
 
static void t2_mutex_lock (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_smp_release_global_lock)
 Test scenario that a thread release the global lock.
 
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 (void *p1, void *p2, void *p3)
 
 ZTEST (smp, test_inc_concurrency)
 Test if the concurrency of SMP works or not.
 
static void process_events (void *arg0, void *arg1, void *arg2)
 Torture test for context switching code.
 
static void signal_raise (void *arg0, void *arg1, void *arg2)
 
 ZTEST (smp, test_smp_switch_torture)
 
static void check_affinity (void *arg0, void *arg1, void *arg2)
 Torture test for cpu affinity code.
 
 ZTEST (smp, test_smp_affinity)
 
static void * smp_tests_setup (void)
 
 ZTEST_SUITE (smp, NULL, smp_tests_setup, NULL, NULL, NULL)
 

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_MAX_NUM_CPUS]
 
static struct k_thread tthread [CONFIG_MP_MAX_NUM_CPUS]
 
static volatile int thread_started [CONFIG_MP_MAX_NUM_CPUS - 1]
 
static struct k_poll_signal tsignal [CONFIG_MP_MAX_NUM_CPUS]
 
static struct k_poll_event tevent [CONFIG_MP_MAX_NUM_CPUS]
 
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   ((int)(20000 * RUN_FACTOR))

◆ MAX_NUM_THREADS

#define MAX_NUM_THREADS   CONFIG_MP_MAX_NUM_CPUS

◆ RUN_FACTOR

#define RUN_FACTOR   (CONFIG_SMP_TEST_RUN_FACTOR / 100.0)

◆ SLEEP_MS_LONG

#define SLEEP_MS_LONG   ((int)(15000 * RUN_FACTOR))

◆ SPAWN_AB_PRIO

#define SPAWN_AB_PRIO   K_PRIO_COOP(10)

◆ STACK_SIZE

#define STACK_SIZE   (384 + CONFIG_TEST_EXTRA_STACK_SIZE)

◆ T2_STACK_SIZE

#define T2_STACK_SIZE   (2048 + CONFIG_TEST_EXTRA_STACK_SIZE)

◆ THREAD_DELAY

#define THREAD_DELAY   1

◆ 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_MAX_NUM_CPUS  ,
(384+CONFIG_TEST_EXTRA_STACK_SIZE)   
)
static

◆ K_THREAD_STACK_DEFINE()

K_THREAD_STACK_DEFINE ( t2_stack  ,
(2048+CONFIG_TEST_EXTRA_STACK_SIZE)   
)

◆ run_concurrency()

static int run_concurrency ( void *  p1,
void *  p2,
void *  p3 
)
static

◆ signal_raise()

static void signal_raise ( void *  arg0,
void *  arg1,
void *  arg2 
)
static

◆ smp_tests_setup()

static void * smp_tests_setup ( void  )
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.

◆ thread_ab_entry()

static void __no_optimization thread_ab_entry ( void *  p1,
void *  p2,
void *  p3 
)
static

◆ thread_entry_fn()

static void thread_entry_fn ( 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

◆ ZTEST() [1/3]

ZTEST ( smp  ,
test_get_cpu   
)

◆ ZTEST() [2/3]

ZTEST ( smp  ,
test_smp_affinity   
)

◆ ZTEST() [3/3]

ZTEST ( smp  ,
test_smp_switch_torture   
)

◆ ZTEST_SUITE()

ZTEST_SUITE ( smp  ,
NULL  ,
smp_tests_setup  ,
NULL  ,
NULL  ,
NULL   
)

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

◆ tevent

struct k_poll_event tevent[CONFIG_MP_MAX_NUM_CPUS]
static

◆ thread_started

volatile int thread_started[CONFIG_MP_MAX_NUM_CPUS - 1]
static

◆ tinfo

ZTEST_BMEM volatile struct thread_info tinfo[CONFIG_MP_MAX_NUM_CPUS]
static

◆ tsignal

struct k_poll_signal tsignal[CONFIG_MP_MAX_NUM_CPUS]
static

◆ tthread

struct k_thread tthread[CONFIG_MP_MAX_NUM_CPUS]
static