Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: benchmarks: add test kernel_freq_change #19850

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/benchmarks/kernel_freq_change/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025 😄

#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

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

FILE(GLOB app_sources src/main.c)
target_sources(app PRIVATE ${app_sources})
4 changes: 4 additions & 0 deletions tests/benchmarks/kernel_freq_change/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_ZTEST=y
CONFIG_NRFS=y
CONFIG_CLOCK_CONTROL=y
CONFIG_ASSERT=y
142 changes: 142 additions & 0 deletions tests/benchmarks/kernel_freq_change/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025 😄

*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
#include <zephyr/devicetree/clocks.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h>

struct timer_data {
int duration_count;
int stop_count;
};
static void duration_expire(struct k_timer *timer);
static void stop_expire(struct k_timer *timer);

/** TESTPOINT: init timer via K_TIMER_DEFINE */
K_TIMER_DEFINE(ktimer, duration_expire, stop_expire);

static ZTEST_BMEM struct timer_data tdata;

#define DURATION 100
#define LESS_DURATION 70


/*
* Set Global Domain frequency (HSFLL120)
*/
static void set_global_domain_frequency(uint32_t freq_mhz)
{
int err;
int res;
struct onoff_client cli;
const struct nrf_clock_spec clk_spec_global_hsfll = {
.frequency = freq_mhz
};
const struct device *hsfll_dev = DEVICE_DT_GET(DT_NODELABEL(hsfll120));

TC_PRINT("Requested frequency [Hz]: %d\n", clk_spec_global_hsfll.frequency);
sys_notify_init_spinwait(&cli.notify);
err = nrf_clock_control_request(hsfll_dev, &clk_spec_global_hsfll, &cli);
TC_PRINT("Return code: %d\n", err);
__ASSERT_NO_MSG(err < 3);
__ASSERT_NO_MSG(err >= 0);
do {
err = sys_notify_fetch_result(&cli.notify, &res);
k_yield();
} while (err == -EAGAIN);
TC_PRINT("Clock control request return value: %d\n", err);
TC_PRINT("Clock control request response code: %d\n", res);
__ASSERT_NO_MSG(err == 0);
__ASSERT_NO_MSG(res == 0);
}

/*
*help function
*/
static void duration_expire(struct k_timer *timer)
{
tdata.duration_count++;
}

static void stop_expire(struct k_timer *timer)
{
tdata.stop_count++;
}

static void init_data_count(void)
{
tdata.duration_count = 0;
tdata.stop_count = 0;
}

/**
* @brief Test millisecond time duration
*
* @details initialize a timer, then providing time duration in
* millisecond, and check the duration time whether correct.
*
* @see k_timer_init(), k_timer_start(), k_timer_stop(),
* k_busy_wait()
*
*
*/
static void test_ms_time_duration(void)
{
init_data_count();
k_timer_start(&ktimer, K_MSEC(DURATION), K_NO_WAIT);

/** TESTPOINT: waiting time less than duration and check the count*/
k_busy_wait(LESS_DURATION * 1000);
zassert_true(tdata.duration_count == 0);
zassert_true(tdata.stop_count == 0);

/** TESTPOINT: proving duration in millisecond */
init_data_count();
k_timer_start(&ktimer, K_MSEC(100), K_MSEC(50));

/** TESTPOINT: waiting time more than duration and check the count */
k_usleep(1); /* align to tick */
k_busy_wait((DURATION + 1) * 1000);
zassert_true(tdata.duration_count == 1, "duration %u not 1",
tdata.duration_count);
zassert_true(tdata.stop_count == 0,
"stop %u not 0", tdata.stop_count);

/** cleanup environment */
k_timer_stop(&ktimer);
}

ZTEST(clock, test_ms_time_duration_gd_no_scalling)
{
test_ms_time_duration();
}

ZTEST(clock, test_ms_time_duration_gd_320MHz)
{
set_global_domain_frequency(MHZ(320));
test_ms_time_duration();
}

ZTEST(clock, test_ms_time_duration_gd_256MHz)
{
set_global_domain_frequency(MHZ(256));
test_ms_time_duration();
}

ZTEST(clock, test_ms_time_duration_gd_128MHz)
{
set_global_domain_frequency(MHZ(128));
test_ms_time_duration();
}

ZTEST(clock, test_ms_time_duration_gd_64MHz)
{
set_global_domain_frequency(MHZ(64));
test_ms_time_duration();
}

ZTEST_SUITE(clock, NULL, NULL, NULL, NULL, NULL);
12 changes: 12 additions & 0 deletions tests/benchmarks/kernel_freq_change/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
common:
tags:
- ci_tests_benchmarks_peripheral_load
harness: ztest

tests:
benchmarks.kernel_freq_change:
platform_allow:
- nrf54h20dk/nrf54h20/cpuapp
- nrf54h20dk/nrf54h20/cpurad
integration_platforms:
- nrf54h20dk/nrf54h20/cpuapp

Check warning on line 12 in tests/benchmarks/kernel_freq_change/testcase.yaml

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

YAMLLint (new-line-at-end-of-file)

tests/benchmarks/kernel_freq_change/testcase.yaml:12 no new line character at the end of file
Loading