diff --git a/unit_test/template/test/CMakeLists.txt b/unit_test/template/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d3a86a654849719a0e87bae4cb5976d64e9ee24 --- /dev/null +++ b/unit_test/template/test/CMakeLists.txt @@ -0,0 +1,25 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# CMakeLists.txt Template file +# + +set(TEST_SRC mod_template) +set(TEST_FILE mod_template) + +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}//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_xxx) +list(APPEND MOCK_REPLACEMENTS fwk_yyy) + +include(${SCP_ROOT}/unit_test/module_common.cmake) diff --git a/unit_test/template/test/config_template.h b/unit_test/template/test/config_template.h new file mode 100644 index 0000000000000000000000000000000000000000..31f9491555d3cbf999102be120167fc6056a9d0f --- /dev/null +++ b/unit_test/template/test/config_template.h @@ -0,0 +1,18 @@ +/* + * Arm SCP/MCP Software + * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * config_template.h Template file + */ + +#include + +#include + +#include +#include +#include + +/* Add here the configurations for your test cases */ diff --git a/unit_test/template/test/fwk_module_idx.h b/unit_test/template/test/fwk_module_idx.h new file mode 100644 index 0000000000000000000000000000000000000000..f8a0c3e4290d01c8c78c4872af65e1c15276b91a --- /dev/null +++ b/unit_test/template/test/fwk_module_idx.h @@ -0,0 +1,31 @@ +/* + * Arm SCP/MCP Software + * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * fwk_module_idx Template file + */ + +#ifndef TEST_FWK_MODULE_IDX_H +#define TEST_FWK_MODULE_IDX_H + +#include + +enum fwk_module_idx { + FWK_MODULE_IDX_MODULE1, + FWK_MODULE_IDX_MODULE2, + FWK_MODULE_IDX_MODULE3, + FWK_MODULE_IDX_COUNT, +}; + +static const fwk_id_t fwk_module_id_module1 = + FWK_ID_MODULE_INIT(FWK_MODULE_IDX_MODULE1); + +static const fwk_id_t fwk_module_id_module2 = + FWK_ID_MODULE_INIT(FWK_MODULE_IDX_MODULE2); + +static const fwk_id_t fwk_module_id_module3 = + FWK_ID_MODULE_INIT(FWK_MODULE_IDX_MODULE3); + +#endif /* TEST_FWK_MODULE_IDX_H */ diff --git a/unit_test/template/test/mod_template_unit_test.c b/unit_test/template/test/mod_template_unit_test.c new file mode 100644 index 0000000000000000000000000000000000000000..b124333169b7a95c10af56e35233e0913fb966a5 --- /dev/null +++ b/unit_test/template/test/mod_template_unit_test.c @@ -0,0 +1,47 @@ +/* + * Arm SCP/MCP Software + * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * mod_template_unit_test.c Template file + * This is the minimum file setup you need to get started with Unit Testing + */ + +#include "scp_unity.h" +#include "unity.h" + +/* + * You may need to include mocked fwk support, for example for identifiers: + * #include + * and so on. + */ + +#include + +#include +#include + +#include UNIT_TEST_SRC + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +int template_test_main(void) +{ + UNITY_BEGIN(); + + return UNITY_END(); +} + +#if !defined(TEST_ON_TARGET) +int main(void) +{ + return template_test_main(); +} +#endif diff --git a/unit_test/user_guide.md b/unit_test/user_guide.md index 2d6e89699bc32b39600c7554cd13242e488fca6e..7f9a00032f1f8d87c72a391bfcbba04c0f73257c 100644 --- a/unit_test/user_guide.md +++ b/unit_test/user_guide.md @@ -262,11 +262,11 @@ from hand-written code. ## Adding test for new modules -The ```scmi``` and ```scmi_clock``` test directories are provided -as a reference for new modules. The following process is intended -as a general guide, and will vary on a case-by-case basis. +A template of minimum required files is provided as a reference for new modules. -1. Duplicate existing reference test directories as a starting point. +See unit_test/template/test + +1. Duplicate existing reference test directory as a starting point. 2. Modify *.cmake file for our specific test case: a. Change TEST_MODULE to name of module @@ -312,9 +312,6 @@ the guidelines below: - One test scenario for each test case. For example, if testing one case for a function, have a test function for that case only. - Name the test functions according to the test being performed. -- When an addition or change is made to a module that did not have unit testing - before, it is recommended that the enclosing functions affected by the change - should then be added for unit testing. ### Executing Tests on target hardware or FVP models @@ -334,3 +331,15 @@ to understand setup needed building test that can be executed on target 4. Platform must provide definition for plat_execute_all_tests which is called by module/ut. See example product/juno/scp_ut/tests_entry.c + +## Unit testing requirement guidelines + +Unit Testing (UT) has been introduced with the aim of improving the quality and +reliability of the code. +In this introductory phase, we suggest that contributors become familiar with +the unit testing in SCP-firmware. +In the meantime, while we are not enforcing contibutors to add unit testing on +their additions or modifications, we encourage them to attempt adding UT +whenever compatible with their development. +We foresee that UT will become a mandatory requirement later in the future for +contributions into SCP-firmware project.