From b29ab436f65fa5fe2bd75cc78a73f3d2b0a1b709 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Fri, 2 Feb 2024 15:50:34 +0100 Subject: [PATCH 1/2] [nrf fromtree] tests: drivers: timer: add nrf_grtc_timer tests Add NRF GRTC timer test for nRF54L15. Signed-off-by: Magdalena Pastula (cherry picked from commit c57946173f417b2c3ff644991f2385a6d4716fec) --- .../timer/nrf_grtc_timer/CMakeLists.txt | 9 +++++ tests/drivers/timer/nrf_grtc_timer/prj.conf | 2 + tests/drivers/timer/nrf_grtc_timer/src/main.c | 40 +++++++++++++++++++ .../timer/nrf_grtc_timer/testcase.yaml | 4 ++ 4 files changed, 55 insertions(+) create mode 100644 tests/drivers/timer/nrf_grtc_timer/CMakeLists.txt create mode 100644 tests/drivers/timer/nrf_grtc_timer/prj.conf create mode 100644 tests/drivers/timer/nrf_grtc_timer/src/main.c create mode 100644 tests/drivers/timer/nrf_grtc_timer/testcase.yaml diff --git a/tests/drivers/timer/nrf_grtc_timer/CMakeLists.txt b/tests/drivers/timer/nrf_grtc_timer/CMakeLists.txt new file mode 100644 index 00000000000..6dfe69d0045 --- /dev/null +++ b/tests/drivers/timer/nrf_grtc_timer/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(nrf_grtc_timer) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/timer/nrf_grtc_timer/prj.conf b/tests/drivers/timer/nrf_grtc_timer/prj.conf new file mode 100644 index 00000000000..dea03477519 --- /dev/null +++ b/tests/drivers/timer/nrf_grtc_timer/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_NRF_GRTC_TIMER=y diff --git a/tests/drivers/timer/nrf_grtc_timer/src/main.c b/tests/drivers/timer/nrf_grtc_timer/src/main.c new file mode 100644 index 00000000000..197270cc6a4 --- /dev/null +++ b/tests/drivers/timer/nrf_grtc_timer/src/main.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +#define GRTC_SLEW_TICKS 10 + +ZTEST(nrf_grtc_timer, test_get_ticks) +{ + k_timeout_t t = K_MSEC(1); + + uint64_t exp_ticks = z_nrf_grtc_timer_read() + t.ticks; + int64_t ticks; + + /* Relative 1ms from now timeout converted to GRTC */ + ticks = z_nrf_grtc_timer_get_ticks(t); + zassert_true((ticks >= exp_ticks) && (ticks <= (exp_ticks + GRTC_SLEW_TICKS)), + "Unexpected result %" PRId64 " (expected: %" PRId64 ")", ticks, exp_ticks); + + /* Absolute timeout 1ms in the past */ + t = Z_TIMEOUT_TICKS(Z_TICK_ABS(sys_clock_tick_get() - K_MSEC(1).ticks)); + + exp_ticks = z_nrf_grtc_timer_read() - K_MSEC(1).ticks; + ticks = z_nrf_grtc_timer_get_ticks(t); + zassert_true((ticks >= exp_ticks) && (ticks <= (exp_ticks + GRTC_SLEW_TICKS)), + "Unexpected result %" PRId64 " (expected: %" PRId64 ")", ticks, exp_ticks); + + /* Absolute timeout 10ms in the future */ + t = Z_TIMEOUT_TICKS(Z_TICK_ABS(sys_clock_tick_get() + K_MSEC(10).ticks)); + exp_ticks = z_nrf_grtc_timer_read() + K_MSEC(10).ticks; + ticks = z_nrf_grtc_timer_get_ticks(t); + zassert_true((ticks >= exp_ticks) && (ticks <= (exp_ticks + GRTC_SLEW_TICKS)), + "Unexpected result %" PRId64 " (expected: %" PRId64 ")", ticks, exp_ticks); +} + +ZTEST_SUITE(nrf_grtc_timer, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/drivers/timer/nrf_grtc_timer/testcase.yaml b/tests/drivers/timer/nrf_grtc_timer/testcase.yaml new file mode 100644 index 00000000000..81b320c7c9b --- /dev/null +++ b/tests/drivers/timer/nrf_grtc_timer/testcase.yaml @@ -0,0 +1,4 @@ +tests: + drivers.timer.nrf_grtc_timer: + tags: drivers + platform_allow: nrf54l15pdk_nrf54l15_cpuapp From d1546b87165f6c2298fe77ed59a9b2675a343a6a Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Mon, 15 Apr 2024 14:12:27 +0200 Subject: [PATCH 2/2] [nrf fromtree] tests: drivers: nrf_grtc_timer: add nRF54H20 target GRTC peripheral is present on nRF54H20, so the tests should be executed on this target as well. Signed-off-by: Nikodem Kastelik (cherry picked from commit 1f9bec7f0844784cc790cac20b85d098294ecbfa) --- tests/drivers/timer/nrf_grtc_timer/testcase.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/drivers/timer/nrf_grtc_timer/testcase.yaml b/tests/drivers/timer/nrf_grtc_timer/testcase.yaml index 81b320c7c9b..654594cfe0a 100644 --- a/tests/drivers/timer/nrf_grtc_timer/testcase.yaml +++ b/tests/drivers/timer/nrf_grtc_timer/testcase.yaml @@ -1,4 +1,7 @@ tests: drivers.timer.nrf_grtc_timer: tags: drivers - platform_allow: nrf54l15pdk_nrf54l15_cpuapp + platform_allow: + - nrf54l15pdk_nrf54l15_cpuapp + - nrf54h20dk_nrf54h20_cpuapp + - nrf54h20dk_nrf54h20_cpurad