Skip to content

Commit

Permalink
tests: sched: Enhance tests to improve code coverage
Browse files Browse the repository at this point in the history
call k_wakeup() if the timer has expired and the thread
is not even in the sleep state.

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
  • Loading branch information
ajaykish authored and nashif committed Jul 27, 2018
1 parent 8780636 commit dbc8789
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/kernel/sched/schedule_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void test_main(void)
ztest_unit_test(test_sched_is_preempt_thread),
ztest_unit_test(test_slice_reset),
ztest_unit_test(test_slice_scheduling),
ztest_unit_test(test_priority_scheduling)
ztest_unit_test(test_priority_scheduling),
ztest_unit_test(test_wakeup_expired_timer_thread)
);
ztest_run_test_suite(threads_scheduling);
}
1 change: 1 addition & 0 deletions tests/kernel/sched/schedule_api/src/test_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ void test_sched_is_preempt_thread(void);
void test_slice_reset(void);
void test_slice_scheduling(void);
void test_priority_scheduling(void);
void test_wakeup_expired_timer_thread(void);

#endif /* __TEST_SCHED_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "test_sched.h"
#define THREADS_NUM 3
#define DURATION 1
static K_THREAD_STACK_ARRAY_DEFINE(tstack, THREADS_NUM, STACK_SIZE);

static struct thread_data tdata[THREADS_NUM];
Expand All @@ -16,6 +17,8 @@ K_THREAD_STACK_DEFINE(t_stack, STACK_SIZE);
struct k_thread t;

K_SEM_DEFINE(pend_sema, 0, 1);
K_SEM_DEFINE(timer_sema, 0, 1);
struct k_timer timer;

static void thread_entry(void *p1, void *p2, void *p3)
{
Expand Down Expand Up @@ -67,6 +70,18 @@ static void teardown_threads(void)
k_thread_priority_set(k_current_get(), old_prio);
}

static void timer_handler(struct k_timer *timer)
{
ARG_UNUSED(timer);
k_sem_give(&timer_sema);
}

static void thread_handler(void *p1, void *p2, void *p3)
{
k_timer_init(&timer, timer_handler, NULL);
k_timer_start(&timer, DURATION, 0);
}

/*test cases*/

/**
Expand Down Expand Up @@ -324,3 +339,22 @@ void test_unlock_preemptible(void)
/* restore environment */
teardown_threads();
}

/**
* @brief validate k_wakeup() in some corner scenario
* @details trigger a timer and after expiration of timer
* call k_wakeup(), even the thread is not in sleep state neither
* in pending state
*
* @see k_wakeup()
*/
void test_wakeup_expired_timer_thread(void)
{
k_tid_t tid = k_thread_create(&tthread[0], t_stack, STACK_SIZE,
thread_handler, NULL, NULL, NULL,
K_PRIO_PREEMPT(0), 0, 0);
k_sem_take(&timer_sema, K_FOREVER);
/* wakeup a thread if the timer is expired */
k_wakeup(tid);
k_thread_abort(tid);
}

0 comments on commit dbc8789

Please sign in to comment.