Commit 78fe3646 authored by Sean Kyer's avatar Sean Kyer Committed by Henrik Brix Andersen
Browse files

tests: cpu_freq: Add SoC and on_demand tests



Add tests for CPU frequency subsystem covering
SoC integration of pstate as well as the on_demand
policy.

Signed-off-by: default avatarSean Kyer <Sean.Kyer@analog.com>
parent 3b60bb91
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 Analog Devices, Inc.
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(cpu_freq_soc_test)

target_sources(app PRIVATE src/main.c)
+12 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 Analog Devices, Inc.
#
# SPDX-License-Identifier: Apache-2.0

CONFIG_LOG=y
CONFIG_ZTEST=y

CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_LOG_LEVEL_DBG=y
CONFIG_CPU_FREQ_POLICY_ON_DEMAND=y
# Long interval so test can run without automatic frequency changes
CONFIG_CPU_FREQ_INTERVAL_MS=1000000
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Analog Devices, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
#include <zephyr/logging/log.h>
#include <zephyr/cpu_freq/cpu_freq.h>

LOG_MODULE_REGISTER(cpu_freq_soc_test, LOG_LEVEL_INF);

const struct pstate *soc_pstates_dt[] = {
	DT_FOREACH_CHILD_STATUS_OKAY_SEP(DT_PATH(performance_states), PSTATE_DT_GET, (,))};

/*
 * Test SoC integration of CPU Freq
 */
ZTEST(cpu_freq_soc, test_soc_pstates)
{
	int ret;

	zassert_true(ARRAY_SIZE(soc_pstates_dt) > 0, "No p-states defined in devicetree");

	LOG_INF("%d p-states defined for %s", ARRAY_SIZE(soc_pstates_dt), CONFIG_BOARD_TARGET);

	zassert_equal(cpu_freq_pstate_set(NULL), -EINVAL, "Expected -EINVAL for NULL pstate");

	for (int i = 0; i < ARRAY_SIZE(soc_pstates_dt); i++) {
		const struct pstate *state = soc_pstates_dt[i];

		/* Set performance state using pstate driver */
		ret = cpu_freq_pstate_set(state);
		zassert_equal(ret, 0, "Failed to set p-state %d", i);
	}
}

ZTEST_SUITE(cpu_freq_soc, NULL, NULL, NULL, NULL, NULL);
+9 −0
Original line number Diff line number Diff line
tests:
  subsys.cpu_freq.soc:
    platform_allow:
      - native_sim
      - native_sim/native/64
    tags: cpu_freq
    integration_platforms:
      - native_sim
      - native_sim/native/64
+9 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 Analog Devices, Inc.
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(cpu_freq_on_demand_test)

target_sources(app PRIVATE src/main.c)
Loading