Skip to content

Commit

Permalink
fch_polled/unit_test: Add unit tests for fch_polled
Browse files Browse the repository at this point in the history
This change adds unit tests for new fch_polled
module.

Change-Id: Ia6ec7e5d009afd6c75cff3894ef4e7a98b4e19f3
Signed-off-by: Girish Pathak <[email protected]>
Signed-off-by: Ahmed Gadallah <[email protected]>
  • Loading branch information
girishpathak authored and leandro-arm committed Sep 29, 2023
1 parent 53823a0 commit db575b2
Show file tree
Hide file tree
Showing 9 changed files with 1,114 additions and 0 deletions.
30 changes: 30 additions & 0 deletions module/fch_polled/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Arm SCP/MCP Software
# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#

set(TEST_SRC mod_fch_polled)
set(TEST_FILE mod_fch_polled)

set(UNIT_TEST_TARGET mod_${TEST_MODULE}_unit_test)

set(MODULE_SRC ${MODULE_ROOT}/${TEST_MODULE}/src)
set(MODULE_INC ${MODULE_ROOT}/${TEST_MODULE}/include)
list(APPEND OTHER_MODULE_INC ${MODULE_ROOT}/transport/include)
list(APPEND OTHER_MODULE_INC ${MODULE_ROOT}/timer/include)

set(MODULE_UT_SRC ${CMAKE_CURRENT_LIST_DIR})
set(MODULE_UT_INC ${CMAKE_CURRENT_LIST_DIR})
set(MODULE_UT_MOCK_SRC ${CMAKE_CURRENT_LIST_DIR}/mocks)

list(APPEND MOCK_REPLACEMENTS fwk_module)
list(APPEND MOCK_REPLACEMENTS fwk_core)
list(APPEND MOCK_REPLACEMENTS fwk_interrupt)
list(APPEND MOCK_REPLACEMENTS fwk_id)

include(${SCP_ROOT}/unit_test/module_common.cmake)

target_compile_definitions(${UNIT_TEST_TARGET} PRIVATE BUILD_HAS_MOD_TRANSPORT)
target_compile_definitions(${UNIT_TEST_TARGET} PRIVATE BUILD_HAS_FAST_CHANNELS)
127 changes: 127 additions & 0 deletions module/fch_polled/test/config_fch_polled.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <Mockfwk_module.h>

#include <mod_fch_polled.h>

#include <fwk_element.h>
#include <fwk_id.h>
#include <fwk_macros.h>

#define FCH_MIN_POLL_RATE_US 4000

#define SCP_SCMI_FAST_CHANNEL_BASE 0xA0000000
#define SCP_SYSTEM_ACCESS_PORT1_BASE 0xB0000000

#define FAKE_RATE_LIMIT 0x0FFF

enum fake_fch_polled {
FAKE_FCH_POLLED_0,
FAKE_FCH_POLLED_1,
FAKE_FCH_POLLED_COUNT,
};

#define FCH_ADDR_INIT(scp_addr, ap_addr) \
&((struct mod_fch_polled_channel_config){ \
.fch_addr = { \
.local_view_address = scp_addr, \
.target_view_address = ap_addr, \
} })

static struct mod_fch_polled_config fake_fch_config = {
.fch_alarm_id = FWK_ID_SUB_ELEMENT_INIT(FWK_MODULE_IDX_TIMER, 0, 0),
.fch_poll_rate = FCH_MIN_POLL_RATE_US,
.rate_limit = FAKE_RATE_LIMIT,
};

static struct mod_fch_polled_config fake_fch_config_2 = {
.fch_alarm_id = FWK_ID_SUB_ELEMENT_INIT(FWK_MODULE_IDX_TIMER, 0, 0),
.fch_poll_rate = (FCH_MIN_POLL_RATE_US - 1),
.rate_limit = FAKE_RATE_LIMIT,
};

