Skip to content
Permalink
Browse files

tests: kernel: submit a simple test for zero-latency irqs

The commit contributes a simple test for the Zero-Latency
IRQ feature (CONFIG_ZERO_LATENCY_IRQS=y) for ARM platforms.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and nashif committed Jun 25, 2019
1 parent 94cb13f commit e5c0e3caa1323c3ee3c1861c99403006ab5bbf85
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(arm_zero_latency_irqs)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
@@ -0,0 +1,45 @@
Title: Test to verify the behavior of CONFIG_ZERO_LATENCY_IRQS at runtime (ARM Only)

Description:

This test verifies the behavior of CONFIG_ZERO_LATENCY_IRQS at runtime.
In particular, it tests that IRQs configured with the IRQ_ZERO_LATENCY
flag are assigned the highest priority in the system (and, therefore,
cannot be masked-out by irq_lock()).
Only for ARMv7-M and ARMv8-M Mainline targets.

---------------------------------------------------------------------------

Building and Running Project:

This project outputs to the console. It can be built and executed on QEMU as
follows:

ninja/make run

---------------------------------------------------------------------------

Troubleshooting:

Problems caused by out-dated project information can be addressed by
issuing one of the following commands then rebuilding the project:

ninja/make clean # discard results of previous builds
# but keep existing configuration info
or
ninja/make pristine # discard results of previous builds
# and restore pre-defined configuration info

---------------------------------------------------------------------------

Sample Output:

Running test suite zero_latency_irqs
===================================================================
starting test - test_arm_zero_latency_irqs
Available IRQ line: 70
PASS - test_arm_zero_latency_irqs
===================================================================
Test suite zero_latency_irqs succeeded
===================================================================
PROJECT EXECUTION SUCCESSFUL
@@ -0,0 +1,3 @@
CONFIG_ZTEST=y
CONFIG_DYNAMIC_INTERRUPTS=y
CONFIG_ZERO_LATENCY_IRQS=y
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <ztest.h>
#include <arch/cpu.h>
#include <arch/arm/cortex_m/cmsis.h>

static volatile int test_flag;

void arm_zero_latency_isr_handler(void *args)
{
ARG_UNUSED(args);

test_flag = 1;
}

void test_arm_zero_latency_irqs(void)
{
/* Determine an NVIC IRQ line that is not currently in use. */
int i, key;

zassert_false(test_flag, "Test flag not initialized to zero\n");

for (i = CONFIG_NUM_IRQS - 1; i >= 0; i--) {
if (NVIC_GetEnableIRQ(i) == 0) {
/*
* Interrupts configured statically with IRQ_CONNECT(.)
* are automatically enabled. NVIC_GetEnableIRQ()
* returning false, here, implies that the IRQ line is
* not enabled, thus, currently not in use by Zephyr.
*/
break;
}
}

zassert_true(i >= 0,
"No available IRQ line to configure as zero-latency\n");

TC_PRINT("Available IRQ line: %u\n", i);

/* Configure the available IRQ line as zero-latency. */

z_arch_irq_connect_dynamic(i, 0 /* Unused */,
arm_zero_latency_isr_handler,
NULL,
IRQ_ZERO_LATENCY);

NVIC_ClearPendingIRQ(i);
NVIC_EnableIRQ(i);

/* Lock interrupts */
key = irq_lock();

/* Set the zero-latency IRQ to pending state. */
NVIC_SetPendingIRQ(i);

/*
* Instruction barriers to make sure the NVIC IRQ is
* set to pending state before 'test_flag' is checked.
*/
__DSB();
__ISB();

/* Confirm test flag is set by the zero-latency ISR handler. */
zassert_true(test_flag == 1, "Test flag not set by ISR\n");

irq_unlock(key);
}
/**
* @}
*/
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#if !defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
#error test can only run on Cortex-M3/M4/M7/M33 MCUs
#endif

#include <ztest.h>

extern void test_arm_zero_latency_irqs(void);

void test_main(void)
{
ztest_test_suite(zero_latency_irqs,
ztest_unit_test(test_arm_zero_latency_irqs));
ztest_run_test_suite(zero_latency_irqs);
}
@@ -0,0 +1,5 @@
tests:
arch.zero_latency_interrupts:
filter: CONFIG_ARMV7_M_ARMV8_M_MAINLINE
tags: arm interrupt
arch_whitelist: arm

0 comments on commit e5c0e3c

Please sign in to comment.
You can’t perform that action at this time.