Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1868, Add TBL API test cases #1872

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/cfe_testcase/src/tbl_content_access_test.c
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ void TestGetAddress(void)
/* 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);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(NULL, CFE_FT_Global.TblHandle), CFE_TBL_BAD_ARGUMENT);

/* Returns CFE_TBL_INFO_UPDATED since it was just loaded */
LoadTable(&TestTable, CFE_SUCCESS);
390 changes: 372 additions & 18 deletions modules/cfe_testcase/src/tbl_content_mang_test.c

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions modules/cfe_testcase/src/tbl_information_test.c
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@

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

void TestGetStatus(void)
{
@@ -53,6 +54,7 @@ void TestGetInfo(void)
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);
UtAssert_INT32_EQ(CFE_TBL_GetInfo(&TblInfo, NULL), CFE_TBL_BAD_ARGUMENT);

/* This is only checking some parts of the TblInfo struct */
size_t expectedSize = sizeof(TBL_TEST_Table_t);
@@ -76,9 +78,13 @@ 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;
CFE_SB_MsgId_t TestMsgId = CFE_TEST_CMD_MID;
CFE_MSG_FcnCode_t TestCmdCode = 0;
uint32 TestParameter = 0;

UtAssert_INT32_EQ(CFE_TBL_NotifyByMessage(CFE_TBL_BAD_TABLE_HANDLE, TestMsgId, TestCmdCode, TestParameter),
CFE_TBL_ERR_INVALID_HANDLE);

UtAssert_INT32_EQ(CFE_TBL_NotifyByMessage(CFE_FT_Global.TblHandle, TestMsgId, TestCmdCode, TestParameter),
CFE_SUCCESS);

174 changes: 156 additions & 18 deletions modules/cfe_testcase/src/tbl_registration_test.c
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@

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

int32 CallbackFunc(void *TblPtr)
{
@@ -41,22 +42,38 @@ int32 CallbackFunc(void *TblPtr)

void TestTableRegistration(void)
{
char BadTblName[CFE_TBL_MAX_FULL_NAME_LEN + 2];
CFE_TBL_Handle_t OtherHandle;

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);

/* invalid table handle arg */
UtAssert_INT32_EQ(
CFE_TBL_Register(NULL, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, &CallbackFunc),
CFE_TBL_BAD_ARGUMENT);

/* 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),
/* Duplicate table (should return the same handle) */
UtAssert_INT32_EQ(CFE_TBL_Register(&OtherHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t),
CFE_TBL_OPT_DEFAULT, &CallbackFunc),
CFE_TBL_WARN_DUPLICATE);

UtAssert_INT32_EQ(OtherHandle, CFE_FT_Global.TblHandle);

/* Duplicate table with different size */
UtAssert_INT32_EQ(CFE_TBL_Register(&OtherHandle, CFE_FT_Global.TblName, sizeof(TBL_TEST_Table_t) / 2,
CFE_TBL_OPT_DEFAULT, &CallbackFunc),
CFE_TBL_ERR_DUPLICATE_DIFF_SIZE);

/* Unregister the table */
UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE);
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);

@@ -88,35 +105,87 @@ void TestTableRegistration(void)
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);
}

