tests: kernel: interrupt: Clean up prevent_irq test
This commit cleans up the "prevent interruption" test and adds a documentation comment for it. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
parent
6820fdf0fb
commit
1b8c8e25ff
1 changed files with 17 additions and 8 deletions
|
@ -8,19 +8,28 @@
|
|||
#include "interrupt_util.h"
|
||||
|
||||
#define DURATION 5
|
||||
#define HANDLER_TOKEN 0xDEADBEEF
|
||||
|
||||
static struct k_timer irqlock_timer;
|
||||
|
||||
volatile u32_t check_lock_new;
|
||||
u32_t check_lock_old = 0xBEEF;
|
||||
volatile u32_t handler_result;
|
||||
|
||||
static void timer_handler(struct k_timer *timer)
|
||||
{
|
||||
ARG_UNUSED(timer);
|
||||
check_lock_new = 0xBEEF;
|
||||
handler_result = HANDLER_TOKEN;
|
||||
printk("timer fired\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test interrupt prevention
|
||||
*
|
||||
* @ingroup kernel_interrupt_tests
|
||||
*
|
||||
* This routine tests if the kernel is capable of preventing interruption, by
|
||||
* locking interrupts and busy-waiting to see if the system timer interrupt is
|
||||
* serviced while interrupts are locked; in addition, this test also verifies
|
||||
* that the system timer interrupt is serviced after interrupts are unlocked.
|
||||
*/
|
||||
void test_prevent_interruption(void)
|
||||
{
|
||||
int key;
|
||||
|
@ -28,7 +37,7 @@ void test_prevent_interruption(void)
|
|||
printk("locking interrupts\n");
|
||||
key = irq_lock();
|
||||
|
||||
check_lock_new = 0;
|
||||
handler_result = 0;
|
||||
|
||||
k_timer_init(&irqlock_timer, timer_handler, NULL);
|
||||
|
||||
|
@ -38,15 +47,15 @@ void test_prevent_interruption(void)
|
|||
*/
|
||||
k_timer_start(&irqlock_timer, DURATION, K_NO_WAIT);
|
||||
k_busy_wait(MS_TO_US(1000));
|
||||
zassert_not_equal(check_lock_new, check_lock_old,
|
||||
"Interrupt locking didn't work properly");
|
||||
zassert_not_equal(handler_result, HANDLER_TOKEN,
|
||||
"timer interrupt was serviced while interrupts are locked");
|
||||
|
||||
printk("unlocking interrupts\n");
|
||||
irq_unlock(key);
|
||||
|
||||
k_busy_wait(MS_TO_US(1000));
|
||||
|
||||
zassert_equal(check_lock_new, check_lock_old,
|
||||
zassert_equal(handler_result, HANDLER_TOKEN,
|
||||
"timer should have fired");
|
||||
|
||||
k_timer_stop(&irqlock_timer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue