Skip to content

Commit

Permalink
Fix #1867, Add FS API test cases
Browse files Browse the repository at this point in the history
Adds FS functional test cases to cover all missing items that
were identified as part of the scrub in issue #1724.

Where a specific condition is not testable because it requires
a failure of another subsystem, it is marked as `covtest` to
indicate it is only verifiable in coverage test environment.
  • Loading branch information
jphickey committed Aug 23, 2021
1 parent 5e41330 commit 19e5f2f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
50 changes: 43 additions & 7 deletions modules/cfe_testcase/src/fs_util_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,35 @@ void TestInputFile(void)
CFE_FS_INVALID_PATH);
UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, sizeof(OutNameBuf), 0, NULL, Path, Ext),
CFE_FS_INVALID_PATH);

/* A short output buffer that is too small to fit the result */
UtAssert_INT32_EQ(CFE_FS_ParseInputFileNameEx(OutNameBuf, InNameBuf, 8, sizeof(InNameBuf), Name, Path, Ext),
CFE_FS_FNAME_TOO_LONG);
}

void TestFileName(void)
{
const char Path[] = "/func/FileName.test";
char Path[OS_MAX_PATH_LEN + 4];
char Name[OS_MAX_FILE_NAME];
const char ExpectedName[] = "FileName.test";

UtPrintf("Testing: CFE_FS_ExtractFilenameFromPath");

snprintf(Path, sizeof(Path), "/func/FileName.test");
UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, Name), CFE_SUCCESS);
UtAssert_StrCmp(Name, ExpectedName, "Extract Filename: %s", Name);

UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(NULL, Name), CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, NULL), CFE_FS_BAD_ARGUMENT);

memset(Path, 'x', sizeof(Path) - 1);
Path[sizeof(Path) - 1] = 0;
Path[0] = '/';
UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, Name), CFE_FS_FNAME_TOO_LONG);

Path[0] = 'x';
Path[OS_MAX_PATH_LEN - 1] = 0;
UtAssert_INT32_EQ(CFE_FS_ExtractFilenameFromPath(Path, Name), CFE_FS_INVALID_PATH);
}

/* FT helper stub compatible with background file write DataGetter */
Expand All @@ -119,32 +133,54 @@ bool FS_DataGetter(void *Meta, uint32 RecordNum, void **Buffer, size_t *BufSize)
void FS_OnEvent(void *Meta, CFE_FS_FileWriteEvent_t Event, int32 Status, uint32 RecordNum, size_t BlockSize,
size_t Position)
{
OS_TaskDelay(100);
}

void TestFileDump(void)
{
int32 count;
int32 MaxWait = 20;

memset(&CFE_FT_Global.FuncTestState, 0, sizeof(CFE_FT_Global.FuncTestState));
CFE_FT_Global.FuncTestState.FileSubType = 2;
CFE_FT_Global.FuncTestState.GetData = FS_DataGetter;
CFE_FT_Global.FuncTestState.OnEvent = FS_OnEvent;
strncpy(CFE_FT_Global.FuncTestState.FileName, "/ram/FT.bin", sizeof(CFE_FT_Global.FuncTestState.FileName));
strncpy(CFE_FT_Global.FuncTestState.Description, "FT", sizeof(CFE_FT_Global.FuncTestState.Description));
int count = 0;
int MaxWait = 20;

UtPrintf("Testing: CFE_FS_BackgroundFileDumpRequest, CFE_FS_BackgroundFileDumpIsPending");

UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState), false);

/* With an empty "FileName" field, it should fail path validation */
CFE_FT_Global.FuncTestState.GetData = FS_DataGetter;
CFE_FT_Global.FuncTestState.OnEvent = FS_OnEvent;
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_FS_INVALID_PATH);
strncpy(CFE_FT_Global.FuncTestState.FileName, "/ram/FT.bin", sizeof(CFE_FT_Global.FuncTestState.FileName));

/* With an empty "GetData" field, it should fail validation */
CFE_FT_Global.FuncTestState.GetData = NULL;
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_FS_BAD_ARGUMENT);
CFE_FT_Global.FuncTestState.GetData = FS_DataGetter;

/* With an empty "OnEvent" field, it should fail validation */
CFE_FT_Global.FuncTestState.OnEvent = NULL;
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_FS_BAD_ARGUMENT);
CFE_FT_Global.FuncTestState.OnEvent = FS_OnEvent;

/* This should work */
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_SUCCESS);

/* Duplicate request should get rejected */
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState),
CFE_STATUS_REQUEST_ALREADY_PENDING);

/* Wait for background task to complete */
count = 0;
while (CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState) && count < MaxWait)
{
OS_TaskDelay(100);
count++;
}

UtAssert_True(count < MaxWait, "count (%i) < MaxWait (%i)", count, MaxWait);
UtAssert_INT32_LT(count, MaxWait);

UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(NULL), CFE_FS_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(NULL), false);
Expand Down
2 changes: 1 addition & 1 deletion modules/core_api/fsw/inc/cfe_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ CFE_Status_t CFE_FS_WriteHeader(osal_id_t FileDes, CFE_FS_Header_t *Hdr);
** to be put into the file's Standard cFE File Header.
**
** \return Execution status, see \ref CFEReturnCodes, or OSAL status
** \retval #CFE_STATUS_EXTERNAL_RESOURCE_FAIL \copybrief CFE_STATUS_EXTERNAL_RESOURCE_FAIL
** \retval #CFE_STATUS_EXTERNAL_RESOURCE_FAIL \covtest \copybrief CFE_STATUS_EXTERNAL_RESOURCE_FAIL
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
**
** \note This function invokes OSAL API routines and the current implementation may return
Expand Down

0 comments on commit 19e5f2f

Please sign in to comment.