Skip to content

Commit

Permalink
tests: add critical region tests
Browse files Browse the repository at this point in the history
[KRKNWK-18043]

Signed-off-by: Krzysztof Taborowski <[email protected]>
  • Loading branch information
ktaborowski committed Nov 16, 2023
1 parent 3f9cbb1 commit 5aa5ffe
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/functional/critical_region/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(sidewalk_test_critical_region)

# add test file
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
target_include_directories(app PRIVATE .)

# generate runner for the test
test_runner_generate(${app_sources})
15 changes: 15 additions & 0 deletions tests/functional/critical_region/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
config SIDEWALK_BUILD
default y

config SIDEWALK_CRITICAL_REGION
default y

config SIDEWALK_CRITICAL_REGION_RE_ENTRY_MAX
default 2

source "Kconfig.zephyr"
9 changes: 9 additions & 0 deletions tests/functional/critical_region/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_UNITY=y
CONFIG_MAIN_THREAD_PRIORITY=14
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_RESET_ON_FATAL_ERROR=n
62 changes: 62 additions & 0 deletions tests/functional/critical_region/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <unity.h>
#include <sid_pal_critical_region_ifc.h>
#include <sid_error.h>

#if defined(CONFIG_CPU_CORTEX_M)
#include <cmsis_core.h>
#else
#error "Architecture not supported"
#endif

#define TEST_IRQ (30)
#define TEST_IRQ_PRIO (2)
#define TEST_IRQ_FLAGS (0)

#define UNCHANGED 0
#define CHANGED 1
static volatile int resource;

static void irq_cb(void)
{
resource = CHANGED;
}

static void trigger_irq(int irq)
{
NVIC_SetPendingIRQ(irq);
}

void test_sid_pal_critical_region_with_timer(void)
{
IRQ_CONNECT(TEST_IRQ, TEST_IRQ_PRIO, irq_cb, NULL, TEST_IRQ_FLAGS);
irq_enable(TEST_IRQ);

resource = UNCHANGED;
trigger_irq(TEST_IRQ);
TEST_ASSERT_EQUAL_UINT32(CHANGED, resource);

sid_pal_enter_critical_region();
resource = UNCHANGED;
trigger_irq(TEST_IRQ);
TEST_ASSERT_EQUAL_UINT32(UNCHANGED, resource);
sid_pal_exit_critical_region();

trigger_irq(TEST_IRQ);
TEST_ASSERT_EQUAL_UINT32(CHANGED, resource);
}

/* It is required to be added to each test. That is because unity is using
* different main signature (returns int) and zephyr expects main which does
* not return value.
*/
extern int unity_main(void);

int main(void)
{
return unity_main();
}
6 changes: 6 additions & 0 deletions tests/functional/critical_region/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
sidewalk.functional.critical_region:
platform_allow: nrf52840dk_nrf52840 nrf5340dk_nrf5340_cpuapp
integration_platforms:
- nrf52840dk_nrf52840
- nrf5340dk_nrf5340_cpuapp

0 comments on commit 5aa5ffe

Please sign in to comment.