Skip to content

Commit

Permalink
Merge pull request #1734 from nmullane/table-api-functional-tests
Browse files Browse the repository at this point in the history
Add table api functional tests
  • Loading branch information
astrogeco committed Aug 9, 2021
2 parents 95349ed + 343e0d0 commit 9b634da
Show file tree
Hide file tree
Showing 11 changed files with 738 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
include_directories(inc)

# 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_application_control_test.c
src/es_info_test.c
Expand All @@ -13,10 +16,15 @@ add_cfe_app(cfe_testcase
src/fs_util_test.c
src/message_id_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
src/time_arithmetic_test.c
src/time_current_test.c
src/time_conversion_test.c
)

# register the dependency on cfe_assert
add_cfe_app_dependency(cfe_testcase cfe_assert)
add_cfe_tables(cfeTestAppTable tables/cfe_test_tbl.c)
46 changes: 46 additions & 0 deletions modules/cfe_testcase/inc/cfe_test_tbl.h
Original file line number Diff line number Diff line change
@@ -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 */
4 changes: 4 additions & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void CFE_TestMain(void)
FSUtilTestSetup();
MessageIdTestSetup();
SBPipeMangSetup();
TBLContentAccessTestSetup();
TBLContentMangTestSetup();
TBLInformationTestSetup();
TBLRegistrationTestSetup();
TimeArithmeticTestSetup();
TimeCurrentTestSetup();
TimeConversionTestSetup();
Expand Down
12 changes: 12 additions & 0 deletions modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@
* Includes
*/
#include "cfe.h"
#include "cfe_test_tbl.h"

#include "uttest.h"
#include "utassert.h"

typedef struct
{
CFE_FS_FileWriteMetaData_t FuncTestState;

/* Generic utility counter */
int Count;

/* 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;

extern CFE_FT_Global_t CFE_FT_Global;
Expand Down Expand Up @@ -95,6 +103,10 @@ void FSHeaderTestSetup(void);
void FSUtilTestSetup(void);
void MessageIdTestSetup(void);
void SBPipeMangSetup(void);
void TBLContentAccessTestSetup(void);
void TBLContentMangTestSetup(void);
void TBLInformationTestSetup(void);
void TBLRegistrationTestSetup(void);
void TimeArithmeticTestSetup(void);
void TimeCurrentTestSetup(void);
void TimeConversionTestSetup(void);
Expand Down
52 changes: 52 additions & 0 deletions modules/cfe_testcase/src/cfe_test_table.c
Original file line number Diff line number Diff line change
@@ -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_table.c
**
** Purpose:
** Initialization of variables used by table functional tests and
** function definitions for setup and teardown table 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);
}
47 changes: 47 additions & 0 deletions modules/cfe_testcase/src/cfe_test_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*************************************************************************
**
** 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:
** Declare global struct variable and function prototypes for table tests
**
*************************************************************************/

/**
* @file
*
* Declarations and prototypes for cfe_test module table tests
*/

#ifndef CFE_TEST_TABLE_H
#define CFE_TEST_TABLE_H

/*
* Includes
*/
#include "cfe_test.h"

CFE_FT_Global_t CFE_FT_Global;

void RegisterTestTable(void);
void UnregisterTestTable(void);

#endif /* CFE_TEST_TABLE_H */
167 changes: 167 additions & 0 deletions modules/cfe_testcase/src/tbl_content_access_test.c
Original file line number Diff line number Diff line change
@@ -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");
}
Loading

0 comments on commit 9b634da

Please sign in to comment.