void TestTableMaxLimits(void)
{
CFE_TBL_Handle_t Handles[CFE_PLATFORM_TBL_MAX_NUM_HANDLES + 1];
char TblName[CFE_TBL_MAX_FULL_NAME_LEN];
uint32 numTblsCreated = 0; /* Track num created to unregister them all */

/*
* 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++)
while (numTblsCreated <= CFE_PLATFORM_TBL_MAX_NUM_HANDLES)
{
sprintf(TblName2, "%d", i);
if (CFE_TBL_Register(&TblHandles[i], TblName2, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL) ==
CFE_SUCCESS)
snprintf(TblName, sizeof(TblName), "Tbl%u", (unsigned int)numTblsCreated);
CFE_Assert_STATUS_STORE(
CFE_TBL_Register(&Handles[numTblsCreated], TblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL));
if (CFE_Assert_STATUS_MAY_BE(CFE_TBL_ERR_REGISTRY_FULL))
{
numTblsCreated++;
break;
}
if (!CFE_Assert_STATUS_MUST_BE(CFE_SUCCESS))
{
break;
}
++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 (!UtAssert_NONZERO(numTblsCreated))
{
if (CFE_TBL_Unregister(TblHandles[i]) != CFE_SUCCESS)
UtAssert_WARN("Table test cannot create any tables");
return;
}

UtAssert_UINT32_LT(numTblsCreated, CFE_PLATFORM_TBL_MAX_NUM_TABLES);
UtAssert_UINT32_LT(numTblsCreated, CFE_PLATFORM_TBL_MAX_NUM_HANDLES);

/* Delete one table so the registry isn't full anymore */
--numTblsCreated;
UtAssert_INT32_EQ(CFE_TBL_Unregister(Handles[numTblsCreated]), CFE_SUCCESS);

if (!UtAssert_NONZERO(numTblsCreated))
{
UtAssert_WARN("Table test cannot run CFE_TBL_Share max without at least one table");
return;
}

/*
* A shared table has a unique handle but not a unique entry in the registry.
* By calling CFE_TBL_Share it should consume handles but not registry entries
*/
snprintf(TblName, sizeof(TblName), "CFE_TEST_APP.Tbl%u", (unsigned int)0);
while (numTblsCreated <= CFE_PLATFORM_TBL_MAX_NUM_HANDLES)
{
CFE_Assert_STATUS_STORE(CFE_TBL_Share(&Handles[numTblsCreated], TblName));
if (CFE_Assert_STATUS_MAY_BE(CFE_TBL_ERR_HANDLES_FULL))
{
UtAssert_Failed("Failed to unregister table number %d", i);
break;
}
if (!CFE_Assert_STATUS_MUST_BE(CFE_SUCCESS))
{
break;
}
++numTblsCreated;
}

UtAssert_UINT32_LT(numTblsCreated, CFE_PLATFORM_TBL_MAX_NUM_HANDLES);

/* also confirm not able to register a new table, either */
snprintf(TblName, sizeof(TblName), "Tbl%u", (unsigned int)numTblsCreated);
UtAssert_INT32_EQ(
CFE_TBL_Register(&Handles[numTblsCreated], TblName, sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, NULL),
CFE_TBL_ERR_HANDLES_FULL);

/* Unregister all table handles */
while (numTblsCreated > 0)
{
--numTblsCreated;
UtAssert_INT32_EQ(CFE_TBL_Unregister(Handles[numTblsCreated]), CFE_SUCCESS);
}
}

@@ -126,13 +195,82 @@ void TestTableShare(void)
CFE_TBL_Handle_t SharedTblHandle;
const char * SharedTblName = "SAMPLE_APP.SampleAppTable";
const char * BadTblName = "SampleAppTable";

