From 31774262d28dd19de6d572d7320b0f30241d793b Mon Sep 17 00:00:00 2001 From: Niall Mullane Date: Wed, 28 Jul 2021 16:38:11 -0400 Subject: [PATCH 1/4] Fix #1685, Add table registration functional tests This commit also restructures header files to be used by all table functional tests This commit also adds to the global test struct with constants used by all table functional tests --- modules/cfe_testcase/CMakeLists.txt | 2 + modules/cfe_testcase/src/cfe_test.c | 5 +- modules/cfe_testcase/src/cfe_test.h | 6 + modules/cfe_testcase/src/cfe_test_table.c | 52 +++++++ modules/cfe_testcase/src/cfe_test_table.h | 62 ++++++++ .../cfe_testcase/src/tbl_registration_test.c | 138 ++++++++++++++++++ 6 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 modules/cfe_testcase/src/cfe_test_table.c create mode 100644 modules/cfe_testcase/src/cfe_test_table.h create mode 100644 modules/cfe_testcase/src/tbl_registration_test.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index 1318d7926..3569b406f 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -1,6 +1,7 @@ # Filenames based on doxygen groups. # Create the app module add_cfe_app(cfe_testcase + src/cfe_test_table.c src/cfe_test.c src/es_info_test.c src/es_task_test.c @@ -10,6 +11,7 @@ add_cfe_app(cfe_testcase src/fs_header_test.c src/fs_util_test.c src/sb_pipe_mang_test.c + src/tbl_registration_test.c src/time_arithmetic_test.c src/time_current_test.c ) diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index 016eadc57..26f61e967 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -59,8 +59,9 @@ void CFE_TestMain(void) FSHeaderTestSetup(); FSUtilTestSetup(); SBPipeMangSetup(); - TimeArithmeticTestSetup(); - TimeCurrentTestSetup(); + TBLRegistrationTestSetup(); + // TimeArithmeticTestSetup(); + // TimeCurrentTestSetup(); /* * Execute the tests diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index e661c6849..8d5498c62 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -46,6 +46,11 @@ typedef struct { CFE_FS_FileWriteMetaData_t FuncTestState; + /* Table information used by all table tests */ + CFE_TBL_Handle_t TblHandle; + const char * TblName; + const char * RegisteredTblName; + const char * TblFilename; } CFE_FT_Global_t; /** @@ -86,6 +91,7 @@ void ESTaskTestSetup(void); void FSHeaderTestSetup(void); void FSUtilTestSetup(void); void SBPipeMangSetup(void); +void TBLRegistrationTestSetup(void); void TimeArithmeticTestSetup(void); void TimeCurrentTestSetup(void); diff --git a/modules/cfe_testcase/src/cfe_test_table.c b/modules/cfe_testcase/src/cfe_test_table.c new file mode 100644 index 000000000..07ef95047 --- /dev/null +++ b/modules/cfe_testcase/src/cfe_test_table.c @@ -0,0 +1,52 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: cfe_test.c +** +** Purpose: +** Initialization routine for CFE functional test +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" +#include "cfe_test_table.h" + +/* Constant Table information used by all table tests */ +CFE_FT_Global_t CFE_FT_Global = { + .TblName = "TestTable", .RegisteredTblName = "CFE_TEST_APP.TestTable", .TblFilename = "test_tbl.tbl"}; + +/* Setup function to register a table */ +void RegisterTestTable(void) +{ + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_DEFAULT, NULL), + CFE_SUCCESS); +} + +/* Teardown function to unregister a table */ +void UnregisterTestTable(void) +{ + UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_FT_Global.TblHandle), CFE_SUCCESS); +} \ No newline at end of file diff --git a/modules/cfe_testcase/src/cfe_test_table.h b/modules/cfe_testcase/src/cfe_test_table.h new file mode 100644 index 000000000..227ca95de --- /dev/null +++ b/modules/cfe_testcase/src/cfe_test_table.h @@ -0,0 +1,62 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: cfe_test_table.c +** +** Purpose: +** Table struct definition and helper functions used by table tests +** +*************************************************************************/ + +/** + * @file + * + * Table struct definition and helper function prototypes + */ + +#ifndef CFE_TEST_TABLE_H +#define CFE_TEST_TABLE_H + +/* + * Includes + */ +#include "cfe_test.h" +#include "cfe_tbl_filedef.h" + +CFE_TBL_Handle_t TblHandle; +/* Constant Table information used by all table tests */ +const char *TblName; +const char *RegisteredTblName; +const char *TblFilename; + +void RegisterTestTable(void); +void UnregisterTestTable(void); +void CreateTableFile(void); + +/* + * Test table structure + */ +typedef struct +{ + uint16 Int1; + uint16 Int2; +} TBL_TEST_Table_t; + +#endif /* CFE_TEST_TABLE_H */ diff --git a/modules/cfe_testcase/src/tbl_registration_test.c b/modules/cfe_testcase/src/tbl_registration_test.c new file mode 100644 index 000000000..abe7160f6 --- /dev/null +++ b/modules/cfe_testcase/src/tbl_registration_test.c @@ -0,0 +1,138 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: tbl_registration_test.c +** +** Purpose: +** Functional test of Table Registration APIs +** +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" +#include "cfe_test_table.h" + +int32 CallbackFunc(void *TblPtr) +{ + return 1; +} + +void TestTableRegistration(void) +{ + UtPrintf("Testing: CFE_TBL_Register, CFE_TBL_Unregister"); + char BadTblName[CFE_TBL_MAX_FULL_NAME_LEN + 2]; + BadTblName[CFE_TBL_MAX_FULL_NAME_LEN + 1] = '\0'; + memset(BadTblName, 'a', sizeof(BadTblName) - 1); + + /* Successfully create table */ + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_DEFAULT, &CallbackFunc), + CFE_SUCCESS); + + /* Duplicate table */ + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_DEFAULT, &CallbackFunc), + CFE_TBL_WARN_DUPLICATE); + + /* Unregister the table */ + UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_FT_Global.TblHandle), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_FT_Global.TblHandle), CFE_TBL_ERR_INVALID_HANDLE); + + /* Invalid Name */ + UtAssert_INT32_EQ( + CFE_TBL_Register(&CFE_FT_Global.TblHandle, BadTblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL), + CFE_TBL_ERR_INVALID_NAME); + UtAssert_INT32_EQ( + CFE_TBL_Register(&CFE_FT_Global.TblHandle, "", sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL), + CFE_TBL_ERR_INVALID_NAME); + + /* Invalid Table Size */ + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, 0, CFE_TBL_OPT_DEFAULT, NULL), + CFE_TBL_ERR_INVALID_SIZE); + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, + CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE + 1, CFE_TBL_OPT_SNGL_BUFFER, NULL), + CFE_TBL_ERR_INVALID_SIZE); + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, + CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE + 1, CFE_TBL_OPT_DBL_BUFFER, NULL), + CFE_TBL_ERR_INVALID_SIZE); + + /* Invalid Table Options */ + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_DBL_BUFFER | CFE_TBL_OPT_USR_DEF_ADDR, NULL), + CFE_TBL_ERR_INVALID_OPTIONS); + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_CRITICAL | CFE_TBL_OPT_DUMP_ONLY, NULL), + CFE_TBL_ERR_INVALID_OPTIONS); + UtAssert_INT32_EQ(CFE_TBL_Register(&CFE_FT_Global.TblHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_CRITICAL | CFE_TBL_OPT_USR_DEF_ADDR, NULL), + CFE_TBL_ERR_INVALID_OPTIONS); + + /* + * Create the maximum number of tables + * There are already some tables in this system, so this will + * stop succeeding before it reaches the end of the loop + * Check that after the loop no more tables can be created + */ + CFE_TBL_Handle_t TblHandles[CFE_PLATFORM_TBL_MAX_NUM_TABLES]; + char TblName2[10]; + int numTblsCreated = 0; /* Track num created to unregister them all */ + for (int i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_TABLES; i++) + { + sprintf(TblName2, "%d", i); + if (CFE_TBL_Register(&TblHandles[i], TblName2, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL) == + CFE_SUCCESS) + { + numTblsCreated++; + } + } + UtAssert_INT32_EQ(CFE_TBL_Register(&TblHandles[numTblsCreated], CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), + CFE_TBL_OPT_DEFAULT, &CallbackFunc), + CFE_TBL_ERR_REGISTRY_FULL); + /* Unregister the tables */ + for (int i = 0; i < numTblsCreated; i++) + { + if (CFE_TBL_Unregister(TblHandles[i]) != CFE_SUCCESS) + { + UtAssert_Failed("Failed to unregister table number %d", i); + } + } +} + +void TestTableShare(void) +{ + UtPrintf("Testing: CFE_TBL_Share"); + CFE_TBL_Handle_t SharedTblHandle; + const char * SharedTblName = "SAMPLE_APP.SampleAppTable"; + const char * BadTblName = "SampleAppTable"; + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, SharedTblName), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, NULL), CFE_TBL_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, BadTblName), CFE_TBL_ERR_INVALID_NAME); +} + +void TBLRegistrationTestSetup(void) +{ + UtTest_Add(TestTableRegistration, NULL, NULL, "Test Table Registration"); + UtTest_Add(TestTableShare, NULL, NULL, "Test Table Sharing"); +} From 7e854ff49c1b79aa8e07629afacb8935a06ee66e Mon Sep 17 00:00:00 2001 From: Niall Mullane Date: Thu, 29 Jul 2021 16:16:55 -0400 Subject: [PATCH 2/4] Fix #1688, Add table information functional tests --- modules/cfe_testcase/CMakeLists.txt | 1 + modules/cfe_testcase/src/cfe_test.c | 1 + modules/cfe_testcase/src/cfe_test.h | 1 + .../cfe_testcase/src/tbl_information_test.c | 96 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 modules/cfe_testcase/src/tbl_information_test.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index 3569b406f..67b351136 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -11,6 +11,7 @@ add_cfe_app(cfe_testcase src/fs_header_test.c src/fs_util_test.c src/sb_pipe_mang_test.c + src/tbl_information_test.c src/tbl_registration_test.c src/time_arithmetic_test.c src/time_current_test.c diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index 26f61e967..71ef1b709 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -59,6 +59,7 @@ void CFE_TestMain(void) FSHeaderTestSetup(); FSUtilTestSetup(); SBPipeMangSetup(); + TBLInformationTestSetup(); TBLRegistrationTestSetup(); // TimeArithmeticTestSetup(); // TimeCurrentTestSetup(); diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index 8d5498c62..da533c47c 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -91,6 +91,7 @@ void ESTaskTestSetup(void); void FSHeaderTestSetup(void); void FSUtilTestSetup(void); void SBPipeMangSetup(void); +void TBLInformationTestSetup(void); void TBLRegistrationTestSetup(void); void TimeArithmeticTestSetup(void); void TimeCurrentTestSetup(void); diff --git a/modules/cfe_testcase/src/tbl_information_test.c b/modules/cfe_testcase/src/tbl_information_test.c new file mode 100644 index 000000000..6adcbd541 --- /dev/null +++ b/modules/cfe_testcase/src/tbl_information_test.c @@ -0,0 +1,96 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: tbl_information_test.c +** +** Purpose: +** Functional test of Table Information APIs +** +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" +#include "cfe_test_table.h" + +void TestGetStatus(void) +{ + UtPrintf("Testing: CFE_TBL_GetStatus"); + /* + * This assert assumes there are no pending actions for this table + * Since manage has never been called, I think this is a safe assumption + */ + UtAssert_INT32_EQ(CFE_TBL_GetStatus(CFE_FT_Global.TblHandle), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_GetStatus(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestGetInfo(void) +{ + UtPrintf("Testing: CFE_TBL_GetInfo"); + CFE_TBL_Info_t TblInfo; + const char * BadTblName = "BadTable"; + UtAssert_INT32_EQ(CFE_TBL_GetInfo(&TblInfo, CFE_FT_Global.RegisteredTblName), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_GetInfo(NULL, CFE_FT_Global.TblName), CFE_TBL_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_TBL_GetInfo(&TblInfo, BadTblName), CFE_TBL_ERR_INVALID_NAME); + + /* This is only checking some parts of the TblInfo struct */ + size_t expectedSize = sizeof(TBL_TEST_Table_t); + uint32 expectedNumUsers = 1; + bool expectedTableLoaded = false; + bool expectedDumpOnly = false; + bool expectedDoubleBuf = false; + bool expectedUserDefAddr = false; + bool expectedCritical = false; + UtAssert_UINT32_EQ(TblInfo.Size, expectedSize); + UtAssert_UINT32_EQ(TblInfo.NumUsers, expectedNumUsers); + UtAssert_INT32_EQ(TblInfo.TableLoadedOnce, expectedTableLoaded); + UtAssert_INT32_EQ(TblInfo.DumpOnly, expectedDumpOnly); + UtAssert_INT32_EQ(TblInfo.DoubleBuffered, expectedDoubleBuf); + UtAssert_INT32_EQ(TblInfo.UserDefAddr, expectedUserDefAddr); + UtAssert_INT32_EQ(TblInfo.Critical, expectedCritical); +} + +void TestNotifyByMessage(void) +{ + UtPrintf("Testing: CFE_TBL_NotifyByMessage"); + CFE_TBL_Handle_t SharedTblHandle; + const char * SharedTblName = "SAMPLE_APP.SampleAppTable"; + CFE_SB_MsgId_t TestMsgId = 0x9999; + CFE_MSG_FcnCode_t TestCmdCode = 0x9999; + uint32 TestParameter = 0; + UtAssert_INT32_EQ(CFE_TBL_NotifyByMessage(CFE_FT_Global.TblHandle, TestMsgId, TestCmdCode, TestParameter), + CFE_SUCCESS); + + /* Attempt on table not owned by this app */ + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, SharedTblName), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_NotifyByMessage(SharedTblHandle, TestMsgId, TestCmdCode, TestParameter), + CFE_TBL_ERR_NO_ACCESS); +} + +void TBLInformationTestSetup(void) +{ + UtTest_Add(TestGetStatus, RegisterTestTable, UnregisterTestTable, "Test Table Get Status"); + UtTest_Add(TestGetInfo, RegisterTestTable, UnregisterTestTable, "Test Table Get Info"); + UtTest_Add(TestNotifyByMessage, RegisterTestTable, UnregisterTestTable, "Test Table Notify by Message"); +} From 9aa907adba6a100b667b08a6b65992e962fa997a Mon Sep 17 00:00:00 2001 From: Niall Mullane Date: Fri, 30 Jul 2021 10:44:22 -0400 Subject: [PATCH 3/4] Fix #1686, Add manage table content functional tests --- modules/cfe_testcase/CMakeLists.txt | 4 + modules/cfe_testcase/inc/cfe_test_tbl.h | 46 ++++++ modules/cfe_testcase/src/cfe_test.c | 5 +- modules/cfe_testcase/src/cfe_test.h | 2 + modules/cfe_testcase/src/cfe_test_table.c | 6 +- modules/cfe_testcase/src/cfe_test_table.h | 23 +-- .../cfe_testcase/src/tbl_content_mang_test.c | 132 ++++++++++++++++++ modules/cfe_testcase/tables/cfe_test_tbl.c | 36 +++++ 8 files changed, 230 insertions(+), 24 deletions(-) create mode 100644 modules/cfe_testcase/inc/cfe_test_tbl.h create mode 100644 modules/cfe_testcase/src/tbl_content_mang_test.c create mode 100644 modules/cfe_testcase/tables/cfe_test_tbl.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index 67b351136..d3208cb56 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories(inc) + # Filenames based on doxygen groups. # Create the app module add_cfe_app(cfe_testcase @@ -11,6 +13,7 @@ add_cfe_app(cfe_testcase src/fs_header_test.c src/fs_util_test.c src/sb_pipe_mang_test.c + src/tbl_content_mang_test.c src/tbl_information_test.c src/tbl_registration_test.c src/time_arithmetic_test.c @@ -19,3 +22,4 @@ add_cfe_app(cfe_testcase # register the dependency on cfe_assert add_cfe_app_dependency(cfe_testcase cfe_assert) +add_cfe_tables(cfeTestAppTable tables/cfe_test_tbl.c) diff --git a/modules/cfe_testcase/inc/cfe_test_tbl.h b/modules/cfe_testcase/inc/cfe_test_tbl.h new file mode 100644 index 000000000..d8c01898d --- /dev/null +++ b/modules/cfe_testcase/inc/cfe_test_tbl.h @@ -0,0 +1,46 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: cfe_test_table.h +** +** Purpose: +** CFE Test Table struct definition +** +*************************************************************************/ + +/** + * @file + * + * CFE Test Table struct definition + */ + +#ifndef CFE_TEST_TBL_H +#define CFE_TEST_TBL_H + +/* + * Test table structure + */ +typedef struct +{ + uint16 Int1; + uint16 Int2; +} TBL_TEST_Table_t; + +#endif /* CFE_TEST_TBL_H */ diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index 71ef1b709..bc8bf4ba1 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -59,10 +59,11 @@ void CFE_TestMain(void) FSHeaderTestSetup(); FSUtilTestSetup(); SBPipeMangSetup(); + TBLContentMangTestSetup(); TBLInformationTestSetup(); TBLRegistrationTestSetup(); - // TimeArithmeticTestSetup(); - // TimeCurrentTestSetup(); + TimeArithmeticTestSetup(); + TimeCurrentTestSetup(); /* * Execute the tests diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index da533c47c..d524974ed 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -39,6 +39,7 @@ * Includes */ #include "cfe.h" +#include "cfe_test_tbl.h" #include "uttest.h" #include "utassert.h" @@ -91,6 +92,7 @@ void ESTaskTestSetup(void); void FSHeaderTestSetup(void); void FSUtilTestSetup(void); void SBPipeMangSetup(void); +void TBLContentMangTestSetup(void); void TBLInformationTestSetup(void); void TBLRegistrationTestSetup(void); void TimeArithmeticTestSetup(void); diff --git a/modules/cfe_testcase/src/cfe_test_table.c b/modules/cfe_testcase/src/cfe_test_table.c index 07ef95047..b0fcc8cc5 100644 --- a/modules/cfe_testcase/src/cfe_test_table.c +++ b/modules/cfe_testcase/src/cfe_test_table.c @@ -18,11 +18,11 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ** -** File: cfe_test.c +** File: cfe_test_table.c ** ** Purpose: -** Initialization routine for CFE functional test -** Demonstration of how to register and use the UT assert functions. +** Initialization of variables used by table functional tests and +** function definitions for setup and teardown table functions ** *************************************************************************/ diff --git a/modules/cfe_testcase/src/cfe_test_table.h b/modules/cfe_testcase/src/cfe_test_table.h index 227ca95de..1e28b06e8 100644 --- a/modules/cfe_testcase/src/cfe_test_table.h +++ b/modules/cfe_testcase/src/cfe_test_table.h @@ -18,17 +18,17 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ** -** File: cfe_test_table.c +** File: cfe_test_table.h ** ** Purpose: -** Table struct definition and helper functions used by table tests +** Declare global struct variable and function prototypes for table tests ** *************************************************************************/ /** * @file * - * Table struct definition and helper function prototypes + * Declarations and prototypes for cfe_test module table tests */ #ifndef CFE_TEST_TABLE_H @@ -38,25 +38,10 @@ * Includes */ #include "cfe_test.h" -#include "cfe_tbl_filedef.h" -CFE_TBL_Handle_t TblHandle; -/* Constant Table information used by all table tests */ -const char *TblName; -const char *RegisteredTblName; -const char *TblFilename; +CFE_FT_Global_t CFE_FT_Global; void RegisterTestTable(void); void UnregisterTestTable(void); -void CreateTableFile(void); - -/* - * Test table structure - */ -typedef struct -{ - uint16 Int1; - uint16 Int2; -} TBL_TEST_Table_t; #endif /* CFE_TEST_TABLE_H */ diff --git a/modules/cfe_testcase/src/tbl_content_mang_test.c b/modules/cfe_testcase/src/tbl_content_mang_test.c new file mode 100644 index 000000000..93a4b22e6 --- /dev/null +++ b/modules/cfe_testcase/src/tbl_content_mang_test.c @@ -0,0 +1,132 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: tbl_content_mang_test.c +** +** Purpose: +** Functional test of Table Manage Content APIs +** +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" +#include "cfe_test_table.h" + +/* Does not test partial loads */ +void TestLoad(void) +{ + UtPrintf("Testing: CFE_TBL_Load"); + CFE_TBL_Handle_t BadTblHandle; + const char * BadTblName = "BadTableName"; + UtAssert_INT32_EQ( + CFE_TBL_Register(&BadTblHandle, BadTblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DBL_BUFFER, NULL), + CFE_SUCCESS); + + /* Load from file */ + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"), CFE_SUCCESS); + /* Load again */ + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"), CFE_SUCCESS); + /* Table name mismatches */ + UtAssert_INT32_EQ(CFE_TBL_Load(BadTblHandle, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"), + CFE_TBL_ERR_FILE_FOR_WRONG_TABLE); + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, "/cf/sample_app_tbl.tbl"), + CFE_TBL_ERR_FILE_FOR_WRONG_TABLE); + /* This is a very unintuitive error message. CFE_TBL_ERR_FILE_NOT_FOUND would be more accurate */ + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, "/cf/not_cfe_test_tbl.tbl"), + CFE_TBL_ERR_ACCESS); + + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_TBL_BAD_TABLE_HANDLE, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"), + CFE_TBL_ERR_INVALID_HANDLE); + + /* Load from memory */ + TBL_TEST_Table_t TestTable = {1, 2}; + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_ADDRESS, &TestTable), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_ADDRESS, NULL), CFE_TBL_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_TBL_BAD_TABLE_HANDLE, CFE_TBL_SRC_ADDRESS, &TestTable), + CFE_TBL_ERR_INVALID_HANDLE); + + /* Attempt to load a dump only table */ + CFE_TBL_Handle_t DumpTblHandle; + const char * DumpTblName = "DumpOnlyTable"; + UtAssert_INT32_EQ( + CFE_TBL_Register(&DumpTblHandle, DumpTblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DUMP_ONLY, NULL), + CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Load(DumpTblHandle, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"), CFE_TBL_ERR_DUMP_ONLY); + + /* Load a shared table */ + CFE_TBL_Handle_t SharedTblHandle; + const char * SharedTblName = "SAMPLE_APP.SampleAppTable"; + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, SharedTblName), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Load(SharedTblHandle, CFE_TBL_SRC_FILE, "/cf/sample_app_tbl.tbl"), CFE_SUCCESS); +} + +void TestUpdate(void) +{ + UtPrintf("Testing: CFE_TBL_Update"); + /* Haven't figured out how to get an update pending */ + UtAssert_INT32_EQ(CFE_TBL_Update(CFE_FT_Global.TblHandle), CFE_TBL_INFO_NO_UPDATE_PENDING); + UtAssert_INT32_EQ(CFE_TBL_Update(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestValidate(void) +{ + UtPrintf("Testing: CFE_TBL_Validate"); + /* Haven't figured out how to get a validation pending */ + UtAssert_INT32_EQ(CFE_TBL_Validate(CFE_FT_Global.TblHandle), CFE_TBL_INFO_NO_VALIDATION_PENDING); + UtAssert_INT32_EQ(CFE_TBL_Validate(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestManage(void) +{ + UtPrintf("Testing: CFE_TBL_Manage"); + UtAssert_INT32_EQ(CFE_TBL_Manage(CFE_FT_Global.TblHandle), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Manage(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestDumpToBuffer(void) +{ + UtPrintf("Testing: CFE_TBL_DumpToBuffer"); + /* This should at least return an info code such as CFE_TBL_INFO_NO_UPDATE_PENDING when CFE_TBL_Update is called + * with no pending update instead of returning CFE_SUCCESS whether or not it actually dumped*/ + UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(CFE_FT_Global.TblHandle), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestModified(void) +{ + UtPrintf("Testing: CFE_TBL_Modified"); + UtAssert_INT32_EQ(CFE_TBL_Modified(CFE_FT_Global.TblHandle), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_Modified(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TBLContentMangTestSetup(void) +{ + UtTest_Add(TestLoad, RegisterTestTable, UnregisterTestTable, "Test Table Load"); + UtTest_Add(TestUpdate, RegisterTestTable, UnregisterTestTable, "Test Table Update"); + UtTest_Add(TestValidate, RegisterTestTable, UnregisterTestTable, "Test Table Validate"); + UtTest_Add(TestManage, RegisterTestTable, UnregisterTestTable, "Test Table Manage"); + UtTest_Add(TestDumpToBuffer, RegisterTestTable, UnregisterTestTable, "Test Table Dump to Buffer"); + UtTest_Add(TestModified, RegisterTestTable, UnregisterTestTable, "Test Table Modified"); +} diff --git a/modules/cfe_testcase/tables/cfe_test_tbl.c b/modules/cfe_testcase/tables/cfe_test_tbl.c new file mode 100644 index 000000000..81116b796 --- /dev/null +++ b/modules/cfe_testcase/tables/cfe_test_tbl.c @@ -0,0 +1,36 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: cfe_test_tbl.c +** +** Purpose: +** Create a file containing a CFE Test Table +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_tbl_filedef.h" +#include "cfe_test_tbl.h" + +TBL_TEST_Table_t TestTable = {1, 2}; +CFE_TBL_FILEDEF(TestTable, CFE_TEST_APP.TestTable, Table Test Table, cfe_test_tbl.tbl) \ No newline at end of file From 343e0d037cb6e225dc71607181ef229ab473aa57 Mon Sep 17 00:00:00 2001 From: Niall Mullane Date: Mon, 2 Aug 2021 15:05:04 -0400 Subject: [PATCH 4/4] Fix #1687, Add access table content functional tests --- modules/cfe_testcase/CMakeLists.txt | 1 + modules/cfe_testcase/src/cfe_test.c | 1 + modules/cfe_testcase/src/cfe_test.h | 1 + .../src/tbl_content_access_test.c | 167 ++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 modules/cfe_testcase/src/tbl_content_access_test.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index d3208cb56..3e6c21c7f 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -13,6 +13,7 @@ add_cfe_app(cfe_testcase src/fs_header_test.c src/fs_util_test.c src/sb_pipe_mang_test.c + src/tbl_content_access_test.c src/tbl_content_mang_test.c src/tbl_information_test.c src/tbl_registration_test.c diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index bc8bf4ba1..a95433e7a 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -59,6 +59,7 @@ void CFE_TestMain(void) FSHeaderTestSetup(); FSUtilTestSetup(); SBPipeMangSetup(); + TBLContentAccessTestSetup(); TBLContentMangTestSetup(); TBLInformationTestSetup(); TBLRegistrationTestSetup(); diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index d524974ed..ed98436e7 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -92,6 +92,7 @@ void ESTaskTestSetup(void); void FSHeaderTestSetup(void); void FSUtilTestSetup(void); void SBPipeMangSetup(void); +void TBLContentAccessTestSetup(void); void TBLContentMangTestSetup(void); void TBLInformationTestSetup(void); void TBLRegistrationTestSetup(void); diff --git a/modules/cfe_testcase/src/tbl_content_access_test.c b/modules/cfe_testcase/src/tbl_content_access_test.c new file mode 100644 index 000000000..08c60e868 --- /dev/null +++ b/modules/cfe_testcase/src/tbl_content_access_test.c @@ -0,0 +1,167 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: tbl_content_access_test.c +** +** Purpose: +** Functional test of Table Access Content APIs +** +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" +#include "cfe_test_table.h" + +/* + * Helper function to attempt to load the test table with data and assert with the provided CFE_Status_t + */ +void LoadTable(TBL_TEST_Table_t *TestTable, CFE_Status_t ExpectedStatus) +{ + UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_ADDRESS, TestTable), ExpectedStatus); +} + +void TestGetAddress(void) +{ + UtPrintf("Testing: CFE_TBL_GetAddress"); + void * TblPtr; + TBL_TEST_Table_t *TestTblPtr; + TBL_TEST_Table_t TestTable = {1, 2}; + /* Never loaded */ + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_ERR_NEVER_LOADED); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(NULL, CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_BAD_ARGUMENT); + + /* Returns CFE_TBL_INFO_UPDATED since it was just loaded */ + LoadTable(&TestTable, CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_SUCCESS); + + /* Check table contents */ + TestTblPtr = (TBL_TEST_Table_t *)TblPtr; + UtAssert_INT32_EQ(TestTblPtr->Int1, TestTable.Int1); + UtAssert_INT32_EQ(TestTblPtr->Int2, TestTable.Int2); + + /* Unregistered table */ + UnregisterTestTable(); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_ERR_INVALID_HANDLE); + + /* Access a shared table */ + CFE_TBL_Handle_t SharedTblHandle; + const char * SharedTblName = "SAMPLE_APP.SampleAppTable"; + UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, SharedTblName), CFE_SUCCESS); + /* Returns CFE_TBL_INFO_UPDATED since it hasn't been touched since it was loaded */ + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, SharedTblHandle), CFE_TBL_INFO_UPDATED); + UtAssert_INT32_EQ(CFE_TBL_Unregister(SharedTblHandle), CFE_SUCCESS); +} + +void TestReleaseAddress(void) +{ + UtPrintf("Testing: CFE_TBL_GetAddress"); + void * TblPtr; + TBL_TEST_Table_t TestTable = {1, 2}; + /* Never loaded */ + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_TBL_ERR_NEVER_LOADED); + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE); + /* Successful load and release */ + LoadTable(&TestTable, CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED); + + /* Attempt to load while address is locked */ + LoadTable(&TestTable, CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED); + LoadTable(&TestTable, CFE_TBL_INFO_TABLE_LOCKED); + + /* Release and try again */ + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_SUCCESS); + /* It is necessary to call CFE_TBL_Manage because the table still thinks there is a load in progress from the failed + load while the table was locked. This call shouldn't be necesssary. */ + UtAssert_INT32_EQ(CFE_TBL_Manage(CFE_FT_Global.TblHandle), CFE_TBL_INFO_UPDATED); + LoadTable(&TestTable, CFE_SUCCESS); + + /* Attempt to release an unregistered table */ + UnregisterTestTable(); + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_TBL_ERR_INVALID_HANDLE); +} + +void TestGetReleaseAddresses(void) +{ + int numValidTbls = 5; + char TblName[10]; + CFE_TBL_Handle_t TblHandles[numValidTbls + 1]; + void * TblPtrs[numValidTbls + 1]; + TBL_TEST_Table_t TblPtrsList[numValidTbls + 1]; + TBL_TEST_Table_t TestTable = {1, 2}; + + /* Put an invalid handle at the start*/ + TblHandles[0] = CFE_TBL_BAD_TABLE_HANDLE; + TblPtrs[0] = TblPtrsList; + for (int i = 1; i < numValidTbls + 1; i++) + { + sprintf(TblName, "%d", i); + UtAssert_INT32_EQ( + CFE_TBL_Register(&TblHandles[i], TblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL), + CFE_SUCCESS); + TblPtrs[i] = TblPtrsList + i; + } + + UtAssert_INT32_EQ(CFE_TBL_GetAddresses(NULL, numValidTbls, TblHandles), CFE_TBL_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_TBL_GetAddresses((void ***)&TblPtrs, numValidTbls, NULL), CFE_TBL_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_TBL_GetAddresses((void ***)&TblPtrs, numValidTbls, TblHandles), CFE_TBL_ERR_INVALID_HANDLE); + /* Skip the first table handle to only consider valid handles */ + UtAssert_INT32_EQ(CFE_TBL_GetAddresses((void ***)&TblPtrs, numValidTbls, TblHandles + 1), CFE_TBL_ERR_NEVER_LOADED); + + /* Load data and then get addresses */ + for (int i = 1; i < numValidTbls + 1; i++) + { + if (CFE_TBL_Load(TblHandles[i], CFE_TBL_SRC_ADDRESS, &TestTable) != CFE_SUCCESS) + { + UtAssert_Failed("Failed to load data for table number %d", i); + } + } + /* First time returns status message of CFE_TBL_INFO_UPDATED */ + UtAssert_INT32_EQ(CFE_TBL_GetAddresses((void ***)&TblPtrs, numValidTbls, TblHandles + 1), CFE_TBL_INFO_UPDATED); + UtAssert_INT32_EQ(CFE_TBL_GetAddresses((void ***)&TblPtrs, numValidTbls, TblHandles + 1), CFE_SUCCESS); + /* Attempt to release the invalid handle at the start of the array */ + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddresses(numValidTbls, TblHandles), CFE_TBL_ERR_INVALID_HANDLE); + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddresses(numValidTbls, NULL), CFE_TBL_BAD_ARGUMENT); + /* Skip the invalid handle */ + UtAssert_INT32_EQ(CFE_TBL_ReleaseAddresses(numValidTbls, TblHandles + 1), CFE_SUCCESS); + + /* Unregister all tables */ + for (int i = 1; i < numValidTbls + 1; i++) + { + if (CFE_TBL_Unregister(TblHandles[i]) != CFE_SUCCESS) + { + UtAssert_Failed("Failed to unregister table number %d", i); + } + } +} + +void TBLContentAccessTestSetup(void) +{ + UtTest_Add(TestGetAddress, RegisterTestTable, NULL, "Test Table Get Address"); + UtTest_Add(TestReleaseAddress, RegisterTestTable, NULL, "Test Table Release Address"); + UtTest_Add(TestGetReleaseAddresses, NULL, NULL, "Test Table Get and Release Addresses"); +} \ No newline at end of file