tests: kernel: validate k_can_yield
Validate the behaviour of `k_can_yield` in pre-kernel, ISR, and idle thread and standard thread contexts. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
1ef647f396
commit
775030e6f1
3 changed files with 17 additions and 0 deletions
|
@ -42,6 +42,7 @@
|
|||
#define EXEC_CTX_TYPE_CMD 1
|
||||
|
||||
#define UNKNOWN_COMMAND -1
|
||||
#define INVALID_BEHAVIOUR -2
|
||||
|
||||
/*
|
||||
* Get the timer type dependent IRQ number. If timer type
|
||||
|
@ -227,6 +228,10 @@ static void isr_handler(const void *data)
|
|||
{
|
||||
ARG_UNUSED(data);
|
||||
|
||||
if (k_can_yield()) {
|
||||
isr_info.error = INVALID_BEHAVIOUR;
|
||||
}
|
||||
|
||||
switch (isr_info.command) {
|
||||
case THREAD_SELF_CMD:
|
||||
isr_info.data = (void *)k_current_get();
|
||||
|
@ -817,6 +822,11 @@ static void k_yield_entry(void *arg0, void *arg1, void *arg2)
|
|||
zassert_equal(thread_evidence, 0,
|
||||
"Helper created at higher priority ran prematurely.");
|
||||
|
||||
/*
|
||||
* Validate the thread is allowed to yield
|
||||
*/
|
||||
zassert_true(k_can_yield(), "Thread incorrectly detected it could not yield");
|
||||
|
||||
/*
|
||||
* Test that the thread will yield to the higher priority helper.
|
||||
* thread_evidence is still 0.
|
||||
|
|
|
@ -135,6 +135,7 @@ static struct init_record {
|
|||
bool pre_kernel;
|
||||
bool is_in_isr;
|
||||
bool is_pre_kernel;
|
||||
bool could_yield;
|
||||
} init_records[4];
|
||||
|
||||
__pinned_data
|
||||
|
@ -146,6 +147,7 @@ static int add_init_record(bool pre_kernel)
|
|||
rp->pre_kernel = pre_kernel;
|
||||
rp->is_pre_kernel = k_is_pre_kernel();
|
||||
rp->is_in_isr = k_is_in_isr();
|
||||
rp->could_yield = k_can_yield();
|
||||
++rp;
|
||||
return 0;
|
||||
}
|
||||
|
@ -205,6 +207,8 @@ void test_pre_kernel_detection(void)
|
|||
"rec %zu isr", rp - init_records);
|
||||
zassert_equal(rp->is_pre_kernel, true,
|
||||
"rec %zu pre-kernel", rp - init_records);
|
||||
zassert_equal(rp->could_yield, false,
|
||||
"rec %zu could-yield", rp - init_records);
|
||||
++rp;
|
||||
}
|
||||
zassert_equal(rp - init_records, 2U,
|
||||
|
@ -215,6 +219,8 @@ void test_pre_kernel_detection(void)
|
|||
"rec %zu isr", rp - init_records);
|
||||
zassert_equal(rp->is_pre_kernel, false,
|
||||
"rec %zu post-kernel", rp - init_records);
|
||||
zassert_equal(rp->could_yield, true,
|
||||
"rec %zu could-yield", rp - init_records);
|
||||
++rp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,6 +213,7 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
|
|||
/* make sure this is idle thread */
|
||||
zassert_true(z_is_idle_thread_object(_current), NULL);
|
||||
zassert_true(ticks == _kernel.idle, NULL);
|
||||
zassert_false(k_can_yield(), NULL);
|
||||
idle_entered = true;
|
||||
|
||||
if (enter_low_power) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue