Skip to content

Commit

Permalink
Fix #1480, Expand FS Header Functional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Jun 24, 2021
1 parent da76015 commit fb697ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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 @@ -52,6 +52,17 @@
#define UtAssert_ResourceID_Undefined(id) \
UtAssert_True(!CFE_RESOURCEID_TEST_DEFINED(id), "%s (%lu) not defined", #id, CFE_RESOURCEID_TO_ULONG(id))

/* Assert a return code is not equal to cfe_success */
#define UtAssert_NOT_CFE_SUCCESS(actual) \
do \
{ \
int32 rcact = (int32)(actual); \
UtAssert_True(rcact < CFE_SUCCESS, "%s == (%ld) ", #actual, (long)rcact); \
} while (0)

/* Log calls to void functions */
#define UtAssert_VOIDCALL(func) (func, UtAssert(true, #func, __FILE__, __LINE__))

void CFE_TestMain(void);
void ESInfoTestSetup(void);
void ESTaskTestSetup(void);
Expand Down
25 changes: 19 additions & 6 deletions modules/cfe_testcase/src/fs_header_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ static osal_id_t setup_file(void)
void TestCreateHeader(void)
{
CFE_FS_Header_t Header;
CFE_FS_Header_t HeaderFail;
const char * TestDescription = "TEST_HEADER";
osal_id_t fd = setup_file();

UtPrintf("Testing: CFE_FS_InitHeader, CFE_FS_WriteHeader");

CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG);
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, NULL), CFE_FS_BAD_ARGUMENT);
UtAssert_NOT_CFE_SUCCESS(CFE_FS_WriteHeader(OS_OBJECT_ID_UNDEFINED, &Header));

UtAssert_VOIDCALL(CFE_FS_InitHeader(NULL, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_VOIDCALL(CFE_FS_InitHeader(&HeaderFail, NULL, CFE_FS_SubType_ES_ERLOG));
UtAssert_VOIDCALL(CFE_FS_InitHeader(&HeaderFail, TestDescription, 256));

OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
}
Expand All @@ -69,14 +77,17 @@ void TestReadHeader(void)

UtPrintf("Testing: CFE_FS_ReadHeader");

CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG);
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(CFE_FS_ReadHeader(&ReadHeader, fd), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(Header.ContentType, ReadHeader.ContentType);
UtAssert_INT32_EQ(Header.SubType, ReadHeader.SubType);
UtAssert_StrCmp(TestDescription, ReadHeader.Description, "ReadHeader.Description = %s", ReadHeader.Description);

UtAssert_INT32_EQ(CFE_FS_ReadHeader(NULL, fd), CFE_FS_BAD_ARGUMENT);
UtAssert_NOT_CFE_SUCCESS(CFE_FS_ReadHeader(&ReadHeader, OS_OBJECT_ID_UNDEFINED));

OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
}
Expand All @@ -86,18 +97,20 @@ void TestTimeStamp(void)
CFE_FS_Header_t Header;
CFE_FS_Header_t ReadHeader;
const char * TestDescription = "TEST_HEADER";
CFE_TIME_SysTime_t NewTimestamp = {10, 10};
CFE_TIME_SysTime_t NewTimestamp = {0xFFFFFFFF, 0xFFFFFFFF};
osal_id_t fd = setup_file();

UtPrintf("Testing: CFE_FS_SetTimestamp");

CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG);
UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, &Header), sizeof(CFE_FS_Header_t));
UtAssert_INT32_EQ(CFE_FS_SetTimestamp(fd, NewTimestamp), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_FS_ReadHeader(&ReadHeader, fd), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(10, ReadHeader.TimeSeconds);
UtAssert_INT32_EQ(10, ReadHeader.TimeSubSeconds);
UtAssert_UINT32_EQ(0xFFFFFFFF, ReadHeader.TimeSeconds);
UtAssert_UINT32_EQ(0xFFFFFFFF, ReadHeader.TimeSubSeconds);

UtAssert_NOT_CFE_SUCCESS(CFE_FS_SetTimestamp(OS_OBJECT_ID_UNDEFINED, NewTimestamp));

OS_close(fd);
OS_remove(OS_TEST_HEADER_FILENAME);
Expand Down

0 comments on commit fb697ef

Please sign in to comment.