/*!
*\brief Fast Channels in shared memory. Similar to mod_scmi_perf
*/
struct mod_scmi_perf_fast_channel_limit {
/*! Performance limit max. */
uint32_t range_max;
/*! Performance limit min. */
uint32_t range_min;
};

/*!
*\brief Fast channels memory offset
*/
enum mod_scmi_perf_fast_channel_memory_offset {
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LEVEL_SET = 0,
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LIMIT_SET = sizeof(uint32_t),
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LEVEL_GET =
sizeof(uint32_t) + sizeof(struct mod_scmi_perf_fast_channel_limit),
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LIMIT_GET =
sizeof(uint32_t) * 2 + sizeof(struct mod_scmi_perf_fast_channel_limit),
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_TOTAL = sizeof(uint32_t) * 2 +
sizeof(struct mod_scmi_perf_fast_channel_limit) * 2
};

#define FCH_ADDRESS_LEVEL_SET(PERF_IDX) \
(SCP_SCMI_FAST_CHANNEL_BASE + \
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LEVEL_SET + \
(MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_TOTAL * PERF_IDX))

#define FCH_ADDRESS_LIMIT_SET(PERF_IDX) \
(SCP_SCMI_FAST_CHANNEL_BASE + \
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LIMIT_SET + \
(MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_TOTAL * PERF_IDX))

#define FCH_ADDRESS_LEVEL_SET_AP(PERF_IDX) \
(SCP_SCMI_FAST_CHANNEL_BASE + \
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LEVEL_SET + \
(MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_TOTAL * PERF_IDX) - \
SCP_SYSTEM_ACCESS_PORT1_BASE)

#define FCH_ADDRESS_LIMIT_SET_AP(PERF_IDX) \
(SCP_SCMI_FAST_CHANNEL_BASE + \
MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_LIMIT_SET + \
(MOD_SCMI_PERF_FAST_CHANNEL_OFFSET_TOTAL * PERF_IDX) - \
SCP_SYSTEM_ACCESS_PORT1_BASE)

static const struct fwk_element fake_fch_polled_element_table[] = {
[0] = {
.name = "FCH_0_LEVEL_SET",
.data = FCH_ADDR_INIT(
FCH_ADDRESS_LEVEL_SET(0),
FCH_ADDRESS_LEVEL_SET_AP(0)
)
},
[1] = {
.name = "FCH_0_LIMIT_SET",
.data =FCH_ADDR_INIT(
FCH_ADDRESS_LIMIT_SET(0),
FCH_ADDRESS_LIMIT_SET_AP(0)
),
},

};

static const struct fwk_element *fch_polled_get_element_table(
fwk_id_t module_id)
{
return fake_fch_polled_element_table;
}

struct fwk_module_config config_fake_fch_polled = {
.data = &fake_fch_config,
.elements = FWK_MODULE_DYNAMIC_ELEMENTS(fch_polled_get_element_table),
};

static fwk_id_t fake_fch_0 =
FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_FCH_POLLED, FAKE_FCH_POLLED_0);

static const fwk_id_t fake_fch_1 =
FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_FCH_POLLED, FAKE_FCH_POLLED_1);
20 changes: 20 additions & 0 deletions module/fch_polled/test/fwk_module_idx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Arm SCP/MCP Software
* Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef TEST_FWK_MODULE_MODULE_IDX_H
#define TEST_FWK_MODULE_MODULE_IDX_H

#include <fwk_id.h>

enum fwk_module_idx {
FWK_MODULE_IDX_TRANSPORT,
FWK_MODULE_IDX_TIMER,
FWK_MODULE_IDX_FCH_POLLED,
FWK_MODULE_IDX_COUNT,
};

#endif /* TEST_FWK_MODULE_MODULE_IDX_H */
4 changes: 4 additions & 0 deletions module/fch_polled/test/mocks/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DisableFormat": true,
"SortIncludes": false,
}
Loading

0 comments on commit db575b2

Please sign in to comment.