From 6b6a4fcac00bf46b68bf7e59a666e7a2d1680096 Mon Sep 17 00:00:00 2001 From: Nicola Mazzucato Date: Tue, 20 Nov 2018 09:24:08 +0000 Subject: [PATCH 1/7] doc: Add comments describing the module pre-runtime phase Change-Id: I7c7990674526c0ecb1cba7362bc8ceccce174639 Signed-off-by: Nicola Mazzucato --- doc/framework.md | 12 ++++++++---- product/host/fw/firmware.mk | 3 +++ product/n1sdp/mcp_ramfw/firmware.mk | 3 +++ product/n1sdp/scp_ramfw/firmware.mk | 3 +++ product/sgi575/mcp_romfw/firmware.mk | 3 +++ product/sgi575/scp_ramfw/firmware.mk | 3 +++ product/sgi575/scp_romfw/firmware.mk | 3 +++ product/sgm775/scp_ramfw/firmware.mk | 3 +++ product/sgm775/scp_romfw/firmware.mk | 3 +++ 9 files changed, 32 insertions(+), 4 deletions(-) diff --git a/doc/framework.md b/doc/framework.md index 2d743157f..9b3ed5944 100644 --- a/doc/framework.md +++ b/doc/framework.md @@ -184,12 +184,12 @@ NULL then the framework assumes that no elements will be provided. Each of the entries in the element table is a pointer to a *struct fwk_element* structure. Elements are made available to the module during the *element -initialization* phase. +initialization* stage. The second member of the structure is an optional void pointer that points to module-specific configuration data. The format of this configuration data is defined by the module itself. This data is made available to the module -during the *module initialization* phase. +during the *module initialization* stage. ### Elements @@ -378,6 +378,10 @@ order: - Bind - Start +Each stage is executed for each module before moving onto the next stage, and +modules are processed in the order they are given in the *BS_FIRMWARE_MODULES* +list. + Once these stages have all been completed the firmware as a whole is considered to be fully initialized and execution enters the *runtime phase*. The stages are described in the following sub-sections. @@ -514,7 +518,7 @@ functionality of the framework. If this driver module requires configuration data to be used in the log driver functions, the usual method of module configuration will not suffice. This is because the log driver functions could be called before the module receives its -configuration data in the initialization phase of the framework. To allow the +configuration data in the initialization stage of the framework. To allow the passing of configuration data to this module, the log component in the framework externally declares a pointer to configuration data: (fwk_log.h) @@ -538,4 +542,4 @@ void *fwk_log_driver_config = &cfg; The driver module can then access its log framework related configuration data at any time. It is expected that the driver module performs initialization using -this configuration data in the fwk_log_driver_init() function. \ No newline at end of file +this configuration data in the fwk_log_driver_init() function. diff --git a/product/host/fw/firmware.mk b/product/host/fw/firmware.mk index a683670ba..0d45a2460 100644 --- a/product/host/fw/firmware.mk +++ b/product/host/fw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := host BS_FIRMWARE_HAS_MULTITHREADING := yes diff --git a/product/n1sdp/mcp_ramfw/firmware.mk b/product/n1sdp/mcp_ramfw/firmware.mk index 74d827de7..9fd0b8cd1 100644 --- a/product/n1sdp/mcp_ramfw/firmware.mk +++ b/product/n1sdp/mcp_ramfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m7 BS_FIRMWARE_HAS_MULTITHREADING := yes diff --git a/product/n1sdp/scp_ramfw/firmware.mk b/product/n1sdp/scp_ramfw/firmware.mk index 4e2d2cfe0..9ec509e29 100644 --- a/product/n1sdp/scp_ramfw/firmware.mk +++ b/product/n1sdp/scp_ramfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m7 BS_FIRMWARE_HAS_MULTITHREADING := yes diff --git a/product/sgi575/mcp_romfw/firmware.mk b/product/sgi575/mcp_romfw/firmware.mk index 618d0b3d6..ce2a741f8 100644 --- a/product/sgi575/mcp_romfw/firmware.mk +++ b/product/sgi575/mcp_romfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m7 BS_FIRMWARE_HAS_MULTITHREADING := no diff --git a/product/sgi575/scp_ramfw/firmware.mk b/product/sgi575/scp_ramfw/firmware.mk index ebc4b668a..1a3371114 100644 --- a/product/sgi575/scp_ramfw/firmware.mk +++ b/product/sgi575/scp_ramfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m7 BS_FIRMWARE_HAS_MULTITHREADING := yes diff --git a/product/sgi575/scp_romfw/firmware.mk b/product/sgi575/scp_romfw/firmware.mk index 4d8359ce1..6368507fa 100644 --- a/product/sgi575/scp_romfw/firmware.mk +++ b/product/sgi575/scp_romfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m7 BS_FIRMWARE_HAS_MULTITHREADING := no diff --git a/product/sgm775/scp_ramfw/firmware.mk b/product/sgm775/scp_ramfw/firmware.mk index ed810a8fd..0949b4828 100644 --- a/product/sgm775/scp_ramfw/firmware.mk +++ b/product/sgm775/scp_ramfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m3 BS_FIRMWARE_HAS_MULTITHREADING := yes diff --git a/product/sgm775/scp_romfw/firmware.mk b/product/sgm775/scp_romfw/firmware.mk index 1250577ee..899f7ce1f 100644 --- a/product/sgm775/scp_romfw/firmware.mk +++ b/product/sgm775/scp_romfw/firmware.mk @@ -4,6 +4,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# The order of the modules in the BS_FIRMWARE_MODULES list is the order in which +# the modules are initialized, bound, started during the pre-runtime phase. +# BS_FIRMWARE_CPU := cortex-m3 BS_FIRMWARE_HAS_MULTITHREADING := no -- GitLab From ae5d178b5921c47017ac3504ec224ce29226bf69 Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 14:31:48 +0000 Subject: [PATCH 2/7] test: add test and refactor for fwk_module_bind Comments have been added to clarify the tests. The tests have been moved at the end of the file to follow the declaration order of the functions in fwk_module.h. Sub-tests have been added to cover missing paths. Change-Id: I0c22a76d87e093db151894714e7c80fbb14a8e19 Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 150 ++++++++++++++++++++++--------- 1 file changed, 106 insertions(+), 44 deletions(-) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index 113cf1b13..8d1ec7d72 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -4,7 +4,6 @@ * * SPDX-License-Identifier: BSD-3-Clause */ - #include #include #include @@ -87,6 +86,7 @@ static int bind_count_call; static int start_return_val; static int start_count_call; static int process_bind_request_return_val; +static bool process_bind_request_return_api; static bool get_element_table0_return_val; static bool get_element_table1_return_val; static int process_event_return_val; @@ -141,7 +141,8 @@ static int process_bind_request(fwk_id_t source_id, fwk_id_t target_id, (void) source_id; (void) target_id; (void) api_id; - *api = &fake_api; + if (process_bind_request_return_api) + *api = &fake_api; return process_bind_request_return_val; } @@ -215,6 +216,7 @@ static void test_case_setup(void) bind_return_val = FWK_SUCCESS; start_return_val = FWK_SUCCESS; process_bind_request_return_val = FWK_SUCCESS; + process_bind_request_return_api = true; process_event_return_val = FWK_SUCCESS; thread_init_return_val = FWK_SUCCESS; @@ -481,24 +483,6 @@ static void test___fwk_module_init_failure(void) assert(state == FWK_MODULE_STATE_UNINITIALIZED); } -static void test_fwk_module_bind_failure(void) -{ - int result; - struct fake_api fake_api; - - /* Start function failure */ - start_return_val = FWK_E_PARAM; - __fwk_module_reset(); - result = __fwk_module_init(); - assert(result == FWK_E_PARAM); - start_return_val = FWK_SUCCESS; - - /* The framework is not in the good stage for binding */ - process_bind_request_return_val = FWK_SUCCESS; - result = fwk_module_bind(MODULE0_ID, API1_ID, &fake_api); - assert(result == FWK_E_STATE); -} - static void test___fwk_module_init_bind_failure(void) { int result; @@ -533,27 +517,6 @@ static void test___fwk_module_init_bind_failure(void) } -static void test_fwk_module_bind(void) -{ - int result; - struct fake_api *fake_api; - - /* The framework component is in the bound stage */ - result = fwk_module_bind(FWK_ID_MODULE(2), API0_ID, &fake_api); - assert(result == FWK_E_PARAM); - - result = fwk_module_bind(MODULE1_ID, FWK_ID_API(1, 0), &fake_api); - assert(result == FWK_E_PARAM); - - process_bind_request_return_val = FWK_E_PARAM; - result = fwk_module_bind(MODULE0_ID, API1_ID, &fake_api); - assert(result == FWK_E_PARAM); - - process_bind_request_return_val = FWK_SUCCESS; - result = fwk_module_bind(MODULE0_ID, API1_ID, &fake_api); - assert(result == FWK_SUCCESS); -} - static void test___fwk_module_init_start_failure(void) { int result; @@ -936,14 +899,111 @@ static void test_fwk_module_get_data(void) assert(result == NULL); } +static void test_fwk_module_bind_stage_failure(void) +{ + int result; + struct fake_api api; + + /* + * The framework is forced into the initialization stage + */ + __fwk_module_reset(); + init_return_val = FWK_E_PARAM; + result = __fwk_module_init(); + assert(result == FWK_E_PARAM); + init_return_val = FWK_SUCCESS; + + /* + * The binding request should fail because the framework is in + * MODULE_STAGE_INITIALIZE and the module is in + * FWK_MODULE_STATE_UNINITIALIZED state. + */ + result = fwk_module_bind(MODULE0_ID, API1_ID, &api); + assert(result == FWK_E_STATE); + + /* + * The framework is forced into the start stage + */ + start_return_val = FWK_E_PARAM; + __fwk_module_reset(); + result = __fwk_module_init(); + assert(result == FWK_E_PARAM); + start_return_val = FWK_SUCCESS; + + /* + * The binding request should fail because it cannot be called when the + * framework is in MODULE_STAGE_START stage. + */ + process_bind_request_return_val = FWK_SUCCESS; + result = fwk_module_bind(MODULE0_ID, API1_ID, &api); + assert(result == FWK_E_STATE); +} + +static void test_fwk_module_bind(void) +{ + int result; + struct fake_api *api; + void *null_api = NULL; + + /* The framework component is forced into the bound stage */ + __fwk_module_reset(); + bind_return_val = FWK_E_PARAM; + result = __fwk_module_init(); + assert(result == FWK_E_PARAM); + bind_return_val = FWK_SUCCESS; + + /* The binding request should fail because the target ID is not valid */ + result = fwk_module_bind(FWK_ID_MODULE(2), API0_ID, &api); + assert(result == FWK_E_PARAM); + + /* The binding request should fail because the API ID is not valid */ + result = fwk_module_bind(MODULE1_ID, FWK_ID_API(1, 0), &api); + assert(result == FWK_E_PARAM); + + /* + * The binding request should fail because API0_ID does not belong to + * MODULE1_ID. + */ + result = fwk_module_bind(MODULE1_ID, API0_ID, &api); + assert(result == FWK_E_PARAM); + + /* + * The binding request should fail because the API address pointer is NULL + */ + result = fwk_module_bind(MODULE0_ID, API1_ID, NULL); + assert(result == FWK_E_PARAM); + + /* + * The binding request should fail because the process_bind_request function + * associated with the module fails. + */ + process_bind_request_return_val = FWK_E_PARAM; + result = fwk_module_bind(MODULE0_ID, API1_ID, &api); + assert(result == FWK_E_PARAM); + process_bind_request_return_val = FWK_SUCCESS; + + /* + * The binding request should fail because the address of the API is + * initially NULL and is not modified by the module process_bind_request() + * function. + */ + process_bind_request_return_api = false; + result = fwk_module_bind(MODULE0_ID, API1_ID, &null_api); + assert(result == FWK_E_HANDLER); + assert(null_api == NULL); + process_bind_request_return_api = true; + + /* The binding request should return successfully */ + result = fwk_module_bind(MODULE0_ID, API1_ID, &api); + assert(result == FWK_SUCCESS); +} + static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test___fwk_module_init_memory_allocation_failure), FWK_TEST_CASE(test_fwk_module_check_call_failed), FWK_TEST_CASE(test___fwk_module_init_module_desc_bad_params), FWK_TEST_CASE(test___fwk_module_init_failure), - FWK_TEST_CASE(test_fwk_module_bind_failure), FWK_TEST_CASE(test___fwk_module_init_bind_failure), - FWK_TEST_CASE(test_fwk_module_bind), FWK_TEST_CASE(test___fwk_module_init_start_failure), FWK_TEST_CASE(test_fwk_check_call_succeed), FWK_TEST_CASE(test_fwk_thread_failure), @@ -955,7 +1015,9 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test_fwk_module_is_valid_event_id), FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), FWK_TEST_CASE(test_fwk_module_get_name), - FWK_TEST_CASE(test_fwk_module_get_data) + FWK_TEST_CASE(test_fwk_module_get_data), + FWK_TEST_CASE(test_fwk_module_bind_stage_failure), + FWK_TEST_CASE(test_fwk_module_bind) }; struct fwk_test_suite_desc test_suite = { -- GitLab From 9e12e1b050b086dd6c1c5aa33a1596334714c1a7 Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 15:01:30 +0000 Subject: [PATCH 3/7] test: add sub-test and refactor fwk_module_check_call Comments have been added to describe more the tests. The tests have been moved down with respect to the function declaration in fwk_module.h. test_fwk_module_check_call_failed is now independent of the order of execution of the tests. Change-Id: Ia33a1a91eb742c883da5d6f81fc77258ce0a8f20 Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 91 +++++++++++++++++++------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index 8d1ec7d72..24a625da4 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -359,22 +359,6 @@ static void test___fwk_module_init_memory_allocation_failure(void) assert(__fwk_module_get_ctx(MODULE1_ID)->subscription_dlist_table == NULL); } -static void test_fwk_module_check_call_failed(void) -{ - int result; - fwk_id_t id; - - /* Invalid ID */ - id = FWK_ID_ELEMENT(0xEF, 0xDBE); - result = fwk_module_check_call(id); - assert(result == FWK_E_PARAM); - - /* Module 0 is not initialized */ - id = MODULE0_ID; - result = fwk_module_check_call(id); - assert(result == FWK_E_INIT); -} - static void test___fwk_module_init_module_desc_bad_params(void) { int result; @@ -549,25 +533,6 @@ static void test___fwk_module_init_start_failure(void) assert(state == (FWK_MODULE_STATE_BOUND)); } -static void test_fwk_check_call_succeed(void) -{ - int result; - fwk_id_t id; - - /* Force the modules to be initialized but not bound */ - bind_return_val = FWK_E_PARAM; - __fwk_module_reset(); - result = __fwk_module_init(); - - id = MODULE0_ID; - result = fwk_module_check_call(id); - assert(result == FWK_SUCCESS); - - id = ELEM0_ID; - result = fwk_module_check_call(id); - assert(result == FWK_SUCCESS); -} - static void test_fwk_thread_failure(void) { int result; @@ -899,6 +864,58 @@ static void test_fwk_module_get_data(void) assert(result == NULL); } +static void test_fwk_module_check_call_failed(void) +{ + int result; + fwk_id_t id; + struct fwk_module_ctx *module_ctx; + + __fwk_module_reset(); + __fwk_module_init(); + + /* The ID is invalid, so that __fwk_module_get_state fails */ + id = FWK_ID_ELEMENT(0xEF, 0xDBE); + result = fwk_module_check_call(id); + assert(result == FWK_E_PARAM); + + /* The modules are not successfully initialized */ + init_return_val = FWK_E_PARAM; + __fwk_module_reset(); + __fwk_module_init(); + + /* Module 0 is not initialized */ + id = MODULE0_ID; + result = fwk_module_check_call(id); + assert(result == FWK_E_INIT); + + /* Force module 0 in FWK_MODULE_STATE_SUSPENDED state */ + module_ctx = __fwk_module_get_ctx(id); + module_ctx->state = FWK_MODULE_STATE_SUSPENDED; + result = fwk_module_check_call(id); + assert(result == FWK_E_STATE); +} + +static void test_fwk_module_check_call_succeed(void) +{ + int result; + fwk_id_t id; + + /* Force the modules to be initialized but not bound */ + bind_return_val = FWK_E_PARAM; + __fwk_module_reset(); + result = __fwk_module_init(); + + /* The module is initialized so the function should return successfully */ + id = MODULE0_ID; + result = fwk_module_check_call(id); + assert(result == FWK_SUCCESS); + + /* The element is initialized so the function should return successfully */ + id = ELEM0_ID; + result = fwk_module_check_call(id); + assert(result == FWK_SUCCESS); +} + static void test_fwk_module_bind_stage_failure(void) { int result; @@ -1000,12 +1017,10 @@ static void test_fwk_module_bind(void) static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test___fwk_module_init_memory_allocation_failure), - FWK_TEST_CASE(test_fwk_module_check_call_failed), FWK_TEST_CASE(test___fwk_module_init_module_desc_bad_params), FWK_TEST_CASE(test___fwk_module_init_failure), FWK_TEST_CASE(test___fwk_module_init_bind_failure), FWK_TEST_CASE(test___fwk_module_init_start_failure), - FWK_TEST_CASE(test_fwk_check_call_succeed), FWK_TEST_CASE(test_fwk_thread_failure), FWK_TEST_CASE(test___fwk_module_init_succeed), FWK_TEST_CASE(test___fwk_module_get_state), @@ -1016,6 +1031,8 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), FWK_TEST_CASE(test_fwk_module_get_name), FWK_TEST_CASE(test_fwk_module_get_data), + FWK_TEST_CASE(test_fwk_module_check_call_failed), + FWK_TEST_CASE(test_fwk_module_check_call_succeed), FWK_TEST_CASE(test_fwk_module_bind_stage_failure), FWK_TEST_CASE(test_fwk_module_bind) }; -- GitLab From 33d8304e89d31443954fd93d15e0c33d54ed1516 Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 16:23:15 +0000 Subject: [PATCH 4/7] test: add test for fwk_module_is_valid_sub_element_id Change-Id: I1bcd66e6ddb51587a4d7a824331eebb8b117698c Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index 24a625da4..7de545a84 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -16,6 +16,7 @@ #define ELEM0_IDX 0 #define ELEM1_IDX 1 #define ELEM2_IDX 0 +#define SUB_ELEM0_IDX 0 #define API0_IDX 0 #define API1_IDX 1 #define EVENT0_IDX 0 @@ -30,6 +31,9 @@ #define ELEM0_ID FWK_ID_ELEMENT(MODULE0_IDX, ELEM0_IDX) #define ELEM1_ID FWK_ID_ELEMENT(MODULE0_IDX, ELEM1_IDX) #define ELEM2_ID FWK_ID_ELEMENT(MODULE1_IDX, ELEM2_IDX) +#define SUB_ELEM0_ID FWK_ID_SUB_ELEMENT(MODULE0_IDX, \ + ELEM0_IDX, \ + SUB_ELEM0_IDX) #define API0_ID FWK_ID_API(MODULE0_IDX, API0_IDX) #define API1_ID FWK_ID_API(MODULE0_IDX, API1_IDX) #define EVENT0_ID FWK_ID_EVENT(MODULE1_IDX, EVENT0_IDX) @@ -260,6 +264,7 @@ static void test_case_setup(void) fake_element_desc_table0[0].name = "FAKE ELEM 0"; fake_element_desc_table0[0].data = &config_elem0; + fake_element_desc_table0[0].sub_element_count = 1; fake_element_desc_table0[1].name = "FAKE ELEM 1"; fake_element_desc_table0[1].data = &config_elem1; fake_element_desc_table0[2].name = NULL; @@ -710,6 +715,34 @@ static void test_fwk_module_is_valid_element_id(void) assert(!result); } +static void test_fwk_module_is_valid_sub_element_id(void) +{ + bool result; + + /* Valid sub-element ID */ + result = fwk_module_is_valid_sub_element_id(SUB_ELEM0_ID); + assert(result); + + /* Invalid type */ + result = fwk_module_is_valid_sub_element_id(NOTIFICATION0_ID); + assert(!result); + + /* Invalid module IDX */ + result = fwk_module_is_valid_sub_element_id(FWK_ID_SUB_ELEMENT(5, ELEM0_IDX, + SUB_ELEM0_IDX)); + assert(!result); + + /* Invalid element IDX */ + result = fwk_module_is_valid_sub_element_id(FWK_ID_SUB_ELEMENT(MODULE0_IDX, + 5, SUB_ELEM0_IDX)); + assert(!result); + + /* Invalid sub-element ID */ + result = fwk_module_is_valid_sub_element_id(FWK_ID_SUB_ELEMENT(MODULE0_IDX, + ELEM0_IDX, 5)); + assert(!result); +} + static void test_fwk_module_is_valid_api_id(void) { fwk_id_t id; @@ -1026,6 +1059,7 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test___fwk_module_get_state), FWK_TEST_CASE(test_fwk_module_is_valid_module_id), FWK_TEST_CASE(test_fwk_module_is_valid_element_id), + FWK_TEST_CASE(test_fwk_module_is_valid_sub_element_id), FWK_TEST_CASE(test_fwk_module_is_valid_api_id), FWK_TEST_CASE(test_fwk_module_is_valid_event_id), FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), -- GitLab From 0c914e3b41f1a5613a08b9ae6522515bef64439a Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 16:24:37 +0000 Subject: [PATCH 5/7] test: add test for fwk_module_is_valid_entity_id Change-Id: I34616c0adf5479e56da53cf64322e67729bd589d Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index 7de545a84..2571f7ba8 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -743,6 +743,39 @@ static void test_fwk_module_is_valid_sub_element_id(void) assert(!result); } +static void test_fwk_module_is_valid_entity_id(void) +{ + bool result; + + /* Valid module ID */ + result = fwk_module_is_valid_entity_id(MODULE0_ID); + assert(result); + + /* Invalid module ID */ + result = fwk_module_is_valid_entity_id(FWK_ID_MODULE(5)); + assert(!result); + + /* Valid element ID */ + result = fwk_module_is_valid_entity_id(ELEM0_ID); + assert(result); + + /* Invalid element ID */ + result = fwk_module_is_valid_entity_id(FWK_ID_ELEMENT(5, 5)); + assert(!result); + + /* Valid sub-element ID */ + result = fwk_module_is_valid_entity_id(SUB_ELEM0_ID); + assert(result); + + /* Invalid sub-element ID */ + result = fwk_module_is_valid_sub_element_id(FWK_ID_SUB_ELEMENT(5, 5, 5)); + assert(!result); + + /* Invalid entity as a notification is not an entity */ + result = fwk_module_is_valid_entity_id(NOTIFICATION0_ID); + assert(!result); +} + static void test_fwk_module_is_valid_api_id(void) { fwk_id_t id; @@ -1060,6 +1093,7 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test_fwk_module_is_valid_module_id), FWK_TEST_CASE(test_fwk_module_is_valid_element_id), FWK_TEST_CASE(test_fwk_module_is_valid_sub_element_id), + FWK_TEST_CASE(test_fwk_module_is_valid_entity_id), FWK_TEST_CASE(test_fwk_module_is_valid_api_id), FWK_TEST_CASE(test_fwk_module_is_valid_event_id), FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), -- GitLab From e8d0304302530ac3c92c1c612f4806e5734616d0 Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 16:25:07 +0000 Subject: [PATCH 6/7] test: add test for fwk_module_get_element_count Change-Id: I0567ad4ec82892f5028aa107b476252f74cc4ef8 Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index 2571f7ba8..fddde0c1a 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -884,6 +884,23 @@ static void test_fwk_module_is_valid_notification_id(void) assert(!result); } +static void test_fwk_module_get_element_count(void) +{ + int element_count; + + /* Valid module ID with 2 elements */ + element_count = fwk_module_get_element_count(MODULE0_ID); + assert(element_count == 2); + + /* Invalid module ID */ + element_count = fwk_module_get_element_count(FWK_ID_MODULE(5)); + assert(element_count == FWK_E_PARAM); + + /* The function should fails as it expects a module ID */ + element_count = fwk_module_get_element_count(ELEM0_ID); + assert(element_count == FWK_E_PARAM); +} + static void test_fwk_module_get_name(void) { fwk_id_t id; @@ -1097,6 +1114,7 @@ static const struct fwk_test_case_desc test_case_table[] = { FWK_TEST_CASE(test_fwk_module_is_valid_api_id), FWK_TEST_CASE(test_fwk_module_is_valid_event_id), FWK_TEST_CASE(test_fwk_module_is_valid_notification_id), + FWK_TEST_CASE(test_fwk_module_get_element_count), FWK_TEST_CASE(test_fwk_module_get_name), FWK_TEST_CASE(test_fwk_module_get_data), FWK_TEST_CASE(test_fwk_module_check_call_failed), -- GitLab From 8505659ac9aa6f20d3d21c5a443285fe6faabd7d Mon Sep 17 00:00:00 2001 From: Elieva Pignat Date: Mon, 7 Jan 2019 16:25:38 +0000 Subject: [PATCH 7/7] test: fwk_module tests independent of the order The execution order of the tests should not affect the tests. The framework is reset and re-initiated in the setup function such that the framework is in a known state before the start of each test. Change-Id: Iea393f69b5f6fc294a6efa531cd122ba6758956b Signed-off-by: Elieva Pignat --- framework/test/test_fwk_module.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/framework/test/test_fwk_module.c b/framework/test/test_fwk_module.c index fddde0c1a..e3d932af9 100644 --- a/framework/test/test_fwk_module.c +++ b/framework/test/test_fwk_module.c @@ -288,6 +288,9 @@ static void test_case_setup(void) module_config_table[0] = &fake_module_config0; module_config_table[1] = &fake_module_config1; module_config_table[2] = NULL; + + __fwk_module_reset(); + __fwk_module_init(); } static void test___fwk_module_init_memory_allocation_failure(void) @@ -602,6 +605,8 @@ static void test___fwk_module_init_succeed(void) /* Module 1 has no element */ fake_module_config1.get_element_table = NULL; + bind_count_call = 0; + start_count_call = 0; __fwk_module_reset(); result = __fwk_module_init(); assert(result == FWK_SUCCESS); @@ -953,9 +958,6 @@ static void test_fwk_module_check_call_failed(void) fwk_id_t id; struct fwk_module_ctx *module_ctx; - __fwk_module_reset(); - __fwk_module_init(); - /* The ID is invalid, so that __fwk_module_get_state fails */ id = FWK_ID_ELEMENT(0xEF, 0xDBE); result = fwk_module_check_call(id); -- GitLab