static void start_threads(void) { k_thread_spawn(stack1, STACK_SIZE, AlternateTask, NULL, NULL, NULL, K_PRIO_PREEMPT(12), 0, 0); k_thread_spawn(stack2, STACK_SIZE, RegressionTask, NULL, NULL, NULL, K_PRIO_PREEMPT(12), 0, 0); }
/*test cases*/ void test_msgq_purge_when_put(void) { struct k_msgq msgq; int ret; k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN); /*fill the queue to full*/ for (int i = 0; i < MSGQ_LEN; i++) { ret = k_msgq_put(&msgq, (void *)&data[i], K_NO_WAIT); zassert_equal(ret, 0, NULL); } /*create another thread waiting to put msg*/ k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, tThread_entry, &msgq, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); k_sleep(TIMEOUT >> 1); /**TESTPOINT: msgq purge while another thread waiting to put msg*/ k_msgq_purge(&msgq); k_sleep(TIMEOUT >> 1); k_thread_abort(tid); /*verify msg put after purge*/ for (int i = 0; i < MSGQ_LEN; i++) { ret = k_msgq_put(&msgq, (void *)&data[i], K_NO_WAIT); zassert_equal(ret, 0, NULL); } }
static void tsema_thread_thread(struct k_sem *psem) { /**TESTPOINT: thread-thread sync via sema*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, tThread_entry, psem, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); zassert_false(k_sem_take(psem, K_FOREVER), NULL); /*clean the spawn thread avoid side effect in next TC*/ k_thread_abort(tid); }
static void thread_alert(void) { handler_executed = 0; /**TESTPOINT: thread-thread sync via alert*/ k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, tThread_entry, NULL, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); alert_send(); k_sleep(TIMEOUT); k_thread_abort(tid); }
void test_pipe_get_put(void) { /**TESTPOINT: test API sequence: [get, put]*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, tThread_block_put, &kpipe, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); /*get will be executed previor to put*/ tpipe_get(&kpipe); k_sem_take(&end_sema, K_FOREVER); k_thread_abort(tid); }
void test_pipe_block_put(void) { /**TESTPOINT: test k_pipe_block_put without semaphore*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, tThread_block_put, &kpipe, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); k_sleep(10); tpipe_get(&kpipe); k_sem_take(&end_sema, K_FOREVER); k_thread_abort(tid); }
void test_pipe_block_put_sema(void) { struct k_sem sync_sema; k_sem_init(&sync_sema, 0, 1); /**TESTPOINT: test k_pipe_block_put with semaphore*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, tThread_block_put, &pipe, &sync_sema, NULL, K_PRIO_PREEMPT(0), 0, 0); k_sleep(10); tpipe_get(&pipe); k_sem_take(&end_sema, K_FOREVER); k_thread_abort(tid); }
static void tcoop_ctx(void *p1, void *p2, void *p3) { /** TESTPOINT: The thread's priority is in the cooperative range.*/ zassert_false(k_is_preempt_thread(), NULL); k_thread_priority_set(k_current_get(), K_PRIO_PREEMPT(1)); /** TESTPOINT: The thread's priority is in the preemptible range.*/ zassert_true(k_is_preempt_thread(), NULL); k_sched_lock(); /** TESTPOINT: The thread has locked the scheduler.*/ zassert_false(k_is_preempt_thread(), NULL); k_sched_unlock(); /** TESTPOINT: The thread has not locked the scheduler.*/ zassert_true(k_is_preempt_thread(), NULL); k_sem_give(&end_sema); }
static void tstack_thread_thread(struct k_stack *pstack) { k_sem_init(&end_sema, 0, 1); /**TESTPOINT: thread-thread data passing via stack*/ k_tid_t tid = k_thread_spawn(threadstack, STACK_SIZE, tThread_entry, pstack, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); tstack_push(pstack); k_sem_take(&end_sema, K_FOREVER); k_sem_take(&end_sema, K_FOREVER); tstack_pop(pstack); /* clear the spawn thread to avoid side effect */ k_thread_abort(tid); }
static void tmutex_test_lock(struct k_mutex *pmutex, void (*entry_fn)(void *, void *, void *)) { k_mutex_init(pmutex); k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, entry_fn, pmutex, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); k_mutex_lock(pmutex, K_FOREVER); TC_PRINT("access resource from main thread\n"); /* wait for spawn thread to take action */ k_sleep(TIMEOUT); /* teardown */ k_thread_abort(tid); }
static void tpipe_thread_thread(struct k_pipe *ppipe) { k_sem_init(&end_sema, 0, 1); /**TESTPOINT: thread-thread data passing via pipe*/ k_tid_t tid = k_thread_create(&tdata, tstack, STACK_SIZE, tThread_entry, ppipe, NULL, NULL, K_PRIO_PREEMPT(0), 0, 0); tpipe_put(ppipe); k_sem_take(&end_sema, K_FOREVER); k_sem_take(&end_sema, K_FOREVER); tpipe_get(ppipe); /* clear the spawned thread avoid side effect */ k_thread_abort(tid); }
/*test cases*/ void test_sched_is_preempt_thread(void) { k_sem_init(&end_sema, 0, 1); /*create preempt thread*/ k_tid_t tid = k_thread_spawn(tstack, STACK_SIZE, tpreempt_ctx, NULL, NULL, NULL, K_PRIO_PREEMPT(1), 0, 0); k_sem_take(&end_sema, K_FOREVER); k_thread_abort(tid); /*create coop thread*/ tid = k_thread_spawn(tstack, STACK_SIZE, tcoop_ctx, NULL, NULL, NULL, K_PRIO_COOP(1), 0, 0); k_sem_take(&end_sema, K_FOREVER); k_thread_abort(tid); /*invoke isr*/ irq_offload(tIsr, NULL); }
/* test cases*/ void test_mslab_threadsafe(void) { k_tid_t tid[THREAD_NUM]; k_mem_slab_init(&mslab2, tslab, BLK_SIZE2, BLK_NUM); k_sem_init(&sync_sema, 0, THREAD_NUM); /* create multiple threads to invoke same memory slab APIs*/ for (int i = 0; i < THREAD_NUM; i++) { tid[i] = k_thread_create(&tdata[i], tstack[i], STACK_SIZE, tmslab_api, NULL, NULL, NULL, K_PRIO_PREEMPT(1), 0, 0); } /* TESTPOINT: all threads complete and exit the entry function*/ for (int i = 0; i < THREAD_NUM; i++) { k_sem_take(&sync_sema, K_FOREVER); } /* test case tear down*/ for (int i = 0; i < THREAD_NUM; i++) { k_thread_abort(tid[i]); } }