Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random UT failures on PosixFile #2862

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rlcheng do we have a test that proves that preallocate errors on a "0" size argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont have one. Currently the SeekInvalidSize test randomly picks using the range original_file_state.position + 1, std::numeric+_limits. Seems to be always a positive non zero value that gets multiplied by -1. We can change the range to: 0, std::numeric_limits.

This should guarantee in a randomized test we can get a 0 or negative value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's track as a separate issue. Rather than randomizing, we should just add a specific test to the interface tests.

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
Loading