Skip to content

Commit ab60e15

Browse files
finikorgjhedberg
authored andcommitted
tests: nmi: Add NMI registration API test
Test that NMI registration works as expected. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent 85db428 commit ab60e15

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

tests/arch/x86/nmi/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(nmi)
6+
7+
enable_language(C ASM)
8+
9+
FILE(GLOB app_sources src/*.c)
10+
target_sources(app PRIVATE ${app_sources})
11+
12+
target_include_directories(app PRIVATE
13+
${ZEPHYR_BASE}/kernel/include
14+
${ZEPHYR_BASE}/arch/${ARCH}/include
15+
)

tests/arch/x86/nmi/README.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Title: NMI registration support
2+
3+
Description:
4+
5+
This test verifies that NMI registration works as expected.
6+
7+
--------------------------------------------------------------------------------
8+
9+
Building and Running Project:
10+
11+
This project outputs to the console. It can be built and executed
12+
on QEMU as follows:
13+
14+
make run
15+
16+
Sample output is:
17+
18+
Booting from ROM..*** Booting Zephyr OS build v2.4.0-rc1-197-g77a5f92715f7 ***
19+
Running test suite nmi
20+
===================================================================
21+
START - test_nmi_handler
22+
Testing to see interrupt handler executes properly
23+
PASS - test_nmi_handler
24+
===================================================================
25+
Test suite nmi succeeded
26+
===================================================================
27+
PROJECT EXECUTION SUCCESSFUL

tests/arch/x86/nmi/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y

tests/arch/x86/nmi/src/main.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <ztest.h>
9+
#include <tc_util.h>
10+
11+
#include <kernel_internal.h>
12+
#if defined(__GNUC__)
13+
#include "test_asm_inline_gcc.h"
14+
#else
15+
#include "test_asm_inline_other.h"
16+
#endif
17+
18+
static volatile int int_handler_executed;
19+
20+
bool z_x86_do_kernel_nmi(const z_arch_esf_t *esf)
21+
{
22+
int_handler_executed++;
23+
24+
return true;
25+
}
26+
27+
void test_nmi_handler(void)
28+
{
29+
TC_PRINT("Testing to see interrupt handler executes properly\n");
30+
31+
_trigger_isr_handler(IV_NON_MASKABLE_INTERRUPT);
32+
33+
zassert_not_equal(int_handler_executed, 0,
34+
"Interrupt handler did not execute");
35+
zassert_equal(int_handler_executed, 1,
36+
"Interrupt handler executed more than once! (%d)\n",
37+
int_handler_executed);
38+
}
39+
40+
void test_main(void)
41+
{
42+
ztest_test_suite(nmi, ztest_unit_test(test_nmi_handler));
43+
ztest_run_test_suite(nmi);
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Intel x86 GCC specific test inline assembler functions and macros */
2+
3+
/*
4+
* Copyright (c) 2015, Wind River Systems, Inc.
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#ifndef _TEST_ASM_INLINE_GCC_H
10+
#define _TEST_ASM_INLINE_GCC_H
11+
12+
#if !defined(__GNUC__) || !defined(CONFIG_X86)
13+
#error test_asm_inline_gcc.h goes only with x86 GCC
14+
#endif
15+
16+
#define _trigger_isr_handler(irq) __asm__ volatile("int %0" : : "i" (irq) : "memory")
17+
18+
#endif /* _TEST_ASM_INLINE_GCC_H */

tests/arch/x86/nmi/testcase.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tests:
2+
arch.interrupt.nmi:
3+
arch_allow: x86
4+
platform_allow: qemu_x86_64
5+
tags: interrupt

0 commit comments

Comments
 (0)