UtAssert_INT32_EQ(CFE_TBL_Share(NULL, SharedTblName), CFE_TBL_BAD_ARGUMENT);
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 TestTblNonAppContext(void)
{
CFE_TBL_Handle_t Handle;
void * TblPtr;

/* Attempt to register another table */
UtAssert_INT32_EQ(
CFE_TBL_Register(&Handle, "OtherTable", sizeof(TBL_TEST_Table_t), CFE_TBL_OPT_DEFAULT, &CallbackFunc),
CFE_ES_ERR_RESOURCEID_NOT_VALID);

/* Calling any other API (with a valid handle) should be rejected from this context */
UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_GetStatus(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Load(CFE_FT_Global.TblHandle, CFE_TBL_SRC_FILE, "/cf/cfe_test_tbl.tbl"),
CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Manage(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Modified(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_NotifyByMessage(CFE_FT_Global.TblHandle, CFE_TEST_CMD_MID, 0, 0),
CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddress(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Share(&Handle, CFE_FT_Global.TblName), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Update(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Validate(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);

/* Attempt to unregister a table */
UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_FT_Global.TblHandle), CFE_ES_ERR_RESOURCEID_NOT_VALID);
}

void TestTableBadContext(void)
{
uint32 RetryCount;
osal_id_t OtherTaskId;
OS_task_prop_t TaskProp;

/* Create one (good) handle first from this task */
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);

/* Create a separate task to run the tests, to confirm TBL context checks */
UtAssert_INT32_EQ(OS_TaskCreate(&OtherTaskId, "NonCfe", TestTblNonAppContext, OSAL_TASK_STACK_ALLOCATE, 16384,
OSAL_PRIORITY_C(200), 0),
OS_SUCCESS);

/* wait for task to exit itself */
RetryCount = 0;
while (RetryCount < 20)
{
/*
* poll until OS_TaskGetInfo() returns an error, then the task has exited
*/
if (OS_TaskGetInfo(OtherTaskId, &TaskProp) != OS_SUCCESS)
{
break;
}

OS_TaskDelay(100);
++RetryCount;
}

UtAssert_UINT32_LT(RetryCount, 20);
UtAssert_INT32_EQ(CFE_TBL_Unregister(CFE_FT_Global.TblHandle), CFE_SUCCESS);
}

void TBLRegistrationTestSetup(void)
{
UtTest_Add(TestTableRegistration, NULL, NULL, "Test Table Registration");
UtTest_Add(TestTableMaxLimits, NULL, NULL, "Table Max Limits");
UtTest_Add(TestTableShare, NULL, NULL, "Test Table Sharing");
UtTest_Add(TestTableBadContext, NULL, NULL, "Test Table Bad Context");
}
8 changes: 7 additions & 1 deletion modules/cfe_testcase/tables/cfe_test_tbl.c
Original file line number Diff line number Diff line change
@@ -32,5 +32,11 @@
#include "cfe_tbl_filedef.h"
#include "cfe_test_tbl.h"

TBL_TEST_Table_t TestTable = {1, 2};
/*
* The test table data should contain some identifiable numeric values,
* so any issues with paritial loading/byteswapping are morely likely
* to be detected.
*/
TBL_TEST_Table_t TestTable = {0xf007, 0xba11};

CFE_TBL_FILEDEF(TestTable, CFE_TEST_APP.TestTable, Table Test Table, cfe_test_tbl.tbl)
7 changes: 4 additions & 3 deletions modules/core_api/fsw/inc/cfe_tbl.h
Original file line number Diff line number Diff line change
@@ -303,21 +303,22 @@ CFE_Status_t CFE_TBL_Unregister(CFE_TBL_Handle_t TblHandle);
**
** \return Execution status, see \ref CFEReturnCodes
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
** \retval #CFE_TBL_WARN_SHORT_FILE \copybrief CFE_TBL_WARN_SHORT_FILE
** \retval #CFE_TBL_WARN_PARTIAL_LOAD \copybrief CFE_TBL_WARN_PARTIAL_LOAD
** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID
** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS
** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE
** \retval #CFE_TBL_ERR_DUMP_ONLY \copybrief CFE_TBL_ERR_DUMP_ONLY
** \retval #CFE_TBL_ERR_ILLEGAL_SRC_TYPE \copybrief CFE_TBL_ERR_ILLEGAL_SRC_TYPE
** \retval #CFE_TBL_ERR_LOAD_IN_PROGRESS \copybrief CFE_TBL_ERR_LOAD_IN_PROGRESS
** \retval #CFE_TBL_ERR_LOAD_INCOMPLETE \copybrief CFE_TBL_ERR_LOAD_INCOMPLETE
** \retval #CFE_TBL_ERR_NO_BUFFER_AVAIL \copybrief CFE_TBL_ERR_NO_BUFFER_AVAIL
** \retval #CFE_TBL_ERR_ACCESS \copybrief CFE_TBL_ERR_ACCESS
** \retval #CFE_TBL_ERR_FILE_TOO_LARGE \copybrief CFE_TBL_ERR_FILE_TOO_LARGE
** \retval #CFE_TBL_ERR_BAD_CONTENT_ID \copybrief CFE_TBL_ERR_BAD_CONTENT_ID
** \retval #CFE_TBL_ERR_BAD_SUBTYPE_ID \copybrief CFE_TBL_ERR_BAD_SUBTYPE_ID
** \retval #CFE_TBL_ERR_NO_STD_HEADER \copybrief CFE_TBL_ERR_NO_STD_HEADER
** \retval #CFE_TBL_ERR_NO_TBL_HEADER \copybrief CFE_TBL_ERR_NO_TBL_HEADER
** \retval #CFE_TBL_ERR_PARTIAL_LOAD \copybrief CFE_TBL_ERR_PARTIAL_LOAD
** \retval #CFE_TBL_BAD_ARGUMENT \copybrief CFE_TBL_BAD_ARGUMENT
** \retval #CFE_TBL_WARN_PARTIAL_LOAD \copybrief CFE_TBL_WARN_PARTIAL_LOAD
**
** \sa #CFE_TBL_Update, #CFE_TBL_Validate, #CFE_TBL_Manage
**