Skip to content

Commit

Permalink
Fix random UT failures on PosixFile (nasa#2862)
Browse files Browse the repository at this point in the history
* Fix Random UT Failure: PosixFile (nasa#2835)
 * Fix UT failing FinalizeCrc test when crc calculation miss match.
   Miss match due to file crc and shadow being out of sync when
   both are not reinialized at the same time.

 * Update File::open in File.ccp to match shadow operation in
   FileRules.cpp to only reset crc when status is OP_OK.

 * Update FileRules.cpp to print out rule name during test.

 * Remove changing file mode in shadow_open() in FileRules.cpp to
   OPEN_NO_MODE when status is not OP_OK.

* Fix Random UT Failure: PosixFile (nasa#2835)
 * Fix additional issue where randomly generate file name may be
   too large for POSIX.

* Fix Random UT Failure: PosixFile (nasa#2835)
 * 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 authored Sep 18, 2024
1 parent 6a921a1 commit 3f8830b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Os/Posix/test/ut/PosixFileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ bool check_permissions(const char* path, int permission) {
//!
std::shared_ptr<std::string> get_test_filename(bool random) {
const char* filename = TEST_FILE;
char full_buffer[PATH_MAX];
char buffer[PATH_MAX - sizeof(BASE_PATH)];
char full_buffer[_POSIX_PATH_MAX];
char buffer[_POSIX_PATH_MAX - sizeof(BASE_PATH)];
// When random, select random characters
if (random) {
filename = buffer;
Expand All @@ -47,7 +47,7 @@ std::shared_ptr<std::string> get_test_filename(bool random) {
}
buffer[i] = 0; // Terminate random string
}
(void) snprintf(full_buffer, PATH_MAX, "%s/%s", BASE_PATH, filename);
(void) snprintf(full_buffer, _POSIX_PATH_MAX, "%s/%s", BASE_PATH, filename);
// Create a shared pointer wrapping our filename buffer
std::shared_ptr<std::string> pointer(new std::string(full_buffer), std::default_delete<std::string>());
return pointer;
Expand Down
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 3f8830b

Please sign in to comment.