Skip to content

Commit

Permalink
Fix nasa#1730, Explain FS Header offset & add offset functional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Jul 29, 2021
1 parent 33a4f19 commit 1a6e828
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/cfe_testcase/src/fs_header_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void TestCreateHeader(void)

cFE_FTAssert_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(OS_lseek(fd, 0, OS_SEEK_CUR), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(CFE_FS_WriteHeader(fd, NULL), CFE_FS_BAD_ARGUMENT);
cFE_FTAssert_NOT_CFE_SUCCESS(CFE_FS_WriteHeader(OS_OBJECT_ID_UNDEFINED, &Header));
Expand All @@ -80,6 +81,7 @@ void TestReadHeader(void)
cFE_FTAssert_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(OS_lseek(fd, 0, OS_SEEK_CUR), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(Header.ContentType, ReadHeader.ContentType);
UtAssert_INT32_EQ(Header.SubType, ReadHeader.SubType);
Expand All @@ -105,6 +107,8 @@ void TestTimeStamp(void)
cFE_FTAssert_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(OS_lseek(fd, sizeof(Header.Description), OS_SEEK_CUR), sizeof(CFE_FS_Header_t));

UtAssert_INT32_EQ(CFE_FS_ReadHeader(&ReadHeader, fd), sizeof(CFE_FS_Header_t));

UtAssert_UINT32_EQ(0xFFFFFFFF, ReadHeader.TimeSeconds);
Expand Down
6 changes: 6 additions & 0 deletions modules/core_api/fsw/inc/cfe_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
** \par Assumptions, External Events, and Notes:
** -# The File has already been successfully opened using #OS_OpenCreate and
** the caller has a legitimate File Descriptor.
** -# File offset behavior: Agnostic on entry since it will move the offset to the start of the file,
** on success the offset will be at the end of the header, undefined offset behavior for error cases.
**
** \param[in, out] Hdr Pointer to a variable of type #CFE_FS_Header_t that will be
** filled with the contents of the Standard cFE File Header. *Hdr is the contents of the
Expand Down Expand Up @@ -116,6 +118,8 @@ void CFE_FS_InitHeader(CFE_FS_Header_t *Hdr, const char *Description, uint32 Sub
** the caller has a legitimate File Descriptor.
** -# The \c SubType field has been filled appropriately by the Application.
** -# The \c Description field has been filled appropriately by the Application.
** -# File offset behavior: Agnostic on entry since it will move the offset to the start of the file,
** on success the offset will be at the end of the header, undefined offset behavior for error cases.
**
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_OpenCreate
** that is associated with the file whose header is to be read.
Expand Down Expand Up @@ -144,6 +148,8 @@ CFE_Status_t CFE_FS_WriteHeader(osal_id_t FileDes, CFE_FS_Header_t *Hdr);
** -# The File has already been successfully opened using #OS_OpenCreate and
** the caller has a legitimate File Descriptor.
** -# The \c NewTimestamp field has been filled appropriately by the Application.
** -# File offset behavior: Agnostic on entry since it will move the offset,
** on success the offset will be at the end of the time stamp, undefined offset behavior for error cases.
**
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_OpenCreate
** that is associated with the file whose header is to be read.
Expand Down

0 comments on commit 1a6e828

Please sign in to comment.