Skip to content

Commit

Permalink
Fix Random UT Failure: PosixFile (nasa#2835)
Browse files Browse the repository at this point in the history
 * Fix preallocate test from picking 0 for length, which causes
   unintentional error in preallocate cmd.
 * Fix seek() in SyntheticFileSystem and assert_file_seek() to allow
   for offset being 0.
  • Loading branch information
rlcheng committed Sep 17, 2024
1 parent 2e39bf6 commit 7d0bb43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Os/test/ut/file/FileRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void Os::Test::File::Tester::assert_file_seek(const FwSignedSizeType original_po
ASSERT_EQ(this->m_shadow.position(shadow_position), Os::File::Status::OP_OK);

const FwSignedSizeType expected_offset = (absolute) ? seek_desired : (original_position + seek_desired);
if (expected_offset > 0) {
if (expected_offset >= 0) {
ASSERT_EQ(new_position, expected_offset);
} else {
ASSERT_EQ(new_position, original_position);
Expand Down Expand Up @@ -497,7 +497,7 @@ void Os::Test::File::Tester::Preallocate::action(
state.assert_file_consistent();
FileState original_file_state = state.current_file_state();
FwSignedSizeType offset = static_cast<FwSignedSizeType>(STest::Pick::lowerUpper(0, FILE_DATA_MAXIMUM));
FwSignedSizeType length = static_cast<FwSignedSizeType>(STest::Pick::lowerUpper(0, FILE_DATA_MAXIMUM));
FwSignedSizeType length = static_cast<FwSignedSizeType>(STest::Pick::lowerUpper(1, FILE_DATA_MAXIMUM));
Os::File::Status status = state.m_file.preallocate(offset, length);
ASSERT_EQ(Os::File::Status::OP_OK, status);
state.shadow_preallocate(offset, length);
Expand Down
2 changes: 1 addition & 1 deletion Os/test/ut/file/SyntheticFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Os::File::Status SyntheticFile::seek(const FwSignedSizeType offset, const SeekTy
status = Os::File::Status::NOT_OPENED;
} else {
FwSignedSizeType new_offset = (absolute) ? offset : (offset + this->m_data->m_pointer);
if (new_offset > 0) {
if (new_offset >= 0) {
this->m_data->m_pointer = new_offset;
} else {
status = Os::File::Status::INVALID_ARGUMENT;
Expand Down

0 comments on commit 7d0bb43

Please sign in to comment.