Skip to content

Commit

Permalink
Fix #1686, Add manage table content functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nmullane committed Aug 2, 2021
1 parent 93b6bb6 commit 1445691
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 27 deletions.
4 changes: 4 additions & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_directories(inc)

# Filenames based on doxygen groups.
# Create the app module
add_cfe_app(cfe_testcase
Expand All @@ -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
Expand All @@ -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)
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 */
5 changes: 3 additions & 2 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ void CFE_TestMain(void)
FSHeaderTestSetup();
FSUtilTestSetup();
SBPipeMangSetup();
TBLContentMangTestSetup();
TBLInformationTestSetup();
TBLRegistrationTestSetup();
// TimeArithmeticTestSetup();
// TimeCurrentTestSetup();
TimeArithmeticTestSetup();
TimeCurrentTestSetup();

/*
* Execute the tests
Expand Down
11 changes: 11 additions & 0 deletions modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Includes
*/
#include "cfe.h"
#include "cfe_test_tbl.h"

#include "uttest.h"
#include "utassert.h"
Expand Down Expand Up @@ -91,9 +92,19 @@ void ESTaskTestSetup(void);
void FSHeaderTestSetup(void);
void FSUtilTestSetup(void);
void SBPipeMangSetup(void);
void TBLContentMangTestSetup(void);
void TBLInformationTestSetup(void);
void TBLRegistrationTestSetup(void);
void TimeArithmeticTestSetup(void);
void TimeCurrentTestSetup(void);

/* Table information used by all table tests */
CFE_TBL_Handle_t TblHandle;
const char * TblName;
const char * RegisteredTblName;
const char * TblFilename;

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

#endif /* CFE_TEST_H */
7 changes: 3 additions & 4 deletions modules/cfe_testcase/src/cfe_test_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
**
*************************************************************************/

Expand All @@ -31,7 +31,6 @@
*/

#include "cfe_test.h"
#include "cfe_test_table.h"

/* Constant Table information used by all table tests */
CFE_FT_Global_t CFE_FT_Global = {
Expand Down
24 changes: 3 additions & 21 deletions modules/cfe_testcase/src/cfe_test_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
** File: cfe_test_table.c
**
** Purpose:
** Table struct definition and helper functions used by table tests
** Define global struct variable for table tests
**
*************************************************************************/

/**
* @file
*
* Table struct definition and helper function prototypes
* Declarations and prototypes for cfe_test module
*/

#ifndef CFE_TEST_TABLE_H
Expand All @@ -38,25 +38,7 @@
* 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;
CFE_FT_Global_t CFE_FT_Global;

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

0 comments on commit 1445691

Please sign in to comment.